Re: [Muine] m4a support (try #2)



On Tue, Jan 18, 2005 at 06:50:38AM -0800, Peter Johanson wrote:
> 
> oh, and i forgot to mention that currently most faad2 distributions are
> stupid, and forget to put mp4ff_int_types.h anywhere, which is needed by
> mp4ff.h. I'm not sure if you're suppod to use it locally to define
> things, or what. Best bet is to take the mp4ff_int_types.h from
> common/mp4ff/mp4ff_int_types.h and putting it in /usr/local/include. Not
> sure how this should be handled, or if we should put that in the local
> muine sources or what. Thoughts?

Ok, replying to myself for the 3rd time (making me the biggest luser on
the list, i expect my trophy soon). Here's a revised patch that changes
the autotools foo a tad, and disables this code by default (since faad
installs seem to be broken on most distros wrt the header situation).

As for that mp4ff.h header, it tries to include a file
mp4ff_int_types.h, that on any platform other than win32 just does:
#include <stdint.h>

So in reality all linux distros should be saying screw
mp4ff_int_types.h, and replace that include with the one listed above.
I've this fixed in gentoo already, but other distros may have to follow
suit to have this working.

-pete

PS - I think i'm done being lame, someone else want to comment?

> 

-- 
Peter Johanson
<latexer gentoo org>
Index: configure.in
===================================================================
RCS file: /cvs/gnome/muine/configure.in,v
retrieving revision 1.102
diff -a -u -r1.102 configure.in
--- configure.in	10 Jan 2005 17:59:26 -0000	1.102
+++ configure.in	18 Jan 2005 16:31:49 -0000
@@ -97,6 +97,29 @@
 AC_CHECK_HEADER(FLAC/all.h, FLAC_LIBS="-lFLAC", AC_MSG_ERROR(You need FLAC))
 AC_SUBST(FLAC_LIBS)
 
+dnl Check for FAAD 
+have_faad2=no
+AC_ARG_ENABLE(aac,
+	      [  --enable-aac   Enable faad2 library support],
+	      [ if test "x$enableval" = "xyes"; then
+	       		have_faad2=yes
+		elif test "x$enableval" = "xno"; then
+			have_faad2=no
+		else
+			have_faad2=no
+		fi
+])
+
+if test x$have_faad2 = xyes; then
+	AC_CHECK_HEADER(mp4ff.h, FAAD_LIBS="-lmp4ff -lfaad", AC_MSG_ERROR(faad2 library not found))
+	AC_DEFINE(HAVE_FAAD, 1, faad2 support)
+else
+	AC_DEFINE(HAVE_FAAD, 0, faad2 support)
+fi
+
+AM_CONDITIONAL(HAVE_FAAD, test "x$have_faad2" = "xyes")
+AC_SUBST(FAAD_LIBS)
+
 dnl Check for Mono
 AC_PATH_PROG(MCS, mcs)
 AC_PATH_PROG(MONO, mono)
Index: libmuine/Makefile.am
===================================================================
RCS file: /cvs/gnome/muine/libmuine/Makefile.am,v
retrieving revision 1.16
diff -a -u -r1.16 Makefile.am
--- libmuine/Makefile.am	14 Jan 2005 23:33:45 -0000	1.16
+++ libmuine/Makefile.am	18 Jan 2005 16:31:50 -0000
@@ -52,4 +52,4 @@
 	mm-keys.c			\
 	mm-keys.h
 	
-libmuine_la_LIBADD = id3-vfs/libid3-vfs.la egg/libegg.la $(MUINE_LIBS) $(OGG_LIBS) $(VORBIS_LIBS) $(VORBISFILE_LIBS) $(GDBM_LIBS) $(ID3TAG_LIBS) $(FLAC_LIBS)
+libmuine_la_LIBADD = id3-vfs/libid3-vfs.la egg/libegg.la $(MUINE_LIBS) $(OGG_LIBS) $(VORBIS_LIBS) $(VORBISFILE_LIBS) $(GDBM_LIBS) $(ID3TAG_LIBS) $(FLAC_LIBS) $(FAAD_LIBS)
Index: libmuine/metadata.c
===================================================================
RCS file: /cvs/gnome/muine/libmuine/metadata.c,v
retrieving revision 1.14
diff -a -u -r1.14 metadata.c
--- libmuine/metadata.c	26 Dec 2004 11:00:28 -0000	1.14
+++ libmuine/metadata.c	18 Jan 2005 16:31:50 -0000
@@ -26,11 +26,17 @@
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
+#include <config.h>
 
 #include "id3-vfs/id3-vfs.h"
 #include "ogg-helper.h"
 #include "metadata.h"
 
+#if HAVE_FAAD
+#include <faad.h>
+#include <mp4ff.h>
+#endif /* HAVE_FAAD */
+
 struct _Metadata {
 	char *title;
 
@@ -373,6 +379,125 @@
 	return metadata;
 }
 
+#if HAVE_FAAD
+
+uint32_t mp4_read_callback(void *user_data, void *buffer, uint32_t length);
+uint32_t mp4_seek_callback(void *user_data, uint64_t position);
+
+uint32_t mp4_read_callback(void *user_data, void *buffer, uint32_t length) {
+	GnomeVFSFileSize read;
+	gnome_vfs_read((GnomeVFSHandle*)user_data, (gpointer *)buffer,  length, &read);
+	return (uint32_t)read;
+}
+
+uint32_t mp4_seek_callback(void *user_data, uint64_t position) {
+	return (uint32_t) gnome_vfs_seek ((GnomeVFSHandle*) user_data, GNOME_VFS_SEEK_START, position);
+}
+
+static Metadata *
+assign_metadata_mp4 (const char *filename,
+		      char **error_message_return)
+{
+	Metadata *m = NULL;
+	GnomeVFSHandle *fh;
+	mp4ff_t *mp4f;
+	mp4ff_callback_t *mp4cb = (mp4ff_callback_t*) malloc (sizeof(mp4ff_callback_t));
+	gchar *value;
+	unsigned char *buff = NULL;
+        int buff_size = 0;
+	mp4AudioSpecificConfig mp4ASC;
+	long samples;
+	float f = 1024.0;
+
+	if (gnome_vfs_open (&fh, filename, GNOME_VFS_OPEN_READ) != GNOME_VFS_OK) {                                              
+                *error_message_return = g_strdup ("Failed to open file for reading");                                                                           
+                return NULL;                                                    
+        }
+
+	mp4cb->read = mp4_read_callback;
+	mp4cb->seek = mp4_seek_callback;
+	mp4cb->user_data = fh;
+
+	mp4f = mp4ff_open_read (mp4cb);
+
+	if (!mp4f)
+	{
+		*error_message_return = g_strdup ("Unable to open the AAC file");
+		return NULL;
+	}
+
+	if (mp4ff_total_tracks (mp4f) > 1)
+	{
+		 *error_message_return = g_strdup("Multi-track AAC files not supported");
+		 return NULL;
+	}
+
+	m = g_new0 (Metadata, 1);
+
+	if (mp4ff_meta_get_artist (mp4f, &value) && value != NULL)
+	{
+		if(g_utf8_validate (value, -1, NULL))
+		{
+			m->artists = g_new (char *, 2);
+			m->artists[0] = g_strdup (value);
+			m->artists[1] = NULL;
+			m->artists_count = 1;
+		}
+		g_free(value);
+	}
+	if (mp4ff_meta_get_title (mp4f, &value) && value != NULL)
+	{
+		if(g_utf8_validate (value, -1, NULL))
+			m->title = g_strdup (value);
+		g_free(value);
+	}
+	if (mp4ff_meta_get_album (mp4f, &value) && value != NULL)
+	{
+		if(g_utf8_validate (value, -1, NULL))
+			m->album = g_strdup (value);
+		g_free(value);
+	}
+	if (mp4ff_meta_get_track (mp4f, &value) && value != NULL)
+	{
+		m->track_number = atoi (value);
+		g_free (value);
+	}
+	if (mp4ff_meta_get_disc (mp4f, &value) && value != NULL)
+	{
+		m->disc_number = atoi (value);
+		g_free (value);
+	}
+
+	/*
+	 * duration code shameless based on code from frontend/main.c in faad2
+	 */
+
+	samples = mp4ff_num_samples (mp4f, 0);
+	mp4ff_get_decoder_config (mp4f, 0, &buff, &buff_size);
+
+	if (buff)
+	{
+		if (AudioSpecificConfig (buff, buff_size, &mp4ASC) >= 0)
+		{
+			free (buff);
+		        if (mp4ASC.sbr_present_flag == 1)
+		        {   
+		            f = f * 2.0;
+		        }	
+
+			m->duration = (float) samples * (float) (f-1.0)/(float) mp4ASC.samplingFrequency;
+		}
+	}
+
+	mp4ff_close (mp4f);
+	free (mp4cb);
+	gnome_vfs_close (fh);
+
+	return m;
+}
+
+#endif /* HAVE_FAAD */
+
 static ov_callbacks file_info_callbacks =
 {
         ogg_helper_read,
@@ -693,6 +818,11 @@
 	else if (!strcmp (info->mime_type, "application/x-flac") ||
 		 !strcmp (info->mime_type, "audio/x-flac"))
 		m = assign_metadata_flac (escaped, error_message_return);
+#if HAVE_FAAD
+	else if (!strcmp (info->mime_type, "application/x-m4a") ||
+		 !strcmp (info->mime_type, "audio/x-m4a"))
+		m = assign_metadata_mp4 (filename, error_message_return);
+#endif /* HAVE_FAAD */
 	else
 		*error_message_return = g_strdup ("Unknown format");
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]