]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Simplify parse_tag().
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 13 Aug 2021 18:19:43 +0000 (20:19 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 May 2022 19:37:35 +0000 (21:37 +0200)
We don't care about arbitrarily named tags, and those tags we're
interested in are generally present in form of the standard tags
(ATOM_TITLE, ATOM_ARTIST etc.).

Since we now always call get_metadata_name() to get the string
representation of the tag, we don't need to make a copy any more,
just pass the const pointer directly to tag_add_field().

With this change in place it is obvious that we never pass a NULL or
empty tag name to tag_add_field(), and we don't pass a NULL pointer
for the value argument either, so remove the safety check.

mp4.c

diff --git a/mp4.c b/mp4.c
index deb05747072f9500af5bfab2e98eeffbbe50e2e1..d8aea78379aeabc80987481229c2e537cef8a93f 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -599,8 +599,6 @@ static int32_t read_stsd(struct mp4 *f)
 static int32_t tag_add_field(struct mp4_metadata *tags, const char *item,
                const char *value, int32_t len)
 {
-       if (!item || (item && !*item) || !value)
-               return 0;
        tags->tags = para_realloc(tags->tags,
                (tags->count + 1) * sizeof(struct mp4_tag));
        tags->tags[tags->count].item = para_strdup(item);
@@ -673,7 +671,6 @@ static const char *get_metadata_name(uint8_t atom_type)
 static void parse_tag(struct mp4 *f, uint8_t parent, int32_t size)
 {
        uint64_t subsize, sumsize;
-       char *name = NULL;
        char *data = NULL;
        uint32_t len = 0;
        uint64_t destpos;
@@ -687,13 +684,6 @@ static void parse_tag(struct mp4 *f, uint8_t parent, int32_t size)
                uint8_t header_size = 0;
                subsize = atom_read_header(f, &atom_type, &header_size);
                destpos = get_position(f) + subsize - header_size;
-               if (atom_type == ATOM_NAME) {
-                       read_char(f);   /* version */
-                       read_int24(f);  /* flags */
-                       free(name);
-                       name = read_string(f, subsize - (header_size + 4));
-                       continue;
-               }
                if (atom_type != ATOM_DATA)
                        continue;
                read_char(f);   /* version */
@@ -703,13 +693,10 @@ static void parse_tag(struct mp4 *f, uint8_t parent, int32_t size)
                data = read_string(f, subsize - (header_size + 8));
                len = subsize - (header_size + 8);
        }
-       if (data) {
-               if (!name)
-                       name = para_strdup(get_metadata_name(parent));
-               tag_add_field(&(f->tags), name, data, len);
-               free(data);
-       }
-       free(name);
+       if (!data)
+               return;
+       tag_add_field(&f->tags, get_metadata_name(parent), data, len);
+       free(data);
 }
 
 static int32_t read_mdhd(struct mp4 *f)