From patchwork Fri Sep 7 19:40:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Heitmueller X-Patchwork-Id: 10270 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp1941645jap; Fri, 7 Sep 2018 12:41:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaJBTqdUSPqLE8PCXQOplNopTRza/zX2hzbN++qnoQJp90uUclHjHxBSj43zUQPKuDtyztB X-Received: by 2002:a1c:4c0e:: with SMTP id z14-v6mr6406577wmf.89.1536349286901; Fri, 07 Sep 2018 12:41:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536349286; cv=none; d=google.com; s=arc-20160816; b=0cENrx1t2Ea0NcQq8czyAPE0IqH1sZUI7FZdoe4AOlxSk7QPPc24ZhMIW9ibSWClUc WX1oMCH9dM7lJI4JBN07ECviJZMiuR37vo1gZ2XJc1gaZvb/MNjTtb9NLVXfAeTOfNWA 2L25HeekoB65R4bfhM5s+lAkO1TqYRJZLJlh4gp4vY4w5CM1CaGj9yu7sqPfJ/Ncq8AS iEkMCk8v6kbRTUtYIobqQg/YPycDfGzrkfqTTYrp5P792f4hb6nBJ8H5o4v9pSxOXldr 0IIoTrEJvLKSrzFQg2ePOJMN1kgTkcnt64SPfho1orx5Yod1GUdiA7jQ2O8FehBJbtc/ v/iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=vxwXfw+P96NxCggpmyUNkkbBE2dxdHaqNbsWtL4AIAY=; b=yBUtsP0EXf3XMMxyjddZJo3RfKah/v/rLNRUouqddlxMQSBx2Eqyp0BR+4rXcwmu8f QfhiTVW5VB5hqeCIwPS4s6JuxHM9NMAdAs9ST5kcbm+ihhw7LuElai+3BrD89wJORh5p UwF0IplmElxzJ325DURZgIH/iSCoemr4fyWUIws4ijbzo89ta9f+JTOM70lklLix4XVQ +FdbWa4yR4QILqVYv7FWe7BGdVzjzE2UZ2RTRlR4XfpO1upWw0qRh6Ds5lqsBP+LkVFO DTYZ7vy2vvekv0d9fFKhbNWN6kxSx80nOoRRD2L2AOlU7TJ4UawzFNXkgpY9a1+Cozjv 85IA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g3-v6si8167681wrs.292.2018.09.07.12.41.26; Fri, 07 Sep 2018 12:41:26 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 08E9968A0BC; Fri, 7 Sep 2018 22:40:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from was-smtp1.livetimenet.net (50-206-97-56-was-smtp1.livetimenet.net [50.206.97.56]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D174689FC4 for ; Fri, 7 Sep 2018 22:40:35 +0300 (EEST) Received: by was-smtp1.livetimenet.net with esmtpsa (TLSv1.2:AES128-SHA256:128) (Exim 4.84_2) (envelope-from ) id 1fyMcT-0006Sz-Jz; Fri, 07 Sep 2018 15:40:42 -0400 From: Devin Heitmueller To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Sep 2018 15:40:28 -0400 Message-Id: <20180907194028.4629-6-dheitmueller@ltnglobal.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20180907194028.4629-1-dheitmueller@ltnglobal.com> References: <20180907194028.4629-1-dheitmueller@ltnglobal.com> X-Spam-Score: -1.9 (-) Subject: [FFmpeg-devel] [PATCH 5/5] decklink: Add support for output of Active Format Description (AFD) X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: jgreen@ltnglobal.com, Devin Heitmueller MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Implement support for including AFD in decklink output when putting out 10-bit VANC data. Updated to reflect feedback from Marton Balint , Carl Eugen Hoyos and Aaron Levinson . Signed-off-by: Devin Heitmueller --- libavdevice/decklink_enc.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp index 6f1941b29f..48a4f0e950 100644 --- a/libavdevice/decklink_enc.cpp +++ b/libavdevice/decklink_enc.cpp @@ -362,8 +362,57 @@ static void construct_cc(AVFormatContext *avctx, struct decklink_ctx *ctx, } } +static void construct_afd(AVFormatContext *avctx, struct decklink_ctx *ctx, + AVPacket *pkt, struct klvanc_line_set_s *vanc_lines, + AVStream *st) +{ + struct klvanc_packet_afd_s *afd; + uint16_t *afd_words; + uint16_t len; + int size, ret; + + const uint8_t *data = av_packet_get_side_data(pkt, AV_PKT_DATA_AFD, &size); + if (!data || size == 0) + return; + + ret = klvanc_create_AFD(&afd); + if (ret) { + return; + } + + ret = klvanc_set_AFD_val(afd, data[0]); + if (ret) { + av_log(avctx, AV_LOG_ERROR, "Invalid AFD value specified: %d\n", + data[0]); + klvanc_destroy_AFD(afd); + return; + } + + /* FIXME: Should really rely on the coded_width but seems like that + is not accessible to libavdevice outputs */ + if (av_cmp_q((AVRational) {st->codecpar->width, st->codecpar->height}, (AVRational) {4, 3}) == 1) + afd->aspectRatio = ASPECT_16x9; + else + afd->aspectRatio = ASPECT_4x3; + + ret = klvanc_convert_AFD_to_words(afd, &afd_words, &len); + klvanc_destroy_AFD(afd); + if (ret) { + av_log(avctx, AV_LOG_ERROR, "Failed converting AFD packet to words\n"); + return; + } + + ret = klvanc_line_insert(ctx->vanc_ctx, vanc_lines, afd_words, len, 12, 0); + free(afd_words); + if (ret) { + av_log(avctx, AV_LOG_ERROR, "VANC line insertion failed\n"); + return; + } +} + static int decklink_construct_vanc(AVFormatContext *avctx, struct decklink_ctx *ctx, - AVPacket *pkt, decklink_frame *frame) + AVPacket *pkt, decklink_frame *frame, + AVStream *st) { struct klvanc_line_set_s vanc_lines = { 0 }; int ret = 0, i; @@ -372,6 +421,7 @@ static int decklink_construct_vanc(AVFormatContext *avctx, struct decklink_ctx * return 0; construct_cc(avctx, ctx, pkt, &vanc_lines); + construct_afd(avctx, ctx, pkt, &vanc_lines, st); IDeckLinkVideoFrameAncillary *vanc; int result = ctx->dlo->CreateAncillaryData(bmdFormat10BitYUV, &vanc); @@ -461,7 +511,7 @@ static int decklink_write_video_packet(AVFormatContext *avctx, AVPacket *pkt) frame = new decklink_frame(ctx, avpacket, st->codecpar->codec_id, ctx->bmd_height, ctx->bmd_width); #if CONFIG_LIBKLVANC - if (decklink_construct_vanc(avctx, ctx, pkt, frame)) + if (decklink_construct_vanc(avctx, ctx, pkt, frame, st)) av_log(avctx, AV_LOG_ERROR, "Failed to construct VANC\n"); #endif }