From a5a44e8fd804abfdf92763f247885d40c7cd69d6 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 23 Aug 2021 16:24:38 +0200 Subject: [PATCH] mp4: Merge parse_leaf_atom() into parse_sub_atoms(). This gets rid of the distinction between atoms with and without subatoms, which was confusing because some atoms "without" subatoms in fact do contain subatoms, we just did not want to parse them recursively in parse_sub_atoms(). With this weirdness gone, we may move on to simplify the atoms enum and atom_name_to_type() further, but this is left to a subsequent patch. --- mp4.c | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/mp4.c b/mp4.c index d030d62d..10ff3bfe 100644 --- a/mp4.c +++ b/mp4.c @@ -158,8 +158,6 @@ enum atoms { ATOM_DATE, ATOM_COMMENT, - SUBATOMIC = 128, - /* atoms without subatoms */ ATOM_MDHD, /* track header */ ATOM_STSD, /* sample description box */ @@ -657,29 +655,6 @@ static int32_t read_meta(struct mp4 *f, uint64_t size) return 1; } -static int parse_leaf_atom(struct mp4 *f, uint64_t size, uint8_t header_size, - uint8_t atom_type) -{ - uint64_t dest_position = get_position(f) + size - 8; - int ret = 1; /* return success for atoms we don't care about */ - - switch (atom_type) { - case ATOM_STSZ: ret = read_stsz(f); break; - case ATOM_STTS: ret = read_stts(f); break; - case ATOM_STSC: ret = read_stsc(f); break; - case ATOM_STCO: ret = read_stco(f); break; - case ATOM_STSD: ret = read_stsd(f); break; - case ATOM_MDHD: ret = read_mdhd(f); break; - case ATOM_META: - f->meta_offset = get_position(f) - header_size; - f->meta_size = size; - ret = read_meta(f, size); - break; - } - set_position(f, dest_position); - return ret; -} - static bool need_atom(uint8_t atom_type, bool meta_only) { /* these are needed in any case */ @@ -734,10 +709,21 @@ static int parse_sub_atoms(struct mp4 *f, uint64_t total_size, bool meta_only) } if (!need_atom(atom_type, meta_only)) continue; - if (atom_type < SUBATOMIC) /* atom contains subatoms */ + switch (atom_type) { + case ATOM_STSZ: ret = read_stsz(f); break; + case ATOM_STTS: ret = read_stts(f); break; + case ATOM_STSC: ret = read_stsc(f); break; + case ATOM_STCO: ret = read_stco(f); break; + case ATOM_STSD: ret = read_stsd(f); break; + case ATOM_MDHD: ret = read_mdhd(f); break; + case ATOM_META: + f->meta_offset = get_position(f) - header_size; + f->meta_size = size; + ret = read_meta(f, size); + break; + default: ret = parse_sub_atoms(f, size - header_size, meta_only); - else - ret = parse_leaf_atom(f, size, header_size, atom_type); + } if (ret <= 0) return ret; } -- 2.39.2