[gst-devel] gst_caps_replace()?

David Schleef ds at schleef.org
Mon Dec 29 11:32:08 CET 2003


On Sun, Dec 28, 2003 at 10:58:20AM +0100, Ronald Bultje wrote:
> On Sat, 2003-12-27 at 20:15, Benjamin Otte wrote:
> > On Wed, 24 Dec 2003, Ronald Bultje wrote:
> > > *oldcaps = newcaps (or gst_caps_copy (newcaps));
> > Which one? ;)
> 
> This 'or' was intended to kick the person that removed caps refcounting.
> It's pretty annoying that, if we want to replace something with a newly
> created caps, we'll create one, copy it (which re-created it) and then
> remove the original:
> 
> GstCaps *caps = gst_caps_new_simple ("bla", NULL), old = ..;
> gst_caps_replace_simple (&old, caps);
> gst_caps_free (caps);
> 
> That's why I "proposed" to remove the copy in the replace and require
> the caller to do that.

There is a gst_caps_replace(GstCaps **caps, GstCaps *newcaps)
function.  The second parameter is "GstCaps *" instead of "const
GstCaps *", indicating that the function takes ownership of the caps.
This is the rule with every function that takes GstCaps *, although
with a few possible exceptions (mistakes, mostly).

The same is true about const return values -- if the function returns
a const GstCaps *, you don't have ownership.  This is inconsistent
in a few places, notably gst_caps_get_structure(), which takes a
const GstCaps *, but returns a GstStructure *.  You are supposed to
know that if you call it with a const GstCaps *, you get a const
GstStructure *.



dave...





More information about the gstreamer-devel mailing list