closedcaption: Replace GST_VIDEO_CAPTION_TYPE_CEA608_IN_CEA708_RAW with CEA608_S334_1A
authorSebastian Dröge <sebastian@centricular.com>
Mon, 10 Dec 2018 13:54:49 +0000 (15:54 +0200)
committerSebastian Dröge <slomo@coaxion.net>
Sat, 15 Dec 2018 21:31:28 +0000 (21:31 +0000)
As a side-effect we can now actually store the line offset in the
line21dec element, and have to perform fewer transformations in the
decklink elements (which were also buggy as they assumed a single byte
triplet per meta).

ext/closedcaption/gstcccombiner.c
ext/closedcaption/gstccextractor.c
ext/closedcaption/gstline21dec.c
sys/decklink/gstdecklinkvideosink.cpp
sys/decklink/gstdecklinkvideosrc.cpp

index 144f650d12851779f76b965e2d1412f6b4d40b43..dd119201199ac48faeb40592afd5330a5ea9743a 100644 (file)
@@ -48,7 +48,7 @@ static GstStaticPadTemplate captiontemplate =
     GST_PAD_SINK,
     GST_PAD_REQUEST,
     GST_STATIC_CAPS
-    ("closedcaption/x-cea-608,format={ (string) raw, (string) cc_data}; "
+    ("closedcaption/x-cea-608,format={ (string) raw, (string) s334-1a}; "
         "closedcaption/x-cea-708,format={ (string) cc_data, (string) cdp }"));
 
 G_DEFINE_TYPE (GstCCCombiner, gst_cc_combiner, GST_TYPE_AGGREGATOR);
@@ -353,9 +353,8 @@ gst_cc_combiner_sink_event (GstAggregator * aggregator,
         if (gst_structure_has_name (s, "closedcaption/x-cea-608")) {
           if (strcmp (format, "raw") == 0) {
             self->current_caption_type = GST_VIDEO_CAPTION_TYPE_CEA608_RAW;
-          } else if (strcmp (format, "cc_data") == 0) {
-            self->current_caption_type =
-                GST_VIDEO_CAPTION_TYPE_CEA608_IN_CEA708_RAW;
+          } else if (strcmp (format, "s334-1a") == 0) {
+            self->current_caption_type = GST_VIDEO_CAPTION_TYPE_CEA608_S334_1A;
           } else {
             g_assert_not_reached ();
           }
index 5e5abfda107a06bdf64b28981d377f44acfb8aac..b18cfabd03e65d9178ca1bd29017ad16bf0761cf 100644 (file)
@@ -57,7 +57,7 @@ static GstStaticPadTemplate captiontemplate =
     GST_PAD_SRC,
     GST_PAD_SOMETIMES,
     GST_STATIC_CAPS
-    ("closedcaption/x-cea-608,format={ (string) raw, (string) cc_data}; "
+    ("closedcaption/x-cea-608,format={ (string) raw, (string) s334-1a}; "
         "closedcaption/x-cea-708,format={ (string) cc_data, (string) cdp }"));
 
 G_DEFINE_TYPE (GstCCExtractor, gst_cc_extractor, GST_TYPE_ELEMENT);
@@ -284,9 +284,9 @@ create_caps_from_caption_type (GstVideoCaptionType caption_type,
       caption_caps = gst_caps_new_simple ("closedcaption/x-cea-608",
           "format", G_TYPE_STRING, "raw", NULL);
       break;
-    case GST_VIDEO_CAPTION_TYPE_CEA608_IN_CEA708_RAW:
+    case GST_VIDEO_CAPTION_TYPE_CEA608_S334_1A:
       caption_caps = gst_caps_new_simple ("closedcaption/x-cea-608",
-          "format", G_TYPE_STRING, "cc_data", NULL);
+          "format", G_TYPE_STRING, "s334-1a", NULL);
       break;
     case GST_VIDEO_CAPTION_TYPE_CEA708_RAW:
       caption_caps = gst_caps_new_simple ("closedcaption/x-cea-708",
index 03bf94cf6935c3d9072c1517bcbbe63ea825126d..53833860fd1d3ff0b4dad438669e2da5aad10adb 100644 (file)
@@ -408,13 +408,25 @@ gst_line_21_decoder_scan (GstLine21Decoder * self, GstVideoFrame * frame)
     GST_DEBUG_OBJECT (self, "No CC found");
     self->line21_offset = -1;
   } else {
-    guint8 ccdata[6] = { 0xfc, 0x80, 0x80, 0xfd, 0x80, 0x80 };  /* Initialize the ccdata */
+    guint base_line1 = 0, base_line2 = 0;
+    guint8 ccdata[6] = { 0x80, 0x80, 0x80, 0x00, 0x80, 0x80 };  /* Initialize the ccdata */
+
+    if (GST_VIDEO_FRAME_HEIGHT (frame) == 525) {
+      base_line1 = 9;
+      base_line2 = 272;
+    } else if (GST_VIDEO_FRAME_HEIGHT (frame) == 625) {
+      base_line1 = 5;
+      base_line2 = 318;
+    }
+
+    ccdata[0] |= (base_line1 < i ? i - base_line1 : 0) & 0x1f;
     ccdata[1] = sliced[0].data[0];
     ccdata[2] = sliced[0].data[1];
+    ccdata[3] |= (base_line2 < i ? i - base_line2 : 0) & 0x1f;
     ccdata[4] = sliced[1].data[0];
     ccdata[5] = sliced[1].data[1];
     gst_buffer_add_video_caption_meta (frame->buffer,
-        GST_VIDEO_CAPTION_TYPE_CEA608_IN_CEA708_RAW, ccdata, 6);
+        GST_VIDEO_CAPTION_TYPE_CEA608_S334_1A, ccdata, 6);
     GST_TRACE_OBJECT (self,
         "Got CC 0x%02x 0x%02x / 0x%02x 0x%02x '%c%c / %c%c'", ccdata[1],
         ccdata[2], ccdata[4], ccdata[5],
index dfc847a1232762438922e1dc33b93ca3fbb2f35a..ef8a20fdd0b6a916011de0a04d9a5d4fca5f39d9 100644 (file)
@@ -808,26 +808,11 @@ gst_decklink_video_sink_prepare (GstBaseSink * bsink, GstBuffer * buffer)
 
           break;
         }
-        case GST_VIDEO_CAPTION_TYPE_CEA608_IN_CEA708_RAW:{
-          guint8 data[3];
-
-          /* This is the offset from line 9 for 525-line fields and from line
-           * 5 for 625-line fields.
-           *
-           * The highest bit is set for field 1 but not for field 0
-           */
-          data[0] =
-              self->info.height ==
-              525 ? self->caption_line - 9 : self->caption_line - 5;
-          if (cc_meta->data[0] == 0xFD)
-            data[0] |= 0x80;
-          data[1] = cc_meta->data[1];
-          data[2] = cc_meta->data[2];
-
+        case GST_VIDEO_CAPTION_TYPE_CEA608_S334_1A:{
           if (!gst_video_vbi_encoder_add_ancillary (self->vbiencoder,
                   FALSE,
                   GST_VIDEO_ANCILLARY_DID16_S334_EIA_708 >> 8,
-                  GST_VIDEO_ANCILLARY_DID16_S334_EIA_708 & 0xff, data, 3))
+                  GST_VIDEO_ANCILLARY_DID16_S334_EIA_708 & 0xff, cc_meta->data, cc_meta->size))
             GST_WARNING_OBJECT (self, "Couldn't add meta to ancillary data");
 
           got_captions = TRUE;
index bb14d3730ae13bf735329a0d87d0bfbb5ecd4b5c..1ef7f93883b840e95c044053c153a04f81b712ef 100644 (file)
@@ -850,13 +850,8 @@ extract_cc_from_vbi (GstDecklinkVideoSrc * self, GstBuffer ** buffer,
             GST_DEBUG_OBJECT (self,
                 "Adding CEA-608 meta to buffer for line %d", fi);
             GST_MEMDUMP_OBJECT (self, "CEA608", gstanc.data, gstanc.data_count);
-            /* The first byte actually contains the field and line offset but
-             * for CEA608-in-CEA708 we can't store the line offset, and it's
-             * generally not needed
-             */
-            gstanc.data[0] = (gstanc.data[0] & 0x80) ? 0xFD : 0xFC;
             gst_buffer_add_video_caption_meta (*buffer,
-                GST_VIDEO_CAPTION_TYPE_CEA608_IN_CEA708_RAW, gstanc.data,
+                GST_VIDEO_CAPTION_TYPE_CEA608_S334_1A, gstanc.data,
                 gstanc.data_count);
             break;
           default: