GstMeta buffers

Sebastian Dröge sebastian at centricular.com
Fri Sep 30 07:14:21 UTC 2016


On Thu, 2016-09-29 at 22:21 +0000, John P Poet wrote:
> In the example for creating a new meta info type:
> 
> https://gstreamer.freedesktop.org/data/doc/gstreamer/head/pwg/html/se
> ction-allocation-meta.html
> 
> It says
> 
> > Lastly, you implement a gst_buffer_add_*_meta() that adds the
> metadata implementation to a buffer and sets the values of the
> metadata.
> 
> And the example just show assigning values to local variables in the
> structure.  It does not show any memory allocation, so I assume that
> is not necessary.  In that structure I would like it to hold a c++
> class:
> 
> struct _VANCMeta {
>   GstMeta       meta;
>   AncillaryPacket packet;
> };
> 
> AncillaryPacket would have various methods as well as data.  Will
> that work, or do I need to use more "base" types in my metadata
> structure?  There are only a few data elements in there, so just
> having those elements in the VANCMeta struct would be easy, but it
> would be nice to have the methods automatically available by whatever
> reads the metadata.

You can use a C++ class but you will have to store it as a pointer, and
make sure that you call delete on it when the meta is freed.

Storing C++ classes directly in C structs causes memory leaks as their
destructor can't be called.

> If I do need to just have 'simple' data types, and one of those types
> is an array of uint16_t, is there a preferred way of allocating the
> memory for it?  I assume I would use a GArray rather than a
> GstBuffer, right?   Or would I just use a basic C style array of
> uint16_t?

You could use either of those 3 options, whichever is easier to use in
your case.


> I would like to understand how the memory is deallocated after the
> life of the struct is over.  Who is responsible for that
> deallocation, and how do they know how to deallocate the memory?

You're responsible for deallocating everything that you allocated
yourself in the free_function you passed to gst_meta_register().

Also make sure to initialize all your fields in the init_func().

-- 
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 931 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20160930/ee3b43c2/attachment.sig>


More information about the gstreamer-devel mailing list