How to parse current capabilities of a pad in a plugin?

Tim Müller tim at centricular.com
Thu Jan 28 02:43:39 PST 2016


On Thu, 2016-01-28 at 01:52 -0800, ssshukla26 wrote:

Hi,

> I want to get capabilities set on my sink pad in a pipe !
> 
> Let suppose my pipe is as follows
> 
> gst-launch-1.0 -e filesrc location=rawvideo_yuv420.yuv
> blocksize=460800 !
> *video/x-raw,format=I420,width=640,height=480,framerate=30/1* !
> myh264encoder silent=true ! decodebin ! autovideosink 
> 
> My gstreamer plugin is *myh264encoder*. 
> 
> Now how can I get width as 640 and height as 480 and framerate as 30
> from
> the caps "*video/x-
> raw,format=I420,width=640,height=480,framerate=30/1*"
> inside my gstreamer plugin's init function ?

You can't get this information in your plugin's init function, because
when you are in your init function, the data flow hasn't started yet,
so the caps are not known yet.

Your element will receive a CAPS event on its sink pad when the caps
are known. If you use the GstVideoEncoder base class (as you should)
you can override the ::set_format() vfunc to get the input caps.

> 3) I used *gst_pad_set_event_function* technique, but am not sure
> that am
> implementing it correctly
> 
> - /*Under init function of my plugin I do as below*/
> 
> filter->sinkpad = gst_pad_new_from_static_template (&sink_factory,
> "sink");
> gst_pad_set_event_function
> (filter->sinkpad,GST_DEBUG_FUNCPTR(g*st_myencoder_sink_event*));
> gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
> 
> - /*Implementing the sink event function as below*/
> 
> static gboolean *gst_myencoder_sink_event* (GstPad * pad, GstObject *
> parent, GstEvent * event)
> {
>     gboolean ret;
>     GstMyEncoder *filter = GST_MYENCODER (parent);
> 
>     switch (GST_EVENT_TYPE (event)) {
>         case GST_EVENT_CAPS:
>             {
>                 GstCaps * caps;
> 
>                 gst_event_parse_caps (event, &caps);
>                 /* do something with the caps */
>                 GstStructure *structure = gst_caps_get_structure
> (caps, 0);
>                 gchar *str = gst_value_serialize
> (gst_structure_get_value(structure,"width"));
>                 g_print("width = %s\n",str);
>                 g_free(str);
> 
>                 /* and forward */
>                 ret = gst_pad_event_default (pad, parent, event);
>                 break;
>             }
>         default:
>             ret = gst_pad_event_default (pad, parent, event);
>             break;
>     }
>     return ret;
> }

This looks fine, but I don't think you want to forward the caps event
here, since your encoder will output different caps.

Just use the GstVideoEncoder base class instead.

Cheers
 -Tim

-- 
Tim Müller, Centricular Ltd - http://www.centricular.com




More information about the gstreamer-devel mailing list