]> git.tue.mpg.de Git - paraslash.git/commitdiff
mp4: Further reduce the indentation of mp4ff_parse_tag().
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 9 Aug 2021 18:27:28 +0000 (20:27 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 May 2022 19:37:35 +0000 (21:37 +0200)
Handle the easy cases first. Again, this patch looks unreviewable,
but it in essence it is only one large block that is shifted to the
left with no other changes.

mp4.c

diff --git a/mp4.c b/mp4.c
index 537788639e3a2d5991f1bc901205804389c49320..44b185c1fb52252d8b830e6a68f7e64cc5d8bdb2 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -973,70 +973,69 @@ static int32_t mp4ff_parse_tag(mp4ff_t * f, const uint8_t parent_atom_type,
                destpos = mp4ff_position(f) + subsize - header_size;
                if (done)
                        continue;
-               if (atom_type == ATOM_DATA) {
+               if (atom_type == ATOM_NAME) {
                        mp4ff_read_char(f);     /* version */
                        mp4ff_read_int24(f);    /* flags */
-                       mp4ff_read_int32(f);    /* reserved */
-
-                       /* some need special attention */
-                       if (parent_atom_type == ATOM_GENRE2 || parent_atom_type == ATOM_TEMPO) {
-                               if (subsize - header_size >= 8 + 2) {
-                                       uint16_t val = mp4ff_read_int16(f);
-
-                                       if (parent_atom_type == ATOM_TEMPO) {
-                                               char temp[16];
-                                               sprintf(temp,
-                                                       "%.5u BPM",
-                                                       val);
-                                               mp4ff_tag_add_field(&(f-> tags), "tempo", temp, -1);
-                                       } else {
-                                               const char *temp = mp4ff_meta_index_to_genre(val);
-                                               if (temp) {
-                                                       mp4ff_tag_add_field (&(f->tags), "genre", temp, -1);
-                                               }
+                       free(name);
+                       name = mp4ff_read_string(f, (uint32_t) (subsize - (header_size + 4)));
+                       continue;
+               }
+               if (atom_type != ATOM_DATA)
+                       continue;
+               mp4ff_read_char(f);     /* version */
+               mp4ff_read_int24(f);    /* flags */
+               mp4ff_read_int32(f);    /* reserved */
+
+               /* some need special attention */
+               if (parent_atom_type == ATOM_GENRE2 || parent_atom_type == ATOM_TEMPO) {
+                       if (subsize - header_size >= 8 + 2) {
+                               uint16_t val = mp4ff_read_int16(f);
+
+                               if (parent_atom_type == ATOM_TEMPO) {
+                                       char temp[16];
+                                       sprintf(temp,
+                                               "%.5u BPM",
+                                               val);
+                                       mp4ff_tag_add_field(&(f-> tags), "tempo", temp, -1);
+                               } else {
+                                       const char *temp = mp4ff_meta_index_to_genre(val);
+                                       if (temp) {
+                                               mp4ff_tag_add_field (&(f->tags), "genre", temp, -1);
                                        }
-                                       done = 1;
                                }
-                       } else if (parent_atom_type == ATOM_TRACK || parent_atom_type == ATOM_DISC) {
-                               if (!done && (subsize - header_size) >= (sizeof (char) + sizeof (uint8_t) * 3 + sizeof (uint32_t) +     /* version + flags + reserved */
-                                                                        +(parent_atom_type == ATOM_TRACK ? sizeof (uint16_t) : 0)      /* leading uint16_t if ATOM_TRACK */
-                                                                        +sizeof (uint16_t)     /* track / disc */
-                                                                        +sizeof (uint16_t))    /* totaltracks / totaldiscs */) {
-                                       uint16_t index, total;
-                                       char temp[32];
+                               done = 1;
+                       }
+               } else if (parent_atom_type == ATOM_TRACK || parent_atom_type == ATOM_DISC) {
+                       if (!done && (subsize - header_size) >= (sizeof (char) + sizeof (uint8_t) * 3 + sizeof (uint32_t) +     /* version + flags + reserved */
+                                                                +(parent_atom_type == ATOM_TRACK ? sizeof (uint16_t) : 0)      /* leading uint16_t if ATOM_TRACK */
+                                                                +sizeof (uint16_t)     /* track / disc */
+                                                                +sizeof (uint16_t))    /* totaltracks / totaldiscs */) {
+                               uint16_t index, total;
+                               char temp[32];
+                               mp4ff_read_int16(f);
+                               index = mp4ff_read_int16(f);
+                               total = mp4ff_read_int16(f);
+                               if (parent_atom_type == ATOM_TRACK)
                                        mp4ff_read_int16(f);
-                                       index = mp4ff_read_int16(f);
-                                       total = mp4ff_read_int16(f);
-                                       if (parent_atom_type == ATOM_TRACK)
-                                               mp4ff_read_int16(f);
-
-                                       sprintf(temp, "%d", index);
-                                       mp4ff_tag_add_field(&(f->tags), parent_atom_type == ATOM_TRACK ?
-                                               "track" : "disc", temp, -1);
-                                       if (total > 0) {
-                                               sprintf(temp, "%d",
-                                                       total);
-                                               mp4ff_tag_add_field(& (f-> tags),
-                                                       parent_atom_type == ATOM_TRACK?
-                                                       "totaltracks" : "totaldiscs", temp, -1);
-                                       }
-                                       done = 1;
+
+                               sprintf(temp, "%d", index);
+                               mp4ff_tag_add_field(&(f->tags), parent_atom_type == ATOM_TRACK ?
+                                       "track" : "disc", temp, -1);
+                               if (total > 0) {
+                                       sprintf(temp, "%d",
+                                               total);
+                                       mp4ff_tag_add_field(& (f-> tags),
+                                               parent_atom_type == ATOM_TRACK?
+                                               "totaltracks" : "totaldiscs", temp, -1);
                                }
-                       } else {
-                               free(data);
-                               data = mp4ff_read_string(f, (uint32_t) (subsize - (header_size + 8)));
-                               len = (uint32_t) (subsize - (header_size + 8));
-                       }
-               } else if (atom_type == ATOM_NAME) {
-                       if (!done) {
-                               mp4ff_read_char(f);     /* version */
-                               mp4ff_read_int24(f);    /* flags */
-                               free(name);
-                               name = mp4ff_read_string(f, (uint32_t) (subsize - (header_size + 4)));
+                               done = 1;
                        }
+               } else {
+                       free(data);
+                       data = mp4ff_read_string(f, (uint32_t) (subsize - (header_size + 8)));
+                       len = (uint32_t) (subsize - (header_size + 8));
                }
        }
-
        if (data) {
                if (!done) {
                        if (name == NULL)