shithub: aacdec

Download patch

ref: b5b68e541c7164b5be892b3f56d2d2b2a2f511a2
parent: 4c96445961d393dd08e924b8d430612cda152261
author: menno <menno>
date: Sun Dec 29 08:13:36 EST 2002

replaygain stuff fixed for foobar

--- a/common/mp4v2/mp4.cpp
+++ b/common/mp4v2/mp4.cpp
@@ -2546,13 +2546,12 @@
 	}
 }
 
-extern "C" void MP4TagAddEntry(MP4FileHandle hFile, MP4TrackId trackId,
+extern "C" bool MP4TagAddEntry(MP4FileHandle hFile, MP4TrackId trackId,
                                const char *name, const char *value)
 {
 	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
 		try {
-			((MP4File*)hFile)->TagAddEntry(trackId, name, value);
-            return;
+			return ((MP4File*)hFile)->TagAddEntry(trackId, name, value);
 		}
 		catch (MP4Error* e) {
 			PRINT_ERROR(e);
--- a/common/mp4v2/mp4.h
+++ b/common/mp4v2/mp4.h
@@ -909,7 +909,7 @@
 
 void MP4TagCreate(MP4FileHandle hFile, MP4TrackId trackId);
 bool MP4TagDelete(MP4FileHandle hFile, MP4TrackId trackId);
-void MP4TagAddEntry(MP4FileHandle hFile, MP4TrackId trackId,
+bool MP4TagAddEntry(MP4FileHandle hFile, MP4TrackId trackId,
                     const char *name, const char *value);
 #if 0
 void MP4TagDeleteEntry(MP4FileHandle hFile, MP4TrackId trackId,
--- a/common/mp4v2/mp4file.cpp
+++ b/common/mp4v2/mp4file.cpp
@@ -2346,7 +2346,7 @@
     return true;
 }
 
-void MP4File::TagAddEntry(MP4TrackId trackId,
+bool MP4File::TagAddEntry(MP4TrackId trackId,
                           const char *name, const char *value)
 {
     MP4StringProperty *pNameProperty = NULL;
@@ -2358,6 +2358,8 @@
         pTagAtom = m_pRootAtom->FindAtom("moov.udta.TAG4");
     else
         pTagAtom = m_pRootAtom->FindAtom(MakeTrackName(trackId, "udta.TAG4"));
+    if (!pTagAtom)
+        return false;
 
     pTagAtom->FindProperty("TAG4.entryCount",
         (MP4Property**)&pCountProperty);
@@ -2376,6 +2378,8 @@
     pValueProperty->AddValue((char*)value);
 
     pCountProperty->IncrementValue();
+
+    return true;
 }
 
 #if 0
--- a/common/mp4v2/mp4file.h
+++ b/common/mp4v2/mp4file.h
@@ -425,7 +425,7 @@
     /* tagging */
     void TagCreate(MP4TrackId trackId);
     bool TagDelete(MP4TrackId trackId);
-    void TagAddEntry(MP4TrackId trackId,
+    bool TagAddEntry(MP4TrackId trackId,
         const char *name, const char *value);
     u_int32_t TagGetNumEntries(MP4TrackId trackId);
     void TagGetEntry(MP4TrackId trackId, u_int32_t index,
--- a/plugins/foo_mp4/foo_mp4.cpp
+++ b/plugins/foo_mp4/foo_mp4.cpp
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: foo_mp4.cpp,v 1.11 2002/12/29 12:26:30 menno Exp $
+** $Id: foo_mp4.cpp,v 1.12 2002/12/29 13:13:36 menno Exp $
 **/
 
 #include <mp4.h>
@@ -147,20 +147,8 @@
         if (track < 1) return 0;
 
         MP4TagDelete(hFile, track);
+        MP4TagCreate(hFile, track);
 
-        int numItems = info->meta_get_count();
-        if (numItems > 0)
-        {
-            MP4TagCreate(hFile, track);
-
-            for (int i = 0; i < numItems; i++)
-            {
-                const char *n = info->meta_enum_name(i);
-                const char *v = info->meta_enum_value(i);
-                MP4TagAddEntry(hFile, track, n, v);
-            }
-        }
-
         /* replay gain writing */
         const char *p = NULL;
 
@@ -176,6 +164,21 @@
         p = info->info_get("REPLAYGAIN_ALBUM_GAIN");
         if (p)
             MP4TagAddEntry(hFile, track, "REPLAYGAIN_ALBUM_GAIN", p);
+
+        int numItems = info->meta_get_count();
+        if (numItems > 0)
+        {
+            for (int i = 0; i < numItems; i++)
+            {
+                const char *n = info->meta_enum_name(i);
+                const char *v = info->meta_enum_value(i);
+                MP4TagAddEntry(hFile, track, n, v);
+            }
+        }
+
+        numItems = MP4TagGetNumEntries(hFile, track);
+        if (numItems == 0)
+            MP4TagDelete(hFile, track);
 
         /* end */
         return 1;