+
+#if CONFIG_LIBZVBI
+ if (!no_video && ctx->teletext_lines && videoFrame->GetPixelFormat() == bmdFormat8BitYUV && videoFrame->GetWidth() == 720) {
+ IDeckLinkVideoFrameAncillary *vanc;
+ AVPacket txt_pkt;
+ uint8_t txt_buf0[1611]; // max 35 * 46 bytes decoded teletext lines + 1 byte data_identifier
+ uint8_t *txt_buf = txt_buf0;
+
+ if (videoFrame->GetAncillaryData(&vanc) == S_OK) {
+ int i;
+ int64_t line_mask = 1;
+ txt_buf[0] = 0x10; // data_identifier - EBU_data
+ txt_buf++;
+ for (i = 6; i < 336; i++, line_mask <<= 1) {
+ uint8_t *buf;
+ if ((ctx->teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(i, (void**)&buf) == S_OK) {
+ if (teletext_data_unit_from_vbi_data(i, buf, txt_buf) >= 0)
+ txt_buf += 46;
+ }
+ if (i == 22)
+ i = 317;
+ }
+ vanc->Release();
+ if (txt_buf - txt_buf0 > 1) {
+ int stuffing_units = (4 - ((45 + txt_buf - txt_buf0) / 46) % 4) % 4;
+ while (stuffing_units--) {
+ memset(txt_buf, 0xff, 46);
+ txt_buf[1] = 0x2c; // data_unit_length
+ txt_buf += 46;
+ }
+ av_init_packet(&txt_pkt);
+ txt_pkt.pts = pkt.pts;
+ txt_pkt.dts = pkt.dts;
+ txt_pkt.stream_index = ctx->teletext_st->index;
+ txt_pkt.data = txt_buf0;
+ txt_pkt.size = txt_buf - txt_buf0;
+ if (avpacket_queue_put(&ctx->queue, &txt_pkt) < 0) {
+ ++ctx->dropped;
+ }
+ }
+ }
+ }
+#endif
+