From df6826829971cc26ee52ab924789cdcc14db6c09 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 19 Aug 2021 19:06:10 +0200 Subject: [PATCH] mp4: Simplify parse_atoms(). We are only interested in subatoms of the moov atom, so skip everything else. Rename the function to parse_root_atoms() and remove the comment which does not convey any information anymore. --- mp4.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/mp4.c b/mp4.c index c77cedd2..469ec7d7 100644 --- a/mp4.c +++ b/mp4.c @@ -903,8 +903,7 @@ static int parse_sub_atoms(struct mp4 *f, uint64_t total_size, int meta_only) return 1; } -/* parse root atoms */ -static int parse_atoms(struct mp4 *f, int meta_only) +static int parse_root_atoms(struct mp4 *f, int meta_only) { int ret; uint64_t size; @@ -916,23 +915,15 @@ static int parse_atoms(struct mp4 *f, int meta_only) while ((ret = atom_read_header(f, &atom_type, &header_size, &size)) > 0) { f->file_size += size; f->last_atom = atom_type; - - if (atom_type == ATOM_MOOV && size > header_size) { - f->moov_offset = get_position(f) - header_size; - f->moov_size = size; - } - - /* parse subatoms */ - if (meta_only && !need_parse_when_meta_only(atom_type)) { - set_position(f, get_position(f) + size - header_size); - } else if (atom_type < SUBATOMIC) { - ret = parse_sub_atoms(f, size - header_size, meta_only); - if (ret <= 0) - break; - } else { - /* skip this atom */ + if (atom_type != ATOM_MOOV || size <= header_size) { /* skip */ set_position(f, get_position(f) + size - header_size); + continue; } + f->moov_offset = get_position(f) - header_size; + f->moov_size = size; + ret = parse_sub_atoms(f, size - header_size, meta_only); + if (ret <= 0) + break; } if (ret < 0) return ret; @@ -947,7 +938,7 @@ struct mp4 *mp4_open_read(const struct mp4_callback *cb) struct mp4 *f = para_calloc(sizeof(struct mp4)); f->cb = cb; - ret = parse_atoms(f, 0); + ret = parse_root_atoms(f, 0); if (ret < 0) { free(f); return NULL; @@ -1073,7 +1064,7 @@ struct mp4 *mp4_open_meta(const struct mp4_callback *cb) struct mp4 *f = para_calloc(sizeof(struct mp4)); f->cb = cb; - ret = parse_atoms(f, 1); + ret = parse_root_atoms(f, 1); if (ret < 0) { free(f); return NULL; -- 2.39.2