]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Merge parse_leaf_atom() into parse_sub_atoms().
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 23 Aug 2021 14:24:38 +0000 (16:24 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 May 2022 19:37:36 +0000 (21:37 +0200)
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

diff --git a/mp4.c b/mp4.c
index d030d62d3e759c81ddfa440a6b47613e87f4d14e..10ff3bfe3b3033785e4bdc397e3cee302ff5271b 100644 (file)
--- 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;
        }