Skip to content

Commit

Permalink
restructure to nimble package; wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mashingan committed Jan 6, 2020
1 parent e790b50 commit ec3e3fc
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 76 deletions.
1 change: 1 addition & 0 deletions config.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
switch("passC", "$parentDir/cinclude")
1 change: 1 addition & 0 deletions examples/config.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
switch("path", "$projectDir/../src")
7 changes: 4 additions & 3 deletions examples/metadata.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import libavformat/avformat
import libavutil/[dict, log]
#import libavformat/avformat
#import libavutil/[dict, log]
import ffmpeg
import os, strformat

proc main =
Expand Down Expand Up @@ -27,4 +28,4 @@ proc main =

avformat_close_input(addr fmt)

main()
main()
3 changes: 2 additions & 1 deletion src/ffmpeg.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import ffmpeg/utiltypes
import ffmpeg/libavcodec/[avcodec, ac3_parser, adts_parser, avdct,
avfft, d3d11va, dirac, dv_profile, dxva2,
jni, mediacodec, qsv, vaapi, vdpau, version,
#jni, mediacodec, qsv, vaapi, vdpau, version,
jni, mediacodec, vaapi, vdpau, version,
videotoolbox, vorbis_parser, xvmc]

import ffmpeg/libavdevice/avdevice
Expand Down
11 changes: 9 additions & 2 deletions src/ffmpeg/libavcodec/ac3_parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,12 @@
## Extract the bitstream ID and the frame size from AC-3 data.
##

proc av_ac3_parse_header*(buf: ptr uint8_t; size: csize; bitstream_id: ptr uint8_t;
frame_size: ptr uint16_t): cint
when defined(windows):
{.push importc, dynlib: "avcodec(|-55|-56|-57|-58|-59).dll".}
elif defined(macosx):
{.push importc, dynlib: "avcodec(|.55|.56|.57|.58|.59).dylib".}
else:avcodec
{.push importc, dynlib: "avcodec.so(|.55|.56|.57|.58|.59)".}

proc av_ac3_parse_header*(buf: ptr uint8; size: csize; bitstream_id: ptr uint8;
frame_size: ptr uint16): cint
9 changes: 8 additions & 1 deletion src/ffmpeg/libavcodec/adts_parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ const
## @return Returns 0 on success, error code on failure.
##

proc av_adts_header_parse*(buf: ptr uint8_t; samples: ptr uint32_t; frames: ptr uint8_t): cint
when defined(windows):
{.push importc, dynlib: "avcodec(|-55|-56|-57|-58|-59).dll".}
elif defined(macosx):
{.push importc, dynlib: "avcodec(|.55|.56|.57|.58|.59).dylib".}
else:avcodec
{.push importc, dynlib: "avcodec.so(|.55|.56|.57|.58|.59)".}

proc av_adts_header_parse*(buf: ptr uint8; samples: ptr uint32; frames: ptr uint8): cint
28 changes: 18 additions & 10 deletions src/ffmpeg/libavcodec/avdct.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@
##

import
libavutil/opt
../utiltypes

## *
## AVDCT context.
## @note function pointers can be NULL if the specific features have been
## disabled at build time.
##

{.pragma: avdct, importc, header:"<libavcodec/avdct.h>".}

type
AVDCT* {.bycopy.} = object
AVDCT* {.avdct.} = object
av_class*: ptr AVClass
idct*: proc (block: ptr int16_t) ## *
## IDCT input permutation.
idct*: proc (`block`: ptr int16) ## IDCT input permutation.
## Several optimized IDCTs need a permutated input (relative to the
## normal order of the reference IDCT).
## This permutation must be performed before the idct_put/add.
Expand All @@ -42,9 +43,9 @@ type
## - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
## -> simple_idct_mmx -> ...)
##
## align 16
idct_permutation*: array[64, uint8_t]
fdct*: proc (block: ptr int16_t) ## *
## align 16
idct_permutation*: array[64, uint8]
fdct*: proc (`block`: ptr int16) ## *
## DCT algorithm.
## must use AVOptions to set this field.
##
Expand All @@ -54,9 +55,9 @@ type
## must use AVOptions to set this field.
##
idct_algo*: cint
get_pixels*: proc (block: ptr int16_t; ## align 16
pixels: ptr uint8_t; ## align 8
line_size: ptrdiff_t)
get_pixels*: proc (`block`: ptr int16; ## align 16
pixels: ptr uint8; ## align 8
line_size: csize)
bits_per_sample*: cint


Expand All @@ -68,6 +69,13 @@ type
## To free it use av_free()
##

when defined(windows):
{.push importc, dynlib: "avcodec(|-55|-56|-57|-58|-59).dll".}
elif defined(macosx):
{.push importc, dynlib: "avcodec(|.55|.56|.57|.58|.59).dylib".}
else:avcodec
{.push importc, dynlib: "avcodec.so(|.55|.56|.57|.58|.59)".}

proc avcodec_dct_alloc*(): ptr AVDCT
proc avcodec_dct_init*(a1: ptr AVDCT): cint
proc avcodec_dct_get_class*(): ptr AVClass
40 changes: 26 additions & 14 deletions src/ffmpeg/libavcodec/avfft.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,36 @@
## @{
##

{.pragma: avfft, importc, header:"<libavcodec/avfft.h>".}

type
FFTContext* {.avfft.} = object
FFTSample* = cfloat
FFTComplex* {.bycopy.} = object
FFTComplex* {.avfft.} = object
re*: FFTSample
im*: FFTSample

## Real Discrete Fourier Transform

type
RDFTContext* {.avfft.} = object
RDFTransformType* = enum
DFT_R2C, IDFT_C2R, IDFT_R2C, DFT_C2R

## Discrete Cosine Transform

type
DCTContext* {.avfft.} = object
DCTTransformType* = enum
DCT_II = 0, DCT_III, DCT_I, DST_I


when defined(windows):
{.push importc, dynlib: "avcodec(|-55|-56|-57|-58|-59).dll".}
elif defined(macosx):
{.push importc, dynlib: "avcodec(|.55|.56|.57|.58|.59).dylib".}
else:avcodec
{.push importc, dynlib: "avcodec.so(|.55|.56|.57|.58|.59)".}

## *
## Set up a complex FFT.
Expand All @@ -59,12 +83,6 @@ proc av_imdct_calc*(s: ptr FFTContext; output: ptr FFTSample; input: ptr FFTSamp
proc av_imdct_half*(s: ptr FFTContext; output: ptr FFTSample; input: ptr FFTSample)
proc av_mdct_calc*(s: ptr FFTContext; output: ptr FFTSample; input: ptr FFTSample)
proc av_mdct_end*(s: ptr FFTContext)
## Real Discrete Fourier Transform

type
RDFTransformType* = enum
DFT_R2C, IDFT_C2R, IDFT_R2C, DFT_C2R



## *
Expand All @@ -76,12 +94,6 @@ type
proc av_rdft_init*(nbits: cint; trans: RDFTransformType): ptr RDFTContext
proc av_rdft_calc*(s: ptr RDFTContext; data: ptr FFTSample)
proc av_rdft_end*(s: ptr RDFTContext)
## Discrete Cosine Transform

type
DCTTransformType* = enum
DCT_II = 0, DCT_III, DCT_I, DST_I


## *
## Set up DCT.
Expand All @@ -94,7 +106,7 @@ type
## @note the first element of the input of DST-I is ignored
##

proc av_dct_init*(nbits: cint; type: DCTTransformType): ptr DCTContext
proc av_dct_init*(nbits: cint; `type`: DCTTransformType): ptr DCTContext
proc av_dct_calc*(s: ptr DCTContext; data: ptr FFTSample)
proc av_dct_end*(s: ptr DCTContext)
## *
Expand Down
17 changes: 14 additions & 3 deletions src/ffmpeg/libavcodec/d3d11va.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
## Public libavcodec D3D11VA header.
##

when not defined(_WIN32_WINNT) or _WIN32_WINNT < 0x00000602:
when defined(windows):
import winlean
{.pragma: d3d11, importc, header: "<d3d11.h>".}

when not defined(WIN32_WINNT):# or WIN32_WINNT < 0x00000602:
const
_WIN32_WINNT* = 0x00000602
WIN32_WINNT* = 0x00000602
## *
## @defgroup lavc_codec_hwaccel_d3d11va Direct3D11
## @ingroup lavc_codec_hwaccel
Expand All @@ -50,6 +54,12 @@ const
## Use av_d3d11va_alloc_context() exclusively to allocate an AVD3D11VAContext.
##

type
ID3D11VideoContext* {.d3d11.} = object
ID3D11VideoDecoder* {.d3d11.} = object
D3D11_VIDEO_DECODER_CONFIG* {.d3d11.} = object
ID3D11VideoDecoderOutputView* {.d3d11.} = object

type
AVD3D11VAContext* {.bycopy.} = object
decoder*: ptr ID3D11VideoDecoder ## *
Expand All @@ -70,7 +80,7 @@ type
surface*: ptr ptr ID3D11VideoDecoderOutputView ## *
## A bit field configuring the workarounds needed for using the decoder
##
workaround*: uint64_t ## *
workaround*: uint64 ## *
## Private to the FFmpeg AVHWAccel implementation
##
report_id*: cuint ## *
Expand All @@ -86,6 +96,7 @@ type
##

proc av_d3d11va_alloc_context*(): ptr AVD3D11VAContext
{.importc, dynlib: "d3d11.dll".}
## *
## @}
##
40 changes: 24 additions & 16 deletions src/ffmpeg/libavcodec/dirac.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
## @author Jordi Ortiz
##

import
avcodec
#import avcodec
import ../libavutil/rational
import ../libavutil/pixfmt

## *
## The spec limits the number of wavelet decompositions to 4 for both
Expand Down Expand Up @@ -67,26 +68,27 @@ type
DIRAC_PCODE_INTRA_REF_PICT = 0x000000CC, DIRAC_PCODE_PICTURE_HQ = 0x000000E8,
DIRAC_PCODE_MAGIC = 0x42424344

{.pragma: dirac, importc, header: "<libavcodec/dirac.h>".}

type
DiracVersionInfo* {.bycopy.} = object
DiracVersionInfo* {.dirac.} = object
major*: cint
minor*: cint

AVDiracSeqHeader* {.bycopy.} = object
AVDiracSeqHeader* {.dirac.} = object
width*: cuint
height*: cuint
chroma_format*: uint8_t ## /< 0: 444 1: 422 2: 420
interlaced*: uint8_t
top_field_first*: uint8_t
frame_rate_index*: uint8_t ## /< index into dirac_frame_rate[]
aspect_ratio_index*: uint8_t ## /< index into dirac_aspect_ratio[]
clean_width*: uint16_t
clean_height*: uint16_t
clean_left_offset*: uint16_t
clean_right_offset*: uint16_t
pixel_range_index*: uint8_t ## /< index into dirac_pixel_range_presets[]
color_spec_index*: uint8_t ## /< index into dirac_color_spec_presets[]
chroma_format*: uint8 ## /< 0: 444 1: 422 2: 420
interlaced*: uint8
top_field_first*: uint8
frame_rate_index*: uint8 ## /< index into dirac_frame_rate[]
aspect_ratio_index*: uint8 ## /< index into dirac_aspect_ratio[]
clean_width*: uint16
clean_height*: uint16
clean_left_offset*: uint16
clean_right_offset*: uint16
pixel_range_index*: uint8 ## /< index into dirac_pixel_range_presets[]
color_spec_index*: uint8 ## /< index into dirac_color_spec_presets[]
profile*: cint
level*: cint
framerate*: AVRational
Expand All @@ -99,6 +101,12 @@ type
version*: DiracVersionInfo
bit_depth*: cint

when defined(windows):
{.push importc, dynlib: "avcodec(|-55|-56|-57|-58|-59).dll".}
elif defined(macosx):
{.push importc, dynlib: "avcodec(|.55|.56|.57|.58|.59).dylib".}
else:avcodec
{.push importc, dynlib: "avcodec.so(|.55|.56|.57|.58|.59)".}

## *
## Parse a Dirac sequence header.
Expand All @@ -112,5 +120,5 @@ type
## @return 0 on success, a negative AVERROR code on failure
##

proc av_dirac_parse_sequence_header*(dsh: ptr ptr AVDiracSeqHeader; buf: ptr uint8_t;
proc av_dirac_parse_sequence_header*(dsh: ptr ptr AVDiracSeqHeader; buf: ptr uint8;
buf_size: csize; log_ctx: pointer): cint
19 changes: 13 additions & 6 deletions src/ffmpeg/libavcodec/dv_profile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
##

import
libavutil/pixfmt, libavutil/rational, avcodec
import ../libavutil/pixfmt
import ../libavutil/rational

## minimum number of bytes to read from a DV stream in order to
## determine the profile
Expand All @@ -33,7 +33,7 @@ const
##

type
AVDVProfile* {.bycopy.} = object
AVDVProfile* {.importc, header: "<libavformat/dv_profile.>".} = object
dsf*: cint ## value of the dsf in the DV header
video_stype*: cint ## stype for VAUX source pack
frame_size*: cint ## total size of one frame in bytes
Expand All @@ -46,15 +46,22 @@ type
sar*: array[2, AVRational] ## sample aspect ratios for 4:3 and 16:9
pix_fmt*: AVPixelFormat ## picture pixel format
bpm*: cint ## blocks per macroblock
block_sizes*: ptr uint8_t ## AC block sizes, in bits
block_sizes*: ptr uint8 ## AC block sizes, in bits
audio_stride*: cint ## size of audio_shuffle table
audio_min_samples*: array[3, cint] ## min amount of audio samples
## for 48kHz, 44.1kHz and 32kHz
audio_samples_dist*: array[5, cint] ## how many samples are supposed to be
## in each frame in a 5 frames window
audio_shuffle*: array[9, uint8_t] ## PCM shuffling table
audio_shuffle*: array[9, uint8] ## PCM shuffling table


when defined(windows):
{.push importc, dynlib: "avcodec(|-55|-56|-57|-58|-59).dll".}
elif defined(macosx):
{.push importc, dynlib: "avcodec(|.55|.56|.57|.58|.59).dylib".}
else:avcodec
{.push importc, dynlib: "avcodec.so(|.55|.56|.57|.58|.59)".}

## *
## Get a DV profile for the provided compressed frame.
##
Expand All @@ -64,7 +71,7 @@ type
## @return the DV profile for the supplied data or NULL on failure
##

proc av_dv_frame_profile*(sys: ptr AVDVProfile; frame: ptr uint8_t; buf_size: cuint): ptr AVDVProfile
proc av_dv_frame_profile*(sys: ptr AVDVProfile; frame: ptr uint8; buf_size: cuint): ptr AVDVProfile
## *
## Get a DV profile for the provided stream parameters.
##
Expand Down
Loading

0 comments on commit ec3e3fc

Please sign in to comment.