From 3432c8dabd431afeb43bb38520b3e4b13dadfac5 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 14 Aug 2021 19:00:06 +0200 Subject: [PATCH] mp4: Call metadata structures "meta". Currently they are called "tags" or "data", both of which are confusing because struct mp4_metadata has a member called "tags", and "data" is also used for generic buffers in the various I/O helpers. --- mp4.c | 74 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/mp4.c b/mp4.c index 1158a381..0aac88fa 100644 --- a/mp4.c +++ b/mp4.c @@ -62,7 +62,7 @@ struct mp4 { struct mp4_track *track[MAX_TRACKS]; /* metadata */ - struct mp4_metadata tags; + struct mp4_metadata meta; }; int32_t mp4_total_tracks(const struct mp4 *f) @@ -596,21 +596,21 @@ static int32_t read_stsd(struct mp4 *f) return 0; } -static int32_t tag_add_field(struct mp4_metadata *tags, const char *item, +static int32_t tag_add_field(struct mp4_metadata *meta, const char *item, const char *value, int32_t len) { - tags->tags = para_realloc(tags->tags, - (tags->count + 1) * sizeof(struct mp4_tag)); - tags->tags[tags->count].item = para_strdup(item); - tags->tags[tags->count].len = len; + meta->tags = para_realloc(meta->tags, + (meta->count + 1) * sizeof(struct mp4_tag)); + meta->tags[meta->count].item = para_strdup(item); + meta->tags[meta->count].len = len; if (len >= 0) { - tags->tags[tags->count].value = para_malloc(len + 1); - memcpy(tags->tags[tags->count].value, value, len); - tags->tags[tags->count].value[len] = 0; + meta->tags[meta->count].value = para_malloc(len + 1); + memcpy(meta->tags[meta->count].value, value, len); + meta->tags[meta->count].value[len] = 0; } else { - tags->tags[tags->count].value = para_strdup(value); + meta->tags[meta->count].value = para_strdup(value); } - tags->count++; + meta->count++; return 1; } @@ -695,7 +695,7 @@ static void parse_tag(struct mp4 *f, uint8_t parent, int32_t size) } if (!data) return; - tag_add_field(&f->tags, get_metadata_name(parent), data, len); + tag_add_field(&f->meta, get_metadata_name(parent), data, len); free(data); } @@ -892,17 +892,17 @@ struct mp4 *mp4_open_read(const struct mp4_callback *cb) return f; } -static int32_t tag_delete(struct mp4_metadata *tags) +static int32_t tag_delete(struct mp4_metadata *meta) { uint32_t i; - for (i = 0; i < tags->count; i++) { - free(tags->tags[i].item); - free(tags->tags[i].value); + for (i = 0; i < meta->count; i++) { + free(meta->tags[i].item); + free(meta->tags[i].value); } - free(tags->tags); - tags->tags = NULL; - tags->count = 0; + free(meta->tags); + meta->tags = NULL; + meta->count = 0; return 0; } @@ -924,7 +924,7 @@ void mp4_close(struct mp4 *f) } } - tag_delete(&(f->tags)); + tag_delete(&(f->meta)); free(f); } @@ -1115,7 +1115,7 @@ struct mp4 *mp4_open_meta(const struct mp4_callback *cb) */ struct mp4_metadata *mp4_get_meta(struct mp4 *f) { - return &f->tags; + return &f->meta; } static uint32_t find_atom(struct mp4 *f, uint64_t base, uint32_t size, @@ -1397,18 +1397,18 @@ static void *membuffer_detach(struct membuffer *buf) return ret; } -static uint32_t create_ilst(const struct mp4_metadata *data, void **out_buffer, +static uint32_t create_ilst(const struct mp4_metadata *meta, void **out_buffer, uint32_t * out_size) { struct membuffer *buf = membuffer_create(); unsigned metaptr; - char *mask = para_calloc(data->count); + char *mask = para_calloc(meta->count); const char *tracknumber_ptr = 0, *totaltracks_ptr = 0; const char *discnumber_ptr = 0, *totaldiscs_ptr = 0; const char *genre_ptr = 0, *tempo_ptr = 0; - for (metaptr = 0; metaptr < data->count; metaptr++) { - struct mp4_tag *tag = &data->tags[metaptr]; + for (metaptr = 0; metaptr < meta->count; metaptr++) { + struct mp4_tag *tag = &meta->tags[metaptr]; if (!strcasecmp(tag->item, "tracknumber") || !strcasecmp(tag->item, "track")) { if (tracknumber_ptr == 0) @@ -1454,13 +1454,13 @@ static uint32_t create_ilst(const struct mp4_metadata *data, void **out_buffer, else membuffer_write_int16_tag(buf, "gnre", index); } - for (metaptr = 0; metaptr < data->count; metaptr++) { + for (metaptr = 0; metaptr < meta->count; metaptr++) { struct mp4_tag *tag; const char *std_meta_atom; if (mask[metaptr]) continue; - tag = &data->tags[metaptr]; + tag = &meta->tags[metaptr]; std_meta_atom = find_standard_meta(tag->item); if (std_meta_atom) membuffer_write_std_tag(buf, std_meta_atom, tag->value); @@ -1522,14 +1522,14 @@ static unsigned membuffer_transfer_from_file(struct membuffer *buf, struct mp4 * return bytes; } -static uint32_t create_meta(const struct mp4_metadata *data, void **out_buffer, +static uint32_t create_meta(const struct mp4_metadata *meta, void **out_buffer, uint32_t * out_size) { struct membuffer *buf; uint32_t ilst_size; void *ilst_buffer; - if (!create_ilst(data, &ilst_buffer, &ilst_size)) + if (!create_ilst(meta, &ilst_buffer, &ilst_size)) return 0; buf = membuffer_create(); @@ -1544,14 +1544,14 @@ static uint32_t create_meta(const struct mp4_metadata *data, void **out_buffer, return 1; } -static uint32_t create_udta(const struct mp4_metadata *data, void **out_buffer, +static uint32_t create_udta(const struct mp4_metadata *meta, void **out_buffer, uint32_t * out_size) { struct membuffer *buf; uint32_t meta_size; void *meta_buffer; - if (!create_meta(data, &meta_buffer, &meta_size)) + if (!create_meta(meta, &meta_buffer, &meta_size)) return 0; buf = membuffer_create(); @@ -1590,7 +1590,7 @@ static uint32_t modify_moov(struct mp4 *f, void **out_buffer, struct membuffer *buf; void *new_udta_buffer; uint32_t new_udta_size; - if (!create_udta(&f->tags, &new_udta_buffer, &new_udta_size)) + if (!create_udta(&f->meta, &new_udta_buffer, &new_udta_size)) return 0; buf = membuffer_create(); @@ -1614,7 +1614,7 @@ static uint32_t modify_moov(struct mp4 *f, void **out_buffer, void *new_meta_buffer; uint32_t new_meta_size; - if (!create_meta(&f->tags, &new_meta_buffer, &new_meta_size)) + if (!create_meta(&f->meta, &new_meta_buffer, &new_meta_size)) return 0; buf = membuffer_create(); @@ -1642,7 +1642,7 @@ static uint32_t modify_moov(struct mp4 *f, void **out_buffer, ilst_offset = get_position(f); ilst_size = read_int32(f); - if (!create_ilst(&f->tags, &new_ilst_buffer, &new_ilst_size)) + if (!create_ilst(&f->meta, &new_ilst_buffer, &new_ilst_size)) return 0; size_delta = new_ilst_size - (ilst_size - 8); @@ -1741,9 +1741,9 @@ static char *meta_find_by_name(const struct mp4 *f, const char *item) { uint32_t i; - for (i = 0; i < f->tags.count; i++) - if (!strcasecmp(f->tags.tags[i].item, item)) - return para_strdup(f->tags.tags[i].value); + for (i = 0; i < f->meta.count; i++) + if (!strcasecmp(f->meta.tags[i].item, item)) + return para_strdup(f->meta.tags[i].value); return NULL; } -- 2.39.5