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
Showing the changes to libavdevice/decklink_dec.cpp (1 of 2 files). Show all
Unified · Split
| @@ -30,6 +30,7 @@ extern "C" { · 29 unmodified lines | ||
| 30 | 30 | extern "C" { |
| 31 | 31 | #include "config.h" |
| 32 | 32 | #include "libavformat/avformat.h" |
| 33 | +#include "libavutil/avassert.h" | |
| 33 | 34 | #include "libavutil/avutil.h" |
| 34 | 35 | #include "libavutil/common.h" |
| 35 | 36 | #include "libavutil/imgutils.h" |
| @@ -54,21 +55,43 @@ static uint8_t calc_parity_and_line_offset(int line) · 18 unmodified lines | ||
| 54 | 55 | return ret; |
| 55 | 56 | } |
| 56 | 57 | |
| 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) | |
| 58 | 67 | { |
| 59 | 68 | vbi_bit_slicer slicer; |
| 60 | 69 | |
| 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); | |
| 62 | 71 | |
| 63 | 72 | if (vbi_bit_slice(&slicer, src, tgt + 4) == FALSE) |
| 64 | − return -1; | |
| 73 | + return tgt; | |
| 65 | 74 | |
| 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); | |
| 70 | 76 | |
| 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); | |
| 72 | 95 | } |
| 73 | 96 | #endif |
| 74 | 97 | |
| @@ -359,7 +382,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( · 284 unmodified lines | ||
| 359 | 382 | //fprintf(stderr,"Video Frame size %d ts %d\n", pkt.size, pkt.pts); |
| 360 | 383 | |
| 361 | 384 | #if CONFIG_LIBZVBI |
| 362 | − if (!no_video && ctx->teletext_lines && videoFrame->GetPixelFormat() == bmdFormat8BitYUV && videoFrame->GetWidth() == 720) { | |
| 385 | + if (!no_video && ctx->teletext_lines) { | |
| 363 | 386 | IDeckLinkVideoFrameAncillary *vanc; |
| 364 | 387 | AVPacket txt_pkt; |
| 365 | 388 | 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 | ||
| 368 | 391 | if (videoFrame->GetAncillaryData(&vanc) == S_OK) { |
| 369 | 392 | int i; |
| 370 | 393 | int64_t line_mask = 1; |
| 394 | + BMDPixelFormat vanc_format = vanc->GetPixelFormat(); | |
| 371 | 395 | txt_buf[0] = 0x10; // data_identifier - EBU_data |
| 372 | 396 | 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; | |
| 378 | 409 | } |
| 379 | − if (i == 22) | |
| 380 | − i = 317; | |
| 381 | 410 | } |
| 382 | 411 | vanc->Release(); |
| 383 | 412 | if (txt_buf - txt_buf0 > 1) { |