shithub: aacdec

Download patch

ref: 42b2e4697882503c5dcdc6ddfcfb138ebefc5f7a
parent: f04f98d216797a099b0e6234b8fe85bd7dd23807
author: menno <menno>
date: Mon Mar 9 17:22:22 EDT 2009

Patch for MP4 iTunes metadata

--- a/common/mp4ff/mp4ffint.h
+++ b/common/mp4ff/mp4ffint.h
@@ -25,7 +25,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: mp4ffint.h,v 1.26 2009/01/25 20:14:34 menno Exp $
+** $Id: mp4ffint.h,v 1.27 2009/03/09 21:22:22 menno Exp $
 **/
 
 #ifndef MP4FF_INTERNAL_H
@@ -152,6 +152,7 @@
 {
     char *item;
     char *value;
+    uint32_t len;
 } mp4ff_tag_t;
 
 /* metadata list structure */
@@ -285,7 +286,7 @@
 
 #ifdef USE_TAGGING
 /* mp4meta.c */
-static int32_t mp4ff_tag_add_field(mp4ff_metadata_t *tags, const char *item, const char *value);
+static int32_t mp4ff_tag_add_field(mp4ff_metadata_t *tags, const char *item, const char *value, int32_t len);
 static int32_t mp4ff_tag_set_field(mp4ff_metadata_t *tags, const char *item, const char *value);
 static int32_t mp4ff_set_metadata_name(mp4ff_t *f, const uint8_t atom_type, char **name);
 static int32_t mp4ff_parse_tag(mp4ff_t *f, const uint8_t parent_atom_type, const int32_t size);
--- a/common/mp4ff/mp4meta.c
+++ b/common/mp4ff/mp4meta.c
@@ -25,7 +25,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
 **
-** $Id: mp4meta.c,v 1.21 2009/01/19 23:56:30 menno Exp $
+** $Id: mp4meta.c,v 1.22 2009/03/09 21:22:22 menno Exp $
 **/
 
 #ifdef USE_TAGGING
@@ -37,7 +37,7 @@
 
 
 
-static int32_t mp4ff_tag_add_field(mp4ff_metadata_t *tags, const char *item, const char *value)
+static int32_t mp4ff_tag_add_field(mp4ff_metadata_t *tags, const char *item, const char *value, int32_t len)
 {
     void *backup = (void *)tags->tags;
 
@@ -50,7 +50,17 @@
         return 0;
     } else {
         tags->tags[tags->count].item = strdup(item);
-        tags->tags[tags->count].value = strdup(value);
+        tags->tags[tags->count].len = len;
+        if (len >= 0) {
+            tags->tags[tags->count].value = malloc(len + 1);
+            if (tags->tags[tags->count].value != NULL) {
+                memcpy(tags->tags[tags->count].value, value, len);
+                tags->tags[tags->count].value[len] = 0;
+            }
+        }
+        else {
+            tags->tags[tags->count].value = strdup(value);
+        }
 
         if (!tags->tags[tags->count].item || !tags->tags[tags->count].value)
         {
@@ -58,6 +68,7 @@
             if (!tags->tags[tags->count].value) free (tags->tags[tags->count].value);
             tags->tags[tags->count].item = NULL;
             tags->tags[tags->count].value = NULL;
+            tags->tags[tags->count].len = 0;
             return 0;
         }
 
@@ -82,7 +93,7 @@
         }
     }
 
-    return mp4ff_tag_add_field(tags, item, value);
+    return mp4ff_tag_add_field(tags, item, value, 0);
 }
 
 int32_t mp4ff_tag_delete(mp4ff_metadata_t *tags)
@@ -226,6 +237,7 @@
     char * name = NULL;
 	char * data = NULL;
 	uint32_t done = 0;
+    uint32_t len = 0;
 
 
     while (sumsize < size)
@@ -252,7 +264,7 @@
 						{
 							char temp[16];
 							sprintf(temp, "%.5u BPM", val);
-							mp4ff_tag_add_field(&(f->tags), "tempo", temp);
+							mp4ff_tag_add_field(&(f->tags), "tempo", temp, -1);
 						}
 						else
 						{
@@ -259,7 +271,7 @@
 							const char * temp = mp4ff_meta_index_to_genre(val);
 							if (temp)
 							{
-								mp4ff_tag_add_field(&(f->tags), "genre", temp);
+								mp4ff_tag_add_field(&(f->tags), "genre", temp, -1);
 							}
 						}
 						done = 1;
@@ -269,7 +281,7 @@
 					/* modified by AJS */
 					if ( !done && (subsize - header_size) >=
 						(sizeof(char) + sizeof(uint8_t)*3 + sizeof(uint32_t) + /* version + flags + reserved */
-						+ sizeof(uint16_t) /* leading uint16_t */
+						+ (parent_atom_type == ATOM_TRACK ? sizeof(uint16_t) : 0) /* leading uint16_t if ATOM_TRACK */
 						+ sizeof(uint16_t) /* track / disc */
 						+ sizeof(uint16_t)) /* totaltracks / totaldiscs */
 						)
@@ -279,15 +291,15 @@
 						mp4ff_read_int16(f);
 						index = mp4ff_read_int16(f);
 						total = mp4ff_read_int16(f);
-  						/* modified by AJS */
-						/* mp4ff_read_int16(f); */
+                        if (parent_atom_type == ATOM_TRACK)
+                            mp4ff_read_int16(f);
 
 						sprintf(temp,"%d",index);
-						mp4ff_tag_add_field(&(f->tags), parent_atom_type == ATOM_TRACK ? "track" : "disc", temp);
+						mp4ff_tag_add_field(&(f->tags), parent_atom_type == ATOM_TRACK ? "track" : "disc", temp, -1);
 						if (total>0)
 						{
 							sprintf(temp,"%d",total);
-							mp4ff_tag_add_field(&(f->tags), parent_atom_type == ATOM_TRACK ? "totaltracks" : "totaldiscs", temp);
+							mp4ff_tag_add_field(&(f->tags), parent_atom_type == ATOM_TRACK ? "totaltracks" : "totaldiscs", temp, -1);
 						}
 						done = 1;
 					}
@@ -295,6 +307,7 @@
 				{
 					if (data) {free(data);data = NULL;}
 					data = mp4ff_read_string(f,(uint32_t)(subsize-(header_size+8)));
+                    len = (uint32_t)(subsize-(header_size+8));
 				}
 			} else if (atom_type == ATOM_NAME) {
 				if (!done)
@@ -315,7 +328,7 @@
 		if (!done)
 		{
 			if (name == NULL) mp4ff_set_metadata_name(f, parent_atom_type, &name);
-			if (name) mp4ff_tag_add_field(&(f->tags), name, data);
+			if (name) mp4ff_tag_add_field(&(f->tags), name, data, len);
 		}
 
 		free(data);
@@ -363,6 +376,30 @@
     return 0;
 }
 
+static int32_t mp4ff_meta_find_by_name_and_return_len(const mp4ff_t *f, const char *item, char **value)
+{
+    uint32_t i;
+
+    for (i = 0; i < f->tags.count; i++)
+    {
+        if (!stricmp(f->tags.tags[i].item, item))
+        {
+            uint32_t len = f->tags.tags[i].len;
+            *value = NULL;
+            *value = malloc(len);
+            if (*value != NULL) {
+                memcpy(*value, f->tags.tags[i].value, len);
+                return len;
+            }
+        }
+    }
+
+    *value = NULL;
+
+    /* not found */
+    return 0;
+}
+
 int32_t mp4ff_meta_get_num_items(const mp4ff_t *f)
 {
     return f->tags.count;
@@ -403,6 +440,11 @@
     return mp4ff_meta_find_by_name(f, "album", value);
 }
 
+int32_t mp4ff_meta_get_album_artist(const mp4ff_t *f, char **value)
+{
+    return mp4ff_meta_find_by_name(f, "album_artist", value);
+}
+
 int32_t mp4ff_meta_get_date(const mp4ff_t *f, char **value)
 {
     return mp4ff_meta_find_by_name(f, "date", value);
@@ -455,7 +497,7 @@
 
 int32_t mp4ff_meta_get_coverart(const mp4ff_t *f, char **value)
 {
-    return mp4ff_meta_find_by_name(f, "cover", value);
+    return mp4ff_meta_find_by_name_and_return_len(f, "cover", value);
 }
 
 #endif
\ No newline at end of file
--- a/configure.in
+++ b/configure.in
@@ -9,7 +9,7 @@
 
 AC_INIT
 AC_CONFIG_AUX_DIR(.)
-AM_INIT_AUTOMAKE(faad2, 2.7.0)
+AM_INIT_AUTOMAKE(faad2, 2.8.0cvs)
 
 AC_PROG_LIBTOOL
 AC_SUBST(LIBTOOL_DEPS)