changeset 339:e1630c75175b trunk

[svn] MP4 metadata retrieval support.
author nenolod
date Sun, 25 Dec 2005 23:22:44 -0800
parents 8528a27ada8f
children c7a67ac8e19c
files Plugins/Input/aac/src/libmp4.c Plugins/Input/aac/src/mp4_utils.c
diffstat 2 files changed, 81 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/Input/aac/src/libmp4.c	Sun Dec 25 14:38:14 2005 -0800
+++ b/Plugins/Input/aac/src/libmp4.c	Sun Dec 25 23:22:44 2005 -0800
@@ -11,7 +11,10 @@
  * libid3 (3.8.x - www.id3.org)
 */
 
+#include <glib.h>
 #include <gtk/gtk.h>
+#include <string.h>
+#include <stdlib.h>
 #include "faad.h"
 #include "mp4.h"
 
@@ -35,6 +38,7 @@
 static void	mp4_cleanup(void);
 static void	mp4_getSongInfo(char *);
 static int	mp4_isFile(char *);
+static void	mp4_getSongTitle(char *filename, char **, int *);
 static void*	mp4Decode(void *);
 
 InputPlugin mp4_ip =
@@ -60,7 +64,7 @@
     0,	// send visualisation data
     0,	// set player window info
     0,	// set song title text
-    0,	// get song title text
+    mp4_getSongTitle,	// get song title text
     mp4_getSongInfo, // info box
     0,	// to output plugin
   };
@@ -81,6 +85,23 @@
 void getMP4info(char*);
 int getAACTrack(MP4FileHandle);
 
+/*
+ * Function extname (filename)
+ *
+ *    Return pointer within filename to its extenstion, or NULL if
+ *    filename has no extension.
+ *
+ */
+static gchar *
+extname(const char *filename)
+{   
+    gchar *ext = strrchr(filename, '.');
+
+    if (ext != NULL)
+        ++ext;
+
+    return ext;
+}
 
 InputPlugin *get_iplugin_info(void)
 {
@@ -176,6 +197,54 @@
     ;
 }
 
+static gchar   *mp4_get_song_title(char *filename)
+{
+	MP4FileHandle mp4file;
+	gchar *title = NULL;
+
+	if (!(mp4file = MP4Read(filename, 0))) {
+		MP4Close(mp4file);
+	} else {
+		TitleInput *input;
+		gchar *tmpval;
+
+		input = bmp_title_input_new();
+
+		MP4GetMetadataName(mp4file, &input->track_name);
+		MP4GetMetadataAlbum(mp4file, &input->album_name);
+		MP4GetMetadataArtist(mp4file, &input->performer);
+		MP4GetMetadataYear(mp4file, &tmpval);
+		MP4GetMetadataGenre(mp4file, &input->genre);
+
+		input->year = atoi(tmpval);
+
+		input->file_name = g_path_get_basename(filename);
+		input->file_path = g_path_get_dirname(filename);
+		input->file_ext = extname(filename);
+
+		title = xmms_get_titlestring(xmms_get_gentitle_format(), input);
+
+		free (input->file_name);
+		free (input->file_path);
+		free (input);
+	}
+
+	if (!title)
+	{
+		title = g_path_get_basename(filename);
+		if (extname(title))
+			*(extname(title) - 1) = '\0';
+	}
+
+	return title;
+}
+
+static void	mp4_getSongTitle(char *filename, char **title_real, int *len_real)
+{
+	(*title_real) = mp4_get_song_title(filename);
+	(*len_real) = -1;
+}
+
 static void *mp4Decode(void *args)
 {
   MP4FileHandle mp4file;
@@ -214,6 +283,7 @@
       gulong		msDuration;
       MP4SampleId	numSamples;
       MP4SampleId	sampleID = 1;
+      gchar            *title;
 
       decoder = faacDecOpen();
       MP4GetTrackESConfiguration(mp4file, mp4track, &buffer, &bufferSize);
@@ -232,8 +302,8 @@
       numSamples = MP4GetTrackNumberOfSamples(mp4file, mp4track);
       mp4_ip.output->open_audio(FMT_S16_NE, samplerate, channels);
       mp4_ip.output->flush(0);
-      mp4_ip.set_info(args, msDuration, -1, samplerate/1000, channels);
-      g_print("MP4 - %d channels @ %d Hz\n", channels, (int)samplerate);
+      title = mp4_get_song_title(args);
+      mp4_ip.set_info(title, msDuration, -1, samplerate/1000, channels);
 
       while(bPlaying){
 	void*			sampleBuffer;
@@ -256,7 +326,6 @@
 	}
 	rc = MP4ReadSample(mp4file, mp4track, sampleID++, &buffer, &bufferSize,
 			   NULL, NULL, NULL, NULL);
-	//g_print("%d/%d\n", sampleID-1, numSamples);
 	if((rc==0) || (buffer== NULL)){
 	  g_print("MP4: read error\n");
 	  sampleBuffer = NULL;
--- a/Plugins/Input/aac/src/mp4_utils.c	Sun Dec 25 14:38:14 2005 -0800
+++ b/Plugins/Input/aac/src/mp4_utils.c	Sun Dec 25 23:22:44 2005 -0800
@@ -56,7 +56,6 @@
 
     if(!strcmp(trackType, MP4_AUDIO_TRACK_TYPE)){//we found audio track !
       u_int8_t audiotype = MP4GetTrackAudioMpeg4Type(file, trackID);
-      g_print("%s\n", mpeg4AudioNames[audiotype]);
       if(audiotype !=0)
 	return(trackID);
       else
@@ -102,12 +101,20 @@
   //MP4Duration	trackDuration;
   int numTracks;
   int i=0;
+  char *value;
 
   if(!(mp4file = MP4Read(file,0)))
     return;
   //MP4Dump(mp4file, 0, 0);
   numTracks = MP4GetNumberOfTracks(mp4file, NULL, 0);
   g_print("there are %d track(s)\n", numTracks);
+
+  MP4GetMetadataName(mp4file, &value);
+  g_print(" name : %s\n", value);
+
+  MP4GetMetadataArtist(mp4file, &value);
+  g_print(" artist : %s\n", value);
+
   for(i=0;i<numTracks;i++){
     MP4TrackId trackID = MP4FindTrackId(mp4file, i, NULL, 0);
     const char *trackType = MP4GetTrackType(mp4file, trackID);