From c94675f1d4a9b5f8520cf4162c2c6964a760fcca Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Fri, 3 Jul 2020 13:02:33 +1000 Subject: [PATCH] decklinkvideosink: write the cdp timecode data correctly 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: --- sys/decklink/gstdecklinkvideosink.cpp | 52 +++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/sys/decklink/gstdecklinkvideosink.cpp b/sys/decklink/gstdecklinkvideosink.cpp index 0061a2d..d069cd0 100644 --- a/sys/decklink/gstdecklinkvideosink.cpp +++ b/sys/decklink/gstdecklinkvideosink.cpp @@ -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); -- 2.7.4