Commit 9f6364af authored by Avuton Olrich's avatar Avuton Olrich

Remove the internal mp4ff dependency

git-svn-id: https://svn.musicpd.org/mpd/trunk@4401 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 9774768b
......@@ -13,8 +13,6 @@ AC_SUBST(MAD_SUBDIR)
AC_SUBST(MAD_LIB)
AC_SUBST(ID3_SUBDIR)
AC_SUBST(ID3_LIB)
AC_SUBST(MP4FF_LIB)
AC_SUBST(MP4FF_SUBDIR)
AC_SUBST(MPD_LIBS)
AC_SUBST(MPD_CFLAGS)
......@@ -352,26 +350,24 @@ if test x$enable_mpc = xyes; then
CPPFLAGS=$oldcppflags
fi
MP4FF_SUBDIR=""
if test x$enable_aac = xyes; then
if test "x$faad_libraries" != "x" ; then
FAAD_LIBS="-L$faad_libraries"
elif test "x$faad_prefix" != "x" ; then
FAAD_LIBS="-L$faad_prefix/lib"
elif test "x$prefix" != "xNONE"; then
FAAD_LIBS="-L$libdir"
fi
if test "x$faad_libraries" != "x" ; then
FAAD_LIBS="-L$faad_libraries"
elif test "x$faad_prefix" != "x" ; then
FAAD_LIBS="-L$faad_prefix/lib"
elif test "x$prefix" != "xNONE"; then
FAAD_LIBS="-L$libdir"
fi
FAAD_LIBS="$FAAD_LIBS -lfaad"
FAAD_LIBS="$FAAD_LIBS -lfaad -lmp4ff"
if test "x$faad_includes" != "x" ; then
FAAD_CFLAGS="-I$faad_includes"
elif test "x$faad_prefix" != "x" ; then
FAAD_CFLAGS="-I$faad_prefix/include"
elif test "x$prefix" != "xNONE"; then
FAAD_CFLAGS="-I$includedir"
fi
if test "x$faad_includes" != "x" ; then
FAAD_CFLAGS="-I$faad_includes"
elif test "x$faad_prefix" != "x" ; then
FAAD_CFLAGS="-I$faad_prefix/include"
elif test "x$prefix" != "xNONE"; then
FAAD_CFLAGS="-I$includedir"
fi
oldcflags=$CFLAGS
oldlibs=$LIBS
......@@ -380,6 +376,7 @@ if test x$enable_aac = xyes; then
LIBS="$LIBS $MPD_LIBS $FAAD_LIBS"
CPPFLAGS=$CFLAGS
AC_CHECK_HEADER(faad.h,,enable_aac=no)
AC_CHECK_HEADER(mp4ff.h,,enable_aac=no)
if test x$enable_aac = xyes; then
AC_CHECK_DECL(FAAD2_VERSION,,enable_aac=no,[#include <faad.h>])
fi
......@@ -387,14 +384,17 @@ if test x$enable_aac = xyes; then
AC_CHECK_DECL(faacDecInit2,,enable_aac=no,[#include <faad.h>])
fi
if test x$enable_aac = xyes; then
AC_CHECK_LIB(faad,faacDecInit2,[MPD_LIBS="$MPD_LIBS $FAAD_LIBS";MPD_CFLAGS="$MPD_CFLAGS $FAAD_CFLAGS";MP4FF_SUBDIR="mp4ff";MP4FF_LIB="mp4ff/libmp4ff.la"],enable_aac=no)
AC_CHECK_LIB(faad,faacDecInit2,[MPD_LIBS="$MPD_LIBS $FAAD_LIBS";MPD_CFLAGS="$MPD_CFLAGS $FAAD_CFLAGS"],enable_aac=no)
if test x$enable_aac = xno; then
enable_aac=yes
AC_CHECK_LIB(faad,NeAACDecInit2,[MPD_LIBS="$MPD_LIBS $FAAD_LIBS";MPD_CFLAGS="$MPD_CFLAGS $FAAD_CFLAGS";MP4FF_SUBDIR="mp4ff";MP4FF_LIB="mp4ff/libmp4ff.la"],enable_aac=no)
AC_CHECK_LIB(faad,NeAACDecInit2,[MPD_LIBS="$MPD_LIBS $FAAD_LIBS";MPD_CFLAGS="$MPD_CFLAGS $FAAD_CFLAGS"],enable_aac=no)
fi
fi
if test x$enable_aac = xyes; then
AC_MSG_CHECKING(that FAAD2 uses buffer and bufferlen)
AC_CHECK_LIB(mp4ff,mp4ff_open_read,[MPD_LIBS="$MPD_LIBS $FAAD_LIBS";MPD_CFLAGS="$MPD_CFLAGS $FAAD_CFLAGS"],enable_aac=no)
fi
if test x$enable_aac = xyes; then
AC_MSG_CHECKING(that FAAD2 uses buffer and bufferlen)
AC_COMPILE_IFELSE([
#include <faad.h>
......@@ -470,21 +470,21 @@ if test x$enable_oggvorbis = xyes && test x$use_tremor != xyes; then
fi
if test x$use_tremor = xyes; then
if test "x$tremor_libraries" != "x" ; then
TREMOR_LIBS="-L$tremor_libraries"
elif test "x$tremor_prefix" != "x" ; then
TREMOR_LIBS="-L$tremor_prefix/lib"
elif test "x$prefix" != "xNONE"; then
TREMOR_LIBS="-L$libdir"
fi
TREMOR_LIBS="$TREMOR_LIBS -lvorbisidec"
if test "x$tremor_includes" != "x" ; then
TREMOR_CFLAGS="-I$tremor_includes"
elif test "x$tremor_prefix" != "x" ; then
TREMOR_CFLAGS="-I$tremor_prefix/include"
elif test "x$prefix" != "xNONE"; then
TREMOR_CFLAGS="-I$includedir"
fi
if test "x$tremor_libraries" != "x" ; then
TREMOR_LIBS="-L$tremor_libraries"
elif test "x$tremor_prefix" != "x" ; then
TREMOR_LIBS="-L$tremor_prefix/lib"
elif test "x$prefix" != "xNONE"; then
TREMOR_LIBS="-L$libdir"
fi
TREMOR_LIBS="$TREMOR_LIBS -lvorbisidec"
if test "x$tremor_includes" != "x" ; then
TREMOR_CFLAGS="-I$tremor_includes"
elif test "x$tremor_prefix" != "x" ; then
TREMOR_CFLAGS="-I$tremor_prefix/include"
elif test "x$prefix" != "xNONE"; then
TREMOR_CFLAGS="-I$includedir"
fi
ac_save_CFLAGS="$CFLAGS"
ac_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $TREMOR_CFLAGS"
......@@ -629,7 +629,7 @@ if test x$enable_mod = xyes; then
fi
fi
AC_OUTPUT(src/mp4ff/Makefile doc/Makefile src/Makefile Makefile )
AC_OUTPUT(doc/Makefile src/Makefile Makefile )
echo ""
echo "########### MPD CONFIGURATION ############"
......
......@@ -3,6 +3,6 @@ if test -e Makefile
then
make distclean
fi
./autogen.sh --disable-aac
./autogen.sh
make
make dist
bin_PROGRAMS = mpd
SUBDIRS = $(MP4FF_SUBDIR)
mpd_audioOutputs = \
audioOutputs/audioOutput_alsa.c \
......@@ -113,9 +112,7 @@ mpd_SOURCES = \
mpd_CFLAGS = $(MPD_CFLAGS)
mpd_LDADD = $(MPD_LIBS) $(ID3_LIB) $(MAD_LIB) $(MP4FF_LIB)
DIST_SUBDIRS = mp4ff
mpd_LDADD = $(MPD_LIBS) $(ID3_LIB) $(MAD_LIB)
# sparse is a semantic parser
# URL: git://www.kernel.org/pub/scm/devel/sparse/sparse.git
......
......@@ -28,13 +28,12 @@
#include "../outputBuffer.h"
#include "../decode.h"
#include "../mp4ff/mp4ff.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <faad.h>
#include <mp4ff.h>
/* all code here is either based on or copied from FAAD2's frontend code */
......@@ -45,13 +44,13 @@ static int mp4_getAACTrack(mp4ff_t *infile) {
for (i = 0; i < numTracks; i++) {
unsigned char *buff = NULL;
int buff_size = 0;
unsigned int *buff_size = 0;
#ifdef HAVE_MP4AUDIOSPECIFICCONFIG
mp4AudioSpecificConfig mp4ASC;
#else
unsigned long dummy1_32;
unsigned char dummy2_8, dummy3_8, dummy4_8, dummy5_8, dummy6_8,
dummy7_8, dummy8_8;
unsigned char dummy2_8, dummy3_8, dummy4_8, dummy5_8, dummy6_8,
dummy7_8, dummy8_8;
#endif
mp4ff_get_decoder_config(infile, i, &buff, &buff_size);
......@@ -66,7 +65,7 @@ static int mp4_getAACTrack(mp4ff_t *infile) {
#endif
free(buff);
if (rc < 0) continue;
return i;
return i;
}
}
......@@ -79,21 +78,36 @@ static uint32_t mp4_inputStreamReadCallback(void *inStream, void *buffer,
{
return readFromInputStream((InputStream*) inStream, buffer, 1, length);
}
static uint32_t mp4_inputStreamSeekCallback(void *inStream, uint64_t position) {
return seekInputStream((InputStream *) inStream, position, SEEK_SET);
}
}
static faacDecHandle * openConfigureFaad() {
faacDecConfigurationPtr config;
faacDecHandle decoder = faacDecOpen();
config = faacDecGetCurrentConfiguration(decoder);
config->outputFormat = FAAD_FMT_16BIT;
#ifdef HAVE_FAACDECCONFIGURATION_DOWNMATRIX
config->downMatrix = 1;
#endif
#ifdef HAVE_FAACDECCONFIGURATION_DONTUPSAMPLEIMPLICITSBR
config->dontUpSampleImplicitSBR = 0;
#endif
faacDecSetConfiguration(decoder,config);
return decoder;
}
static int mp4_decode(OutputBuffer * cb, DecoderControl * dc, char * path) {
mp4ff_t * mp4fh;
mp4ff_callback_t * mp4cb;
mp4ff_callback_t * mp4cb;
int32_t track;
float time;
int32_t scale;
faacDecHandle decoder;
faacDecHandle * decoder;
faacDecFrameInfo frameInfo;
faacDecConfigurationPtr config;
unsigned char * mp4Buffer;
int mp4BufferSize;
unsigned long sampleRate;
......@@ -141,17 +155,7 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc, char * path) {
return -1;
}
decoder = faacDecOpen();
config = faacDecGetCurrentConfiguration(decoder);
config->outputFormat = FAAD_FMT_16BIT;
#ifdef HAVE_FAACDECCONFIGURATION_DOWNMATRIX
config->downMatrix = 1;
#endif
#ifdef HAVE_FAACDECCONFIGURATION_DONTUPSAMPLEIMPLICITSBR
config->dontUpSampleImplicitSBR = 0;
#endif
faacDecSetConfiguration(decoder,config);
decoder = openConfigureFaad();
dc->audioFormat.bits = 16;
......@@ -305,11 +309,8 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc, char * path) {
}
flushOutputBuffer(cb);
if(dc->stop) {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
}
else dc->state = DECODE_STATE_STOP;
if(dc->stop) dc->stop = 0;
dc->state = DECODE_STATE_STOP;
return 0;
}
......@@ -431,32 +432,32 @@ static char * mp4Suffixes[] = {"m4a", "mp4", NULL};
InputPlugin mp4Plugin =
{
"mp4",
NULL,
"mp4",
NULL,
NULL,
NULL,
mp4_decode,
mp4TagDup,
INPUT_PLUGIN_STREAM_FILE,
mp4Suffixes,
NULL
NULL,
mp4_decode,
mp4TagDup,
INPUT_PLUGIN_STREAM_FILE,
mp4Suffixes,
NULL
};
#else
InputPlugin mp4Plugin =
{
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
0,
NULL,
NULL
NULL,
NULL,
NULL,
NULL,
0,
NULL,
NULL
};
#endif /* HAVE_FAAD */
noinst_LTLIBRARIES = libmp4ff.la
noinst_HEADERS = mp4ff.h
libmp4ff_la_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 = -DUSE_TAGGING=1
/*****************************************************************************
* drms.h : DRMS
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id: drms.h,v 1.3 2004/01/11 15:52:18 menno Exp $
*
* Author: Jon Lech Johansen <jon-vl@nanocrew.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#define DRMS_INIT_UKEY 0
#define DRMS_INIT_IVIV 1
#define DRMS_INIT_NAME 2
#define DRMS_INIT_PRIV 3
extern int drms_get_sys_key( uint32_t *p_sys_key );
extern int drms_get_user_key( uint32_t *p_sys_key,
uint32_t *p_user_key );
extern void *drms_alloc();
extern void drms_free( void *p_drms );
extern int drms_init( void *p_drms, uint32_t i_type,
uint8_t *p_info, uint32_t i_len );
extern void drms_decrypt( void *p_drms, uint32_t *p_buffer,
uint32_t i_len );
# Microsoft Developer Studio Project File - Name="mp4ff" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=mp4ff - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "mp4ff.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "mp4ff.mak" CFG="mp4ff - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "mp4ff - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "mp4ff - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=xicl6.exe
RSC=rc.exe
!IF "$(CFG)" == "mp4ff - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
F90=df.exe
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /O1 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "USE_TAGGING" /YX /FD /c
# ADD BASE RSC /l 0x413 /d "NDEBUG"
# ADD RSC /l 0x413 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=xilink6.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "mp4ff - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
F90=df.exe
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "USE_TAGGING" /YX /FD /GZ /c
# ADD BASE RSC /l 0x413 /d "_DEBUG"
# ADD RSC /l 0x413 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=xilink6.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "mp4ff - Win32 Release"
# Name "mp4ff - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\drms.c
# End Source File
# Begin Source File
SOURCE=.\mp4atom.c
# End Source File
# Begin Source File
SOURCE=.\mp4ff.c
# End Source File
# Begin Source File
SOURCE=.\mp4meta.c
# End Source File
# Begin Source File
SOURCE=.\mp4sample.c
# End Source File
# Begin Source File
SOURCE=.\mp4tagupdate.c
# End Source File
# Begin Source File
SOURCE=.\mp4util.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\drms.h
# End Source File
# Begin Source File
SOURCE=.\drmstables.h
# End Source File
# Begin Source File
SOURCE=.\mp4ff.h
# End Source File
# Begin Source File
SOURCE=.\mp4ff_int_types.h
# End Source File
# Begin Source File
SOURCE=.\mp4ffint.h
# End Source File
# End Group
# End Target
# End Project
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
**
** $Id: mp4ff.h,v 1.19 2004/01/11 15:52:18 menno Exp $
**/
#ifndef MP4FF_H
#define MP4FF_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "mp4ff_int_types.h"
/* file callback structure */
typedef struct
{
uint32_t (*read)(void *user_data, void *buffer, uint32_t length);
uint32_t (*write)(void *udata, void *buffer, uint32_t length);
uint32_t (*seek)(void *user_data, uint64_t position);
uint32_t (*truncate)(void *user_data);
void *user_data;
} mp4ff_callback_t;
/* mp4 main file structure */
typedef void* mp4ff_t;
/* API */
mp4ff_t *mp4ff_open_read(mp4ff_callback_t *f);
void mp4ff_close(mp4ff_t *f);
int32_t mp4ff_get_sample_duration(const mp4ff_t *f, const int32_t track, const int32_t sample);
int32_t mp4ff_get_sample_duration_use_offsets(const mp4ff_t *f, const int32_t track, const int32_t sample);
int64_t mp4ff_get_sample_position(const mp4ff_t *f, const int32_t track, const int32_t sample);
int32_t mp4ff_get_sample_offset(const mp4ff_t *f, const int32_t track, const int32_t sample);
int32_t mp4ff_find_sample(const mp4ff_t *f, const int32_t track, const int64_t offset,int32_t * toskip);
int32_t mp4ff_find_sample_use_offsets(const mp4ff_t *f, const int32_t track, const int64_t offset,int32_t * toskip);
int32_t mp4ff_read_sample(mp4ff_t *f, const int track, const int sample,
unsigned char **audio_buffer, unsigned int *bytes);
int32_t mp4ff_read_sample_v2(mp4ff_t *f, const int track, const int sample,unsigned char *buffer);//returns 0 on error, number of bytes read on success, use mp4ff_read_sample_getsize() to check buffer size needed
int32_t mp4ff_read_sample_getsize(mp4ff_t *f, const int track, const int sample);//returns 0 on error, buffer size needed for mp4ff_read_sample_v2() on success
int32_t mp4ff_get_decoder_config(const mp4ff_t *f, const int track,
unsigned char** ppBuf, unsigned int* pBufSize);
int32_t mp4ff_get_track_type(const mp4ff_t *f, const int track);
int32_t mp4ff_total_tracks(const mp4ff_t *f);
int32_t mp4ff_num_samples(const mp4ff_t *f, const int track);
int32_t mp4ff_time_scale(const mp4ff_t *f, const int track);
uint32_t mp4ff_get_avg_bitrate(const mp4ff_t *f, const int32_t track);
uint32_t mp4ff_get_max_bitrate(const mp4ff_t *f, const int32_t track);
int64_t mp4ff_get_track_duration(const mp4ff_t *f, const int32_t track); //returns (-1) if unknown
int64_t mp4ff_get_track_duration_use_offsets(const mp4ff_t *f, const int32_t track); //returns (-1) if unknown
uint32_t mp4ff_get_sample_rate(const mp4ff_t *f, const int32_t track);
uint32_t mp4ff_get_channel_count(const mp4ff_t * f,const int32_t track);
uint32_t mp4ff_get_audio_type(const mp4ff_t * f,const int32_t track);
/* metadata */
int mp4ff_meta_get_num_items(const mp4ff_t *f);
int mp4ff_meta_get_by_index(const mp4ff_t *f, unsigned int index,
char **item, char **value);
int mp4ff_meta_get_title(const mp4ff_t *f, char **value);
int mp4ff_meta_get_artist(const mp4ff_t *f, char **value);
int mp4ff_meta_get_writer(const mp4ff_t *f, char **value);
int mp4ff_meta_get_album(const mp4ff_t *f, char **value);
int mp4ff_meta_get_date(const mp4ff_t *f, char **value);
int mp4ff_meta_get_tool(const mp4ff_t *f, char **value);
int mp4ff_meta_get_comment(const mp4ff_t *f, char **value);
int mp4ff_meta_get_genre(const mp4ff_t *f, char **value);
int mp4ff_meta_get_track(const mp4ff_t *f, char **value);
int mp4ff_meta_get_disc(const mp4ff_t *f, char **value);
int mp4ff_meta_get_compilation(const mp4ff_t *f, char **value);
int mp4ff_meta_get_tempo(const mp4ff_t *f, char **value);
int32_t mp4ff_meta_get_coverart(const mp4ff_t *f, char **value);
#ifdef USE_TAGGING
/* metadata tag structure */
typedef struct
{
char *item;
char *value;
} mp4ff_tag_t;
/* metadata list structure */
typedef struct
{
mp4ff_tag_t *tags;
uint32_t count;
} mp4ff_metadata_t;
int32_t mp4ff_meta_update(mp4ff_callback_t *f,const mp4ff_metadata_t * data);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
#ifndef _MP4FF_INT_TYPES_H_
#define _MP4FF_INT_TYPES_H_
#ifdef _WIN32
typedef char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#include "config.h"
#if defined(HAVE_STDINT_H)
#include <stdint.h>
#elif defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#elif defined(HAVE_SYS_INTTYPES_H)
#include <sys/inttypes.h>
#elif defined(HAVE_SYS_TYPES_H)
#include <sys/types.h>
#endif
#endif
#endif
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
**
** $Id: mp4sample.c,v 1.15 2004/01/11 15:52:19 menno Exp $
**/
#include <stdlib.h>
#include "mp4ffint.h"
static int32_t mp4ff_chunk_of_sample(const mp4ff_t *f, const int32_t track, const int32_t sample,
int32_t *chunk_sample, int32_t *chunk)
{
int32_t total_entries = 0;
int32_t chunk2entry;
int32_t chunk1, chunk2, chunk1samples, range_samples, total = 0;
if (f->track[track] == NULL)
{
return -1;
}
total_entries = f->track[track]->stsc_entry_count;
chunk1 = 1;
chunk1samples = 0;
chunk2entry = 0;
do
{
chunk2 = f->track[track]->stsc_first_chunk[chunk2entry];
*chunk = chunk2 - chunk1;
range_samples = *chunk * chunk1samples;
if (sample < total + range_samples) break;
chunk1samples = f->track[track]->stsc_samples_per_chunk[chunk2entry];
chunk1 = chunk2;
if(chunk2entry < total_entries)
{
chunk2entry++;
total += range_samples;
}
} while (chunk2entry < total_entries);
if (chunk1samples)
*chunk = (sample - total) / chunk1samples + chunk1;
else
*chunk = 1;
*chunk_sample = total + (*chunk - chunk1) * chunk1samples;
return 0;
}
static int32_t mp4ff_chunk_to_offset(const mp4ff_t *f, const int32_t track, const int32_t chunk)
{
const mp4ff_track_t * p_track = f->track[track];
if (p_track->stco_entry_count && (chunk > p_track->stco_entry_count))
{
return p_track->stco_chunk_offset[p_track->stco_entry_count - 1];
} else if (p_track->stco_entry_count) {
return p_track->stco_chunk_offset[chunk - 1];
} else {
return 8;
}
return 0;
}
static int32_t mp4ff_sample_range_size(const mp4ff_t *f, const int32_t track,
const int32_t chunk_sample, const int32_t sample)
{
int32_t i, total;
const mp4ff_track_t * p_track = f->track[track];
if (p_track->stsz_sample_size)
{
return (sample - chunk_sample) * p_track->stsz_sample_size;
}
else
{
if (sample>=p_track->stsz_sample_count) return 0;//error
for(i = chunk_sample, total = 0; i < sample; i++)
{
total += p_track->stsz_table[i];
}
}
return total;
}
static int32_t mp4ff_sample_to_offset(const mp4ff_t *f, const int32_t track, const int32_t sample)
{
int32_t chunk, chunk_sample, chunk_offset1, chunk_offset2;
mp4ff_chunk_of_sample(f, track, sample, &chunk_sample, &chunk);
chunk_offset1 = mp4ff_chunk_to_offset(f, track, chunk);
chunk_offset2 = chunk_offset1 + mp4ff_sample_range_size(f, track, chunk_sample, sample);
return chunk_offset2;
}
int32_t mp4ff_audio_frame_size(const mp4ff_t *f, const int32_t track, const int32_t sample)
{
int32_t bytes;
const mp4ff_track_t * p_track = f->track[track];
if (p_track->stsz_sample_size)
{
bytes = p_track->stsz_sample_size;
} else {
bytes = p_track->stsz_table[sample];
}
return bytes;
}
int32_t mp4ff_set_sample_position(mp4ff_t *f, const int32_t track, const int32_t sample)
{
int32_t offset;
offset = mp4ff_sample_to_offset(f, track, sample);
mp4ff_set_position(f, offset);
return 0;
}
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
**
** $Id: mp4util.c,v 1.15 2004/01/11 15:52:19 menno Exp $
**/
#include "mp4ffint.h"
#include <stdlib.h>
int32_t mp4ff_read_data(mp4ff_t *f, int8_t *data, uint32_t size)
{
int32_t result = 1;
result = f->stream->read(f->stream->user_data, data, size);
f->current_position += size;
return result;
}
int32_t mp4ff_truncate(mp4ff_t * f)
{
return f->stream->truncate(f->stream->user_data);
}
int32_t mp4ff_write_data(mp4ff_t *f, int8_t *data, uint32_t size)
{
int32_t result = 1;
result = f->stream->write(f->stream->user_data, data, size);
f->current_position += size;
return result;
}
int32_t mp4ff_write_int32(mp4ff_t *f,const uint32_t data)
{
uint32_t result;
uint32_t a, b, c, d;
int8_t temp[4];
*(uint32_t*)temp = data;
a = (uint8_t)temp[0];
b = (uint8_t)temp[1];
c = (uint8_t)temp[2];
d = (uint8_t)temp[3];
result = (a<<24) | (b<<16) | (c<<8) | d;
return mp4ff_write_data(f,(uint8_t*)&result,sizeof(result));
}
int32_t mp4ff_set_position(mp4ff_t *f, const int64_t position)
{
f->stream->seek(f->stream->user_data, position);
f->current_position = position;
return 0;
}
int64_t mp4ff_position(const mp4ff_t *f)
{
return f->current_position;
}
uint64_t mp4ff_read_int64(mp4ff_t *f)
{
uint8_t data[8];
uint64_t result = 0;
int8_t i;
mp4ff_read_data(f, data, 8);
for (i = 0; i < 8; i++)
{
result |= ((uint64_t)data[i]) << ((7 - i) * 8);
}
return result;
}
uint32_t mp4ff_read_int32(mp4ff_t *f)
{
uint32_t result;
uint32_t a, b, c, d;
int8_t data[4];
mp4ff_read_data(f, data, 4);
a = (uint8_t)data[0];
b = (uint8_t)data[1];
c = (uint8_t)data[2];
d = (uint8_t)data[3];
result = (a<<24) | (b<<16) | (c<<8) | d;
return (uint32_t)result;
}
uint32_t mp4ff_read_int24(mp4ff_t *f)
{
uint32_t result;
uint32_t a, b, c;
int8_t data[4];
mp4ff_read_data(f, data, 3);
a = (uint8_t)data[0];
b = (uint8_t)data[1];
c = (uint8_t)data[2];
result = (a<<16) | (b<<8) | c;
return (uint32_t)result;
}
uint16_t mp4ff_read_int16(mp4ff_t *f)
{
uint32_t result;
uint32_t a, b;
int8_t data[2];
mp4ff_read_data(f, data, 2);
a = (uint8_t)data[0];
b = (uint8_t)data[1];
result = (a<<8) | b;
return (uint16_t)result;
}
char * mp4ff_read_string(mp4ff_t * f,uint32_t length)
{
char * str = (char*)malloc(length + 1);
if (str!=0)
{
if ((uint32_t)mp4ff_read_data(f,str,length)!=length)
{
free(str);
str = 0;
}
else
{
str[length] = 0;
}
}
return str;
}
uint8_t mp4ff_read_char(mp4ff_t *f)
{
uint8_t output;
mp4ff_read_data(f, &output, 1);
return output;
}
uint32_t mp4ff_read_mp4_descr_length(mp4ff_t *f)
{
uint8_t b;
uint8_t numBytes = 0;
uint32_t length = 0;
do
{
b = mp4ff_read_char(f);
numBytes++;
length = (length << 7) | (b & 0x7F);
} while ((b & 0x80) && numBytes < 4);
return length;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment