From 7950f206991fdf2cdaade40f44f06158091a9f83 Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Fri, 12 Apr 2024 10:06:24 -0600 Subject: [PATCH 05/16] avformat/mov: add support audio fallback track ref --- libavformat/isom.h | 3 +++ libavformat/mov.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/libavformat/isom.h b/libavformat/isom.h index 4723397048..82429c8b79 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -272,6 +272,9 @@ typedef struct MOVStreamContext { MOVEncryptionIndex *encryption_index; } cenc; + int has_fallback; // Audio fallback track + int fallback; + struct IAMFDemuxContext *iamf; } MOVStreamContext; diff --git a/libavformat/mov.c b/libavformat/mov.c index cdeb35d9db..e1e668e40c 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -9143,6 +9143,23 @@ fail: return ret; } +static int mov_read_fall(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + MOVStreamContext *sc; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + + sc->fallback = avio_rb32(pb); + sc->has_fallback = 1; + + return 0; +} + + static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('A','C','L','R'), mov_read_aclr }, { MKTAG('A','P','R','G'), mov_read_avid }, @@ -9245,6 +9262,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('v','p','c','C'), mov_read_vpcc }, { MKTAG('m','d','c','v'), mov_read_mdcv }, { MKTAG('c','l','l','i'), mov_read_clli }, +{ MKTAG('f','a','l','l'), mov_read_fall }, { MKTAG('d','v','c','C'), mov_read_dvcc_dvvc }, { MKTAG('d','v','v','C'), mov_read_dvcc_dvvc }, { MKTAG('d','v','w','C'), mov_read_dvcc_dvvc }, @@ -10409,6 +10427,23 @@ static int mov_read_header(AVFormatContext *s) err = ff_replaygain_export(st, s->metadata); if (err < 0) return err; + if (sc->has_fallback) { + for (j = 0; j < s->nb_streams; j++) { + if (s->streams[j]->id == sc->fallback) { + AVPacketSideData *sd; + int *fallback; + sd = av_packet_side_data_new(&st->codecpar->coded_side_data, + &st->codecpar->nb_coded_side_data, + AV_PKT_DATA_FALLBACK_TRACK, + sizeof(int), 0); + if (!sd) + return AVERROR(ENOMEM); + fallback = (int*)sd->data; + *fallback = j; + break; + } + } + } break; case AVMEDIA_TYPE_VIDEO: if (sc->display_matrix) { -- 2.39.5 (Apple Git-154)