From: Andre Noll Date: Thu, 19 Aug 2021 17:06:10 +0000 (+0200) Subject: mp4: Simplify parse_atoms(). X-Git-Tag: v0.7.1~7^2~47 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=df6826829971cc26ee52ab924789cdcc14db6c09 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. --- 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;