From a910d66fbce0892ccc3ce67e1e780f29ea9dc4c3 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Wed, 16 Mar 2016 22:09:47 +0900 Subject: [PATCH] Apply Tizen patches 1. Remove FLAC dependancy 2. use dlopen for vorbis encoder to load so when actual needed, this will reduce runtime memory consumption Change-Id: Id3c81f7e65c2fcd6784970b817d81f50eb0ca2d6 --- configure.ac | 23 +++++++++------------ examples/generate.c | 3 +++ src/flac.c | 2 +- src/ogg_vorbis.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index f4ec6c4..60f55e3 100644 --- a/configure.ac +++ b/configure.ac @@ -127,7 +127,7 @@ AC_ARG_ENABLE(alsa, AS_HELP_STRING([--disable-alsa], [disable use of ALSA])) AC_ARG_ENABLE(external-libs, - AS_HELP_STRING([--disable-external-libs], [disable use of FLAC, Ogg and Vorbis [[default=no]]])) + AS_HELP_STRING([--disable-external-libs], [disable use of Ogg and Vorbis [[default=no]]])) AC_ARG_ENABLE(octave, AS_HELP_STRING([--enable-octave], [disable building of GNU Octave module])) @@ -280,7 +280,7 @@ else fi #==================================================================================== -# Check for Ogg, Vorbis and FLAC. +# Check for Ogg, Vorbis. HAVE_EXTERNAL_XIPH_LIBS=0 EXTERNAL_XIPH_CFLAGS="" @@ -292,13 +292,8 @@ m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR], AC_SUBST([pkgconfigdir], ${libdir}/ if test -n "$PKG_CONFIG" ; then if test x$enable_external_libs = xno ; then - AC_MSG_WARN([[*** External libs (FLAC, Ogg, Vorbis) disabled. ***]]) + AC_MSG_WARN([[*** External libs (Ogg, Vorbis) disabled. ***]]) else - PKG_CHECK_MOD_VERSION(FLAC, flac >= 1.3.1, ac_cv_flac=yes, ac_cv_flac=no) - - # Make sure the FLAC_CFLAGS value is sane. - FLAC_CFLAGS=`echo $FLAC_CFLAGS | $SED "s|include/FLAC|include|"` - PKG_CHECK_MOD_VERSION(OGG, ogg >= 1.1.3, ac_cv_ogg=yes, ac_cv_ogg=no) if test x$enable_experimental = xyes ; then @@ -316,12 +311,12 @@ if test -n "$PKG_CONFIG" ; then enable_external_libs=yes fi - if test x$ac_cv_flac$ac_cv_ogg$ac_cv_vorbis$ac_cv_vorbisenc = "xyesyesyesyes" ; then + if test x$ac_cv_ogg$ac_cv_vorbis$ac_cv_vorbisenc = "xyesyesyes" ; then HAVE_EXTERNAL_XIPH_LIBS=1 enable_external_libs=yes - EXTERNAL_XIPH_CFLAGS="$FLAC_CFLAGS $OGG_CFLAGS $VORBIS_CFLAGS $VORBISENC_CFLAGS $SPEEX_CFLAGS" - EXTERNAL_XIPH_LIBS="$FLAC_LIBS $OGG_LIBS $VORBIS_LIBS $VORBISENC_LIBS $SPEEX_LIBS " + EXTERNAL_XIPH_CFLAGS="$OGG_CFLAGS $VORBIS_CFLAGS $VORBISENC_CFLAGS $SPEEX_CFLAGS" + EXTERNAL_XIPH_LIBS="$OGG_LIBS $VORBIS_LIBS $VORBISENC_LIBS $SPEEX_LIBS " else echo AC_MSG_WARN([[*** One or more of the external libraries (ie libflac, libogg and]]) @@ -335,7 +330,7 @@ if test -n "$PKG_CONFIG" ; then fi fi -AC_DEFINE_UNQUOTED([HAVE_EXTERNAL_XIPH_LIBS], $HAVE_EXTERNAL_XIPH_LIBS, [Will be set to 1 if flac, ogg and vorbis are available.]) +AC_DEFINE_UNQUOTED([HAVE_EXTERNAL_XIPH_LIBS], $HAVE_EXTERNAL_XIPH_LIBS, [Will be set to 1 if ogg and vorbis are available.]) #==================================================================================== # Check for libsqlite3 (only used in regtest). @@ -663,13 +658,13 @@ AC_MSG_RESULT([ Experimental code : ................... ${enable_experimental:-no} Using ALSA in example programs : ...... ${enable_alsa:-no} - External FLAC/Ogg/Vorbis : ............ ${enable_external_libs:-no} + External Ogg/Vorbis : .................. ${enable_external_libs:-no} ]) if test -z "$PKG_CONFIG" ; then echo " *****************************************************************" echo " *** The pkg-config program is missing. ***" - echo " *** External FLAC/Ogg/Vorbis libs cannot be found without it. ***" + echo " *** External Ogg/Vorbis libs cannot be found without it. ***" echo " *** http://pkg-config.freedesktop.org/wiki/ ***" echo " *****************************************************************" echo diff --git a/examples/generate.c b/examples/generate.c index 884e8d7..44cb6f2 100644 --- a/examples/generate.c +++ b/examples/generate.c @@ -60,6 +60,9 @@ main (int argc, char **argv) encode_file (argv [1], "imaadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM) ; encode_file (argv [1], "msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM) ; encode_file (argv [1], "gsm610.wav" , SF_FORMAT_WAV | SF_FORMAT_GSM610) ; +#if 0 /* For temporal testing of encoding ogg/vorbis functionality */ + encode_file (argv [1], "pcm16.ogg" , SF_FORMAT_OGG | SF_FORMAT_VORBIS) ; +#endif /* Soundforge W64. */ encode_file (argv [1], "pcmu8.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_U8) ; diff --git a/src/flac.c b/src/flac.c index d2c5cdd..6bd8aae 100644 --- a/src/flac.c +++ b/src/flac.c @@ -29,7 +29,7 @@ #include "sndfile.h" #include "common.h" -#if HAVE_EXTERNAL_XIPH_LIBS +#if 0 /* HAVE_EXTERNAL_XIPH_LIBS : Disable for TIZEN */ #include #include diff --git a/src/ogg_vorbis.c b/src/ogg_vorbis.c index 78acd38..2dad604 100644 --- a/src/ogg_vorbis.c +++ b/src/ogg_vorbis.c @@ -70,9 +70,15 @@ #if HAVE_EXTERNAL_XIPH_LIBS + #include #include + +#ifdef __TIZEN__ +#include /* for dlopen */ +#else #include +#endif #include "ogg.h" @@ -127,6 +133,11 @@ typedef struct /* Encoding quality in range [0.0, 1.0]. */ double quality ; + +#ifdef __TIZEN__ + /* func ptr for encoder */ + void *dl; +#endif } VORBIS_PRIVATE ; static int @@ -338,6 +349,41 @@ vorbis_read_header (SF_PRIVATE *psf, int log_data) return 0 ; } /* vorbis_read_header */ + +#ifdef __TIZEN__ +#define VORBIS_ENC_SO_NAME "/usr/lib/libvorbisenc.so.2" /* FIXME : Any good way to avoid hardcoding? */ +#define VORBIS_ENC_INIT_VBR "vorbis_encode_init_vbr" + +static int +_vorbis_encode_init(SF_PRIVATE *psf) +{ + int (*fn) (vorbis_info *, long, long, float); + void *dl = NULL; + VORBIS_PRIVATE *vdata = (VORBIS_PRIVATE *) psf->codec_data ; + + /* load so */ + dl = dlopen(VORBIS_ENC_SO_NAME, RTLD_GLOBAL | RTLD_NOW); + if (!dl) { + psf_log_printf (psf, "failed to dlopen [%s], error [%s]\n", VORBIS_ENC_SO_NAME, dlerror()); + return -1; + } + dlerror(); + + vdata->dl = dl; + + /* load symbol */ + fn = dlsym(dl, VORBIS_ENC_INIT_VBR); + if (!fn) { + psf_log_printf (psf, "failed to dlsym [%s], error [%s]\n", VORBIS_ENC_INIT_VBR, dlerror()); + return -1; + } + dlerror(); + + /* call function */ + return fn(&vdata->vinfo, psf->sf.channels, psf->sf.samplerate, vdata->quality); +} +#endif /* __TIZEN__ */ + static int vorbis_write_header (SF_PRIVATE *psf, int UNUSED (calc_length)) { @@ -348,7 +394,11 @@ vorbis_write_header (SF_PRIVATE *psf, int UNUSED (calc_length)) vorbis_info_init (&vdata->vinfo) ; /* The style of encoding should be selectable here, VBR quality mode. */ +#ifdef __TIZEN__ + ret = _vorbis_encode_init(psf); +#else ret = vorbis_encode_init_vbr (&vdata->vinfo, psf->sf.channels, psf->sf.samplerate, vdata->quality) ; +#endif #if 0 ret = vorbis_encode_init (&vdata->vinfo, psf->sf.channels, psf->sf.samplerate, -1, 128000, -1) ; /* average bitrate mode */ @@ -483,6 +533,13 @@ vorbis_close (SF_PRIVATE *psf) vorbis_comment_clear (&vdata->vcomment) ; vorbis_info_clear (&vdata->vinfo) ; +#ifdef __TIZEN__ + if (vdata->dl) { + dlclose(vdata->dl); + vdata->dl = NULL; + } +#endif + return 0 ; } /* vorbis_close */ -- 2.7.4