From ca7db7f85ab7f19f91e1f63907c275fecdc39349 Mon Sep 17 00:00:00 2001 From: Leif Andersen Date: Mon, 12 Jun 2017 14:37:38 -0400 Subject: [PATCH] Add bufferskink. --- video/private/ffmpeg-stream.rkt | 15 ++++-------- video/private/ffmpeg.rkt | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/video/private/ffmpeg-stream.rkt b/video/private/ffmpeg-stream.rkt index d17e532..18766b9 100644 --- a/video/private/ffmpeg-stream.rkt +++ b/video/private/ffmpeg-stream.rkt @@ -345,19 +345,14 @@ ['loop (packetqueue-put callback-data packet)] ['close (packetqueue-put callback-data eof)])])) -(define ((dequeue-stream passthrough-proc) mode obj) +(define (dequeue-stream mode obj) (match obj [(struct* codec-obj ([callback-data callback-data])) (match mode - ['init (passthrough-proc mode obj #f)] - ['open (passthrough-proc mode obj #f)] - ['write (define packet (packetqueue-get callback-data)) - (cond - [(eof-object? packet) #f] - [else - (passthrough-proc mode obj packet) - #t])] - ['close (passthrough-proc mode obj #f)])])) + ['init (void)] + ['open (void)] + ['write (packetqueue-get callback-data)] + ['close (void)])])) (define (link infile outfile) diff --git a/video/private/ffmpeg.rkt b/video/private/ffmpeg.rkt index afde573..90b90b1 100644 --- a/video/private/ffmpeg.rkt +++ b/video/private/ffmpeg.rkt @@ -164,6 +164,7 @@ pred interlaced-me = ,(arithmetic-shift 1 29) closed-gop = ,(arithmetic-shift 1 31)))) + (define _avcodec-flags2 (_bitmask `(fast no-ouput = 4 @@ -174,12 +175,14 @@ show-all = ,(arithmetic-shift 1 22) export-mvs = ,(arithmetic-shift 1 28) skip-manual))) + (define _avio-flags (_bitmask `(read = 1 write = 2 read-write = 3 nonblock = 8 direct = #x8000))) + (define _av-dictionary-flags (_bitmask `(match-case ignore-suffix @@ -187,6 +190,7 @@ dont-strdup-val dont-overwrite append))) + (define _avfilter-flags (_bitmask `(dynamic-inputs dynamic-outputs @@ -195,10 +199,17 @@ support-timeline-internal support-timeline = ,(bitwise-ior (arithmetic-shift 1 16) (arithmetic-shift 1 17))))) + (define _avfilter-command-flags (_bitmask `(one fast))) +(define _av-buffer-sink-flags + (_bitmask '(peek + no-request))) + +;; =================================================================================================== + (define _avcodec-id (_enum '(none ;; Video @@ -508,6 +519,7 @@ bgr444be ya8 ))) ;; XXX And more! :) +(define-cpointer-type _avpixel-format-pointer) (define _avcolor-transfer-characteristic _fixint) (define _avcolor-space _fixint) @@ -1184,6 +1196,22 @@ [priv _pointer] [commandqueue _avfilter-command-pointer])) +(define-cstruct _avfilter-in-out + ([name _string] + [filter-ctx _avfilter-context-pointer] + [pad-idx _int] + [next _avfilter-in-out-pointer])) + +(define-cstruct _av-buffersink-params + ([pixel-fmts _avpixel-format-pointer/null])) + +(define-cstruct _av-buffersink-aparams + ([sample-fmts _avsample-format-pointer/null] + [channel-layout _pointer] + [channel-counts _pointer] + [all-channel-counts _int] + [sample-rates _int])) + ;; =================================================================================================== (define-avformat av-register-all (_fun -> _void)) @@ -1465,6 +1493,7 @@ (define-avutil av-get-channel-layout-nb-channels (_fun _av-channel-layout -> _int)) (define-avutil av-compare-ts (_fun _int64 _avrational _int64 _avrational -> _int)) +(define-avutil av-strdup (_fun _string -> _pointer)) (define-swscale sws-getContext (_fun _int _int @@ -1511,3 +1540,16 @@ -> (cond [(>= ret 0) out] [else (error 'graph-create-filter (convert-err ret))]))) +(define-avfilter avfilter-get-by-name (_fun _string -> [ret : _avfilter-pointer/null] + -> (or ret (error 'avfilter "Invalid Filter Name")))) +(define (av-buffersink-get-frame ptr [out #f]) + (define-avfilter av-buffersink-get-frame (_fun _avfilter-context-pointer [out : _av-frame-pointer] + -> [ret : _int] + -> (cond + [(>= ret 0) out] + [else (error 'buffersink-get-frame + (convert-err ret))]))) + (define o (or out (av-frame-alloc))) + (av-buffersink-get-frame ptr o)) +(define-avfilter av-buffersink-params-alloc (_fun -> _av-buffersink-params-pointer)) +(define-avfilter av-buffersink-aparams-alloc (_fun -> _av-buffersink-aparams-pointer))