From patchwork Wed Jan 31 17:26:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 45940 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:2c82:b0:199:de12:6fa6 with SMTP id g2csp4106pzj; Wed, 31 Jan 2024 09:27:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiO8HlODuEBATQKGMVf8oMkLdXY6MON01lIS7bwe7KHCPCj10tW4s+pnF8k4ivGJK6Dr+w X-Received: by 2002:a05:651c:1071:b0:2cc:cd2e:d9fc with SMTP id y17-20020a05651c107100b002cccd2ed9fcmr1357127ljm.36.1706722050550; Wed, 31 Jan 2024 09:27:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706722050; cv=none; d=google.com; s=arc-20160816; b=mjMSKLthEQPh6vTZxi5cJTrCjPFplSoi9s5A25DvPEj2s3CAe4XrLHi+wTe55eW7Oo 3kf4+/liUa3Nu0ha7lDhTIshkbCVqugjqtgSvXualcQ0GmYWA+5A1GgVLczbjDLntcuC b1mHzJY2FtePAzRPttPhKNldcTrMfqfp37KhLRtfXMN7jBDTHWSpz41YA7iXDxUuIJxB ikRcmy8gw8qVh03F8ctvNKcmozIOgZ4blsW0Pky9gSTFpGe/ey4J3Wd1qGlmeQclm5As vV+mjGwFP4XF0dKOk+9FhYsJ3sUnirtZI62cyvbOXsqot8QL/DfJrHAkNkR7vXF1VYF7 IJbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=hQL2Xk1D61U9ztoLQKGlVn8y/vjCHgJfzxI0YUQtfrY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=JYAiBbMu+ctxetvq1JjjUJdNIFB18tbrPUjLzHeldVCvFVDQo+m6/WPdB37RBSNjvl ya2RTc/dMUrMCuQkxwgNntXDBhEef4JGthko7kdMPOadFr661s5nmXlU6jr72qU+AhbG iO933n3TrEFqCJpUsobMZsRols6tlvUZiYrOL9jzZofPpthkNHqqiaREfCh6RNj0RhA2 2xQ4vdGl7Ftdfv1PYGcdKwwBqKWT95YckxCFifQJ37/0LkvVxvMo9shOajSrJLGTYJ7t a4T93vPTtbdhIIwTuiyueR1FcH/3oVES6xd+KkE6hqHOs9ChkfEOhAleZ+OLBbA7IcQi 6pWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=XE0JiNdn; 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 l10-20020a056402124a00b0055f0078ad56si3236940edw.397.2024.01.31.09.27.30; Wed, 31 Jan 2024 09:27:30 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=XE0JiNdn; 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 9336F68D130; Wed, 31 Jan 2024 19:26:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7341868D126 for ; Wed, 31 Jan 2024 19:26:51 +0200 (EET) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d7232dcb3eso30531005ad.2 for ; Wed, 31 Jan 2024 09:26:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706722009; x=1707326809; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=0S6Dxp6dtM4HRx2J5Oaj7u8kJLpmwXWtyLBGa+O3x3I=; b=XE0JiNdn9IJ7nFFd8tm2kkLZp7tHygOcg3fFzwlFxU3SMMiGyj84QjsnPOOTlr2afG MZwcqjBEjEEm1MGRwBBtVOaN9RotZfqC8fmrn6ml139MACqXOQJOOZoTkaQbk72Dc8It BJD0ZKvH+CLaz5Z72UNDBxVXy5GrIsIEfSdrKXi/YfTJJNHMrTYct5473iL5rwdXj6Dy NcoxP4d7FWVWitYAeo5gAXCcZO4Xzx/JjqwEe0kD3nbhcGaqCw2TJo0/HWMArfclF+NN K295QUVzf/zvEVmik0R0FALa9hgBOZArZGVWLQkq5Ph2UpZPY6sezf3RiF1y5C+R5x9N 5kBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706722009; x=1707326809; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0S6Dxp6dtM4HRx2J5Oaj7u8kJLpmwXWtyLBGa+O3x3I=; b=TX3DI1mApaarZ+kJAcnC2RmWr5i8dfTpkECpIZ241FdWZUtGzFqdAq1u2Mi40XXfJg 6c6x0XqxcpZG+AiqzI6jggG+tC1G45Mxtnwk55eZWq6tEyTaeeoyA3jcdNnioCI2QUH0 Oh9pKYZHpWaActqfsiBLUV8JDCGv463FUDz31ayug08Wh+jm1kkdnhv9FbTbHv8ULGFz /OhJLFWDzZOqgqptmQstRUqJWTJojtLLXe0mtRPRosyDbFJ6jXjm/Ubf6GMqP2khMErO Jd9eau0fWjTxfIa4yhePwUOGN2cSV/MIH0LdapvP9ixVnb5lS1Zdq+fGrji7AfxSzR+y UMZg== X-Gm-Message-State: AOJu0YwZBDLWqC8EqyhQXhTN+5qyNq/9qb4P1MzLIpqdUznzuKfsgfHm HPd91BDPEsp7IJ2RYnmgpvmUXH/RDBdaRY8PLFEy7LluhL9LFJBNB/dXjjTe X-Received: by 2002:a17:902:ec81:b0:1d8:eb2b:7b26 with SMTP id x1-20020a170902ec8100b001d8eb2b7b26mr2111256plg.49.1706722008540; Wed, 31 Jan 2024 09:26:48 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id k11-20020a170902f28b00b001d8e4b85636sm5762235plc.138.2024.01.31.09.26.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 09:26:48 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Jan 2024 14:26:52 -0300 Message-ID: <20240131172654.15869-4-jamrial@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131172654.15869-1-jamrial@gmail.com> References: <20240131172654.15869-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/6 v3] avformat/mov: add support for Immersive Audio Model and Formats in ISOBMFF 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: P4VTESTOa1ZA Signed-off-by: James Almer --- configure | 2 +- libavformat/Makefile | 3 +- libavformat/isom.h | 6 + libavformat/mov.c | 283 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 276 insertions(+), 18 deletions(-) diff --git a/configure b/configure index 68f675a4bc..42ba5ec502 100755 --- a/configure +++ b/configure @@ -3545,7 +3545,7 @@ matroska_demuxer_suggest="bzlib zlib" matroska_muxer_select="mpeg4audio riffenc aac_adtstoasc_bsf pgs_frame_merge_bsf vp9_superframe_bsf" mlp_demuxer_select="mlp_parser" mmf_muxer_select="riffenc" -mov_demuxer_select="iso_media riffdec" +mov_demuxer_select="iso_media riffdec iamf_frame_split_bsf" mov_demuxer_suggest="zlib" mov_muxer_select="iso_media riffenc rtpenc_chain vp9_superframe_bsf aac_adtstoasc_bsf ac3_parser" mp3_demuxer_select="mpegaudio_parser" diff --git a/libavformat/Makefile b/libavformat/Makefile index 05b9b8a115..4131279e69 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -364,7 +364,8 @@ OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o OBJS-$(CONFIG_MODS_DEMUXER) += mods.o OBJS-$(CONFIG_MOFLEX_DEMUXER) += moflex.o OBJS-$(CONFIG_MOV_DEMUXER) += mov.o mov_chan.o mov_esds.o \ - qtpalette.o replaygain.o dovi_isom.o + qtpalette.o replaygain.o dovi_isom.o \ + iamf.o OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o vvc.o vpcc.o \ movenchint.o mov_chan.o rtp.o \ movenccenc.o movenc_ttml.o rawutils.o \ diff --git a/libavformat/isom.h b/libavformat/isom.h index a4925b3b08..9f202b3d73 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -33,6 +33,7 @@ #include "libavutil/stereo3d.h" #include "avio.h" +#include "iamf.h" #include "internal.h" #include "dv.h" @@ -167,6 +168,7 @@ typedef struct MOVStreamContext { AVIOContext *pb; int refcount; int pb_is_copied; + int id; ///< AVStream id int ffindex; ///< AVStream index int next_chunk; unsigned int chunk_count; @@ -261,6 +263,10 @@ typedef struct MOVStreamContext { AVEncryptionInfo *default_encrypted_sample; MOVEncryptionIndex *encryption_index; } cenc; + + IAMFContext *iamf; + uint8_t *iamf_descriptors; + int iamf_descriptors_size; } MOVStreamContext; typedef struct HEIFItem { diff --git a/libavformat/mov.c b/libavformat/mov.c index 555c72dc79..981a48e074 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -58,6 +58,7 @@ #include "internal.h" #include "avio_internal.h" #include "demux.h" +#include "iamf_parse.h" #include "dovi_isom.h" #include "riff.h" #include "isom.h" @@ -211,6 +212,7 @@ static int mov_read_covr(MOVContext *c, AVIOContext *pb, int type, int len) } st = c->fc->streams[c->fc->nb_streams - 1]; st->priv_data = sc; + sc->id = st->id; sc->refcount = 1; if (st->attached_pic.size >= 8 && id != AV_CODEC_ID_BMP) { @@ -835,6 +837,178 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_iacb(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + MOVStreamContext *sc; + FFIOContext b; + AVIOContext *descriptor_pb; + AVDictionary *metadata; + IAMFContext *iamf; + char args[32]; + int64_t start_time, duration; + unsigned size; + int nb_frames, disposition; + int version, ret; + + if (atom.size < 5) + return AVERROR_INVALIDDATA; + + if (c->fc->nb_streams < 1) + return 0; + + version = avio_r8(pb); + if (version != 1) { + av_log(c->fc, AV_LOG_ERROR, "%s configurationVersion %d", + version < 1 ? "invalid" : "unsupported", version); + return AVERROR_INVALIDDATA; + } + + size = ffio_read_leb(pb); + if (!size) + return AVERROR_INVALIDDATA; + + st = c->fc->streams[c->fc->nb_streams - 1]; + sc = st->priv_data; + + iamf = sc->iamf = av_mallocz(sizeof(*iamf)); + if (!iamf) + return AVERROR(ENOMEM); + + sc->iamf_descriptors = av_malloc(size); + if (!sc->iamf_descriptors) + return AVERROR(ENOMEM); + + sc->iamf_descriptors_size = size; + ret = avio_read(pb, sc->iamf_descriptors, size); + if (ret != size) + return ret < 0 ? ret : AVERROR_INVALIDDATA; + + ffio_init_read_context(&b, sc->iamf_descriptors, size); + descriptor_pb = &b.pub; + + ret = ff_iamfdec_read_descriptors(iamf, descriptor_pb, size, c->fc); + if (ret < 0) + return ret; + + metadata = st->metadata; + st->metadata = NULL; + start_time = st->start_time; + nb_frames = st->nb_frames; + duration = st->duration; + disposition = st->disposition; + + for (int i = 0; i < iamf->nb_audio_elements; i++) { + IAMFAudioElement *audio_element = iamf->audio_elements[i]; + AVStreamGroup *stg = + avformat_stream_group_create(c->fc, AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT, NULL); + + if (!stg) { + ret = AVERROR(ENOMEM); + goto fail; + } + + stg->id = audio_element->audio_element_id; + stg->params.iamf_audio_element = audio_element->element; + audio_element->element = NULL; + + for (int j = 0; j < audio_element->nb_substreams; j++) { + IAMFSubStream *substream = &audio_element->substreams[j]; + AVStream *stream; + + if (!i && !j) + stream = st; + else + stream = avformat_new_stream(c->fc, NULL); + if (!stream) { + ret = AVERROR(ENOMEM); + goto fail; + } + + stream->start_time = start_time; + stream->nb_frames = nb_frames; + stream->duration = duration; + stream->disposition = disposition; + if (stream != st) { + stream->priv_data = sc; + sc->refcount++; + } + + ret = avcodec_parameters_copy(stream->codecpar, substream->codecpar); + if (ret < 0) + goto fail; + + stream->id = substream->audio_substream_id; + + avpriv_set_pts_info(st, 64, 1, sc->time_scale); + + ret = avformat_stream_group_add_stream(stg, stream); + if (ret < 0) + goto fail; + } + + ret = av_dict_copy(&stg->metadata, metadata, 0); + if (ret < 0) + goto fail; + } + + for (int i = 0; i < iamf->nb_mix_presentations; i++) { + IAMFMixPresentation *mix_presentation = iamf->mix_presentations[i]; + const AVIAMFMixPresentation *mix = mix_presentation->mix; + AVStreamGroup *stg = + avformat_stream_group_create(c->fc, AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION, NULL); + + if (!stg) { + ret = AVERROR(ENOMEM); + goto fail; + } + + stg->id = mix_presentation->mix_presentation_id; + stg->params.iamf_mix_presentation = mix_presentation->mix; + mix_presentation->mix = NULL; + + for (int j = 0; j < mix->nb_submixes; j++) { + const AVIAMFSubmix *submix = mix->submixes[j]; + + for (int k = 0; k < submix->nb_elements; k++) { + const AVIAMFSubmixElement *submix_element = submix->elements[k]; + const AVStreamGroup *audio_element = NULL; + + for (int l = 0; l < c->fc->nb_stream_groups; l++) + if (c->fc->stream_groups[l]->type == AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT && + c->fc->stream_groups[l]->id == submix_element->audio_element_id) { + audio_element = c->fc->stream_groups[l]; + break; + } + av_assert0(audio_element); + + for (int l = 0; l < audio_element->nb_streams; l++) { + ret = avformat_stream_group_add_stream(stg, audio_element->streams[l]); + if (ret < 0 && ret != AVERROR(EEXIST)) + goto fail; + } + } + } + + ret = av_dict_copy(&stg->metadata, metadata, 0); + if (ret < 0) + goto fail; + } + + snprintf(args, sizeof(args), "first_index=%d", st->index); + + ret = ff_stream_add_bitstream_filter(st, "iamf_frame_split", args); + if (ret == AVERROR_BSF_NOT_FOUND) { + av_log(c->fc, AV_LOG_ERROR, "iamf_frame_split bitstream filter " + "not found. This is a bug, please report it.\n"); + ret = AVERROR_BUG; + } +fail: + av_dict_free(&metadata); + + return ret; +} + static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; @@ -1380,7 +1554,7 @@ static int64_t get_frag_time(AVFormatContext *s, AVStream *dst_st, // If the stream is referenced by any sidx, limit the search // to fragments that referenced this stream in the sidx if (sc->has_sidx) { - frag_stream_info = get_frag_stream_info(frag_index, index, dst_st->id); + frag_stream_info = get_frag_stream_info(frag_index, index, sc->id); if (frag_stream_info->sidx_pts != AV_NOPTS_VALUE) return frag_stream_info->sidx_pts; if (frag_stream_info->first_tfra_pts != AV_NOPTS_VALUE) @@ -1391,9 +1565,11 @@ static int64_t get_frag_time(AVFormatContext *s, AVStream *dst_st, for (i = 0; i < frag_index->item[index].nb_stream_info; i++) { AVStream *frag_stream = NULL; frag_stream_info = &frag_index->item[index].stream_info[i]; - for (j = 0; j < s->nb_streams; j++) - if (s->streams[j]->id == frag_stream_info->id) + for (j = 0; j < s->nb_streams; j++) { + MOVStreamContext *sc2 = s->streams[j]->priv_data; + if (sc2->id == frag_stream_info->id) frag_stream = s->streams[j]; + } if (!frag_stream) { av_log(s, AV_LOG_WARNING, "No stream matching sidx ID found.\n"); continue; @@ -1459,12 +1635,13 @@ static int update_frag_index(MOVContext *c, int64_t offset) for (i = 0; i < c->fc->nb_streams; i++) { // Avoid building frag index if streams lack track id. - if (c->fc->streams[i]->id < 0) { + MOVStreamContext *sc = c->fc->streams[i]->priv_data; + if (sc->id < 0) { av_free(frag_stream_info); return AVERROR_INVALIDDATA; } - frag_stream_info[i].id = c->fc->streams[i]->id; + frag_stream_info[i].id = sc->id; frag_stream_info[i].sidx_pts = AV_NOPTS_VALUE; frag_stream_info[i].tfdt_dts = AV_NOPTS_VALUE; frag_stream_info[i].next_trun_dts = AV_NOPTS_VALUE; @@ -3259,7 +3436,7 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) "All samples in data stream index:id [%d:%d] have zero " "duration, stream set to be discarded by default. Override " "using AVStream->discard or -discard for ffmpeg command.\n", - st->index, st->id); + st->index, sc->id); st->discard = AVDISCARD_ALL; } sc->track_end = duration; @@ -4639,6 +4816,50 @@ static void fix_timescale(MOVContext *c, MOVStreamContext *sc) } } +static int mov_update_iamf_streams(MOVContext *c, const AVStream *st) +{ + const MOVStreamContext *sc = st->priv_data; + + for (int i = 0; i < sc->iamf->nb_audio_elements; i++) { + const AVStreamGroup *stg = NULL; + + for (int j = 0; j < c->fc->nb_stream_groups; j++) + if (c->fc->stream_groups[j]->id == sc->iamf->audio_elements[i]->audio_element_id) + stg = c->fc->stream_groups[j]; + av_assert0(stg); + + for (int j = 0; j < stg->nb_streams; j++) { + const FFStream *sti = cffstream(st); + AVStream *out = stg->streams[j]; + FFStream *out_sti = ffstream(stg->streams[j]); + + out->codecpar->bit_rate = 0; + + if (out == st) + continue; + + out->time_base = st->time_base; + out->start_time = st->start_time; + out->duration = st->duration; + out->nb_frames = st->nb_frames; + out->disposition = st->disposition; + out->discard = st->discard; + + av_assert0(!out_sti->index_entries); + out_sti->index_entries = av_malloc(sti->index_entries_allocated_size); + if (!out_sti->index_entries) + return AVERROR(ENOMEM); + + out_sti->index_entries_allocated_size = sti->index_entries_allocated_size; + out_sti->nb_index_entries = sti->nb_index_entries; + out_sti->skip_samples = sti->skip_samples; + memcpy(out_sti->index_entries, sti->index_entries, sti->index_entries_allocated_size); + } + } + + return 0; +} + static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; @@ -4702,6 +4923,12 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) mov_build_index(c, st); + if (sc->iamf) { + ret = mov_update_iamf_streams(c, st); + if (ret < 0) + return ret; + } + if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) { MOVDref *dref = &sc->drefs[sc->dref_id - 1]; if (c->enable_drefs) { @@ -4934,6 +5161,7 @@ static int heif_add_stream(MOVContext *c, HEIFItem *item) st->priv_data = sc; st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = mov_codec_id(st, item->type); + sc->id = st->id; sc->ffindex = st->index; c->trak_index = st->index; st->avg_frame_rate.num = st->avg_frame_rate.den = 1; @@ -5032,6 +5260,7 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) avio_rb32(pb); /* modification time */ } st->id = (int)avio_rb32(pb); /* track id (NOT 0 !)*/ + sc->id = st->id; avio_rb32(pb); /* reserved */ /* highlevel (considering edits) duration in movie timebase */ @@ -5206,7 +5435,8 @@ static int mov_read_tfdt(MOVContext *c, AVIOContext *pb, MOVAtom atom) int64_t base_media_decode_time; for (i = 0; i < c->fc->nb_streams; i++) { - if (c->fc->streams[i]->id == frag->track_id) { + sc = c->fc->streams[i]->priv_data; + if (sc->id == frag->track_id) { st = c->fc->streams[i]; break; } @@ -5259,7 +5489,8 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) } for (i = 0; i < c->fc->nb_streams; i++) { - if (c->fc->streams[i]->id == frag->track_id) { + sc = c->fc->streams[i]->priv_data; + if (sc->id == frag->track_id) { st = c->fc->streams[i]; sti = ffstream(st); break; @@ -5562,7 +5793,8 @@ static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) track_id = avio_rb32(pb); // Reference ID for (i = 0; i < c->fc->nb_streams; i++) { - if (c->fc->streams[i]->id == track_id) { + sc = c->fc->streams[i]->priv_data; + if (sc->id == track_id) { st = c->fc->streams[i]; break; } @@ -6454,7 +6686,8 @@ static int get_current_encryption_info(MOVContext *c, MOVEncryptionIndex **encry frag_stream_info = get_current_frag_stream_info(&c->frag_index); if (frag_stream_info) { for (i = 0; i < c->fc->nb_streams; i++) { - if (c->fc->streams[i]->id == frag_stream_info->id) { + *sc = c->fc->streams[i]->priv_data; + if ((*sc)->id == frag_stream_info->id) { st = c->fc->streams[i]; break; } @@ -7398,7 +7631,7 @@ static int cenc_filter(MOVContext *mov, AVStream* st, MOVStreamContext *sc, AVPa AVEncryptionInfo *encrypted_sample; int encrypted_index, ret; - frag_stream_info = get_frag_stream_info_from_pkt(&mov->frag_index, pkt, st->id); + frag_stream_info = get_frag_stream_info_from_pkt(&mov->frag_index, pkt, sc->id); encrypted_index = current_index; encryption_index = NULL; if (frag_stream_info) { @@ -8175,6 +8408,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('i','s','p','e'), mov_read_ispe }, { MKTAG('i','p','r','p'), mov_read_iprp }, { MKTAG('i','i','n','f'), mov_read_iinf }, +{ MKTAG('i','a','c','b'), mov_read_iacb }, { 0, NULL } }; @@ -8406,11 +8640,13 @@ static void mov_read_chapters(AVFormatContext *s) AVStream *st = NULL; FFStream *sti = NULL; chapter_track = mov->chapter_tracks[j]; - for (i = 0; i < s->nb_streams; i++) - if (s->streams[i]->id == chapter_track) { + for (i = 0; i < s->nb_streams; i++) { + sc = mov->fc->streams[i]->priv_data; + if (sc->id == chapter_track) { st = s->streams[i]; break; } + } if (!st) { av_log(s, AV_LOG_ERROR, "Referenced QT chapter track not found\n"); continue; @@ -8642,6 +8878,11 @@ static void mov_free_stream_context(AVFormatContext *s, AVStream *st) av_freep(&sc->spherical); av_freep(&sc->mastering); av_freep(&sc->coll); + + ff_iamf_uninit_context(sc->iamf); + av_freep(&sc->iamf); + av_freep(&sc->iamf_descriptors); + sc->iamf_descriptors_size = 0; } static int mov_read_close(AVFormatContext *s) @@ -8896,9 +9137,11 @@ static int mov_read_header(AVFormatContext *s) AVDictionaryEntry *tcr; int tmcd_st_id = -1; - for (j = 0; j < s->nb_streams; j++) - if (s->streams[j]->id == sc->timecode_track) + for (j = 0; j < s->nb_streams; j++) { + MOVStreamContext *sc2 = s->streams[j]->priv_data; + if (sc2->id == sc->timecode_track) tmcd_st_id = j; + } if (tmcd_st_id < 0 || tmcd_st_id == i) continue; @@ -9211,7 +9454,15 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) if (st->codecpar->codec_id == AV_CODEC_ID_EIA_608 && sample->size > 8) ret = get_eia608_packet(sc->pb, pkt, sample->size); - else + else if (sc->iamf_descriptors_size) { + ret = av_new_packet(pkt, sc->iamf_descriptors_size); + if (ret < 0) + return ret; + pkt->pos = avio_tell(sc->pb); + memcpy(pkt->data, sc->iamf_descriptors, sc->iamf_descriptors_size); + sc->iamf_descriptors_size = 0; + ret = av_append_packet(sc->pb, pkt, sample->size); + } else ret = av_get_packet(sc->pb, pkt, sample->size); if (ret < 0) { if (should_retry(sc->pb, ret)) {