From 262be30b6fb941f2f6be2cadc9fe5bc8396b4833 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Tue, 11 Apr 2023 12:40:54 +1000 Subject: [PATCH] ccutils: generate valid padding in field 1 when needing to generate field 2 Fixes CC in Field 2 but not in Field 1 errors. Part-of: --- .../ext/closedcaption/ccutils.c | 13 +++++++- .../tests/check/elements/ccconverter.c | 33 +++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/closedcaption/ccutils.c b/subprojects/gst-plugins-bad/ext/closedcaption/ccutils.c index c783e03be4..455a93e48e 100644 --- a/subprojects/gst-plugins-bad/ext/closedcaption/ccutils.c +++ b/subprojects/gst-plugins-bad/ext/closedcaption/ccutils.c @@ -888,7 +888,18 @@ cc_buffer_take_cc_data (CCBuffer * buf, cea608_1_i += 2; buf->last_cea608_written_was_field1 = TRUE; } else if (cea608_1_i < write_cea608_1_size + field1_padding) { - cc_data[out_i++] = 0xf8; + GST_TRACE_OBJECT (buf, + "write field2:%u field2_i:%u, cea608-2 buf len:%u", + write_cea608_2_size, cea608_2_i, buf->cea608_2->len); + if (cea608_2_i < write_cea608_2_size + || buf->cea608_2->len > write_cea608_2_size) { + /* if we are writing field 2, then we have to write valid field 1 */ + GST_TRACE_OBJECT (buf, "writing valid field1 padding because " + "we need to write valid field2"); + cc_data[out_i++] = 0xfc; + } else { + cc_data[out_i++] = 0xf8; + } cc_data[out_i++] = 0x80; cc_data[out_i++] = 0x80; cea608_1_i += 2; diff --git a/subprojects/gst-plugins-bad/tests/check/elements/ccconverter.c b/subprojects/gst-plugins-bad/tests/check/elements/ccconverter.c index dde484f628..fb1e276d7b 100644 --- a/subprojects/gst-plugins-bad/tests/check/elements/ccconverter.c +++ b/subprojects/gst-plugins-bad/tests/check/elements/ccconverter.c @@ -1014,13 +1014,13 @@ GST_START_TEST (convert_cea608_raw_cea708_cdp_field_one) { const guint8 in[] = { 0x81, 0x82 }; const guint8 out[] = - { 0x96, 0x69, 0x49, 0x5f, 0x43, 0x00, 0x00, 0x72, 0xf4, 0xf8, 0x80, 0x80, + { 0x96, 0x69, 0x49, 0x5f, 0x43, 0x00, 0x00, 0x72, 0xf4, 0xfc, 0x80, 0x80, 0xfd, 0x81, 0x82, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x74, 0x00, 0x00, - 0xb0 + 0xac }; check_conversion (in, sizeof (in), out, sizeof (out), @@ -1257,6 +1257,34 @@ GST_START_TEST (convert_cea708_cc_data_cea708_cdp_field1_overflow) GST_END_TEST; +GST_START_TEST (convert_cea608_raw_field1_cea708_cdp_60fps) +{ + const guint8 in1[] = { 0x81, 0x82 }; + const guint8 *in[] = { in1 }; + guint in_len[] = { sizeof (in1) }; + const guint8 out1[] = + { 0x96, 0x69, 0x2b, 0x8f, 0x43, 0x00, 0x00, 0x72, 0xea, 0xfc, 0x80, 0x80, + 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, + 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, + 0xfa, 0x00, 0x00, 0x74, 0x00, 0x00, 0x6e, + }; + const guint8 out2[] = + { 0x96, 0x69, 0x2b, 0x8f, 0x43, 0x00, 0x01, 0x72, 0xea, 0xfd, 0x81, 0x82, + 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, + 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, 0xfa, 0x00, 0x00, + 0xfa, 0x00, 0x00, 0x74, 0x00, 0x01, 0x68, + }; + const guint8 *out[] = { out1, out2 }; + guint out_len[] = { sizeof (out1), sizeof (out2) }; + check_conversion_multiple (1, in, in_len, G_N_ELEMENTS (out_len), out, + out_len, + "closedcaption/x-cea-608,format=(string)raw,framerate=30/1,field=1", + "closedcaption/x-cea-708,format=(string)cdp,framerate=60/1", NULL, NULL, + 0); +} + +GST_END_TEST; + static Suite * ccextractor_suite (void) { @@ -1303,6 +1331,7 @@ ccextractor_suite (void) tcase_add_test (tc, convert_cea708_cc_data_cea608_raw_field_one); tcase_add_test (tc, convert_cea708_cdp_cea608_raw_field_one); tcase_add_test (tc, convert_cea608_raw_cea608_raw_field_one); + tcase_add_test (tc, convert_cea608_raw_field1_cea708_cdp_60fps); return s; }