Skip to content

Instantly share code, notes, and snippets.

@ganioc
Last active April 20, 2023 07:34
Show Gist options
  • Save ganioc/532144190297e07d3d94dbbe7329478a to your computer and use it in GitHub Desktop.
Save ganioc/532144190297e07d3d94dbbe7329478a to your computer and use it in GitHub Desktop.
Analyze the Streamer demo plugin source code

Intro to H.264 parsing, to insert SEI message using GStreamer-1.0

I found it's easy to write your own plugin to parse the H.264 stream, locate the NAL unit, and insert SEI message in a dynamic way. Searching the google, and viewing Stackoverflow answers, don't give much clues. Even someone is selling a plugin for about 3000 dollars on the net. Oh Jesus!

In fact, the best way is to read the GStreamer official document about writing a basic plugin. And figure out your own one. It's a mystery why there are so many books on FFMPEG while so few on GStreamer. On Amazon, no book execept one user guide of GStreamer , which seems is exactly a copy of official docs. Though the official document is execellent, there is no reason there shouldn't exist a book, for dummy, receipies , head in ... series , anyway.

classes related

There are 2 classes in a plugin. One is "object class" , the other is "element class". Object Class is the base class of all plugins. Element Class is the instance class of the plugin.

class initilization

_class_init()

GObject virtual method implementations. 2 classes initialized: gobject_class, gstelement_class.

gobject_class initialization,

// method to write property gobject_class ->set_property()

// method to read property gobject_class ->get_property()

gobject_class add parameter spec,

gstelement_class initilization,

gstelement_class add sink pad template

gstelement_class add src pad template

instance initilization

_element_init(Gstmyfilter *filter)

filter is the plugin instance. srcpad, sinkpad, silent is defined in the gstmyfilter.h header file, Gstmyfilter struct.

filter->sinkpad initialization from the sink_factory static template; -> set event callback function; -> set chain callback function -> set proxy to capabilities function

add sink pad to filter's element

filter->srcpad initialization from the src_factory static tempate -> set proxy to src capabilites function

add srcpad to filter's element

filter->silent , initialize parameter silent

plugin initialization

_init(GstPlugin *myfilter)

Entry point to initialize the plug-in,

register the element factories and other features, (I dont see any thing here ...)

sink pad event callback function

Handle event from upstream src pad. GST_EVENT_CAPS ...

gst_pad_event_default(pad, parent, event), forward to the parent to handle the event,

sink pad chain callback function

gst_myfilter_chain(GstPad *pad, GstObject *parent, GstBuffer *buf)

The buf is from upstream src pad. In H.264 byte-stream case, the sink pad will receive NAL unit from the upstream src pad. This will ease our work of processing the H.264 stream.

gst_pad_push(filter->srcpad, mbuf) will send the data in mbuf as a whole to the srcpad, and finish the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment