[gst-devel] Caps problem when writing encoder/decoder

Martin Bisson martin.bisson at gmail.com
Wed May 26 04:02:54 CEST 2010


Hunterwood wrote:
> Hi Martin,
>
> thanks for your reply, it solved the problem!
>   
Very glad, I was following your thread closely because I know I was 
going to face pretty much the same obstacles ;)
> The "caps=NULL"-error in the setcaps-function was actually due to the use
> of:
>   base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad));
>
> It seems as if the the caps returned by gst_pad_get_pad_template_caps
> changed after a call to gst_pad_set_caps:
>
> The  first time I recieved:
>   caps = audio/x-raw-int, endianness=(int)1234, signed=(boolean)true,
> width=(int)16, depth=(int)16, rate=(int)48000, channels=(int)1
> The second time it was:
>   caps = audio/x-raw-int, endianness=(int)1234, signed=(boolean)true,
> width=(int)16, depth=(int)16, rate=, channels= (where "rate" and "channels"
> had no type nor value).
>   
Mmm I'm surprised, I didn't think that pad template caps were likely to 
change between calls...  Are you sure the otherpad is the same between 
the 2 calls?
> So I created the caps by gst_caps_new_simple instead.
>
> I still had some problems after that, but the getcaps-function solved it!
>
> At the moment the getcaps-function returns the caps created by
> gst_caps_new_simple. Is this a good way to solve it, or what do you suggest?
>   
You can take a look at the documentation for 
gst_pad_set_getcaps_function 
(http://www.gstreamer.net/data/doc/gstreamer/head/gstreamer/html/GstPad.html#gst-pad-set-getcaps-function).

Basically, from what I understand from your situation, let's say you 
have an audio/x-raw-int sink pad in your encoder outputing through a 
audio/your-xyz-caps source pad.

The get_caps function for your source pad should :
1) get the caps from the sink pad (I use gst_pad_peer_get_caps)
2) convert these (actually, a copy) to equivalent caps for your source 
pad.  In your case, it might just involve changing the name (from 
audio/x-raw-int to audio/your-xyz-caps) using gst_structure_set_name, 
but you might have other changes to make
3) intersect (gst_caps_intersect) these converted caps with the template 
caps from your output pad
4) return this intersection

The get_caps function for your input pad would follow the same 
principles, but reversed.

This is what I did in my case, and from what I understand, it's the 
proper thing to do.

Anyone please feel free to correct me,

Martin




More information about the gstreamer-devel mailing list