~ft/aacdec

3355b74f09a966b393fd49c7230e1161ba4bcfaf — menno 18 years ago 2405cc8
Build system update
XMMS plugin update (now uses mp4ff library)
Thanks ciberfred!
M common/mp4ff/Makefile.am => common/mp4ff/Makefile.am +3 -7
@@ 1,12 1,8 @@
lib_LTLIBRARIES = libmp4ff.la
noinst_LIBRARIES = libmp4ff.a

include_HEADERS = mp4ff.h
libmp4ff_a_CFLAGS = -DUSE_TAGGING=1

libmp4ff_la_SOURCES = mp4ff.c mp4atom.c mp4meta.c mp4sample.c mp4util.c \
libmp4ff_a_SOURCES = mp4ff.c mp4atom.c mp4meta.c mp4sample.c mp4util.c \
   mp4tagupdate.c mp4ff.h mp4ffint.h mp4ff_int_types.h \
   drms.h drms.c drmstables.h

AM_CFLAGS = -O2 -g -DUSE_TAGGING=1
LIBTOOL_DEPS =
LIBS = @MP4FF_LIBS@


M configure.in => configure.in +55 -38
@@ 1,3 1,12 @@
dnl
dnl This is the configure.in for faad2 related to unix creation

dnl - libfaad.so
dnl - libmp4ff.a (only static for moment)
dnl - faad
dnl - xmms input mp4/aac plugin
dnl - mpeg4ip plugin (broken) -> disable for moment

AC_INIT
AC_CONFIG_AUX_DIR(.)
AM_INIT_AUTOMAKE(faad2, 2.0)


@@ 6,9 15,10 @@ AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)

dnl Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
dnl disable for mpeg4ip plugin
dnl AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET


@@ 16,11 26,14 @@ AC_CHECK_PROGS(RPMBUILD, rpmbuild, rpm)

AM_CONFIG_HEADER(config.h)

AC_ARG_WITH( xmms,   [  --with-xmms             compile XMMS plugins],WITHXMMS=$withval, WITHXMMS=no)
AC_ARG_WITH(xmms,[  --with-xmms             compile XMMS-1 plugin],
	     WITHXMMS=$withval, WITHXMMS=no)

AC_ARG_WITH( drm,    [  --with-drm              compile libfaad with DRM support],WITHDRM=$withval, WITHDRM=no)
AC_ARG_WITH(drm,[  --with-drm              compile libfaad with DRM support],
	     WITHDRM=$withval, WITHDRM=no)

AC_ARG_WITH( mp4v2,  [  --with-mp4v2            compile libmp4v2],WITHMP4V2=$withval, WITHMP4V2=no)
dnl AC_ARG_WITH(mp4v2,[  --with-mp4v2            compile libmp4v2],
dnl		WITHMP4V2=$withval, WITHMP4V2=no)

dnl Checks for header files required for mp4.h
AC_HEADER_STDC


@@ 67,32 80,32 @@ MY_CHECK_TYPEDEF_FROM_INCLUDE([float32_t temp],

AC_CHECK_FUNCS(strsep)

MY_CHECK_TYPEDEF_FROM_INCLUDE([in_port_t temp],
        [#include <sys/types.h>
         #include <netinet/in.h>], [HAVE_IN_PORT_T])
MY_CHECK_TYPEDEF_FROM_INCLUDE([socklen_t temp],
        [#include <sys/types.h>
         #include <sys/socket.h>], HAVE_SOCKLEN_T)
MY_CHECK_TYPEDEF_FROM_INCLUDE([fpos_t foo; foo.__pos = 0;],
        [#include <stdio.h>],
        [HAVE_FPOS_T_POS])


AC_CHECK_PROG(external_mp4v2, mpeg4ip-config, yes, no)
AM_CONDITIONAL(WITH_MP4V2, false)

if test x$external_mp4v2 = xyes; then
  AM_CONDITIONAL(HAVE_MPEG4IP, true)
  MPEG4IP_PLAYER_PLUGIN_DIR=`mpeg4ip-config --player-plugin-dir`  
  AC_SUBST(MPEG4IP_PLAYER_PLUGIN_DIR)
  AC_MSG_NOTICE([*** Building with external mp4v2 ***])
else
  AC_MSG_NOTICE([*** Building with internal mp4v2 ***])
  AM_CONDITIONAL(HAVE_MPEG4IP, false)
  if test x$WITHMP4V2 = xyes; then
     AM_CONDITIONAL(WITH_MP4V2, true)
  fi
fi
dnl MY_CHECK_TYPEDEF_FROM_INCLUDE([in_port_t temp],
dnl         [#include <sys/types.h>
dnl          #include <netinet/in.h>], [HAVE_IN_PORT_T])
dnl MY_CHECK_TYPEDEF_FROM_INCLUDE([socklen_t temp],
dnl         [#include <sys/types.h>
dnl          #include <sys/socket.h>], HAVE_SOCKLEN_T)
dnl MY_CHECK_TYPEDEF_FROM_INCLUDE([fpos_t foo; foo.__pos = 0;],
dnl         [#include <stdio.h>],
dnl         [HAVE_FPOS_T_POS])


dnl AC_CHECK_PROG(external_mp4v2, mpeg4ip-config, yes, no)
dnl AM_CONDITIONAL(WITH_MP4V2, false)

dnl if test x$external_mp4v2 = xyes; then
dnl   AM_CONDITIONAL(HAVE_MPEG4IP, true)
dnl   MPEG4IP_PLAYER_PLUGIN_DIR=`mpeg4ip-config --player-plugin-dir`  
dnl   AC_SUBST(MPEG4IP_PLAYER_PLUGIN_DIR)
dnl   AC_MSG_NOTICE([*** Building with external mp4v2 ***])
dnl else
dnl   AC_MSG_NOTICE([*** Building with internal mp4v2 ***])
dnl   AM_CONDITIONAL(HAVE_MPEG4IP, false)
dnl   if test x$WITHMP4V2 = xyes; then
dnl      AM_CONDITIONAL(WITH_MP4V2, true)
dnl   fi
dnl fi

if test x$WITHXMMS = xyes; then
  AC_CHECK_PROGS(XMMS_CONFIG, xmms-config,"not_found")


@@ 109,9 122,9 @@ if test x$WITHXMMS = xyes; then
  fi

  AM_CONDITIONAL(HAVE_XMMS, true)
  AC_MSG_NOTICE("xmms plugin requires libmp4v2 to be build")
  AM_CONDITIONAL(WITH_MP4V2, true)
  AC_CONFIG_FILES(plugins/xmms/Makefile plugins/xmms/src/Makefile)
dnl  AC_MSG_NOTICE("xmms plugin requires libmp4v2 to be build")
dnl  AM_CONDITIONAL(WITH_MP4V2, true)
dnl  AC_CONFIG_FILES(plugins/xmms/Makefile plugins/xmms/src/Makefile)
else
 AC_MSG_NOTICE(no xmms build configured)
 AM_CONDITIONAL(HAVE_XMMS, false)


@@ 121,11 134,15 @@ if test x$WITHDRM = xyes; then
  AC_DEFINE(DRM, 1, [Define if you want to use libfaad together with Digital Radio Mondiale (DRM)])
fi

AC_CONFIG_FILES(libfaad/Makefile frontend/Makefile common/Makefile plugins/Makefile Makefile )

AC_CONFIG_FILES(plugins/mpeg4ip/Makefile)

AC_CONFIG_FILES(libfaad/Makefile)
AC_CONFIG_FILES(common/Makefile)
AC_CONFIG_FILES(common/mp4ff/Makefile)

AC_CONFIG_FILES(plugins/Makefile)
AC_CONFIG_FILES(plugins/xmms/Makefile)
AC_CONFIG_FILES(plugins/xmms/src/Makefile)
dnl AC_CONFIG_FILES(plugins/mpeg4ip/Makefile)
AC_CONFIG_FILES(faad2.spec)
AC_CONFIG_FILES(frontend/Makefile)
AC_CONFIG_FILES(Makefile)

AC_OUTPUT

M frontend/Makefile.am => frontend/Makefile.am +5 -7
@@ 1,13 1,11 @@
bin_PROGRAMS = faad

faad_SOURCES = main.c audio.c $(top_srcdir)/common/faad/getopt.c \
   audio.h

AM_CFLAGS = -O2
INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/common/faad \
   -I$(top_srcdir)/common/mp4ff
LDADD = $(top_builddir)/libfaad/libfaad.la \
   $(top_builddir)/common/mp4ff/libmp4ff.la

faad_LDADD = $(top_builddir)/libfaad/libfaad.la \
	$(top_builddir)/common/mp4ff/libmp4ff.a

CCLD = $(CXX)
faad_SOURCES = main.c \
	audio.c audio.h \
	$(top_srcdir)/common/faad/getopt.c

M libfaad/Makefile.am => libfaad/Makefile.am +5 -6
@@ 1,5 1,8 @@
lib_LTLIBRARIES = libfaad.la
include_HEADERS = ../include/faad.h

include_HEADERS = $(top_srcdir)/include/faad.h

libfaad_la_LDFLAGS = -lm

libfaad_la_SOURCES = bits.c cfft.c decoder.c drc.c \
drm_dec.c error.c filtbank.c \


@@ 19,8 22,4 @@ sbr_huff.h sbr_noise.h sbr_qmf.h sbr_syntax.h sbr_tf_grid.h \
sbr_qmf_c.h codebook/hcb.h \
codebook/hcb_1.h codebook/hcb_2.h codebook/hcb_3.h codebook/hcb_4.h \
codebook/hcb_5.h codebook/hcb_6.h codebook/hcb_7.h codebook/hcb_8.h \
codebook/hcb_9.h codebook/hcb_10.h codebook/hcb_11.h codebook/hcb_sf.h

LIBTOOL_DEPS =
LIBS =

codebook/hcb_9.h codebook/hcb_10.h codebook/hcb_11.h codebook/hcb_sf.h
\ No newline at end of file

M plugins/Makefile.am => plugins/Makefile.am +0 -8
@@ 1,13 1,5 @@
if HAVE_MPEG4IP
if HAVE_XMMS
SUBDIRS = mpeg4ip xmms
else
SUBDIRS = mpeg4ip
endif
else
if HAVE_XMMS
SUBDIRS = xmms
else
SUBDIRS =
endif
endif

M plugins/xmms/ChangeLog => plugins/xmms/ChangeLog +3 -0
@@ 1,3 1,6 @@
22 August 2004:
	* move from libmp4v2 to libmp4ff

1 December 2003:
	* remove aac plug and merge the aac part with the mp4 part
	  so now 2 plugins in one :)

M plugins/xmms/INSTALL => plugins/xmms/INSTALL +2 -4
@@ 1,4 1,2 @@
ton install the mp4/aac plugin run :
 - autoreconf -vfs && configure
and install as root with :
 - make install-strip
the installation of this plugin is provide by the faad2 package.
add to configure time the option '--with-xmms' and the plugin will be build
\ No newline at end of file

M plugins/xmms/NEWS => plugins/xmms/NEWS +5 -0
@@ 1,3 1,8 @@
22 Aout 2004
------------
modification du system de compilation, passage de libmp4v2 a libmp4ff
en static, libfaad en dynamique.

1 Decembre 2003
---------------
merge du plugin aac et du plugin mp4. modification des script du projet faad

M plugins/xmms/README => plugins/xmms/README +2 -17
@@ 1,4 1,4 @@
                             xmms-mp4 plugin v0.4
                             xmms-mp4 plugin v0.5
                              (dynamic version)
                       "a mp4/aac audio player for xmms"
                       coded by ciberfred from france  


@@ 19,20 19,5 @@ ICQ  : 17293220
aac plugin homepage (and more) : http://fondriest.frederic.free.fr/realisations/
IRC  : irc.eu.freenode.net (#lamip)

	-------------------------------------------------------------
			!!!!!!!!!! WARNING !!!!!!!!!!!!
if at the end of some song there is a segfault (xmms going out!),
this is probably you have an old aac song encoded with an old psytel
encoder (maybe a 1.x).
This error is comming from faad2
To remove this error use psystrip.exe windows program on the file. This maybe
resolve this problem.
        -------------------------------------------------------------

This plugin was tested with the psytel encoder v2.15 and a nero encoder

	-------------------------------------------------------------


-- 
Fr�d�ric Fondriest
Frederic Fondriest

D plugins/xmms/configure.in => plugins/xmms/configure.in +0 -38
@@ 1,38 0,0 @@
dnl configure.in for xmms faad2-2.0 package

AC_INIT(src/libmp4.c)
AM_INIT_AUTOMAKE(libmp4, 0.4)

dnl save CFLAGS since AC_PROG_CC insert "-g -O2" if CFLAGS is empty
cflags_save="$CFLAGS"

AM_DISABLE_STATIC

AC_PROG_CC
AC_PROG_LIBTOOL
AC_PROG_INSTALL

AC_CHECK_PROGS(XMMS_CONFIG, xmms-config,
	[AC_MSG_ERROR("*** xmms-config not found check PATH or install xmms")])

AC_CHECK_LIB(mp4v2, MP4Create, ,AC_MSG_ERROR(*** libmp4v2 not installed), -lstdc++)

CFLAGS="$cflags_save `xmms-config --cflags`"
CPPFLAGS="$CPPFLAGS $CFLAGS"
AC_SUBST(CFLAGS)

AC_CHECK_HEADER(pthread.h,,
	AC_MSG_ERROR(*** pthread headers support not installed or not found))
AC_CHECK_HEADER(id3.h,,
	AC_MSG_ERROR(*** id3lib headers support not installed or not found))
AC_CHECK_HEADER(faad.h,,
	AC_MSG_ERROR(*** faad header not installed check your CFLAGS))

AC_OUTPUT(Makefile src/Makefile )

echo ""
echo "-------==========MP4 & MPEG2/4-AAC decoder configured===========------"
echo "CFLAGS:   $CFLAGS"
echo "CXXFLAGS: $CXXFLAGS"
echo "install-dir = `xmms-config --input-plugin-dir`"
echo ""

M plugins/xmms/src/Makefile.am => plugins/xmms/src/Makefile.am +4 -5
@@ 2,12 2,11 @@ libdir = `$(XMMS_CONFIG) --input-plugin-dir`
lib_LTLIBRARIES = libmp4.la

libmp4_la_CFLAGS = `$(XMMS_CONFIG) --cflags` -Wall \
       `$(GTK_CONFIG) --cflags` -DHAVE_GLIB_H=1 \
       -I$(top_srcdir)/include -I$(top_srcdir)/common/mp4v2
       -I$(top_srcdir)/include -I$(top_srcdir)/common/mp4ff

libmp4_la_LIBADD = $(top_builddir)/libfaad/libfaad.la \
       $(top_builddir)/common/mp4v2/libmp4v2.la
       $(top_builddir)/common/mp4ff/libmp4ff.a

libmp4_la_LDFLAGS = -module -avoid-version `$(XMMS_CONFIG) --libs` -lpthread

libmp4_la_LDFLAGS = -module -avoid-version `$(XMMS_CONFIG) --libs` \
       `$(GTK_CONFIG) --libs` -lpthread -lstdc++
libmp4_la_SOURCES = libmp4.c mp4_utils.c aac_utils.c

M plugins/xmms/src/libmp4.c => plugins/xmms/src/libmp4.c +132 -66
@@ 8,17 8,19 @@

#include <pthread.h>
#include <gtk/gtk.h>
#include "faad.h"
#include "mp4.h"
#include <stdio.h>
#include <string.h>

#include <xmms/plugin.h>
#include <xmms/util.h>
#include <xmms/configfile.h>
#include <xmms/titlestring.h>

#include "neaacdec.h"
#include "mp4ff.h"

#define MP4_DESCRIPTION	"MP4 & MPEG2/4-AAC audio player - 1.2.x"
#define MP4_VERSION	"ver. 0.4 - 24 November 2003"
#define LIBMP4V2_VERSION "-faad2-version"
#define MP4_VERSION	"ver. 0.5-faad2-version - 22 August 2004"
#define MP4_ABOUT	"Written by ciberfred"
#define BUFFER_SIZE	FAAD_MIN_STREAMSIZE*64



@@ 76,6 78,8 @@ static pthread_mutex_t	mutex = PTHREAD_MUTEX_INITIALIZER;
static int		seekPosition = -1;


extern int getAACTrack(mp4ff_t *infile);

InputPlugin *get_iplugin_info(void)
{
  return(&mp4_ip);


@@ 112,11 116,11 @@ static int	mp4_isFile(char *filename)
    gchar*	extention;

    extention = strrchr(filename, '.');
    if (extention &&
	!strcasecmp(extention, ".mp4") ||	// official extention
	!strcasecmp(extention, ".m4a") ||	// Apple mp4 extention
	!strcasecmp(extention, ".aac")		// old MPEG2/4-AAC extention
	){
    if(extention &&
       (!strncasecmp(extention, ".mp4", 4) ||	// official extention
	!strncasecmp(extention, ".m4a", 4) ||	// Apple mp4 extention
	!strncasecmp(extention, ".aac", 4)	// old MPEG2/4-AAC extention
	)){
      return (1);
    }
  }


@@ 131,7 135,6 @@ static void	mp4_about(void)
    return;
  aboutbox = xmms_show_message("About MP4 AAC player plugin",
			       "libfaad2-" FAAD2_VERSION "\n"
			       "libmp4v2-" LIBMP4V2_VERSION "\n"
			       "plugin version: " MP4_VERSION "\n"
			       MP4_ABOUT,
			       "Ok", FALSE, NULL, NULL);


@@ 169,61 172,121 @@ static void	mp4_getSongInfo(char *filename)
  if(mp4cfg.file_type == FILE_MP4)
    getMP4info(filename);
  else if(mp4cfg.file_type == FILE_AAC)
    /*
     * check the id3tagv2
    */
    ;
}

uint32_t read_callback(void *user_data, void *buffer, uint32_t length)
{
  return fread(buffer, 1, length, (FILE*)user_data);
}

uint32_t seek_callback(void *user_data, uint64_t position)
{
  return fseek((FILE*)user_data, position, SEEK_SET);
}


static void *mp4Decode(void *args)
{
  MP4FileHandle mp4file;
  FILE*		mp4file;
  unsigned char header[10] = {0};

  pthread_mutex_lock(&mutex);
  seekPosition = -1;
  bPlaying = TRUE;
  if(!(mp4file = MP4Read(args, 0))){
    mp4cfg.file_type = FILE_AAC;
    MP4Close(mp4file);
  }else{

  if(!(mp4file = fopen(args, "rb"))){
    g_print("MP4!AAC - Can't open file\n");
    g_free(args);
    bPlaying = FALSE;
    pthread_mutex_unlock(&mutex);
    pthread_exit(NULL);

  }
  fread(header, 1, 8, mp4file);
  if(header[4]=='f' &&
     header[5]=='t' &&
     header[6]=='y' &&
     header[7]=='p'){
    mp4cfg.file_type = FILE_MP4;
  }else{
    mp4cfg.file_type = FILE_AAC;
  }

  if(mp4cfg.file_type == FILE_MP4){
    // We are reading a MP4 file
  fseek(mp4file, SEEK_SET, 0);
  if(mp4cfg.file_type == FILE_MP4){// We are reading a MP4 file
    mp4ff_t*		infile;
    gint		mp4track;

    if((mp4track = getAACTrack(mp4file)) < 0){
      //TODO: check here for others Audio format.....
    
    mp4ff_callback_t* mp4cb = malloc(sizeof(mp4ff_callback_t));
    mp4cb->read = read_callback;
    mp4cb->seek = seek_callback;
    mp4cb->user_data = mp4file;
    if(!(infile = mp4ff_open_read(mp4cb))){
      g_print("MP4 - Can't open file\n");
    }
    
    if((mp4track = getAACTrack(infile)) < 0){
      /*
       * TODO: check here for others Audio format.....
       *
      */
      g_print("Unsupported Audio track type\n");
      g_free(args);
      MP4Close(mp4file);
      fclose(mp4file);
      bPlaying = FALSE;
      pthread_mutex_unlock(&mutex);
      pthread_exit(NULL);
    }else{
      faacDecHandle	decoder;
    }else{  
      NeAACDecHandle	decoder;
      unsigned char	*buffer	= NULL;
      guint		bufferSize = 0;
      gulong		samplerate;
      guchar		channels;
      guint		avgBitrate;
      MP4Duration	duration;
      gulong		msDuration;
      MP4SampleId	numSamples;
      MP4SampleId	sampleID = 1;

      decoder = faacDecOpen();
      MP4GetTrackESConfiguration(mp4file, mp4track, &buffer, &bufferSize);
      if(faacDecInit2(decoder, buffer, bufferSize, &samplerate, &channels)<0){
      //MP4Duration	duration;
      int		msDuration;
      int		numSamples;
      int		sampleID = 0;
      unsigned int	framesize;
      mp4AudioSpecificConfig mp4ASC;

      decoder = NeAACDecOpen();
      mp4ff_get_decoder_config(infile, mp4track, &buffer, &bufferSize);
      if(NeAACDecInit2(decoder, buffer, bufferSize, &samplerate, &channels)<0){
          goto end;
      }
      g_free(buffer);
      if(buffer){
	framesize = 1024;
	if(NeAACDecAudioSpecificConfig(buffer, bufferSize, &mp4ASC) >= 0){
	  if(mp4ASC.frameLengthFlag == 1) framesize = 960;
	  if(mp4ASC.sbr_present_flag == 1) framesize *= 2;
	}
	g_free(buffer);
      }
      if(channels == 0){
	g_print("Number of Channels not supported\n");
          goto end;
	goto end;
      }

      //duration = MP4GetTrackDuration(mp4file, mp4track);
      //msDuration = MP4ConvertFromTrackDuration(mp4file, mp4track,
      //				       duration,MP4_MSECS_TIME_SCALE);

      //msDuration = mp4ff_get_track_duration(infile, mp4track);
      //printf("%d\n", msDuration);

      //numSamples = MP4GetTrackNumberOfSamples(mp4file, mp4track);
      numSamples = mp4ff_num_samples(infile, mp4track);
      {
	float f = 1024.0;
	if(mp4ASC.sbr_present_flag == 1)
	  f = f * 2.0;
	msDuration = ((float)numSamples*(float)(f-1.0)/
		      (float)samplerate)*1000;
      }
      duration = MP4GetTrackDuration(mp4file, mp4track);
      msDuration = MP4ConvertFromTrackDuration(mp4file, mp4track, duration,
					       MP4_MSECS_TIME_SCALE);
      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);


@@ 235,6 298,7 @@ static void *mp4Decode(void *args)
	gint			rc;

	if(seekPosition!=-1){
	  /*
	  duration = MP4ConvertToTrackDuration(mp4file,
					       mp4track,
					       seekPosition*1000,


@@ 242,11 306,12 @@ static void *mp4Decode(void *args)
	  sampleID = MP4GetSampleIdFromTime(mp4file, mp4track, duration, 0);
	  mp4_ip.output->flush(seekPosition*1000);
	  seekPosition = -1;
	  */
	}
	buffer=NULL;
	bufferSize=0;
	rc = MP4ReadSample(mp4file, mp4track, sampleID++, &buffer, &bufferSize,
			   NULL, NULL, NULL, NULL);
	rc = mp4ff_read_sample(infile, mp4track, sampleID++,
			       &buffer, &bufferSize);
	//g_print("%d/%d\n", sampleID-1, numSamples);
	if((rc==0) || (buffer== NULL)){
	  g_print("MP4: read error\n");


@@ 255,11 320,11 @@ static void *mp4Decode(void *args)
	  mp4_ip.output->buffer_free();
            goto end;
	}else{
	  sampleBuffer = faacDecDecode(decoder, &frameInfo, buffer, bufferSize);
	  sampleBuffer = NeAACDecDecode(decoder, &frameInfo, buffer, bufferSize);
	  if(frameInfo.error > 0){
	    g_print("MP4: %s\n",
		    faacDecGetErrorMessage(frameInfo.error));
          goto end;
	    goto end;
	  }
	  if(buffer){
	    g_free(buffer); buffer=NULL; bufferSize=0;


@@ 273,10 338,9 @@ static void *mp4Decode(void *args)
			   frameInfo.samples<<1,
			   sampleBuffer);
	mp4_ip.output->write_audio(sampleBuffer, frameInfo.samples<<1);
      }

      if(sampleID > numSamples){
	if(sampleID > numSamples){
          break;
	}
      }
      while(bPlaying && mp4_ip.output->buffer_playing() && mp4_ip.output->buffer_free()){
	xmms_usleep(10000);


@@ 284,16 348,18 @@ static void *mp4Decode(void *args)
end:
      mp4_ip.output->close_audio();
      g_free(args);
      faacDecClose(decoder);
      MP4Close(mp4file);
      NeAACDecClose(decoder);
      mp4ff_close(infile);
      if(mp4cb) g_free(mp4cb);
      bPlaying = FALSE;
      fclose(mp4file);
      pthread_mutex_unlock(&mutex);
      pthread_exit(NULL);
    }
  } else{
  }else{
    // WE ARE READING AN AAC FILE
    FILE		*file = NULL;
    faacDecHandle	decoder = 0;
    NeAACDecHandle	decoder = 0;
    guchar		*buffer = 0;
    gulong		bufferconsumed = 0;
    gulong		samplerate = 0;


@@ 303,7 369,7 @@ end:
    gchar		*temp = g_strdup(args);
    gchar		*ext  = strrchr(temp, '.');
    gchar		*xmmstitle = NULL;
    faacDecConfigurationPtr config;
    NeAACDecConfigurationPtr config;

    if((file = fopen(args, "rb")) == 0){
      g_print("AAC: can't find file %s\n", args);


@@ 311,21 377,21 @@ end:
      pthread_mutex_unlock(&mutex);
      pthread_exit(NULL);
    }
    if((decoder = faacDecOpen()) == NULL){
    if((decoder = NeAACDecOpen()) == NULL){
      g_print("AAC: Open Decoder Error\n");
      fclose(file);
      bPlaying = FALSE;
      pthread_mutex_unlock(&mutex);
      pthread_exit(NULL);
    }
    config = faacDecGetCurrentConfiguration(decoder);
    config = NeAACDecGetCurrentConfiguration(decoder);
    config->useOldADTSFormat = 0;
    faacDecSetConfiguration(decoder, config);
    NeAACDecSetConfiguration(decoder, config);
    if((buffer = g_malloc(BUFFER_SIZE)) == NULL){
      g_print("AAC: error g_malloc\n");
      fclose(file);
      bPlaying = FALSE;
      faacDecClose(decoder);
      NeAACDecClose(decoder);
      pthread_mutex_unlock(&mutex);
      pthread_exit(NULL);
    }


@@ 334,7 400,7 @@ end:
      g_free(buffer);
      fclose(file);
      bPlaying = FALSE;
      faacDecClose(decoder);
      NeAACDecClose(decoder);
      pthread_mutex_unlock(&mutex);
      pthread_exit(NULL);
    }


@@ 360,7 426,7 @@ end:
    if(input->track_name) g_free(input->track_name);
    if(input->genre) g_free(input->genre);
    g_free(input);
    bufferconsumed = faacDecInit(decoder,
    bufferconsumed = NeAACDecInit(decoder,
				 buffer,
				 buffervalid,
				 &samplerate,


@@ 389,7 455,7 @@ end:
    mp4_ip.output->flush(0);

    while(bPlaying && buffervalid > 0){
      faacDecFrameInfo	finfo;
      NeAACDecFrameInfo	finfo;
      unsigned long	samplesdecoded;
      char*		sample_buffer = NULL;
      /*


@@ 408,24 474,24 @@ end:
			     BUFFER_SIZE-buffervalid, file);
	bufferconsumed = 0;
      }
      sample_buffer = faacDecDecode(decoder, &finfo, buffer, buffervalid);
      sample_buffer = NeAACDecDecode(decoder, &finfo, buffer, buffervalid);
      if(finfo.error){
	config = faacDecGetCurrentConfiguration(decoder);
	config = NeAACDecGetCurrentConfiguration(decoder);
	if(config->useOldADTSFormat != 1){
	  faacDecClose(decoder);
	  decoder = faacDecOpen();
	  config = faacDecGetCurrentConfiguration(decoder);
	  NeAACDecClose(decoder);
	  decoder = NeAACDecOpen();
	  config = NeAACDecGetCurrentConfiguration(decoder);
	  config->useOldADTSFormat = 1;
	  faacDecSetConfiguration(decoder, config);
	  NeAACDecSetConfiguration(decoder, config);
	  finfo.bytesconsumed=0;
	  finfo.samples = 0;
	  faacDecInit(decoder,
	  NeAACDecInit(decoder,
		      buffer,
		      buffervalid,
		      &samplerate,
		      &channels);
	}else{
	  g_print("FAAD2 Warning %s\n", faacDecGetErrorMessage(finfo.error));
	  g_print("FAAD2 Warning %s\n", NeAACDecGetErrorMessage(finfo.error));
	  buffervalid = 0;
	}
      }


@@ 450,7 516,7 @@ end:
    mp4_ip.output->close_audio();
    bPlaying = FALSE;
    g_free(buffer);
    faacDecClose(decoder);
    NeAACDecClose(decoder);
    g_free(xmmstitle);
    fclose(file);
    seekPosition = -1;

M plugins/xmms/src/mp4_utils.c => plugins/xmms/src/mp4_utils.c +27 -69
@@ 1,9 1,11 @@
/*
** some function for MP4 file based on libmp4v2 from mpeg4ip project
 * some functions for MP4 files
*/
#include <mp4.h>
#include <faad.h>

#include "mp4ff.h"
#include "faad.h"

#include <stdio.h>
const char *mp4AudioNames[]=
  {
    "MPEG-1 Audio Layers 1,2 or 3",


@@ 15,17 17,6 @@ const char *mp4AudioNames[]=
    0
  };

const u_int8_t mp4AudioTypes[] =
  {
    MP4_MPEG1_AUDIO_TYPE,		// 0x6B
    MP4_MPEG2_AUDIO_TYPE,		// 0x69
    MP4_MPEG2_AAC_MAIN_AUDIO_TYPE,	// 0x66
    MP4_MPEG2_AAC_LC_AUDIO_TYPE,	// 0x67
    MP4_MPEG2_AAC_SSR_AUDIO_TYPE,	// 0x68
    MP4_MPEG4_AUDIO_TYPE,		// 0x40
    0
  };

/* MPEG-4 Audio types from 14496-3 Table 1.5.1 (from mp4.h)*/
const char *mpeg4AudioNames[]=
  {


@@ 44,72 35,38 @@ const char *mpeg4AudioNames[]=
    "MPEG-4 Algorithmic Synthesis and Audio FX profile"
  };

int getAACTrack(MP4FileHandle file)
{
  int numTracks = MP4GetNumberOfTracks(file, NULL, 0);
  int i=0;

  for(i=0;i<numTracks;i++){
    MP4TrackId trackID = MP4FindTrackId(file, i, NULL, 0);
    const char *trackType = MP4GetTrackType(file, trackID);
    if(!strcmp(trackType, MP4_AUDIO_TRACK_TYPE)){//we found audio track !
      int j=0;
      u_int8_t audiotype = MP4GetTrackAudioType(file, trackID);
      while(mp4AudioTypes[j]){ // what kind of audio is ?
	if(mp4AudioTypes[j] == audiotype){
	  if(mp4AudioTypes[j] == MP4_MPEG4_AUDIO_TYPE){//MPEG4 audio ok
	    audiotype = MP4GetTrackAudioMpeg4Type(file, trackID);
	    printf("%d-%s\n", audiotype, mpeg4AudioNames[audiotype]);
	    return (trackID);
	  }
	  else{
	    printf("%s\n", mp4AudioNames[j]);
	    if (mp4AudioTypes[j]== MP4_MPEG2_AAC_LC_AUDIO_TYPE ||
		mp4AudioTypes[j]== MP4_MPEG2_AAC_MAIN_AUDIO_TYPE ||
		mp4AudioTypes[j]== MP4_MPEG2_AAC_SSR_AUDIO_TYPE)
	      return(trackID);
	    return(-1);
	  }
	}
	j++;
      }
    }
  }
    return(-1);
}
/*
 * find AAC track
*/

int getAudioTrack(MP4FileHandle file)
int getAACTrack(mp4ff_t *infile)
{
  int numTracks = MP4GetNumberOfTracks(file, NULL,0);
  int i=0;
  int i, rc;
  int numTracks = mp4ff_total_tracks(infile);

  for(i=0;i<numTracks;i++){
    MP4TrackId trackID = MP4FindTrackId(file, i, NULL, 0);
    const char *trackType = MP4GetTrackType(file, trackID);
    if(!strcmp(trackType, MP4_AUDIO_TRACK_TYPE)){
      return(trackID);
    }
  }
  return(-1);
}
  printf("total-tracks: %d\n", numTracks);
  for(i=0; i<numTracks; i++){
    unsigned char*	buff = 0;
    int			buff_size = 0;
    mp4AudioSpecificConfig mp4ASC;

int getVideoTrack(MP4FileHandle file)
{
  int numTracks = MP4GetNumberOfTracks(file, NULL, 0);
  int i=0;

  for(i=0;i<numTracks; i++){
    MP4TrackId trackID = MP4FindTrackId(file, i, NULL, 0);
    const char *trackType = MP4GetTrackType(file, trackID);
    if(!strcmp(trackType, MP4_VIDEO_TRACK_TYPE)){
      return (trackID);
    printf("testing-track: %d\n", i);
    mp4ff_get_decoder_config(infile, i, &buff, &buff_size);
    if(buff){
      rc = NeAACDecAudioSpecificConfig(buff, buff_size, &mp4ASC);
      free(buff);
      if(rc < 0)
	continue;
      return(i);
    }
  }
  return(-1);
}


void getMP4info(char* file)
{
  /*
  MP4FileHandle	mp4file;
  MP4Duration	trackDuration;
  int numTracks;


@@ 148,4 105,5 @@ void getMP4info(char* file)
    printf("\n");
  }
  MP4Close(mp4file);
  */
}