This Week’s Program: Oct 30 - Nov 3
Hello ghouls and fiends! I know it’s November now, but I’m still in Halloween mode and I’m not ready to let it go just yet. You may have noticed that I did not send my Tinyletter last week. Or you may have not because you were very busy planning your costume and I’m sure you looked marvelous.
I’ve spent a whole ton of time writing documentation!
This is how you write some code with this library, in the literal programming style:
#lang racket/base (require gstreamer) (unless (gst-initialized?) (if (gst-initialize) (displayln (gst-version-string)) (error "Could not load GStreamer")))
This loads the
gstreamer module, initializes GStreamer if it hasn’t
already been loaded, and prints the version of GStreamer, or raises an
error if GStreamer can’t initialize. Can you find the documentation
(define my-pipeline (pipeline%-compose "my-pipeline" (element-factory%-make "avfvideosrc") (element-factory%-make "osxvideosink")))
This creates a new GStreamer pipeline called
composing, or chaining together elements. Two in this case: an
avfvideosrc (my Mac’s camera) and an osxvideosink (a little
preview window). Find the documentation
(send my-pipeline set-state 'playing)
This sets the pipeline’s state to playing, which starts up the pipeline. I see a little window with a view of myself through my camera!
(send my-pipeline set-state 'null)
This sets the pipeline state to null, shutting down the pipeline and
closing the camera and preview window. The
pipeline% class is a
bin%, itself a subclass of
element%; that’s where
you’ll find the documentation for the
Let’s get some more information about the avfvideosrc element factory.
(let* ([avfvideosrc (element-factory%-find "avfvideosrc")] [metadata (send avfvideosrc get-metadata)]) (displayln (hash-ref metadata 'description)))
This calls the
get-metadata method on the
element-factory% instance, pulls out the value for the description
key, and displays it. It says:
Reads frames from an iOS AVFoundation device
Cool. We’re working with GStreamer, a robust C media framework, using conventional, idiomatic Racket.
I need to write a bit more documentation to describe basic usage such as this. With this solid foundation in place I can get twisted in my implementation of Overscan.
I love it when I get to say my favorite quote, “I love it when a plan comes together”.