- return NULL;
- ret = para_fread(inbuf, *len, 1, infile);
- if (ret != *len)
- return NULL;
-// PARA_DEBUG_LOG("ret: %d, inbuf[0]: %lx - %lx\n", ret, (long unsigned) inbuf[0],
-// (long unsigned) inbuf[4]);
- return (char *)inbuf;
-}
-
-
-static const char* aac_suffixes[] = {"m4a", "mp4", NULL};
-/** the init function of the aac audio format handler */
-void aac_afh_init(struct audio_format_handler *p)
-{
- af = p;
- af->reposition_stream = aac_reposition_stream;
- af->get_file_info = aac_get_file_info,
- af->read_chunk = aac_read_chunk;
- af->close_audio_file = aac_close_audio_file;
- af->get_header_info = NULL;
- af->suffixes = aac_suffixes;
+ return ret;
+ lseek(fd, 0, SEEK_SET);
+
+ mp4ff = mp4ff_open_read_metaonly(&cb);
+ if (!mp4ff)
+ return -E_MP4FF_OPEN;
+
+ ret = -E_MP4FF_META_READ;
+ rv = mp4ff_meta_get_num_items(mp4ff);
+ 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(mp4ff_tag_t));
+ for (i = 0; i < metadata.count; i++) {
+ mp4ff_tag_t *tag = metadata.tags + i;
+
+ ret = -E_MP4FF_META_READ;
+ if (mp4ff_meta_get_by_index(mp4ff, i,
+ &tag->item, &tag->value) < 0)
+ goto free_tags;
+ PARA_INFO_LOG("found: %s: %s\n", tag->item, tag->value);
+ if (!strcmp(tag->item, "artist"))
+ replace_tag(tag, tags->artist, &found_artist);
+ else if (!strcmp(tag->item, "title"))
+ replace_tag(tag, tags->title, &found_title);
+ else if (!strcmp(tag->item, "album"))
+ replace_tag(tag, tags->album, &found_album);
+ else if (!strcmp(tag->item, "date"))
+ replace_tag(tag, tags->year, &found_year);
+ else if (!strcmp(tag->item, "comment"))
+ replace_tag(tag, tags->comment, &found_comment);
+ }
+ if (!found_artist)
+ add_tag(&metadata, "artist", tags->artist);
+ if (!found_title)
+ add_tag(&metadata, "title", tags->title);
+ if (!found_album)
+ add_tag(&metadata, "album", tags->album);
+ if (!found_year)
+ add_tag(&metadata, "date", tags->year);
+ if (!found_comment)
+ add_tag(&metadata, "comment", tags->comment);
+ ret = -E_MP4FF_META_WRITE;
+ if (mp4ff_meta_update(&cb, &metadata) < 0)
+ goto free_tags;
+ ret = 1;
+free_tags:
+ for (; i > 0; i--) {
+ free(metadata.tags[i - 1].item);
+ free(metadata.tags[i - 1].value);
+ }
+ free(metadata.tags);
+close:
+ mp4ff_close(mp4ff);
+ return ret;
+}
+
+static const char * const aac_suffixes[] = {"m4a", "mp4", NULL};
+/**
+ * the init function of the aac audio format handler
+ *
+ * \param afh pointer to the struct to initialize
+ */
+void aac_afh_init(struct audio_format_handler *afh)
+{
+ afh->get_file_info = aac_get_file_info,
+ afh->suffixes = aac_suffixes;
+ afh->rewrite_tags = aac_afh_rewrite_tags;
+ afh->open = aac_afh_open;
+ afh->get_chunk = aac_afh_get_chunk;
+ afh->close = aac_afh_close;