From: Andre Noll Date: Sat, 14 Aug 2021 15:53:59 +0000 (+0200) Subject: mp4: Simplify and speed up metadata editing. X-Git-Tag: v0.7.1~7^2~84 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=a4d904cc19f2b088cc1c72d9f5ce1fcb998e2dcb;p=paraslash.git mp4: Simplify and speed up metadata editing. 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. --- diff --git a/aac_afh.c b/aac_afh.c index d6ff4e93..84aeaa85 100644 --- 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 d2a54eb2..37a700ba 100644 --- 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 82bd6788..71fd65d9 100644 --- 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);