From patchwork Thu Feb 9 04:41:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marth64 X-Patchwork-Id: 40332 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp127365pzk; Wed, 8 Feb 2023 20:42:24 -0800 (PST) X-Google-Smtp-Source: AK7set8LvMXPD+VbCK3NWmOD8Zy574h0elV9U0h61OGOO8mqx6YFtiAuZdgcAT5O2W04ZhO51iR+ X-Received: by 2002:a17:906:2ed4:b0:878:7c18:8fd9 with SMTP id s20-20020a1709062ed400b008787c188fd9mr9993615eji.44.1675917743762; Wed, 08 Feb 2023 20:42:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675917743; cv=none; d=google.com; s=arc-20160816; b=W+zoDPeau52ib2l20Ty6+6AzxOq/3gWSWof7G8J3YqHRQoYsYKd0VAimZN0WHxROQq 4aPc6nWuEW6ia65u/UInpFjKOa3mcVKosnoBYmOxW+rUno9dEL9OVSjn+OvQq2nTMC67 Qhx8UoO+ij6lPXCmivnZ4ntkaBQ3Ofv7IzGNQ8+Nstz8C37TgHZHXyBB55cZiQF0TEBp O92XjQRc5Mbmx8p26PXbgy7nNkBiRl7PHB5VMf9W7b/bFgzLq9irCERJbihQWM6oGVaD gWxf745m86L7z/5ECUcGw9ppzy7AFVWNi/Bz83BebAH3+DmtfOJUgbdrjQbxLWKemuBF aiMg== 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 :delivered-to; bh=hkts2YYHB4abYhZXvNwA122S2poYwi9ttEfjX5M6JQ0=; b=L+N42p9A9l+P7ItCV0Aywgu5EkJKWVk/cwpmx6mZIg6alumW8mHlGGCzIwqoxE4sJW ChE9bsBP5vBREP4YzHIi9rTcgmaCmG3oy0AqHwi2SkqC3j4lMXjYRZ1FhC77F3QOMYhO JN4+PHzmWznPJVuP+ZR3Kgl/anZiczWRhDWLPHV8eN60PM8JG5wYJmjExPUlMGd2XWKP Y5fH9OO+tXWDgD849A6m8RUpBR2D/iOxcLBW/Dl7Pue+PpAWNV+LPU76rdEGBdSIBDhY TgGNW2uljbaW8lr+nRksFC1YApScPEoB9HipaxB0OEp0kYNo+NHy5YkmuR1Y93BmjKQo iArw== 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 29-20020a170906015d00b0089dfa7a0edasi1130869ejh.443.2023.02.08.20.42.22; Wed, 08 Feb 2023 20:42:23 -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 364B068BE7A; Thu, 9 Feb 2023 06:42:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4B8DD68BACD for ; Thu, 9 Feb 2023 06:42:12 +0200 (EET) Received: by mail-qt1-f172.google.com with SMTP id h24so857341qtr.0 for ; Wed, 08 Feb 2023 20:42:11 -0800 (PST) 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:message-id :reply-to; bh=tivTR21xW8cYDbhuD9Jvvxzhb020xq4do9BxbwTzWUU=; b=C8I49kK8OENqI8WqM6zXtgVkyNUBxaSp6wAdW8yM/7EYCtvBG3whmT6jyXv1fDPzZj 1NJW5H+46laI5JPUVy9lwPadw08pMWPCgjDSWMAd9npUE6tfkXKHpi+Ouqz+reVmYCrl UfyR9Cr7nkQt56MqEl0gkkQ5tyuJcDQq/RxdfYlo7nTFhLow7284Ts+M7ItiZOkrbYrs Y2X2KXszq45HvyVA91etd5+SDtcHtxN0xATlT3BYdiybKNLIuVdXu+zmZeBLSgHEzQ1m oxay2ceD64jxt+bgDbICQRLzjku8PDuAnxyMYRfM+DXpgd6okZIXA7xd2+zy51/V0E34 x/Iw== X-Gm-Message-State: AO0yUKVAGc+8WQdw7n1eonNUWz9OAp9lDVV2wG+yfn3prayGxp2D0yaj C83Pbe3Gy27nF59OZkUVgUK1COn2Gy7RS6CsG2AG3Z8ppKPIPkFRTGsZHn4rZcRHQfs7XFb0Wfx ejobLrtJ9qfCv18yq8tzUlZeQ8t9o4oxRv3zzx21JkZi9UAEP8DApBQJqwWzZ3iu3MKr13A== X-Received: by 2002:a05:622a:4b:b0:3b8:6d44:ca7e with SMTP id y11-20020a05622a004b00b003b86d44ca7emr19564944qtw.4.1675917729928; Wed, 08 Feb 2023 20:42:09 -0800 (PST) Received: from localhost.localdomain ([76.141.0.17]) by smtp.gmail.com with ESMTPSA id ce11-20020a05622a41cb00b003b9b4028d63sm524481qtb.80.2023.02.08.20.42.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 20:42:09 -0800 (PST) From: Marth64 To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 Feb 2023 22:41:00 -0600 Message-Id: <20230209044058.2872534-1-marth64@proxyid.net> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] ffprobe/eac3/mlp/dca: add detection of spatial audio extensions 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: Marth64 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 2AZ65Z2XydmP Signed-off-by: Marth64 --- Adds detection of spatial/object-based audio extensions in E-AC-3, TrueHD, and DCA XLL (DTS). This includes Atmos, DTS:X, and IMAX formats. Please let me know what I could improve, I'm learning still. Thank you. doc/ffprobe.xsd | 1 + fftools/ffprobe.c | 3 +++ libavcodec/ac3dec.c | 1 + libavcodec/ac3dec.h | 1 + libavcodec/avcodec.h | 6 ++++++ libavcodec/codec_par.c | 2 ++ libavcodec/codec_par.h | 6 ++++++ libavcodec/dca_syncwords.h | 3 +++ libavcodec/dca_xll.c | 14 ++++++++++++++ libavcodec/eac3dec.c | 11 ++++++++++- libavcodec/mlpdec.c | 9 +++++++++ 11 files changed, 56 insertions(+), 1 deletion(-) diff --git a/doc/ffprobe.xsd b/doc/ffprobe.xsd index 0920380108..a01a4359dc 100644 --- a/doc/ffprobe.xsd +++ b/doc/ffprobe.xsd @@ -247,6 +247,7 @@ + diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index dfa7ff1b24..7e81088c56 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -3071,6 +3071,9 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id print_int("bits_per_sample", av_get_bits_per_sample(par->codec_id)); print_int("initial_padding", par->initial_padding); + if (par->spatial_ext > 0) { + print_int("spatial_ext", par->spatial_ext); + } break; case AVMEDIA_TYPE_SUBTITLE: diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index 0b120e6140..009acd9ff6 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -1714,6 +1714,7 @@ skip: if (!err) { avctx->sample_rate = s->sample_rate; avctx->bit_rate = s->bit_rate + s->prev_bit_rate; + avctx->spatial_ext = s->eac3_extension_type_a == 1; } if (!avctx->sample_rate) { diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h index 138b462abb..0829f4b40d 100644 --- a/libavcodec/ac3dec.h +++ b/libavcodec/ac3dec.h @@ -102,6 +102,7 @@ typedef struct AC3DecodeContext { int eac3; ///< indicates if current frame is E-AC-3 int eac3_frame_dependent_found; ///< bitstream has E-AC-3 dependent frame(s) int eac3_subsbtreamid_found; ///< bitstream has E-AC-3 additional substream(s) + int eac3_extension_type_a; ///< bitstream has E-AC-3 extension type A enabled frame(s) int dolby_surround_mode; ///< dolby surround mode (dsurmod) int dolby_surround_ex_mode; ///< dolby surround ex mode (dsurexmod) int dolby_headphone_mode; ///< dolby headphone mode (dheadphonmod) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 755e543fac..8b54a99313 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2104,6 +2104,12 @@ typedef struct AVCodecContext { * The decoder can then override during decoding as needed. */ AVChannelLayout ch_layout; + + /** + * Audio only. Whether or not a spatial audio extension is + * detected in the stream (object-based surround). + */ + int spatial_ext; } AVCodecContext; /** diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c index abda649aa8..02f6da5059 100644 --- a/libavcodec/codec_par.c +++ b/libavcodec/codec_par.c @@ -161,6 +161,7 @@ FF_ENABLE_DEPRECATION_WARNINGS par->initial_padding = codec->initial_padding; par->trailing_padding = codec->trailing_padding; par->seek_preroll = codec->seek_preroll; + par->spatial_ext = codec->spatial_ext; break; case AVMEDIA_TYPE_SUBTITLE: par->width = codec->width; @@ -243,6 +244,7 @@ FF_ENABLE_DEPRECATION_WARNINGS codec->initial_padding = par->initial_padding; codec->trailing_padding = par->trailing_padding; codec->seek_preroll = par->seek_preroll; + codec->spatial_ext = par->spatial_ext; break; case AVMEDIA_TYPE_SUBTITLE: codec->width = par->width; diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h index f51d27c590..287b138b6b 100644 --- a/libavcodec/codec_par.h +++ b/libavcodec/codec_par.h @@ -211,6 +211,12 @@ typedef struct AVCodecParameters { * Audio only. The channel layout and number of channels. */ AVChannelLayout ch_layout; + + /** + * Audio only. Whether or not a spatial audio extension is + * detected in the stream (object-based surround). + */ + int spatial_ext; } AVCodecParameters; /** diff --git a/libavcodec/dca_syncwords.h b/libavcodec/dca_syncwords.h index 4d2cd5f56d..ccbc38bb38 100644 --- a/libavcodec/dca_syncwords.h +++ b/libavcodec/dca_syncwords.h @@ -33,4 +33,7 @@ #define DCA_SYNCWORD_SUBSTREAM_CORE 0x02B09261U #define DCA_SYNCWORD_REV1AUX 0x9A1105A0U +#define DCA_SYNCWORD_XLL_X 0x20008 +#define DCA_SYNCWORD_XLL_IMAX (0xF14000D0 >> 1) + #endif /* AVCODEC_DCA_SYNCWORDS_H */ diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c index fe2c766d98..6b64f907cc 100644 --- a/libavcodec/dca_xll.c +++ b/libavcodec/dca_xll.c @@ -1043,6 +1043,7 @@ static int parse_band_data(DCAXllDecoder *s) static int parse_frame(DCAXllDecoder *s, const uint8_t *data, int size, DCAExssAsset *asset) { int ret; + int extradata_peek_pos; if ((ret = init_get_bits8(&s->gb, data, size)) < 0) return ret; @@ -1054,10 +1055,23 @@ static int parse_frame(DCAXllDecoder *s, const uint8_t *data, int size, DCAExssA return ret; if ((ret = parse_band_data(s)) < 0) return ret; + + extradata_peek_pos = (get_bits_count(&s->gb) + 31) & ~31; + if (s->frame_size * 8 > extradata_peek_pos) { + unsigned int extradata_syncword = show_bits(&s->gb, 32); + + if (extradata_syncword == DCA_SYNCWORD_XLL_X) { + s->avctx->spatial_ext = 1; + } else if ((extradata_syncword >> 1) == DCA_SYNCWORD_XLL_IMAX) { + s->avctx->spatial_ext = 1; + } + } + if (ff_dca_seek_bits(&s->gb, s->frame_size * 8)) { av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL frame\n"); return AVERROR_INVALIDDATA; } + return ret; } diff --git a/libavcodec/eac3dec.c b/libavcodec/eac3dec.c index deca51dd3d..5c71751a0c 100644 --- a/libavcodec/eac3dec.c +++ b/libavcodec/eac3dec.c @@ -464,7 +464,16 @@ static int ff_eac3_parse_header(AC3DecodeContext *s) if (get_bits1(gbc)) { int addbsil = get_bits(gbc, 6); for (i = 0; i < addbsil + 1; i++) { - skip_bits(gbc, 8); // skip additional bit stream info + if (i == 0) { + /* In this 8 bit chunk, the LSB is equal to flag_ec3_extension_type_a + which can be used to detect Atmos presence */ + skip_bits(gbc, 7); + if (get_bits1(gbc)) { + s->eac3_extension_type_a = 1; + } + } else { + skip_bits(gbc, 8); // skip additional bit stream info + } } } diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c index 0ee1f0982c..547e68342e 100644 --- a/libavcodec/mlpdec.c +++ b/libavcodec/mlpdec.c @@ -392,6 +392,15 @@ static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb) m->num_substreams = mh.num_substreams; m->substream_info = mh.substream_info; + /* If there is a 4th substream and the MSB of substream_info is set, + * there is a 16-channel spatial presentation (Atmos in TrueHD). + */ + if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD + && m->num_substreams == 4 + && m->substream_info >> 7 == 1) { + m->avctx->spatial_ext = 1; + } + /* limit to decoding 3 substreams, as the 4th is used by Dolby Atmos for non-audio data */ m->max_decoded_substream = FFMIN(m->num_substreams - 1, 2);