From patchwork Thu Nov 16 16:09:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Heitmueller X-Patchwork-Id: 6117 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp5996703jah; Thu, 16 Nov 2017 08:11:15 -0800 (PST) X-Google-Smtp-Source: AGs4zMb0dlArMekJqypYLd0yTf3A2iTlz8a+nJFe07z3jNS20GkGlYuDKRX0PSsMWEVZ6fURt88j X-Received: by 10.223.160.217 with SMTP id n25mr1887468wrn.27.1510848675387; Thu, 16 Nov 2017 08:11:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510848675; cv=none; d=google.com; s=arc-20160816; b=BhiQP4EsX7nehtJnqdq8iZYLraOeXJBlFeWAmdqJfy1FvHygZR8YUudvPA7Aly3LcM AJhRW3TWhpv2sEAGOttqibP1qK8MipYkPJEepW02Jr56CnIfZYKTkA0KzjEnEB5++LLI M2gjf2ugpsNDNaCQbqvpsyaV9abFCIGlVAZ1CO+6BMC84ZJmRR+oFvW0wmaoJys0nKnm qhiN4TfI3FEYg9soU2T/LZzHb4r4HTXnqQLZDhZQg+Bykga22i6f6+0i2XR5GJiBvjFN Ogf8xgjTaDhwumZWcEd021/x+O+Qu8jUJB0fXnqiTyiVC5QKoRO2WGiK2Th3Qo71aAzn Fjag== 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:arc-authentication-results; bh=rKKcX/eL+fxfExlZxc9ewxnI6rQNbleB64l5kQfXU6w=; b=uTURV4F09t8Am2OXvOJsSlrUCXuXCG4ioBI+DAidFmgczqxNF5ARapx11/7QtujUzR mBF7pBk+GIMARXMH2uWHe9YRPO3SOhDYUxBdEGG6v4q7ytEgu3k92fLh6PF6zVlFPWJA xcjfedCxdpjY0YwFRlOTWHrcia2x8Lkmd78EeXskG+IQfvgNpx3au/1btBp/ycgIab1O ftvPlr6PQuGnB6TH8GD8S/1g9CCRGWTo0P0TtWBCfcbpsa7uqQcD0VrWFgbXv9IyzjzR nmbQRI+GxIJllQoQCHlkZHppZmCWz7udrT9w2bxt6mXpIoxAkx7FCFg3lNR0IlK3e8+5 f51g== 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 j199si1223417wmj.150.2017.11.16.08.11.15; Thu, 16 Nov 2017 08:11:15 -0800 (PST) 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 1C4DF680A22; Thu, 16 Nov 2017 18:10:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from was-smtp1.livetimenet.net (50-206-97-56-static.hfc.comcastbusiness.net [50.206.97.56]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9BB8268A106 for ; Thu, 16 Nov 2017 18:10:31 +0200 (EET) Received: by was-smtp1.livetimenet.net with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.84_2) (envelope-from ) id 1eFMkX-0008Gt-Sz; Thu, 16 Nov 2017 11:10:46 -0500 From: Devin Heitmueller To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Nov 2017 11:09:58 -0500 Message-Id: <20171116160958.92931-3-dheitmueller@ltnglobal.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20171116160958.92931-1-dheitmueller@ltnglobal.com> References: <20171116160958.92931-1-dheitmueller@ltnglobal.com> X-Spam-Score: -1.9 (-) Subject: [FFmpeg-devel] [PATCH 2/2] 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. This includes making sure the AFD data is preserved when going from an AVFrame to a V210 packet (needed for 10-bit support). Signed-off-by: Devin Heitmueller --- libavcodec/avcodec.h | 6 ++++++ libavcodec/v210enc.c | 11 +++++++++++ libavdevice/decklink_enc.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 442b558..6981f07 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1327,6 +1327,12 @@ enum AVPacketSideDataType { AV_PKT_DATA_A53_CC, /** + * Active Format Description data consisting of a single byte as specified + * in ETSI TS 101 154 using AVActiveFormatDescription enum. + */ + AV_PKT_DATA_AFD, + + /** * The number of side data elements (in fact a bit more than it). * This is not part of the public API/ABI in the sense that it may * change when new side data types are added. diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c index a825c03..c28f7b1 100644 --- a/libavcodec/v210enc.c +++ b/libavcodec/v210enc.c @@ -245,6 +245,17 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, } } + side_data = av_frame_get_side_data(pic, AV_FRAME_DATA_AFD); + if (side_data && side_data->size) { + uint8_t* buf = av_packet_new_side_data(pkt, AV_PKT_DATA_AFD, side_data->size); + if (buf) { + memcpy(buf, side_data->data, side_data->size); + } else { + av_log(avctx, AV_LOG_ERROR, "Unable to allocate afd side data\n"); + return AVERROR(ENOMEM); + } + } + pkt->flags |= AV_PKT_FLAG_KEY; *got_packet = 1; return 0; diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp index 0dcbe79..070bfad 100644 --- a/libavdevice/decklink_enc.cpp +++ b/libavdevice/decklink_enc.cpp @@ -280,7 +280,8 @@ av_cold int ff_decklink_write_trailer(AVFormatContext *avctx) #if CONFIG_LIBKLVANC 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, size; @@ -334,6 +335,42 @@ static int decklink_construct_vanc(AVFormatContext *avctx, struct decklink_ctx * } } + data = av_packet_get_side_data(pkt, AV_PKT_DATA_AFD, &size); + if (data) { + struct klvanc_packet_afd_s *pkt; + uint16_t *afd; + uint16_t len; + + ret = klvanc_create_AFD(&pkt); + if (ret != 0) + return AVERROR(ENOMEM); + + ret = klvanc_set_AFD_val(pkt, data[0]); + if (ret != 0) { + av_log(avctx, AV_LOG_ERROR, "Invalid AFD value specified: %d\n", + data[0]); + klvanc_destroy_AFD(pkt); + return AVERROR(EINVAL); + } + + /* FIXME: Should really rely on the coded_width but seems like that + is not accessible to libavdevice outputs */ + if ((st->codecpar->width == 1280 && st->codecpar->height == 720) || + (st->codecpar->width == 1920 && st->codecpar->height == 1080)) + pkt->aspectRatio = ASPECT_16x9; + else + pkt->aspectRatio = ASPECT_4x3; + + klvanc_convert_AFD_to_words(pkt, &afd, &len); + klvanc_destroy_AFD(pkt); + + ret = klvanc_line_insert(ctx->vanc_ctx, &vanc_lines, afd, len, 12, 0); + if (ret != 0) { + av_log(avctx, AV_LOG_ERROR, "VANC line insertion failed\n"); + return AVERROR(ENOMEM); + } + } + IDeckLinkVideoFrameAncillary *vanc; int result = ctx->dlo->CreateAncillaryData(bmdFormat10BitYUV, &vanc); if (result != S_OK) { @@ -429,7 +466,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 - ret = decklink_construct_vanc(avctx, ctx, pkt, frame); + ret = decklink_construct_vanc(avctx, ctx, pkt, frame, st); if (ret != 0) { av_log(avctx, AV_LOG_ERROR, "Failed to construct VANC\n"); }