decklinkvideosink: write the cdp timecode data correctly
authorMatthew Waters <matthew@centricular.com>
Fri, 3 Jul 2020 03:02:33 +0000 (13:02 +1000)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 3 Jul 2020 06:54:46 +0000 (06:54 +0000)
We were mixing up the tens part with the unit parts all over the place.

e.g. 12 seconds would be encoded as 0x21 instead of the correct 0x12

Aligns the code with the same change applied to ccconverter.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1400>

sys/decklink/gstdecklinkvideosink.cpp

index 0061a2d..d069cd0 100644 (file)
@@ -853,26 +853,42 @@ convert_cea708_cc_data_cea708_cdp_internal (GstDecklinkVideoSink * self,
 
   if (tc_meta) {
     const GstVideoTimeCode *tc = &tc_meta->tc;
+    guint8 u8;
 
     gst_byte_writer_put_uint8_unchecked (&bw, 0x71);
-    gst_byte_writer_put_uint8_unchecked (&bw, 0xc0 |
-        (((tc->hours % 10) & 0x3) << 4) |
-        ((tc->hours - (tc->hours % 10)) & 0xf));
-
-    gst_byte_writer_put_uint8_unchecked (&bw, 0x80 |
-        (((tc->minutes % 10) & 0x7) << 4) |
-        ((tc->minutes - (tc->minutes % 10)) & 0xf));
-
-    gst_byte_writer_put_uint8_unchecked (&bw,
-        (tc->field_count <
-            2 ? 0x00 : 0x80) | (((tc->seconds %
-                    10) & 0x7) << 4) | ((tc->seconds -
-                (tc->seconds % 10)) & 0xf));
-
-    gst_byte_writer_put_uint8_unchecked (&bw,
-        ((tc->config.flags & GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME) ? 0x80 :
-            0x00) | (((tc->frames % 10) & 0x3) << 4) | ((tc->frames -
-                (tc->frames % 10)) & 0xf));
+    /* reserved 11 - 2 bits */
+    u8 = 0xc0;
+    /* tens of hours - 2 bits */
+    u8 |= ((tc->hours / 10) & 0x3) << 4;
+    /* units of hours - 4 bits */
+    u8 |= (tc->hours % 10) & 0xf;
+    gst_byte_writer_put_uint8_unchecked (&bw, u8);
+
+    /* reserved 1 - 1 bit */
+    u8 = 0x80;
+    /* tens of minutes - 3 bits */
+    u8 |= ((tc->minutes / 10) & 0x7) << 4;
+    /* units of minutes - 4 bits */
+    u8 |= (tc->minutes % 10) & 0xf;
+    gst_byte_writer_put_uint8_unchecked (&bw, u8);
+
+    /* field flag - 1 bit */
+    u8 = tc->field_count < 2 ? 0x00 : 0x80;
+    /* tens of seconds - 3 bits */
+    u8 |= ((tc->seconds / 10) & 0x7) << 4;
+    /* units of seconds - 4 bits */
+    u8 |= (tc->seconds % 10) & 0xf;
+    gst_byte_writer_put_uint8_unchecked (&bw, u8);
+
+    /* drop frame flag - 1 bit */
+    u8 = (tc->config.flags & GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME) ? 0x80 :
+        0x00;
+    /* reserved0 - 1 bit */
+    /* tens of frames - 2 bits */
+    u8 |= ((tc->frames / 10) & 0x3) << 4;
+    /* units of frames 4 bits */
+    u8 |= (tc->frames % 10) & 0xf;
+    gst_byte_writer_put_uint8_unchecked (&bw, u8);
   }
 
   gst_byte_writer_put_uint8_unchecked (&bw, 0x72);