From 98b2c705c4207a55e5747ae598084e0edff7f590 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 5 Dec 2018 19:01:40 +0200 Subject: [PATCH] ccextractor: Copy over timecode meta from the input buffers to the outgoing caption buffers Formats like SCC and MCC work based on timecodes so ideally we pass through the timecodes when writing them. --- ext/closedcaption/gstccextractor.c | 10 ++++++++-- tests/check/elements/ccextractor.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/ext/closedcaption/gstccextractor.c b/ext/closedcaption/gstccextractor.c index eb5ebe3..5e5abfd 100644 --- a/ext/closedcaption/gstccextractor.c +++ b/ext/closedcaption/gstccextractor.c @@ -307,7 +307,7 @@ create_caps_from_caption_type (GstVideoCaptionType caption_type, static GstFlowReturn gst_cc_extractor_handle_meta (GstCCExtractor * filter, GstBuffer * buf, - GstVideoCaptionMeta * meta) + GstVideoCaptionMeta * meta, GstVideoTimeCodeMeta * tc_meta) { GstBuffer *outbuf = NULL; GstEvent *event; @@ -390,6 +390,9 @@ gst_cc_extractor_handle_meta (GstCCExtractor * filter, GstBuffer * buf, GST_BUFFER_DTS (outbuf) = GST_BUFFER_DTS (buf); GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf); + if (tc_meta) + gst_buffer_add_video_time_code_meta (outbuf, &tc_meta->tc); + /* We don't really care about the flow return */ flow = gst_pad_push (filter->captionpad, outbuf); @@ -404,12 +407,15 @@ gst_cc_extractor_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) GstCCExtractor *filter = (GstCCExtractor *) parent; GstFlowReturn flow = GST_FLOW_OK; GstVideoCaptionMeta *cc_meta; + GstVideoTimeCodeMeta *tc_meta; gpointer iter = NULL; + tc_meta = gst_buffer_get_video_time_code_meta (buf); + while ((cc_meta = (GstVideoCaptionMeta *) gst_buffer_iterate_meta_filtered (buf, &iter, GST_VIDEO_CAPTION_META_API_TYPE)) && flow == GST_FLOW_OK) { - flow = gst_cc_extractor_handle_meta (filter, buf, cc_meta); + flow = gst_cc_extractor_handle_meta (filter, buf, cc_meta, tc_meta); } /* If there's an issue handling the CC, return immediately */ diff --git a/tests/check/elements/ccextractor.c b/tests/check/elements/ccextractor.c index 953e9b0..7276085 100644 --- a/tests/check/elements/ccextractor.c +++ b/tests/check/elements/ccextractor.c @@ -86,6 +86,8 @@ GST_START_TEST (captions) GstBuffer *buf, *outbuf; const guint8 caption_data[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; GstCaps *caps; + GstVideoTimeCode *tc; + GstVideoTimeCodeMeta *tc_meta; h = gst_harness_new ("ccextractor"); h2 = gst_harness_new_with_element (h->element, NULL, NULL); @@ -99,10 +101,19 @@ GST_START_TEST (captions) gst_buffer_add_video_caption_meta (buf, GST_VIDEO_CAPTION_TYPE_CEA708_RAW, caption_data, sizeof (caption_data)); + tc = gst_video_time_code_new (30, 1, NULL, GST_VIDEO_TIME_CODE_FLAGS_NONE, 0, + 0, 0, 0, 0); + gst_buffer_add_video_time_code_meta (buf, tc); + outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf)); fail_unless (outbuf != NULL); fail_unless (outbuf == buf); + + tc_meta = gst_buffer_get_video_time_code_meta (outbuf); + fail_unless (tc_meta != NULL); + fail_unless_equals_int (gst_video_time_code_compare (&tc_meta->tc, tc), 0); + gst_buffer_unref (outbuf); gst_buffer_unref (buf); @@ -111,6 +122,12 @@ GST_START_TEST (captions) fail_unless (outbuf != NULL); fail_unless (gst_buffer_memcmp (outbuf, 0, caption_data, sizeof (caption_data)) == 0); + + tc_meta = gst_buffer_get_video_time_code_meta (outbuf); + fail_unless (tc_meta != NULL); + fail_unless_equals_int (gst_video_time_code_compare (&tc_meta->tc, tc), 0); + gst_video_time_code_free (tc); + gst_buffer_unref (outbuf); caps = gst_pad_get_current_caps (h->sinkpad); @@ -129,10 +146,19 @@ GST_START_TEST (captions) gst_buffer_add_video_caption_meta (buf, GST_VIDEO_CAPTION_TYPE_CEA708_RAW, caption_data, sizeof (caption_data)); + tc = gst_video_time_code_new (30, 1, NULL, GST_VIDEO_TIME_CODE_FLAGS_NONE, 0, + 0, 0, 1, 0); + gst_buffer_add_video_time_code_meta (buf, tc); + outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf)); fail_unless (outbuf != NULL); fail_unless (outbuf == buf); + + tc_meta = gst_buffer_get_video_time_code_meta (outbuf); + fail_unless (tc_meta != NULL); + fail_unless_equals_int (gst_video_time_code_compare (&tc_meta->tc, tc), 0); + gst_buffer_unref (outbuf); gst_buffer_unref (buf); @@ -141,6 +167,12 @@ GST_START_TEST (captions) fail_unless (outbuf != NULL); fail_unless (gst_buffer_memcmp (outbuf, 0, caption_data, sizeof (caption_data)) == 0); + + tc_meta = gst_buffer_get_video_time_code_meta (outbuf); + fail_unless (tc_meta != NULL); + fail_unless_equals_int (gst_video_time_code_compare (&tc_meta->tc, tc), 0); + gst_video_time_code_free (tc); + gst_buffer_unref (outbuf); caps = gst_pad_get_current_caps (h->sinkpad); -- 2.7.4