From patchwork Sun Feb 12 00:31:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marth64 X-Patchwork-Id: 40372 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp2458961pzk; Sat, 11 Feb 2023 16:32:09 -0800 (PST) X-Google-Smtp-Source: AK7set/OM0whFk4WJS4QE1CVNiv+YrGgyF3jXs1VZtdL4pU0GXMysm1oQRbSCktYrMM5DkQbb66Y X-Received: by 2002:a17:907:76ca:b0:889:d156:616d with SMTP id kf10-20020a17090776ca00b00889d156616dmr19092167ejc.27.1676161929529; Sat, 11 Feb 2023 16:32:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676161929; cv=none; d=google.com; s=arc-20160816; b=B9LujMlpWalWT1K5zctbOOBNud9cHK7NHAxUS0wka34PeGFMXLfSBqtSQQ2DQopOn9 +BiY6tqWVGoQENfCmXtEqUN4ez56VoLKy0SWMUjqH7srzPQbDz0QAuS8ZfV5Mt6dvrQB FltG/ZOJ/M2d6tccgFcE4AwoPj2MzZ3FPzLZHU7EcfAouN+vo2JbDolnKVs78GSo81eX obQTx8UhbqZ/ClZX8UpmiGl4nxhhuwohE465jyIZxAF2gG1al0UlzzkZMkHZQdIRcK0/ h/vbct5XZPn1rq6pwJY2q/gDVWI2h+HUZcoD9bIRHzm/NLYgfDqK57HDTtHfMJwtS/RN X4GA== 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:delivered-to; bh=3R+hreiEJLdOewvcnjjq5w+6sT0e0EKnX0IkmtDG9po=; b=k6sMrjOC7qeMnGxVXMIksM3IB1OOa7R0SUAEj4YMuY4ANVYXXNy230loFVVyBU03ck A7uEPA0jRE21wAmESz+Eoj3r7coiCYGtF3VcFl6lu3upsffoXiEyHZ6V18BgWZOLwkad xZfr0i4osRYW17R6rzUKTNeOnl1iq2Dh7n+ld0QxxY/+SPNHifuFC7NCg46erGOsU7X7 Vf/aHFTRJXk6P8hvimzruAdvE0CWBSX/n8JLG9bPC+jS1QLrxCSYIFVzEwJUnlvSDnDf bMcFcbVisHxQ4Tm4NFBhs3qsnTRTHtzILMkzG7BNi84846ZnIXJGkomCvDHg/Y86OMYJ xupQ== 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 n16-20020a17090673d000b008788062de96si9990545ejl.710.2023.02.11.16.32.08; Sat, 11 Feb 2023 16:32:09 -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 524F568BC69; Sun, 12 Feb 2023 02:32:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5365868B88C for ; Sun, 12 Feb 2023 02:31:57 +0200 (EET) Received: by mail-qt1-f171.google.com with SMTP id w3so10288183qts.7 for ; Sat, 11 Feb 2023 16:31:57 -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: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=UeJ+hQr7KmwKJNA5n4nrLCB3/Rj1Vki1AdgPylv0NUM=; b=hQ0vtFb4ff82WdFc2JXBEUKjxq/o+cJCHxyBuyaza87eDvJT5hvJl+ecDHE4X5BEVO sqbGFrzxG6+XKeT4IJDGXt1SuGNC8DI6jpeOKBjOE2E5uvFyjr9Fg3b71lTK/i7XJaNi VZdJvphbf64YGgTc7K9kMUD3UzUbCp7ePZWOgNWBMkWOIqgRwbXOaeJMw1fsNRLJ+ZTx ZwqdHzMWq6Ayoom3OJbqwIi9tZkbGjmT1fLkN8ZkXYK0IDCY4i6IzmPuGTM7UkT1jiST s8YTDfHWjYVsuFt3e0X1BqlTodCNz2EeI4649A3jWywONF5bb2gId7ZQ8B3bekQUF1tB BN4g== X-Gm-Message-State: AO0yUKVhtqsHC2ORudetdengNi7ClzLpVSUFNDVOnlCsBFb4BVqFNGKM FVQ73sWlForlsVoQBZH+x1uzbCeVMXJULqUFsY1XCRnukTsiodwyBqavUWhY+0gzGkklJiXW0/n P8+qW3deoDy8Kcz3szqBL8sX7tYsVOL6KC2J5YfXKK/E71XfdJWsVSObUD7MmM4k++n2Z9w== X-Received: by 2002:a05:622a:1a02:b0:3bb:75c7:9326 with SMTP id f2-20020a05622a1a0200b003bb75c79326mr30882763qtb.0.1676161914949; Sat, 11 Feb 2023 16:31:54 -0800 (PST) Received: from localhost.localdomain ([76.141.0.17]) by smtp.gmail.com with ESMTPSA id m28-20020aed27dc000000b003b635a5d56csm6386477qtg.30.2023.02.11.16.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Feb 2023 16:31:54 -0800 (PST) From: Marth64 To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 Feb 2023 18:31:41 -0600 Message-Id: <20230212003141.3164962-1-marth64@proxyid.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <306450> References: <306450> 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: zbWb0bFN/sbr --- - Switched to using profiles for presentation - Updated IMAX DTS:X syncword for earlier detection libavcodec/ac3dec.c | 4 ++++ libavcodec/ac3dec.h | 1 + libavcodec/avcodec.h | 18 ++++++++++++------ libavcodec/codec_desc.c | 2 ++ libavcodec/dca_syncwords.h | 3 +++ libavcodec/dca_xll.c | 24 +++++++++++++++++++++++- libavcodec/dca_xll.h | 3 +++ libavcodec/eac3dec.c | 11 ++++++++++- libavcodec/mlpdec.c | 15 +++++++++++++-- libavcodec/profiles.c | 24 ++++++++++++++++++------ libavcodec/profiles.h | 2 ++ 11 files changed, 91 insertions(+), 16 deletions(-) diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index 0b120e6140..d7070645e6 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -43,6 +43,7 @@ #include "ac3dec.h" #include "ac3dec_data.h" #include "ac3defs.h" +#include "avcodec.h" #include "decode.h" #include "kbdwin.h" @@ -1714,6 +1715,9 @@ skip: if (!err) { avctx->sample_rate = s->sample_rate; avctx->bit_rate = s->bit_rate + s->prev_bit_rate; + + if (s->eac3_extension_type_a == 1) + avctx->profile = FF_PROFILE_EAC3_DDP_ATMOS; } 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..2d3a7a4625 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1616,12 +1616,18 @@ typedef struct AVCodecContext { #define FF_PROFILE_DNXHR_HQX 4 #define FF_PROFILE_DNXHR_444 5 -#define FF_PROFILE_DTS 20 -#define FF_PROFILE_DTS_ES 30 -#define FF_PROFILE_DTS_96_24 40 -#define FF_PROFILE_DTS_HD_HRA 50 -#define FF_PROFILE_DTS_HD_MA 60 -#define FF_PROFILE_DTS_EXPRESS 70 +#define FF_PROFILE_DTS 20 +#define FF_PROFILE_DTS_ES 30 +#define FF_PROFILE_DTS_96_24 40 +#define FF_PROFILE_DTS_HD_HRA 50 +#define FF_PROFILE_DTS_HD_MA 60 +#define FF_PROFILE_DTS_HD_MA_X 61 +#define FF_PROFILE_DTS_HD_MA_X_IMAX 62 +#define FF_PROFILE_DTS_EXPRESS 70 + +#define FF_PROFILE_EAC3_DDP_ATMOS 30 + +#define FF_PROFILE_TRUEHD_ATMOS 30 #define FF_PROFILE_MPEG2_422 0 #define FF_PROFILE_MPEG2_HIGH 1 diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index 57d0f98211..f33bbcd124 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -2931,6 +2931,7 @@ static const AVCodecDescriptor codec_descriptors[] = { .name = "eac3", .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52B (AC-3, E-AC-3)"), .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY, + .profiles = NULL_IF_CONFIG_SMALL(ff_eac3_profiles), }, { .id = AV_CODEC_ID_SIPR, @@ -2959,6 +2960,7 @@ static const AVCodecDescriptor codec_descriptors[] = { .name = "truehd", .long_name = NULL_IF_CONFIG_SMALL("TrueHD"), .props = AV_CODEC_PROP_LOSSLESS, + .profiles = NULL_IF_CONFIG_SMALL(ff_truehd_profiles), }, { .id = AV_CODEC_ID_MP4ALS, diff --git a/libavcodec/dca_syncwords.h b/libavcodec/dca_syncwords.h index 4d2cd5f56d..200702f89e 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 0x00020008U +#define DCA_SYNCWORD_XLL_X_IMAX 0x00F14000U + #endif /* AVCODEC_DCA_SYNCWORDS_H */ diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c index fe2c766d98..efbbae67f8 100644 --- a/libavcodec/dca_xll.c +++ b/libavcodec/dca_xll.c @@ -19,6 +19,7 @@ */ #include "libavutil/channel_layout.h" +#include "avcodec.h" #include "dcadec.h" #include "dcadata.h" #include "dcamath.h" @@ -1043,6 +1044,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 +1056,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_long(&s->gb, 32); + + if (extradata_syncword == DCA_SYNCWORD_XLL_X) { + s->x_syncword_present = 1; + } else if (extradata_syncword == DCA_SYNCWORD_XLL_X_IMAX) { + s->x_imax_syncword_present = 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; } @@ -1428,8 +1443,15 @@ int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame *frame) return AVERROR(EINVAL); } + if (s->x_imax_syncword_present) { + avctx->profile = FF_PROFILE_DTS_HD_MA_X_IMAX; + } else if (s->x_syncword_present) { + avctx->profile = FF_PROFILE_DTS_HD_MA_X; + } else { + avctx->profile = FF_PROFILE_DTS_HD_MA; + } + avctx->bits_per_raw_sample = p->storage_bit_res; - avctx->profile = FF_PROFILE_DTS_HD_MA; avctx->bit_rate = 0; frame->nb_samples = nsamples = s->nframesamples << (s->nfreqbands - 1); diff --git a/libavcodec/dca_xll.h b/libavcodec/dca_xll.h index d7c1a13ec8..a22bbb8d77 100644 --- a/libavcodec/dca_xll.h +++ b/libavcodec/dca_xll.h @@ -135,6 +135,9 @@ typedef struct DCAXllDecoder { DCADSPContext *dcadsp; + int x_syncword_present; ///< Syncword for extension data at end of frame (DTS:X) is present + int x_imax_syncword_present; ///< Syncword for extension data at end of frame (DTS:X IMAX) is present + int output_mask; int32_t *output_samples[DCA_SPEAKER_COUNT]; } DCAXllDecoder; 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..e95357e35a 100644 --- a/libavcodec/mlpdec.c +++ b/libavcodec/mlpdec.c @@ -28,20 +28,21 @@ #include -#include "avcodec.h" #include "libavutil/internal.h" #include "libavutil/intreadwrite.h" #include "libavutil/channel_layout.h" #include "libavutil/mem_internal.h" #include "libavutil/thread.h" #include "libavutil/opt.h" +#include "avcodec.h" #include "codec_internal.h" +#include "config.h" #include "decode.h" #include "get_bits.h" #include "mlp_parse.h" #include "mlpdsp.h" #include "mlp.h" -#include "config.h" +#include "profiles.h" /** number of bits used for VLC lookup - longest Huffman code is 9 */ #if ARCH_ARM @@ -392,6 +393,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->profile = FF_PROFILE_TRUEHD_ATMOS; + } + /* 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); @@ -1452,5 +1462,6 @@ const FFCodec ff_truehd_decoder = { FF_CODEC_DECODE_CB(read_access_unit), .flush = mlp_decode_flush, .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF, + .p.profiles = NULL_IF_CONFIG_SMALL(ff_truehd_profiles), }; #endif /* CONFIG_TRUEHD_DECODER */ diff --git a/libavcodec/profiles.c b/libavcodec/profiles.c index 7af7fbeb13..52066185b1 100644 --- a/libavcodec/profiles.c +++ b/libavcodec/profiles.c @@ -36,15 +36,27 @@ const AVProfile ff_aac_profiles[] = { }; const AVProfile ff_dca_profiles[] = { - { FF_PROFILE_DTS, "DTS" }, - { FF_PROFILE_DTS_ES, "DTS-ES" }, - { FF_PROFILE_DTS_96_24, "DTS 96/24" }, - { FF_PROFILE_DTS_HD_HRA, "DTS-HD HRA" }, - { FF_PROFILE_DTS_HD_MA, "DTS-HD MA" }, - { FF_PROFILE_DTS_EXPRESS, "DTS Express" }, + { FF_PROFILE_DTS, "DTS" }, + { FF_PROFILE_DTS_ES, "DTS-ES" }, + { FF_PROFILE_DTS_96_24, "DTS 96/24" }, + { FF_PROFILE_DTS_HD_HRA, "DTS-HD HRA" }, + { FF_PROFILE_DTS_HD_MA, "DTS-HD MA" }, + { FF_PROFILE_DTS_HD_MA_X, "DTS-HD MA + DTS:X" }, + { FF_PROFILE_DTS_HD_MA_X_IMAX, "DTS-HD MA + DTS:X IMAX" }, + { FF_PROFILE_DTS_EXPRESS, "DTS Express" }, { FF_PROFILE_UNKNOWN }, }; +const AVProfile ff_eac3_profiles[] = { + { FF_PROFILE_EAC3_DDP_ATMOS, "Dolby Digital Plus + Dolby Atmos"}, + { FF_PROFILE_UNKNOWN }, +}; + +const AVProfile ff_truehd_profiles[] = { + { FF_PROFILE_TRUEHD_ATMOS, "Dolby TrueHD + Dolby Atmos"}, + { FF_PROFILE_UNKNOWN }, +}; + const AVProfile ff_dnxhd_profiles[] = { { FF_PROFILE_DNXHD, "DNXHD"}, { FF_PROFILE_DNXHR_LB, "DNXHR LB"}, diff --git a/libavcodec/profiles.h b/libavcodec/profiles.h index 41a19aa9ad..1d523992fc 100644 --- a/libavcodec/profiles.h +++ b/libavcodec/profiles.h @@ -58,6 +58,8 @@ extern const AVProfile ff_aac_profiles[]; extern const AVProfile ff_dca_profiles[]; +extern const AVProfile ff_eac3_profiles[]; +extern const AVProfile ff_truehd_profiles[]; extern const AVProfile ff_dnxhd_profiles[]; extern const AVProfile ff_h264_profiles[]; extern const AVProfile ff_hevc_profiles[];