MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / construct_afd

Function construct_afd

libavdevice/decklink_enc.cpp:494–575  ·  view source on GitHub ↗

See SMPTE ST 2016-3:2009 */

Source from the content-addressed store, hash-verified

492
493/* See SMPTE ST 2016-3:2009 */
494static void construct_afd(AVFormatContext *avctx, struct decklink_ctx *ctx,
495 AVPacket *pkt, struct klvanc_line_set_s *vanc_lines,
496 AVStream *st)
497{
498 struct klvanc_packet_afd_s *afd = NULL;
499 uint16_t *afd_words = NULL;
500 uint16_t len;
501 size_t size;
502 int f1_line = 12, f2_line = 0, ret;
503
504 const uint8_t *data = av_packet_get_side_data(pkt, AV_PKT_DATA_AFD, &size);
505 if (!data || size == 0)
506 return;
507
508 ret = klvanc_create_AFD(&afd);
509 if (ret)
510 return;
511
512 ret = klvanc_set_AFD_val(afd, data[0]);
513 if (ret) {
514 av_log(avctx, AV_LOG_ERROR, "Invalid AFD value specified: %d\n",
515 data[0]);
516 klvanc_destroy_AFD(afd);
517 return;
518 }
519
520 /* Compute the AR flag based on the DAR (see ST 2016-1:2009 Sec 9.1). Note, we treat
521 anything below 1.4 as 4:3 (as opposed to the standard 1.33), because there are lots
522 of streams in the field that aren't *exactly* 4:3 but a tiny bit larger after doing
523 the math... */
524 if (av_cmp_q((AVRational) {st->codecpar->width * st->codecpar->sample_aspect_ratio.num,
525 st->codecpar->height * st->codecpar->sample_aspect_ratio.den}, (AVRational) {14, 10}) == 1)
526 afd->aspectRatio = ASPECT_16x9;
527 else
528 afd->aspectRatio = ASPECT_4x3;
529
530 ret = klvanc_convert_AFD_to_words(afd, &afd_words, &len);
531 if (ret) {
532 av_log(avctx, AV_LOG_ERROR, "Failed converting AFD packet to words\n");
533 goto out;
534 }
535
536 ret = klvanc_line_insert(ctx->vanc_ctx, vanc_lines, afd_words, len, f1_line, 0);
537 if (ret) {
538 av_log(avctx, AV_LOG_ERROR, "VANC line insertion failed\n");
539 goto out;
540 }
541
542 /* For interlaced video, insert into both fields. Switching lines for field 2
543 derived from SMPTE RP 168:2009, Sec 6, Table 2. */
544 switch (ctx->bmd_mode) {
545 case bmdModeNTSC:
546 case bmdModeNTSC2398:
547 f2_line = 273 - 10 + f1_line;
548 break;
549 case bmdModePAL:
550 f2_line = 319 - 6 + f1_line;
551 break;

Callers 1

decklink_construct_vancFunction · 0.85

Calls 3

av_packet_get_side_dataFunction · 0.85
av_logFunction · 0.85
av_cmp_qFunction · 0.85

Tested by

no test coverage detected