GstMeta API

Jon Lovewell jon at csoftware.co.uk
Thu Nov 28 15:50:10 UTC 2019


Hello everyone,

I am experimenting with the GstMeta API, am failing badly and would like to appeal to anyone that might be able to assist.

I have created my own GstMeta called GstMyTestMeta for now.  This meta has a single guint64 field called testfield.

I am using the following pipeline

                videotestsrc ! x264enc ! rtph264pay ! udpsink

I am adding the meta to the buffers as they leave 'videotestsrc' using a pad probe, code is below

static GstPadProbeReturn insert_test_meta(GstPad* pad, GstPadProbeInfo* info, gpointer user_data)
{
       GstBuffer* buffer = GST_PAD_PROBE_INFO_BUFFER(info);

       GstBuffer* wbuffer = gst_buffer_make_writable(buffer);

       /* Making a buffer writable can fail (for example if it
       * cannot be copied and is used more than once)
       */
       if (wbuffer != NULL)
       {
              guint64 testfield = 12345;

              GstMyTestMeta* meta = gst_buffer_add_my_test_meta(wbuffer, testfield);

              G_print("Added meta with timestamp %ld", meta->testfield);
       }

       return GST_PAD_PROBE_OK;
}

I would like to access the meta as it leaves the rtph264pay, again using a pad probe, and add it to the RTP Header as a Header Extension, code is below

static GstPadProbeReturn convert_test_meta_to_rtp_header_extension(GstPad* pad, GstPadProbeInfo* info, gpointer user_data)
{
       GstBuffer* buffer;

       buffer = GST_PAD_PROBE_INFO_BUFFER(info);

       buffer = gst_buffer_make_writable(buffer);

       /* Making a buffer writable can fail (for example if it
       * cannot be copied and is used more than once)
       */
       if (buffer == NULL)
              return GST_PAD_PROBE_OK;

       GstRTPBuffer rtp_buffer = GST_RTP_BUFFER_INIT;

       if (gst_rtp_buffer_map(buffer, GST_MAP_READWRITE, &rtp_buffer))
       {
              GstMyTestMeta *meta = gst_buffer_get_my_test_meta(buffer);

              gchar* data = g_strdup_printf("%ld", meta->testfield);

gboolean added = gst_rtp_buffer_add_extension_onebyte_header(&rtp_buffer, 1, data, strlen(data));

gst_rtp_buffer_unmap(&rtp_buffer);

              g_free(data);
       }

       return GST_PAD_PROBE_OK;
}

I have stepped through the code and know that the meta is being added to the buffer ok, and confirmed by debug output.  However, my program crashes with a memory access violation exception before the second pad probe callback is invoked.

The relevant part of the debug output is show below.  There is more output before the first entry but no more after the last room.

0:00:01.361461200 27732   057F9730 DEBUG               GST_META gstmeta.c:88:gst_meta_api_type_register: register API "GstMyTestMetaAPI"
0:00:01.361520300 27732   057F9730 DEBUG               GST_META gstmeta.c:198:gst_meta_register: register "GstMyTestMeta" implementing "GstMyTestMetaAPI" of size 8
0:00:01.361558300 27732   057F9730 DEBUG             GST_BUFFER gstbuffer.c:2281:gst_buffer_add_meta: alloc metadata 05385E70 (GstMytestMeta) of size 8
0:00:01.362175400 27732   057F9730 DEBUG               GST_PADS gstpad.c:3601:probe_hook_marshal:<videotestsrc0:src> probe returned OK
0:00:01.362241300 27732   057F9730 DEBUG         GST_SCHEDULING gstpad.c:4324:gst_pad_chain_data_unchecked:<x264enc0:sink> calling chainfunction &gst_video_encoder_chain with buffer buffer: 05827358, pts 0:00:00.000000000, dts 99:99:99.999999999, dur 0:00:00.033333333, size 230400, offset 0, offset_end 1, flags 0x40
0:00:01.362289400 27732   057F9730 LOG             videoencoder gstvideoencoder.c:1465:gst_video_encoder_chain:<x264enc0> received buffer of size 230400 with PTS 0:00:00.000000000, DTS 99:99:99.999999999, duration 0:00:00.033333333
0:00:01.362332000 27732   057F9730 LOG             videoencoder gstvideoencoder.c:1552:gst_video_encoder_chain:<x264enc0> passing frame pfn 0 to subclass
0:00:01.362372200 27732   057F9730 LOG               GST_BUFFER gstbuffer.c:1798:gst_buffer_map_range: buffer 05827358, idx 0, length 1, flags 0001
0:00:01.362407300 27732   057F9730 LOG               GST_BUFFER gstbuffer.c:242:_get_merged_memory: buffer 05827358, idx 0, length 1
0:00:01.362442600 27732   057F9730 LOG               GST_BUFFER gstbuffer.c:1798:gst_buffer_map_range: buffer 05827358, idx 0, length 1, flags 0001
0:00:01.362480900 27732   057F9730 LOG               GST_BUFFER gstbuffer.c:242:_get_merged_memory: buffer 05827358, idx 0, length 1
0:00:01.362515500 27732   057F9730 LOG               GST_BUFFER gstbuffer.c:1798:gst_buffer_map_range: buffer 05827358, idx 0, length 1, flags 0001
0:00:01.362549600 27732   057F9730 LOG               GST_BUFFER gstbuffer.c:242:_get_merged_memory: buffer 05827358, idx 0, length 1
0:00:01.362587600 27732   057F9730 DEBUG               GST_META gstmeta.c:88:gst_meta_api_type_register: register API "GstVideoCaptionMetaAPI"
0:00:01.362628600 27732   057F9730 LOG                GST_DEBUG gstinfo.c:1604:gst_debug_apply_entry: category video-anc matches pattern 01049A70 - gets set to level 6
0:00:01.362664600 27732   057F9730 INFO               video-anc video-anc.c:859:gst_video_caption_meta_api_get_type: registering


I have searched for examples on how to use the GstMeta API but without any success.  I believe that it is the intention of this API to support this use case but I am unsure.

I would greatly appreciate any help or assistance that anyone is able to offer.

Kind Regards

Jon Lovewell


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20191128/066b9f78/attachment-0001.html>


More information about the gstreamer-devel mailing list