History

avdevice/decklink_dec: add support for decoding teletext from 10bit ancillary data

This also add supports for 4K DeckLink cards because they always output the ancillary data in 10-bit. v2: - only try teletext decoding for 576i PAL mode - some comments as requested by Aaron Levinson

Marton Balint committed 9 years ago

Commit cc0916b1 parent 4c1aac82 files · +47 −18Browse files

Showing the changes to libavdevice/decklink_dec.cpp (1 of 2 files). Show all

Unified · Split

libavdevice/decklink_dec.cpp+45−16
@@ -30,6 +30,7 @@ extern "C" { · 29 unmodified lines
3030 extern "C" {
3131 #include "config.h"
3232 #include "libavformat/avformat.h"
33+#include "libavutil/avassert.h"
3334 #include "libavutil/avutil.h"
3435 #include "libavutil/common.h"
3536 #include "libavutil/imgutils.h"
@@ -54,21 +55,43 @@ static uint8_t calc_parity_and_line_offset(int line) · 18 unmodified lines
5455 return ret;
5556 }
5657
57−int teletext_data_unit_from_vbi_data(int line, uint8_t *src, uint8_t *tgt)
58+static void fill_data_unit_head(int line, uint8_t *tgt)
59+{
60+ tgt[0] = 0x02; // data_unit_id
61+ tgt[1] = 0x2c; // data_unit_length
62+ tgt[2] = calc_parity_and_line_offset(line); // field_parity, line_offset
63+ tgt[3] = 0xe4; // framing code
64+}
65+
66+static uint8_t* teletext_data_unit_from_vbi_data(int line, uint8_t *src, uint8_t *tgt, vbi_pixfmt fmt)
5867 {
5968 vbi_bit_slicer slicer;
6069
61− vbi_bit_slicer_init(&slicer, 720, 13500000, 6937500, 6937500, 0x00aaaae4, 0xffff, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, VBI_PIXFMT_UYVY);
70+ vbi_bit_slicer_init(&slicer, 720, 13500000, 6937500, 6937500, 0x00aaaae4, 0xffff, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, fmt);
6271
6372 if (vbi_bit_slice(&slicer, src, tgt + 4) == FALSE)
64− return -1;
73+ return tgt;
6574
66− tgt[0] = 0x02; // data_unit_id
67− tgt[1] = 0x2c; // data_unit_length
68− tgt[2] = calc_parity_and_line_offset(line); // field_parity, line_offset
69− tgt[3] = 0xe4; // framing code
75+ fill_data_unit_head(line, tgt);
7076
71− return 0;
77+ return tgt + 46;
78+}
79+
80+static uint8_t* teletext_data_unit_from_vbi_data_10bit(int line, uint8_t *src, uint8_t *tgt)
81+{
82+ uint8_t y[720];
83+ uint8_t *py = y;
84+ uint8_t *pend = y + 720;
85+ /* The 10-bit VBI data is packed in V210, but libzvbi only supports 8-bit,
86+ * so we extract the 8 MSBs of the luma component, that is enough for
87+ * teletext bit slicing. */
88+ while (py < pend) {
89+ *py++ = (src[1] >> 4) + ((src[2] & 15) << 4);
90+ *py++ = (src[4] >> 2) + ((src[5] & 3 ) << 6);
91+ *py++ = (src[6] >> 6) + ((src[7] & 63) << 2);
92+ src += 8;
93+ }
94+ return teletext_data_unit_from_vbi_data(line, y, tgt, VBI_PIXFMT_YUV420);
7295 }
7396 #endif
7497
@@ -359,7 +382,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( · 284 unmodified lines
359382 //fprintf(stderr,"Video Frame size %d ts %d\n", pkt.size, pkt.pts);
360383
361384 #if CONFIG_LIBZVBI
362− if (!no_video && ctx->teletext_lines && videoFrame->GetPixelFormat() == bmdFormat8BitYUV && videoFrame->GetWidth() == 720) {
385+ if (!no_video && ctx->teletext_lines) {
363386 IDeckLinkVideoFrameAncillary *vanc;
364387 AVPacket txt_pkt;
365388 uint8_t txt_buf0[1611]; // max 35 * 46 bytes decoded teletext lines + 1 byte data_identifier
@@ -368,16 +391,22 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( · 2 unmodified lines
368391 if (videoFrame->GetAncillaryData(&vanc) == S_OK) {
369392 int i;
370393 int64_t line_mask = 1;
394+ BMDPixelFormat vanc_format = vanc->GetPixelFormat();
371395 txt_buf[0] = 0x10; // data_identifier - EBU_data
372396 txt_buf++;
373− for (i = 6; i < 336; i++, line_mask <<= 1) {
374− uint8_t *buf;
375− if ((ctx->teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(i, (void**)&buf) == S_OK) {
376− if (teletext_data_unit_from_vbi_data(i, buf, txt_buf) >= 0)
377− txt_buf += 46;
397+ if (ctx->bmd_mode == bmdModePAL && (vanc_format == bmdFormat8BitYUV || vanc_format == bmdFormat10BitYUV)) {
398+ av_assert0(videoFrame->GetWidth() == 720);
399+ for (i = 6; i < 336; i++, line_mask <<= 1) {
400+ uint8_t *buf;
401+ if ((ctx->teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(i, (void**)&buf) == S_OK) {
402+ if (vanc_format == bmdFormat8BitYUV)
403+ txt_buf = teletext_data_unit_from_vbi_data(i, buf, txt_buf, VBI_PIXFMT_UYVY);
404+ else
405+ txt_buf = teletext_data_unit_from_vbi_data_10bit(i, buf, txt_buf);
406+ }
407+ if (i == 22)
408+ i = 317;
378409 }
379− if (i == 22)
380− i = 317;
381410 }
382411 vanc->Release();
383412 if (txt_buf - txt_buf0 > 1) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t