From 3da4c44d1ac8a9e5fc59278e868e8a9efdcfffbf Mon Sep 17 00:00:00 2001 From: "yilun.zhang" Date: Sat, 14 Sep 2024 17:52:26 +0800 Subject: [PATCH] Support decoding MP4 when IAMF is not the first track --- code/test/tools/iamfdec/src/mp4demux.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/code/test/tools/iamfdec/src/mp4demux.c b/code/test/tools/iamfdec/src/mp4demux.c index fca7fb60..da23b1d1 100755 --- a/code/test/tools/iamfdec/src/mp4demux.c +++ b/code/test/tools/iamfdec/src/mp4demux.c @@ -419,7 +419,6 @@ int mov_read_stbl(mp4r_t *mp4r, int size) { int64_t apos = ftell(mp4r->fin); avio_context *list[] = { - atoms_stsd, atoms_stts, atoms_stsc, atoms_stsz, @@ -429,9 +428,12 @@ int mov_read_stbl(mp4r_t *mp4r, int size) { atoms_sgpd #endif }; + STASH_ATOM(); - for (int i = 0; i < sizeof(list) / sizeof(avio_context *); ++i) - atom_seek_parse(mp4r, apos, size, list[i]); + if (atom_seek_parse(mp4r, apos, size, atoms_stsd) == ERR_OK) { + for (int i = 0; i < sizeof(list) / sizeof(avio_context *); ++i) + atom_seek_parse(mp4r, apos, size, list[i]); + } RESTORE_ATOM(); return size; } @@ -504,6 +506,7 @@ int mov_read_stsd(mp4r_t *mp4r, int size) { #endif int n; + int ret = size; // version/flags avio_rb32(); @@ -513,10 +516,14 @@ int mov_read_stsd(mp4r_t *mp4r, int size) { for (int i = 0; i < n; ++i) { mp4r->atom = atoms_iamf; - parse(mp4r, &size); + ret = parse(mp4r, &size); + if (ret == ERR_OK) { + ret = size; + break; + } } RESTORE_ATOM(); - return size; + return ret; } int mov_read_edts(mp4r_t *mp4r, int size) {