<div dir="ltr"><div><div><div><div><div><div>Hi.<br><br></div>I'm writing a couple of plugins for GStreamer for reading and writing raw video streams to and from a video mixer. It is largely based on the shm plugins.<br><br></div>For the source plugin initially the its source pad is defined is initially defined as a static pad template as written in the plugin documentation:<br><br>static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",<br>    GST_PAD_SRC,<br>    GST_PAD_ALWAYS,<br>    GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE("video/x-raw ") \<br>        ", format=(string)BGRA"<br>        ", interlace-mode=(string)progressive"<br>        ", height = " GST_VIDEO_SIZE_RANGE<br>        ", width = " GST_VIDEO_SIZE_RANGE<br>        ", framerate= " GST_VIDEO_FPS_RANGE)<br>    );<br><br></div><div>Should I use "src" or "mypluginsrc" in GST_STATIC_PAD_TEMPLATE(...)?<br><br></div>Anyway this part works okay. Now the tricky part is that the plugin, when used in a pipeline will detect height, width and framerate and set its caps on the source pad according to this and forward the mandated caps settings downstream. My problem I need some help with is to identify when, where and how to set the caps for the source pad. Can you help?<br><br></div>In my case the caps of the pad must be fixed, when the plugin is started whatever startet means. In the documentation I read that I should use gst_pad_use_fixed_caps() so in the init sections of the plugin, I have the following code:<br><br>    self->srcpad = gst_pad_new_from_static_template(&srctemplate, "src");<br>    gst_pad_use_fixed_caps(self->srcpad);<br><br></div>I also in the init section sets the query function<br><br>    gst_pad_set_query_function(self->srcpad, gst_myplugin_src_query);<br><br></div>However the query functions does not seems to be called when using the plugin. Anyway the idea is now to set the fixed caps for the pad when the plugin/element changes state. In the documentation is says that the element should allocate non-stream specific data. I read this as I should not set fixed caps when the element changes state from NULL to READY. So I try to set the caps when the element changes state from READY to PAUSED:<br><br>gst_myplugin_src_change_state (GstElement * element, GstStateChange transition)<br>{<br>  ....<br>  switch (transition) {<br>    case GST_STATE_CHANGE_NULL_TO_READY:<br>      break;<br>    case GST_STATE_CHANGE_READY_TO_PAUSED:<br>      caps = gst_caps_new_simple ("video/x-raw",<br>        "format", G_TYPE_STRING, "BGRA",<br>        "width", G_TYPE_INT, "1024",<br>        "height", G_TYPE_INT, "576",<br>        NULL);<br>      g_message(">>> SNOWMIXSRC Pads setting\n");<br>      if (!gst_pad_set_caps (self->srcpad, caps)) {<br>      GST_ELEMENT_ERROR (element, CORE, NEGOTIATION, (NULL),<br>          ("Failed to set caps on source"));<br>      }<br><div><div><br></div><div>In the final code, the width, height and framerate depends on external settings in another program of course. Now when I compile and install the plugin and use the following pipeline to test it, it fails to set the caps. So obviously I am not setting the caps correctly and quite likely not at the right place.<br><br></div><div>Testing plugin:<br><br></div><div>    gst-launch-1.0 -v mypluginsrc socket-path=something is-live=true ! queue ! fakesink<br><br></div><div>Result:<br><br>  Setting pipeline to PAUSED ...<br>** Message: >>> MYPLUGINSRC CHANGE STATE Null to Ready<br><br>** Message: >>> MYPLUGINSRC CHANGE STATE Ready to Pause<br><br>** Message: >>> MYPLUGINSRC Pads setting<br><br>** Message: >>> MYPLUGINSRC Pads setting error<br><br>Pipeline is live and does not need PREROLL ...<br>/GstPipeline:pipeline0/GstMypluginSrc:mypluginsrc0.GstPad:src: caps = "video/x-raw\,\ format\=\(string\)BGRA\,\ width\=\(int\)1\,\ height\=\(int\)1\,\ framerate\=\(fraction\)0/1\,\ interlace-mode\=\(string\)progressive"<br>ERROR: from element /GstPipeline:pipeline0/GstMypluginSrc:mypluginsrc0: GStreamer error: negotiation problem.<br>Additional debug info:<br>gstmypluginsrc.c(596): gst_myplugin_src_change_state (): /GstPipeline:pipeline0/GstMypluginSrc:mypluginsrc0:<br>Failed to set caps on source<br>ERROR: pipeline doesn't want to preroll.<br>Setting pipeline to PAUSED ...<br>** Message: >>> MYPLUGINSRC CHANGE STATE Other<br><br>/GstPipeline:pipeline0/GstQueue:queue0.GstPad:src: caps = "video/x-raw\,\ format\=\(string\)BGRA\,\ width\=\(int\)1\,\ height\=\(int\)1\,\ framerate\=\(fraction\)0/1\,\ interlace-mode\=\(string\)progressive"<br>Setting pipeline to READY ...<br><br></div><div>The extra messages is generated with g_message(..) in the state change code.<br><br></div><div>Thanks in advance for any hints and suggestions.<br><br></div><div>Peter MM<br></div></div></div>