[Muine] More AAC patch spam.
- From: Peter Johanson <latexer gentoo org>
- To: muine-list gnome org
- Subject: [Muine] More AAC patch spam.
- Date: Tue, 18 Jan 2005 16:11:27 -0800
(yes, there's one more version.)
This version adds support for setting the total_tracks attribute, so
albums composed of AAC files will show up in the new Add Album dialog if
they are tagged properly (see Jorn's post about the implemented
incomplete album handling). In adding this, I reworked most of the code
to make it smaller/cleaner. As usual, testing appreciated.
</spam>
-pete
--
Peter Johanson
<latexer gentoo org>
Index: configure.in
===================================================================
RCS file: /cvs/gnome/muine/configure.in,v
retrieving revision 1.103
diff -a -u -r1.103 configure.in
--- configure.in 16 Jan 2005 19:15:33 -0000 1.103
+++ configure.in 19 Jan 2005 00:05:50 -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 AAC 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 19 Jan 2005 00:05: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.15
diff -a -u -r1.15 metadata.c
--- libmuine/metadata.c 16 Jan 2005 00:25:07 -0000 1.15
+++ libmuine/metadata.c 19 Jan 2005 00:05: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;
@@ -394,6 +400,135 @@
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;
+ gchar *item;
+ unsigned char *buff = NULL;
+ int buff_size = 0;
+ int j, k;
+ 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);
+
+ j = mp4ff_meta_get_num_items (mp4f);
+
+ for (k = 0; k < j; k++)
+ {
+ if (mp4ff_meta_get_by_index (mp4f, k, &item, &value))
+ {
+ if (!strcmp (item, "title"))
+ {
+ if(g_utf8_validate (value, -1, NULL))
+ m->title = g_strdup (value);
+ }
+ else if (!strcmp (item, "artist"))
+ {
+ 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;
+ }
+ }
+ else if (!strcmp (item, "album"))
+ {
+ if(g_utf8_validate (value, -1, NULL))
+ m->album = g_strdup (value);
+ }
+ else if (!strcmp (item, "track"))
+ m->track_number = atoi (value);
+ else if (!strcmp (item, "totaltracks"))
+ m->total_tracks = atoi(value);
+ else if (!strcmp (item, "disc"))
+ m->disc_number = atoi (value);
+ else if (!strcmp (item, "date"))
+ {
+ if(g_utf8_validate (value, -1, NULL))
+ m->year = g_strdup (value);
+ }
+ free (item);
+ 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,
@@ -717,6 +852,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]