From patchwork Wed Sep 21 19:26:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 38135 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp2847571pzh; Wed, 21 Sep 2022 12:26:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM634aHCBf7DaTOeummWoxDMRRZ7aYgrcKt1TtdCK5bR0pCUZsy3jfC0TF8430OecAs+zahT X-Received: by 2002:a17:907:6e1e:b0:782:19e7:f5e8 with SMTP id sd30-20020a1709076e1e00b0078219e7f5e8mr3065738ejc.215.1663788395760; Wed, 21 Sep 2022 12:26:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663788395; cv=none; d=google.com; s=arc-20160816; b=pyq4G9onbA3Nn3zNYjw83Hlx2Ik5lbFAoHCuj6bGEdBK//fOQxwIF4oS7adW/YTWwY 9n8iBRdtUreSfDI+jLy5sjkkghLSP+2+k4qYbDltYjujK5O4e9udKssKI2VDs7HmG8CH IqaIocDEjSUji2pelTzC1nwMZBwNkD6o0iJhDVKUTyDszY4SUCpZEnpIr1c5tHStUWx7 Bv+i5YGEWQ7/+2vJh4LCz5VQ2c7Dih9ZvfFPqWNbhfCPAFsOS3iE7tqG1hxt7+qhBXb2 JywmF388/SF+kcleht2oUgju/Tf61Obc9XrhaVyljm0T3bgcy0TpL8Q0iYolYDbgajhF bNyQ== 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=+Vef1BqiNNRAIgtpFeCJg9xwIX8Mx61+GqCHjK84eBc=; b=fndJ8mhZXW4jECYG1E/TV9qXw6fK4/G2taHhTC/1Z301nRoN5EhixjdbFLChCeBw5A 7xWE29FZEAUwrLgm0LCNIhq7r1ggI1XEulQQVfd7Ikla6psRxHpBirKaepdOBWR+DtE5 gZtf6+XZN6eiZiyTAQaPSr1fu6KDH/601hY0/vTxhF+/hry6ne6o/7f/1oMU77rooYN3 wR7uaNNlY2q5yn+wokh7NPZIzhY8sJKCqB10gLN7Wl3BdQVF7+bSi2MQNiBZNhevMK8h o7c98b5DQ/TlE/MVnXpaE0F6pcM7V/2ug3Riktl3+D7TW07tK5GYBEttzoj3+OqH8xS/ 4Aiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=kSdN0TQl; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d21-20020a50cd55000000b00448856bc455si3170253edj.592.2022.09.21.12.26.33; Wed, 21 Sep 2022 12:26:35 -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=@gmail.com header.s=20210112 header.b=kSdN0TQl; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 14FBF68BAF5; Wed, 21 Sep 2022 22:26:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ABAEB68B82B for ; Wed, 21 Sep 2022 22:26:23 +0300 (EEST) Received: by mail-qk1-f179.google.com with SMTP id d17so4682745qko.13 for ; Wed, 21 Sep 2022 12:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=r7jcdLBgo8v6pL9CpqQ52p4rVAjlnorZ71u+CBo0cUY=; b=kSdN0TQlCjEwzSed6hAuBi6oNnsvH2YqbmRfEB1xua7B3ptjfBRrKH2jOuFL92GTpi rAtEu8tGRmXMUnSqSP3VmL73Zxlkf3llykFeRE14+MnqwUm+bMwo9LKZ84A0ZQsk6ger QgC6cn1lXaoV9U7W7/ybuj+YB2wHUQ9UEOJVZpjZYoMO4wPR0uUQFhQxNnOYCnjqX+VC UL5Mazh1WU8uM8CsKmwx+4OPz/OyBplHsdEECFJwe98TniUnLbbMlMAJGsTeghH1izow o3O91hMIogtIjpa2JMGhrjC3QGUKx7dIOzdtWv4kXDFb9fYEG9FXKizlW7ERwQ3Imhc3 gPQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=r7jcdLBgo8v6pL9CpqQ52p4rVAjlnorZ71u+CBo0cUY=; b=63zGEVqfBi4oW2vcyuhPFGyG+gUMEXbDPHQKzR6uYobrBQcFwSIb5D3hWVOHwsp8+W IPs/1DBBkYDa8w2t/MtRYUXIJwDiIpkx/XPuAy6ba3bNrkxnZ5LVzSlOKvCWqUTlg+F7 yZ1y1XcbupG5pSqzfErH0g6aOatpC0gae2TH9HeTm4OhLk8cX8tG4kTKlYiUCXFKN0HA Cf3IF+Tm1agTZwZCX9PYNUBYVZzDpmA0ABxINeAOx3EYFFUv4Y4oDpPaoimajo6d2i9f xmbmXFpJxJrnxfmpNgYQ99oX6X+2Z+TZC3Pkcmu1njnQTIJjd/auA6zMrm+zl9VKiGY5 7zyA== X-Gm-Message-State: ACrzQf2BM+2dSf6yzroVKWJwG6BrcjuYgJMf30BuWEkbgCjv8gkEsPtw CIoYCm6sohiB0mIO9GcZGuu0VHqTruE= X-Received: by 2002:a05:620a:2683:b0:6cf:3a7e:e006 with SMTP id c3-20020a05620a268300b006cf3a7ee006mr6449831qkp.474.1663788381379; Wed, 21 Sep 2022 12:26:21 -0700 (PDT) Received: from scott-desktop.. (pool-71-114-80-52.washdc.fios.verizon.net. [71.114.80.52]) by smtp.gmail.com with ESMTPSA id e3-20020ac84e43000000b0031f0b43629dsm2366339qtw.23.2022.09.21.12.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 12:26:20 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Wed, 21 Sep 2022 15:26:11 -0400 Message-Id: <20220921192611.3241-1-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc: export flag for MPEG audio dual channel 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: ulmus-scott Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: SpZ+34z94p1g From: ulmus-scott The flag identifies two independant mono channels recorded as stereo. This change has been kicking around in the MythTV modifications since 2006. See https://github.com/MythTV/mythtv/commit/435540c9e8ac245ceca968791c67431f37c8d617 I have changed the names and comment. For the current MythTV modification see https://github.com/ulmus-scott/FFmpeg/commit/645fa6f9a61d23bac0665851d211bbeb3686deb0 --- libavcodec/audiotoolboxdec.c | 2 +- libavcodec/avcodec.h | 11 +++++++++++ libavcodec/mpegaudio_parser.c | 2 +- libavcodec/mpegaudiodecheader.c | 4 +++- libavcodec/mpegaudiodecheader.h | 2 +- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c index 82babe3d31..9d11844142 100644 --- a/libavcodec/audiotoolboxdec.c +++ b/libavcodec/audiotoolboxdec.c @@ -346,7 +346,7 @@ static av_cold int ffat_create_decoder(AVCodecContext *avctx, int bit_rate; if (ff_mpa_decode_header(AV_RB32(pkt->data), &avctx->sample_rate, &in_format.mChannelsPerFrame, &avctx->frame_size, - &bit_rate, &codec_id) < 0) + &bit_rate, &codec_id, &avctx->mpeg_audio_mode_dual_channel) < 0) return AVERROR_INVALIDDATA; avctx->bit_rate = bit_rate; in_format.mSampleRate = avctx->sample_rate; diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 7db5d1b1c5..bcf3a845a8 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2076,6 +2076,17 @@ typedef struct AVCodecContext { * The decoder can then override during decoding as needed. */ AVChannelLayout ch_layout; + + /** + * Audio only. This flag is set when MPEG audio mode dual channel has been detected. + * This signals that the audio is two independent mono channels. + * + * 0 normally, 1 if dual channel flag is set. + * + * - encoding: currently unused (functionally equivalent to stereo, patch welcome) + * - decoding: set by lavc + */ + int mpeg_audio_mode_dual_channel; } AVCodecContext; /** diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c index d54366f10a..d957cf467f 100644 --- a/libavcodec/mpegaudio_parser.c +++ b/libavcodec/mpegaudio_parser.c @@ -70,7 +70,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1, state= (state<<8) + buf[i++]; - ret = ff_mpa_decode_header(state, &sr, &channels, &frame_size, &bit_rate, &codec_id); + ret = ff_mpa_decode_header(state, &sr, &channels, &frame_size, &bit_rate, &codec_id, &avctx->mpeg_audio_mode_dual_channel); if (ret < 4) { if (i > 4) s->header_count = -2; diff --git a/libavcodec/mpegaudiodecheader.c b/libavcodec/mpegaudiodecheader.c index ef63befbf4..6c9a641906 100644 --- a/libavcodec/mpegaudiodecheader.c +++ b/libavcodec/mpegaudiodecheader.c @@ -117,7 +117,7 @@ int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) return 0; } -int ff_mpa_decode_header(uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate, enum AVCodecID *codec_id) +int ff_mpa_decode_header(uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate, enum AVCodecID *codec_id, int *dual_mono) { MPADecodeHeader s1, *s = &s1; @@ -148,5 +148,7 @@ int ff_mpa_decode_header(uint32_t head, int *sample_rate, int *channels, int *fr *sample_rate = s->sample_rate; *channels = s->nb_channels; *bit_rate = s->bit_rate; + *dual_mono = (s->mode == MPA_DUAL) ? 1 : 0; + return s->frame_size; } diff --git a/libavcodec/mpegaudiodecheader.h b/libavcodec/mpegaudiodecheader.h index ed5d1f3b33..e599d287f7 100644 --- a/libavcodec/mpegaudiodecheader.h +++ b/libavcodec/mpegaudiodecheader.h @@ -56,7 +56,7 @@ int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header); /* useful helper to get MPEG audio stream info. Return -1 if error in header, otherwise the coded frame size in bytes */ int ff_mpa_decode_header(uint32_t head, int *sample_rate, - int *channels, int *frame_size, int *bitrate, enum AVCodecID *codec_id); + int *channels, int *frame_size, int *bitrate, enum AVCodecID *codec_id, int *dual_mono); /* fast header check for resync */ static inline int ff_mpa_check_header(uint32_t header){