diff options
author | Mathieu Duponchelle <mathieu@centricular.com> | 2020-07-01 03:59:56 +0200 |
---|---|---|
committer | GStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2020-07-30 23:10:33 +0000 |
commit | 265128e7f7a24a9d4ecd07f4db10c2eb8b3eecc3 (patch) | |
tree | 8ec452ed16ab6fea32f96c7c0eaa1a7432e81943 /ext/closedcaption | |
parent | 480ede1aa772500867bf8c51a8e2ad7fd5fc0a08 (diff) | |
download | gstreamer-plugins-bad-265128e7f7a24a9d4ecd07f4db10c2eb8b3eecc3.tar.gz |
cccombiner: implement samples selection API
Call gst_aggregator_selected_samples() after identifying the
caption buffers that will be added as a meta on the next video
buffer.
Implement GstAggregator.peek_next_sample.
Add an example that demonstrates usage of the new API in
combination with the existing buffer-consumed signal.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1390>
Diffstat (limited to 'ext/closedcaption')
-rw-r--r-- | ext/closedcaption/gstcccombiner.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/ext/closedcaption/gstcccombiner.c b/ext/closedcaption/gstcccombiner.c index 305cd8ee2..b237df346 100644 --- a/ext/closedcaption/gstcccombiner.c +++ b/ext/closedcaption/gstcccombiner.c @@ -98,6 +98,7 @@ gst_cc_combiner_collect_captions (GstCCCombiner * self, gboolean timeout) GST_LOG_OBJECT (self, "No caption pad, passing through video"); video_buf = self->current_video_buffer; self->current_video_buffer = NULL; + gst_aggregator_selected_samples (GST_AGGREGATOR_CAST (self)); goto done; } @@ -203,6 +204,8 @@ gst_cc_combiner_collect_captions (GstCCCombiner * self, gboolean timeout) gst_aggregator_pad_drop_buffer (caption_pad); } while (TRUE); + gst_aggregator_selected_samples (GST_AGGREGATOR_CAST (self)); + if (self->current_frame_captions->len > 0) { guint i; @@ -592,6 +595,57 @@ gst_cc_combiner_sink_query (GstAggregator * aggregator, return ret; } +static GstSample * +gst_cc_combiner_peek_next_sample (GstAggregator * agg, + GstAggregatorPad * aggpad) +{ + GstAggregatorPad *caption_pad, *video_pad; + GstCCCombiner *self = GST_CCCOMBINER (agg); + GstSample *res = NULL; + + caption_pad = + GST_AGGREGATOR_PAD_CAST (gst_element_get_static_pad (GST_ELEMENT_CAST + (self), "caption")); + video_pad = + GST_AGGREGATOR_PAD_CAST (gst_element_get_static_pad (GST_ELEMENT_CAST + (self), "sink")); + + if (aggpad == caption_pad) { + if (self->current_frame_captions->len > 0) { + GstCaps *caps = gst_pad_get_current_caps (GST_PAD (aggpad)); + GstBufferList *buflist = gst_buffer_list_new (); + guint i; + + for (i = 0; i < self->current_frame_captions->len; i++) { + CaptionData *caption_data = + &g_array_index (self->current_frame_captions, CaptionData, i); + gst_buffer_list_add (buflist, gst_buffer_ref (caption_data->buffer)); + } + + res = gst_sample_new (NULL, caps, &aggpad->segment, NULL); + gst_caps_unref (caps); + + gst_sample_set_buffer_list (res, buflist); + gst_buffer_list_unref (buflist); + } + } else if (aggpad == video_pad) { + if (self->current_video_buffer) { + GstCaps *caps = gst_pad_get_current_caps (GST_PAD (aggpad)); + res = gst_sample_new (self->current_video_buffer, + caps, &aggpad->segment, NULL); + gst_caps_unref (caps); + } + } + + if (caption_pad) + gst_object_unref (caption_pad); + + if (video_pad) + gst_object_unref (video_pad); + + return res; +} + static void gst_cc_combiner_class_init (GstCCCombinerClass * klass) { @@ -627,6 +681,7 @@ gst_cc_combiner_class_init (GstCCCombinerClass * klass) aggregator_class->get_next_time = gst_aggregator_simple_get_next_time; aggregator_class->src_query = gst_cc_combiner_src_query; aggregator_class->sink_query = gst_cc_combiner_sink_query; + aggregator_class->peek_next_sample = gst_cc_combiner_peek_next_sample; GST_DEBUG_CATEGORY_INIT (gst_cc_combiner_debug, "cccombiner", 0, "Closed Caption combiner"); |