From patchwork Fri Mar 17 15:02:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Heitmueller X-Patchwork-Id: 40711 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d046:b0:cd:afd7:272c with SMTP id hv6csp635912pzb; Fri, 17 Mar 2023 08:02:48 -0700 (PDT) X-Google-Smtp-Source: AK7set9I388AayJ0Jq+3iTKluJgCLYZCYy8ZZSAFFrgeolaPq19NjBYcLGevzQ3m5NZZW5ElYPdv X-Received: by 2002:a17:907:2c59:b0:921:412b:d8c1 with SMTP id hf25-20020a1709072c5900b00921412bd8c1mr13689688ejc.71.1679065368609; Fri, 17 Mar 2023 08:02:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679065368; cv=none; d=google.com; s=arc-20160816; b=W6YTccI8yFSpjtXO6PwGQLt3k+l+AGOrbJJ90z4qBsOPvLeB9H/01RqTGxssxOW8sV 191eWnk3My6sSzgWEr8zXFBgo2KUVqBCqgwjjnujJKvjjJCvHR6FUN+OeoaXILFXxiys Q2F50wz+9+jjifjF6Mo0v66KKV9L5zH1BA+BLSzUUOzc+2ez4d4p6mH17n21J+htsoXi PY+ucev4prDMyP+tkpcFgFudEGGaTC/Ph2fhVIj9Syj8gI71WhHKUkJrP0w/y/iMhpPz rYPMBjnhHHZzxdQaoP2mPSa5ZlzeshMJMJ1rzUgLyPziECl/AxeR8kcm2ZBJvNULbFoU VfKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=lsiU7fXbnEfxWHjTTRsSMzXSeowsVK0SrMf7kG6k2r0=; b=noAEUIdk7ctda+m5T73mkUYKW2OoTGdE5miXRBibLZDkWTf2Pn1fLRLtzWLluxdBOA 8V9ReBrOeUj2IVqeRaZJXUbNSIUoyP7PhPVOrBR6XvhsalpSBEwkjEutUcVtC4b95qXZ bVT8XuxyJADw6Q/sLpOdNriumCMz9vjBcotgm2fZDH+2+kMdO3VrGAiaUmCE7ZGGCzTA R7Ov1befRw/Qay8LdtI8brEW69fbfvLrwX6sETpY3Wv5EFEqJaRJbbPCm83IR1i9iixY bhOJ37PLECq2kVzMSE0T5M0MGbFmk/RgF5pz7ZXwu8p3joSG4aDs89mKMCuJprbJFXeq X/ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ltnglobal-com.20210112.gappssmtp.com header.s=20210112 header.b=VxdCsaDg; 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 i14-20020a1709064ece00b00930ca0feb65si2280374ejv.1001.2023.03.17.08.02.47; Fri, 17 Mar 2023 08:02:48 -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; dkim=neutral (body hash did not verify) header.i=@ltnglobal-com.20210112.gappssmtp.com header.s=20210112 header.b=VxdCsaDg; 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 4B4CC68C1D1; Fri, 17 Mar 2023 17:02:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A944D68C198 for ; Fri, 17 Mar 2023 17:02:37 +0200 (EET) Received: by mail-qt1-f173.google.com with SMTP id r16so5844314qtx.9 for ; Fri, 17 Mar 2023 08:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ltnglobal-com.20210112.gappssmtp.com; s=20210112; t=1679065356; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=eB3QUOtYzHOtOttNDyuOMgkcn/tWlRQ7wEcXjvawcn8=; b=VxdCsaDgLNlgSwE6sgKGZ79A+VqhJMRV9D+rKggpPNsgXSgH0brfi878Kk1kARbffC Ym060dOX6WrdzyowGuqbZS5yKajsrWSsXz8nlprvmvz9gUd+bZ/L9cxu1WgwPn1yNpgr 09FwmCalZuQ8AEciCzPWuqHz/0/T5earpurPynE6X88l/PRCbmQnvhc7q9Q7sC1hZFxS aZubnb2fmDnS1j+uQYdC/EPx5LwsyI+CyEa5XAJaZMW7akR2ngw726A4HZyHqt8E7QCA hvdPQZEab6bsYFNl3owN99Dh9l5ZA8y5AbEPWz/HE1idbbJsr5mE/3DkE2HcHNIQsdXM vLXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679065356; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eB3QUOtYzHOtOttNDyuOMgkcn/tWlRQ7wEcXjvawcn8=; b=FrRQx3HcefPt5yEVknAZUfNziD/jglwgdn7ZyBzjIhudmC/sge2yyeEUCroupKrb31 W7RP6RqJjPMS3LIMn+HAiyenZR+DlnzBNFiir4dNAj3slUTlnHkeoUwvatxQsOyIIKFq VZ5ixapDvwQP7J0AFH02fyFTuKfIU4WiiNKbLgbRQ/xW4ZrXliQbb1mYqLfZX7rmktQ7 IjkjK0dTpWDFyVM0eVR8TUx4kZ9PM7NUdREi1JmEs75zk8WovyKpG+BLhhLcOjjMYBNh rvQJ66J9/8yUK5Kg0tjdPn96dOTxuA4OKxFTEplcXlFlqnxSeqO2ulN4qsgbvZHcJobZ QKaA== X-Gm-Message-State: AO0yUKWTWpxgfLBTrcp0XnzMjAEjaEHy/hCoL392KRRh8AW82zJ5vVme r4g8XUhdbvqaQo5pwmR5axaAayeOkL6xxGCAWVM= X-Received: by 2002:ac8:5a0c:0:b0:3bf:e796:bfdd with SMTP id n12-20020ac85a0c000000b003bfe796bfddmr5977278qta.9.1679065356112; Fri, 17 Mar 2023 08:02:36 -0700 (PDT) Received: from klab-nyc-kernellabs2.localdomain (pool-71-105-132-214.nycmny.fios.verizon.net. [71.105.132.214]) by smtp.gmail.com with ESMTPSA id v127-20020a379385000000b007456c75edbbsm1768469qkd.129.2023.03.17.08.02.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Mar 2023 08:02:35 -0700 (PDT) From: Devin Heitmueller X-Google-Original-From: Devin Heitmueller To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 Mar 2023 11:02:31 -0400 Message-Id: <20230317150232.17804-1-dheitmueller@ltnglobal.com> X-Mailer: git-send-email 2.35.1.655.ga68dfadae5 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/2] avcodec: Fix warnings with signed/unsigned compare in bitstream.h X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Devin Heitmueller Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: VnUeXWNPDDPj When including the header in decklink_enc.cpp it would be fed through the C++ compiler rather than the C compiler, which has more strict warnings when comparing signed/unsigned values. Make the local variables unsigned to match the arguments they are being passed for those functions. Signed-off-by: Devin Heitmueller --- libavcodec/bytestream.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h index d0033f14f3..67080604b9 100644 --- a/libavcodec/bytestream.h +++ b/libavcodec/bytestream.h @@ -180,7 +180,7 @@ static av_always_inline void bytestream2_skipu(GetByteContext *g, static av_always_inline void bytestream2_skip_p(PutByteContext *p, unsigned int size) { - int size2; + unsigned int size2; if (p->eof) return; size2 = FFMIN(p->buffer_end - p->buffer, size); @@ -268,7 +268,7 @@ static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size) { - int size2 = FFMIN(g->buffer_end - g->buffer, size); + unsigned int size2 = FFMIN(g->buffer_end - g->buffer, size); memcpy(dst, g->buffer, size2); g->buffer += size2; return size2; @@ -287,7 +287,7 @@ static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size) { - int size2; + unsigned int size2; if (p->eof) return 0; size2 = FFMIN(p->buffer_end - p->buffer, size); @@ -311,7 +311,7 @@ static av_always_inline void bytestream2_set_buffer(PutByteContext *p, const uint8_t c, unsigned int size) { - int size2; + unsigned int size2; if (p->eof) return; size2 = FFMIN(p->buffer_end - p->buffer, size); @@ -348,7 +348,7 @@ static av_always_inline unsigned int bytestream2_copy_buffer(PutByteContext *p, GetByteContext *g, unsigned int size) { - int size2; + unsigned int size2; if (p->eof) return 0; From patchwork Fri Mar 17 15:02:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Heitmueller X-Patchwork-Id: 40710 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d046:b0:cd:afd7:272c with SMTP id hv6csp636123pzb; Fri, 17 Mar 2023 08:03:01 -0700 (PDT) X-Google-Smtp-Source: AK7set/WbjovKc2cI6ZGTtcaKTt7039ny/rdSu1MQlqj5yC+XhVCCu35Z3TlEQ/vhdIJt7CggX/D X-Received: by 2002:a17:906:2a56:b0:878:72f7:bd99 with SMTP id k22-20020a1709062a5600b0087872f7bd99mr14103724eje.6.1679065381236; Fri, 17 Mar 2023 08:03:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679065381; cv=none; d=google.com; s=arc-20160816; b=yCBzfWylbDWGFrO1HNQhO5ciDoHnWfQoWC6qcfSt3lxKD/ygKd73y18I0Lr8AQcrDB gVtd8l7DlUKWHUehhxiBmeUiByBMyYHNuwibTJi4DIqQxUug7+kFELQWXNw4yxffXvX7 8SIy8lUq0g78alPf8URXW5+6RTBZxEKlY1mUAzI8/d49FCDdNnugbNZarXB5todxMg8q 8JX1UFCBL2OBVyxKcEC2wgE1TwxuSCLFMGNW3TpuFO/Fxq6P4GoNWflq6y+LF4zehuni ND7B2SicLX+7I7E10WXx6pMFRclgAhg4oDEs7Ra8jd3YwGDA8gMjhi4gjKrCZwoMOBU5 lN1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=Ru6wGKpsKEMSmp+V6C/BV0UlcEzo53FS2hXb/xYOhns=; b=tW2KJygaxnldZlEL1U9auSEf6Ekh+phlYcOzIFlXM9Sajw8tWoonVtkIm2YgHAb6t0 SkxXOp3d0bBen74ds6JIn1vEDvix4YhblMyoOihNmXjhiFi7r4LVyxL99wVxD9Tv40TW QwDeTIYFGF5a+rkDq/pEF26f8qiAjRUJbvNpg9IE9qKVVBayHS1VT7pMzW0HGL2WjcYl laBVP0ktHfWpndbNJ/Og1X1rksXP64mZpCffXRteNz7YEjBv4Fu7SALIV9CzEmvhzChm a3urtzEGPZTOKoHMbsCa+F1GAcU+2xHtcFuEo/Gk9zut81qIBrb00pKW83kF7CuMkEe+ qoLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ltnglobal-com.20210112.gappssmtp.com header.s=20210112 header.b=6riqjnwI; 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 h2-20020a17090634c200b008d207402fccsi2223275ejb.721.2023.03.17.08.03.00; Fri, 17 Mar 2023 08:03:01 -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; dkim=neutral (body hash did not verify) header.i=@ltnglobal-com.20210112.gappssmtp.com header.s=20210112 header.b=6riqjnwI; 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 6F35668C198; Fri, 17 Mar 2023 17:02:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6C62668C128 for ; Fri, 17 Mar 2023 17:02:38 +0200 (EET) Received: by mail-qt1-f179.google.com with SMTP id hf2so1712440qtb.3 for ; Fri, 17 Mar 2023 08:02:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ltnglobal-com.20210112.gappssmtp.com; s=20210112; t=1679065357; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2iy+Gs/W7TvXhpcrUBJcn5Np9KIcLiPBWiCKYc/F4n0=; b=6riqjnwIlWEaENkdzdsSIcK2DCYXMHQrU3wWnWKUbRBT0MOIEi+LdZzV+j5NppE9pW IuD6cpi6TV/yRG6AjKlpmUbQ0Ua2j525sGD22df+R2qgvsB0J8i+yt9WT8t4xnSvAgHH IymdW2NAtcK6d7GpjUs1ks9iIXOQMRgxCuuakFMy2yUaMynCmv8sU9hrXlYkJZ+KRuR+ fjeQu3A5emnVQg+HFLgS4tzYif36xbJc63vBdRihs2y3HVIC1PrRqy9MSYD9LVsR04ez aiOZlPlwgjSx5eJKkgijj/keZGsLxYOhNBqHfNQOAIgy9FqnWm8shPiZQFWMSCKOqiQu JCRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679065357; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2iy+Gs/W7TvXhpcrUBJcn5Np9KIcLiPBWiCKYc/F4n0=; b=3A8BSyPVs5xXyhWcZ0Z95QH8VWxTf7Mp0etqt8YCIRBF9cP7UOAJBggopiV5sA1NJK XhoqFfo+YsNKwud1isqoJcbqSXfuUWcFlx6qCJES7fVnALuRFKQg6VTWdv/85b1E2ETw SEKi4aJa5gsGpuxXHW1eNYf662CPv0cqSPOLGtbRNQU9eJlUeNQ9hhqEqTpmZLpYJDnK tG/LS4Rfzexsf1k2QR0e3LFb3SA64HDLdT7rw19bclj38kJfHKDdn52kgmhRrRUTEi0N Sqxm/12DdQINGy8USrd8v3tKA+no5fa+A3UViFE/euzGxdLQErhY4ySr7r7kKHmSrO76 gPKg== X-Gm-Message-State: AO0yUKVCEtXBmVbiVSW2nff8UFVkVcxKvTqhgw797l95CqZ8g4xNNpHZ XeRjXUkCtfrl1rI9Yo4KwKJRPszWKJn2HuIFTVc= X-Received: by 2002:ac8:5fc3:0:b0:3dc:3a38:3bda with SMTP id k3-20020ac85fc3000000b003dc3a383bdamr622483qta.19.1679065356787; Fri, 17 Mar 2023 08:02:36 -0700 (PDT) Received: from klab-nyc-kernellabs2.localdomain (pool-71-105-132-214.nycmny.fios.verizon.net. [71.105.132.214]) by smtp.gmail.com with ESMTPSA id v127-20020a379385000000b007456c75edbbsm1768469qkd.129.2023.03.17.08.02.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Mar 2023 08:02:36 -0700 (PDT) From: Devin Heitmueller X-Google-Original-From: Devin Heitmueller To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 Mar 2023 11:02:32 -0400 Message-Id: <20230317150232.17804-2-dheitmueller@ltnglobal.com> X-Mailer: git-send-email 2.35.1.655.ga68dfadae5 In-Reply-To: <20230317150232.17804-1-dheitmueller@ltnglobal.com> References: <20230317150232.17804-1-dheitmueller@ltnglobal.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/2] decklink: Add support for compressed AC-3 output over SDI X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Devin Heitmueller Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 8ekt+WzzKegt Extend the decklink output to include support for compressed AC-3, encapsulated using the SMPTE ST 377:2015 standard. This functionality can be exercised by using the "copy" codec when the input audio stream is AC-3. For example: ./ffmpeg -i ~/foo.ts -codec:a copy -f decklink 'UltraStudio Mini Monitor' Note that the default behavior continues to be to do PCM output, which means without specifying the copy codec a stream containing AC-3 will be decoded and downmixed to stereo audio before output. Thanks to Marton Balint for providing feedback. Signed-off-by: Devin Heitmueller --- libavdevice/decklink_enc.cpp | 90 ++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 15 deletions(-) diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp index 8d423f6b6e..8d80f00247 100644 --- a/libavdevice/decklink_enc.cpp +++ b/libavdevice/decklink_enc.cpp @@ -32,6 +32,7 @@ extern "C" { extern "C" { #include "libavformat/avformat.h" +#include "libavcodec/bytestream.h" #include "libavutil/internal.h" #include "libavutil/imgutils.h" #include "avdevice.h" @@ -243,19 +244,32 @@ static int decklink_setup_audio(AVFormatContext *avctx, AVStream *st) av_log(avctx, AV_LOG_ERROR, "Only one audio stream is supported!\n"); return -1; } - if (c->sample_rate != 48000) { - av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate!" - " Only 48kHz is supported.\n"); - return -1; - } - if (c->ch_layout.nb_channels != 2 && c->ch_layout.nb_channels != 8 && c->ch_layout.nb_channels != 16) { - av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels!" - " Only 2, 8 or 16 channels are supported.\n"); + + if (c->codec_id == AV_CODEC_ID_AC3) { + /* Regardless of the number of channels in the codec, we're only + using 2 SDI audio channels at 48000Hz */ + ctx->channels = 2; + } else if (c->codec_id == AV_CODEC_ID_PCM_S16LE) { + if (c->sample_rate != 48000) { + av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate!" + " Only 48kHz is supported.\n"); + return -1; + } + if (c->ch_layout.nb_channels != 2 && c->ch_layout.nb_channels != 8 && c->ch_layout.nb_channels != 16) { + av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels!" + " Only 2, 8 or 16 channels are supported.\n"); + return -1; + } + ctx->channels = c->ch_layout.nb_channels; + } else { + av_log(avctx, AV_LOG_ERROR, "Unsupported codec specified!" + " Only PCM_S16LE and AC-3 are supported.\n"); return -1; } + if (ctx->dlo->EnableAudioOutput(bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger, - c->ch_layout.nb_channels, + ctx->channels, bmdAudioOutputStreamTimestamped) != S_OK) { av_log(avctx, AV_LOG_ERROR, "Could not enable audio output!\n"); return -1; @@ -266,14 +280,41 @@ static int decklink_setup_audio(AVFormatContext *avctx, AVStream *st) } /* The device expects the sample rate to be fixed. */ - avpriv_set_pts_info(st, 64, 1, c->sample_rate); - ctx->channels = c->ch_layout.nb_channels; + avpriv_set_pts_info(st, 64, 1, 48000); ctx->audio = 1; return 0; } +static int create_s337_payload(AVPacket *pkt, enum AVCodecID codec_id, uint8_t **outbuf, int *outsize) +{ + int payload_size = pkt->size + 8; + uint16_t bitcount = pkt->size * 8; + uint8_t *s337_payload; + PutByteContext pb; + int i; + + if (codec_id != AV_CODEC_ID_AC3) + return AVERROR(EINVAL); + + /* Encapsulate AC3 syncframe into SMPTE 337 packet */ + s337_payload = (uint8_t *) av_mallocz(payload_size); + if (s337_payload == NULL) + return AVERROR(ENOMEM); + bytestream2_init_writer(&pb, s337_payload, payload_size); + bytestream2_put_le16u(&pb, 0xf872); /* Sync word 1 */ + bytestream2_put_le16u(&pb, 0x4e1f); /* Sync word 1 */ + bytestream2_put_le16u(&pb, 0x0001); /* Burst Info, including data type (1=ac3) */ + bytestream2_put_le16u(&pb, bitcount); /* Length code */ + for (i = 0; i < pkt->size; i += 2) + bytestream2_put_le16u(&pb, (pkt->data[i] << 8) | pkt->data[i+1]); + + *outsize = payload_size; + *outbuf = s337_payload; + return 0; +} + av_cold int ff_decklink_write_trailer(AVFormatContext *avctx) { struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data; @@ -531,21 +572,40 @@ static int decklink_write_audio_packet(AVFormatContext *avctx, AVPacket *pkt) { struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data; struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx; - int sample_count = pkt->size / (ctx->channels << 1); + AVStream *st = avctx->streams[pkt->stream_index]; + int sample_count; uint32_t buffered; + uint8_t *outbuf = NULL; + int ret = 0; ctx->dlo->GetBufferedAudioSampleFrameCount(&buffered); if (pkt->pts > 1 && !buffered) av_log(avctx, AV_LOG_WARNING, "There's no buffered audio." " Audio will misbehave!\n"); - if (ctx->dlo->ScheduleAudioSamples(pkt->data, sample_count, pkt->pts, + if (st->codecpar->codec_id == AV_CODEC_ID_AC3) { + /* Encapsulate AC3 syncframe into SMPTE 337 packet */ + int outbuf_size; + ret = create_s337_payload(pkt, st->codecpar->codec_id, + &outbuf, &outbuf_size); + if (ret) + return ret; + sample_count = outbuf_size / 4; + } else { + sample_count = pkt->size / (ctx->channels << 1); + outbuf = pkt->data; + } + + if (ctx->dlo->ScheduleAudioSamples(outbuf, sample_count, pkt->pts, bmdAudioSampleRate48kHz, NULL) != S_OK) { av_log(avctx, AV_LOG_ERROR, "Could not schedule audio samples.\n"); - return AVERROR(EIO); + ret = AVERROR(EIO); } - return 0; + if (st->codecpar->codec_id == AV_CODEC_ID_AC3) + av_freep(&outbuf); + + return ret; } extern "C" {