ref: 4c96445961d393dd08e924b8d430612cda152261
parent: 82bc6ccd76179f01824177ed8b7ce5905ec929e2
author: menno <menno>
date: Sun Dec 29 07:26:30 EST 2002
Some bugfixes in tagging. replaygain support
--- a/common/mp4v2/mp4.cpp
+++ b/common/mp4v2/mp4.cpp
@@ -2533,12 +2533,11 @@
}
}
-extern "C" void MP4TagDelete(MP4FileHandle hFile, MP4TrackId trackId)
+extern "C" bool MP4TagDelete(MP4FileHandle hFile, MP4TrackId trackId)
{
if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
try {
- ((MP4File*)hFile)->TagDelete(trackId);
- return;
+ return ((MP4File*)hFile)->TagDelete(trackId);
}
catch (MP4Error* e) {
PRINT_ERROR(e);
@@ -2610,3 +2609,16 @@
}
}
+extern "C" bool MP4TagGetEntryByName(MP4FileHandle hFile, MP4TrackId trackId,
+ char *name, const char **value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->TagGetEntryByName(trackId, name, value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+}
--- a/common/mp4v2/mp4.h
+++ b/common/mp4v2/mp4.h
@@ -908,7 +908,7 @@
u_int32_t dataSize);
void MP4TagCreate(MP4FileHandle hFile, MP4TrackId trackId);
-void MP4TagDelete(MP4FileHandle hFile, MP4TrackId trackId);
+bool MP4TagDelete(MP4FileHandle hFile, MP4TrackId trackId);
void MP4TagAddEntry(MP4FileHandle hFile, MP4TrackId trackId,
const char *name, const char *value);
#if 0
@@ -918,6 +918,8 @@
u_int32_t MP4TagGetNumEntries(MP4FileHandle hFile, MP4TrackId trackId);
void MP4TagGetEntry(MP4FileHandle hFile, MP4TrackId trackId,
u_int32_t index, const char **name, const char **value);
+bool MP4TagGetEntryNyName(MP4FileHandle hFile, MP4TrackId trackId,
+ char *name, const char **value);
#ifdef __cplusplus
}
--- a/common/mp4v2/mp4file.cpp
+++ b/common/mp4v2/mp4file.cpp
@@ -2323,7 +2323,7 @@
AddDescendantAtoms(MakeTrackName(trackId, NULL), "udta.TAG4");
}
-void MP4File::TagDelete(MP4TrackId trackId)
+bool MP4File::TagDelete(MP4TrackId trackId)
{
MP4Atom *pUdtaAtom = NULL;
MP4Atom *pTagAtom = NULL;
@@ -2336,10 +2336,14 @@
pUdtaAtom = m_pRootAtom->FindAtom(MakeTrackName(trackId, "udta"));
pTagAtom = m_pRootAtom->FindAtom(MakeTrackName(trackId, "udta.TAG4"));
}
+ if (!pUdtaAtom || !pTagAtom)
+ return false;
pUdtaAtom->DeleteChildAtom(pTagAtom);
delete pTagAtom;
+
+ return true;
}
void MP4File::TagAddEntry(MP4TrackId trackId,
@@ -2440,4 +2444,24 @@
sprintf(s, "udta.TAG4.entries[%u].value", index);
*value = GetTrackStringProperty(trackId, s);
}
+}
+
+bool MP4File::TagGetEntryByName(MP4TrackId trackId, char *name,
+ const char **value)
+{
+ int numEntries = TagGetNumEntries(trackId);
+
+ for (int i = 0; i < numEntries; i++)
+ {
+ const char *n = NULL, *v = NULL;
+ TagGetEntry(trackId, i, &n, &v);
+
+ if (!strcmp(n, name))
+ {
+ strcpy((char*)*value, v);
+ return true;
+ }
+ }
+
+ return false;
}
--- a/common/mp4v2/mp4file.h
+++ b/common/mp4v2/mp4file.h
@@ -424,13 +424,14 @@
/* tagging */
void TagCreate(MP4TrackId trackId);
- void TagDelete(MP4TrackId trackId);
+ bool TagDelete(MP4TrackId trackId);
void TagAddEntry(MP4TrackId trackId,
const char *name, const char *value);
- void TagDeleteEntry(MP4TrackId trackId, u_int32_t index);
u_int32_t TagGetNumEntries(MP4TrackId trackId);
void TagGetEntry(MP4TrackId trackId, u_int32_t index,
const char **name, const char **value);
+ bool TagGetEntryByName(MP4TrackId trackId, char *name,
+ const char **value);
/* end of MP4 API */
--- 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.10 2002/12/29 11:10:18 menno Exp $
+** $Id: foo_mp4.cpp,v 1.11 2002/12/29 12:26:30 menno Exp $
**/
#include <mp4.h>
@@ -146,8 +146,7 @@
track = GetAACTrack(hFile);
if (track < 1) return 0;
- if (MP4TagGetNumEntries(hFile, track) > 0)
- MP4TagDelete(hFile, track);
+ MP4TagDelete(hFile, track);
int numItems = info->meta_get_count();
if (numItems > 0)
@@ -162,6 +161,23 @@
}
}
+ /* replay gain writing */
+ const char *p = NULL;
+
+ p = info->info_get("REPLAYGAIN_TRACK_PEAK");
+ if (p)
+ MP4TagAddEntry(hFile, track, "REPLAYGAIN_TRACK_PEAK", p);
+ p = info->info_get("REPLAYGAIN_TRACK_GAIN");
+ if (p)
+ MP4TagAddEntry(hFile, track, "REPLAYGAIN_TRACK_GAIN", p);
+ p = info->info_get("REPLAYGAIN_ALBUM_PEAK");
+ if (p)
+ MP4TagAddEntry(hFile, track, "REPLAYGAIN_ALBUM_PEAK", p);
+ p = info->info_get("REPLAYGAIN_ALBUM_GAIN");
+ if (p)
+ MP4TagAddEntry(hFile, track, "REPLAYGAIN_ALBUM_GAIN", p);
+
+ /* end */
return 1;
}
@@ -195,10 +211,27 @@
for (int i = 0; i < numItems; i++)
{
+ float f = 0.0;
const char *n = NULL, *v = NULL;
MP4TagGetEntry(hFile, track, i, &n, &v);
- info->meta_add(n, v);
+
+ if (!strcmp(n, "REPLAYGAIN_TRACK_PEAK"))
+ {
+ sscanf(v, "%f", &f);
+ info->info_set_replaygain_track_peak((double)f);
+ } else if (!strcmp(n, "REPLAYGAIN_TRACK_GAIN")) {
+ sscanf(v, "%f", &f);
+ info->info_set_replaygain_track_gain((double)f);
+ } else if (!strcmp(n, "REPLAYGAIN_ALBUM_PEAK")) {
+ sscanf(v, "%f", &f);
+ info->info_set_replaygain_album_peak((double)f);
+ } else if (!strcmp(n, "REPLAYGAIN_ALBUM_GAIN")) {
+ sscanf(v, "%f", &f);
+ info->info_set_replaygain_album_gain((double)f);
+ } else {
+ info->meta_add(n, v);
+ }
}
return 1;