]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Simplify and speed up metadata editing.
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 14 Aug 2021 15:53:59 +0000 (17:53 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 May 2022 19:37:35 +0000 (21:37 +0200)
Currently the aac audio format handler first calls mp4_open_meta()
to get the metadata tags, then alters the in-memory structure of the
tags according to the command line options and passes this modified
structure to mp4_meta_update() to rewrite the tags. This latter call
parses the tags again, which is unnecessary overhead.

This patch changes the signature of mp4_meta_update() to accept an
mp4 structure instead of a callback structure and uses that instead
of re-opening the file.

aac_afh.c
mp4.c
mp4.h

index d6ff4e936443a228a82950f5211b7f0c984f8105..84aeaa85e6a07bf37033856587eb2f8600cedf01 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
@@ -256,7 +256,7 @@ static int aac_afh_rewrite_tags(const char *map, size_t mapsize,
 
                ret = -E_MP4_META_READ;
                if (!mp4_meta_get_by_index(mp4, i, &tag->item, &tag->value))
-                       goto free_tags;
+                       goto close;
                PARA_INFO_LOG("found: %s: %s\n", tag->item, tag->value);
                if (!strcmp(tag->item, "artist"))
                        replace_tag(tag, tags->artist, &found_artist);
@@ -280,15 +280,9 @@ static int aac_afh_rewrite_tags(const char *map, size_t mapsize,
        if (!found_comment)
                add_tag(&metadata, "comment", tags->comment);
        ret = -E_MP4_META_WRITE;
-       if (!mp4_meta_update(&cb, &metadata))
-               goto free_tags;
+       if (!mp4_meta_update(mp4, &metadata))
+               goto close;
        ret = 1;
-free_tags:
-       for (; i > 0; i--) {
-               free(metadata.tags[i - 1].item);
-               free(metadata.tags[i - 1].value);
-       }
-       free(metadata.tags);
 close:
        mp4_close(mp4);
        return ret;
diff --git a/mp4.c b/mp4.c
index d2a54eb2b0c4370dfe0010a669681f2398f8e6dd..37a700bacb9c005d97750de969661b17dba1b825 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -1709,17 +1709,15 @@ static int32_t write_int32(struct mp4 *f, uint32_t data)
        return write_data(f, temp, sizeof(temp));
 }
 
-int32_t mp4_meta_update(const struct mp4_callback *cb,
-               const struct mp4_metadata *data)
+int32_t mp4_meta_update(struct mp4 *f, struct mp4_metadata *meta)
 {
        void *new_moov_data;
        uint32_t new_moov_size;
 
-       struct mp4 *f = para_calloc(sizeof(struct mp4));
-       f->cb = cb;
+       tag_delete(&f->tags);
+       f->tags = *meta;
        set_position(f, 0);
-       parse_atoms(f, 1);
-       if (!modify_moov(f, data, &new_moov_data, &new_moov_size)) {
+       if (!modify_moov(f, meta, &new_moov_data, &new_moov_size)) {
                mp4_close(f);
                return 0;
        }
@@ -1743,8 +1741,7 @@ int32_t mp4_meta_update(const struct mp4_callback *cb,
                write_data(f, new_moov_data, new_moov_size);
        }
        free(new_moov_data);
-       cb->truncate(cb->user_data);
-       mp4_close(f);
+       f->cb->truncate(f->cb->user_data);
        return 1;
 }
 
diff --git a/mp4.h b/mp4.h
index 82bd6788bd5635eb9323bdb99163510e2462ba79..71fd65d9459b18ea4f9b74da8ea8036c82435fa2 100644 (file)
--- a/mp4.h
+++ b/mp4.h
@@ -33,9 +33,7 @@ struct mp4 *mp4_open_meta(const struct mp4_callback *cb);
 
 int mp4_meta_get_by_index(const struct mp4 *f, unsigned int index,
                             char **item, char **value);
-int32_t mp4_meta_update(const struct mp4_callback *cb,
-               const struct mp4_metadata *data);
-
+int32_t mp4_meta_update(struct mp4 *f, struct mp4_metadata *meta);
 int mp4_meta_get_num_items(const struct mp4 *f);
 char *mp4_meta_get_artist(const struct mp4 *f);
 char *mp4_meta_get_title(const struct mp4 *f);