mp4: Simplify parse_atoms().
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 19 Aug 2021 17:06:10 +0000 (19:06 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 May 2022 19:37:35 +0000 (21:37 +0200)
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

diff --git a/mp4.c b/mp4.c
index c77cedd2bd2fb586a715b12c5808f7691bc35c57..469ec7d7da6ef6d71f8cfd50e701a4920b1e8f4e 100644 (file)
--- 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;