+static int aac_rewrite_tags(const char *map, size_t mapsize,
+ struct taginfo *tags, int fd, const char *filename)
+{
+ MP4FileHandle h;
+ const MP4Tags *mdata;
+ int ret = write_all(fd, map, mapsize);
+
+ if (ret < 0)
+ return ret;
+ lseek(fd, 0, SEEK_SET);
+ h = MP4Modify(filename, 0);
+ if (!h) {
+ PARA_ERROR_LOG("MP4Modify() failed, fd = %d\n", fd);
+ return -E_MP4V2;
+ }
+ mdata = MP4TagsAlloc();
+ assert(mdata);
+ if (!MP4TagsFetch(mdata, h)) {
+ PARA_ERROR_LOG("MP4Tags_Fetch() failed\n");
+ ret = -E_MP4V2;
+ goto close;
+ }
+
+ if (!MP4TagsSetAlbum(mdata, tags->album)) {
+ PARA_ERROR_LOG("Could not set album\n");
+ ret = -E_MP4V2;
+ goto tags_free;
+ }
+ if (!MP4TagsSetArtist(mdata, tags->artist)) {
+ PARA_ERROR_LOG("Could not set album\n");
+ ret = -E_MP4V2;
+ goto tags_free;
+ }
+ if (!MP4TagsSetComments(mdata, tags->comment)) {
+ PARA_ERROR_LOG("Could not set comment\n");
+ ret = -E_MP4V2;
+ goto tags_free;
+ }
+ if (!MP4TagsSetName(mdata, tags->title)) {
+ PARA_ERROR_LOG("Could not set title\n");
+ ret = -E_MP4V2;
+ goto tags_free;
+ }
+ if (!MP4TagsSetReleaseDate(mdata, tags->year)) {
+ PARA_ERROR_LOG("Could not set release date\n");
+ ret = -E_MP4V2;
+ goto tags_free;
+ }
+
+ if (!MP4TagsStore(mdata, h)) {
+ PARA_ERROR_LOG("Could not store tags\n");
+ ret = -E_MP4V2;
+ goto tags_free;
+ }
+ ret = 1;
+tags_free:
+ MP4TagsFree(mdata);
+close:
+ MP4Close(h, 0);
+ return ret;
+}
+
+static const char * const aac_suffixes[] = {"m4a", "mp4", NULL};