Skip to content

Commit

Permalink
create bin% class and add factory methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Sep 29, 2017
1 parent 32e33e4 commit 87ba946
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 29 deletions.
46 changes: 46 additions & 0 deletions gstreamer/bin.rkt
@@ -0,0 +1,46 @@
#lang racket/base

(require (except-in ffi/unsafe/introspection
send get-field set-field! field-bound? is-a? is-a?/c)
racket/class
racket/contract
"gst.rkt"
"element.rkt")

(provide (contract-out [bin%
(class/c
[add
(->m (is-a?/c element%) boolean?)]
[remove
(->m (is-a?/c element%) boolean?)]
[get-by-name
(->m string? (or/c (is-a?/c element%) false/c))]
[add-many
(->m (is-a?/c element%) (is-a?/c element%) ... boolean?)]
[find-unlinked-pad
(->m (gi-enum-value/c pad-direction) (or/c (is-a?/c pad%) false/c))]
[sync-children-states
(->m boolean?)])]))

(define bin-mixin
(make-gobject-delegate add
remove
get-by-name
find-unlinked-pad
sync-children-states))

(define bin%
(class (bin-mixin element%)
(super-new)
(inherit-field pointer)
(define/override (get-by-name name)
(let ([el (super get-by-name name)])
(and el
(new element% [pointer el]))))
(define/public (add-many el_1 . els)
(for/and ([el (list* el_1 els)])
(send this add el)))
(define/override (find-unlinked-pad direction)
(let ([pad (super find-unlinked-pad direction)])
(and pad
(new pad% [pointer pad]))))))
64 changes: 35 additions & 29 deletions gstreamer/main.rkt
Expand Up @@ -7,17 +7,16 @@
racket/class
racket/contract
"gst.rkt"
"element.rkt")
"element.rkt"
"bin.rkt")

(provide (all-from-out "gst.rkt"
"element.rkt")
bin-add-many
"element.rkt"
"bin.rkt")
seconds
element-link-many
_input-selector-sync-mode
_video-test-src-pattern
_audio-test-src-wave
gst-compose
(contract-out [element-factory%-find
(-> string? (or/c false/c
(is-a?/c element-factory%)))]
Expand All @@ -33,7 +32,15 @@
[ghost-pad%-new-no-target
(-> (or/c string? false/c) (gi-enum-value/c pad-direction)
(or/c (is-a?/c ghost-pad%)
false/c))]))
false/c))]
[bin%-new
(->* ()
((or/c string? false/c))
(is-a?/c bin%))]
[bin%-compose
(-> (or/c string? false/c)
(is-a?/c element%) (is-a?/c element%) ...
(or/c (is-a?/c bin%) false/c))]))

(define gst-element-factory (gst 'ElementFactory))

Expand All @@ -59,9 +66,29 @@
(and ghost
(new ghost-pad% [pointer ghost]))))

(define pipeline% (gst 'Pipeline))
(define gst-bin (gst 'Bin))

(define (bin%-new [name #f])
(new bin% [pointer (gst-bin 'new name)]))

(define (bin%-compose name el . els)
(let* ([bin (bin%-new name)]
[sink el]
[source (if (null? els) el (last els))])
(and (send/apply bin add-many el els)
(when (pair? els)
(send/apply el link-many els))
(let ([sink-pad (send sink get-static-pad "sink")])
(if sink-pad
(send bin add-pad (ghost-pad%-new "sink" sink-pad))
#t))
(let ([source-pad (send source get-static-pad "src")])
(if source-pad
(send bin add-pad (ghost-pad%-new "src" source-pad))
#t))
bin)))

(define bin% (gst 'Bin))
(define pipeline% (gst 'Pipeline))

(define event% (gst 'Event))

Expand All @@ -70,29 +97,8 @@
(define (seconds num)
(* num second))

(define (bin-add-many bin . elements)
(for/and ([element elements])
(send bin add element)))

(define _input-selector-sync-mode (_enum '(active-segment clock)))

(define (gst-compose name . elements)
(let* ([bin (bin% 'new name)]
[sink (first elements)]
[source (last elements)])
(and (> (length elements) 0)
(apply bin-add-many bin elements)
(apply element-link-many elements)
(let ([sink-pad (send sink get-static-pad "sink")])
(if sink-pad
(send bin add-pad (ghost-pad% 'new "sink" sink-pad))
#t))
(let ([source-pad (send source get-static-pad "src")])
(if source-pad
(send bin add-pad (ghost-pad% 'new "src" source-pad))
#t))
bin)))

(define _video-test-src-pattern (_enum '(smpte
snow black white red green blue
checkers1 checkers2 checkers4 checkers8
Expand Down

0 comments on commit 87ba946

Please sign in to comment.