struct taginfo *tags, int fd, __a_unused const char *filename)
{
int ret, i;
- int32_t rv;
- struct mp4_metadata metadata;
+ struct mp4_metadata *metadata;
struct mp4 *mp4;
struct mp4_callback cb = {
.read = aac_afh_meta_read_cb,
mp4 = mp4_open_meta(&cb);
if (!mp4)
return -E_MP4_OPEN;
-
- ret = -E_MP4_META_READ;
- rv = mp4_meta_get_num_items(mp4);
- if (rv < 0)
- goto close;
- metadata.count = rv;
- PARA_NOTICE_LOG("%d metadata item(s) found\n", rv);
-
- metadata.tags = para_malloc((metadata.count + 5) * sizeof(struct mp4_tag));
- for (i = 0; i < metadata.count; i++) {
- struct mp4_tag *tag = metadata.tags + i;
-
- ret = -E_MP4_META_READ;
- if (!mp4_meta_get_by_index(mp4, i, &tag->item, &tag->value))
- goto close;
- PARA_INFO_LOG("found: %s: %s\n", tag->item, tag->value);
+ metadata = mp4_get_meta(mp4);
+ PARA_NOTICE_LOG("%u metadata item(s) found\n", metadata->count);
+ metadata->tags = para_realloc(metadata->tags,
+ (metadata->count + 5) * sizeof(struct mp4_tag));
+ for (i = 0; i < metadata->count; i++) {
+ struct mp4_tag *tag = metadata->tags + i;
if (!strcmp(tag->item, "artist"))
replace_tag(tag, tags->artist, &found_artist);
else if (!strcmp(tag->item, "title"))
replace_tag(tag, tags->comment, &found_comment);
}
if (!found_artist)
- add_tag(&metadata, "artist", tags->artist);
+ add_tag(metadata, "artist", tags->artist);
if (!found_title)
- add_tag(&metadata, "title", tags->title);
+ add_tag(metadata, "title", tags->title);
if (!found_album)
- add_tag(&metadata, "album", tags->album);
+ add_tag(metadata, "album", tags->album);
if (!found_year)
- add_tag(&metadata, "date", tags->year);
+ add_tag(metadata, "date", tags->year);
if (!found_comment)
- add_tag(&metadata, "comment", tags->comment);
+ add_tag(metadata, "comment", tags->comment);
ret = -E_MP4_META_WRITE;
- if (!mp4_meta_update(mp4, &metadata))
+ if (!mp4_meta_update(mp4, metadata))
goto close;
ret = 1;
close:
PARA_ERROR(MP4_BAD_SAMPLE, "mp4: invalid sample number"), \
PARA_ERROR(MP4_BAD_SAMPLERATE, "mp4: invalid sample rate"), \
PARA_ERROR(MP4_BAD_SAMPLE_COUNT, "mp4: invalid number of samples"), \
- PARA_ERROR(MP4_META_READ, "mp4: could not read mp4 metadata"), \
PARA_ERROR(MP4_META_WRITE, "mp4: could not update mp4 metadata"), \
PARA_ERROR(MP4_OPEN, "mp4: open failed"), \
PARA_ERROR(MP4_TRACK, "mp4: no audio track"), \
return f;
}
-int32_t mp4_meta_get_num_items(const struct mp4 *f)
+/**
+ * Return the metadata of an mp4 file.
+ *
+ * \param f As returned by either \ref mp4_open_read() or \ref mp4_open_meta().
+ *
+ * The caller is allowed to add, delete or modify the entries of the returned
+ * structure in order to pass the modified version to \ref mp4_meta_update().
+ */
+struct mp4_metadata *mp4_get_meta(struct mp4 *f)
{
- return f->tags.count;
-}
-
-int32_t mp4_meta_get_by_index(const struct mp4 *f, uint32_t index,
- char **item, char **value)
-{
- if (index >= f->tags.count) {
- *item = NULL;
- *value = NULL;
- return 0;
- } else {
- *item = para_strdup(f->tags.tags[index].item);
- *value = para_strdup(f->tags.tags[index].value);
- return 1;
- }
+ return &f->tags;
}
static uint32_t find_atom(struct mp4 *f, uint64_t base, uint32_t size,
struct membuffer *buf;
void *new_meta_buffer;
uint32_t new_meta_size;
+
if (!create_meta(data, &new_meta_buffer, &new_meta_size))
return 0;
void *new_moov_data;
uint32_t new_moov_size;
- tag_delete(&f->tags);
- f->tags = *meta;
set_position(f, 0);
if (!modify_moov(f, meta, &new_moov_data, &new_moov_size)) {
mp4_close(f);
return 0;
}
-
/* copy moov atom to end of the file */
if (f->last_atom != ATOM_MOOV) {
char *free_data = "free";
uint64_t mp4_get_duration(const struct mp4 *f, int32_t track);
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);
+struct mp4_metadata *mp4_get_meta(struct mp4 *f);
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);
char *mp4_meta_get_date(const struct mp4 *f);