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);
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;
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;
}
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;
}
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);