Apply Tizen patches 84/134384/1 accepted/tizen/unified/20170630.083223 submit/tizen/20170621.021850
authorSeungbae Shin <seungbae.shin@samsung.com>
Wed, 16 Mar 2016 13:09:47 +0000 (22:09 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Fri, 16 Jun 2017 07:06:25 +0000 (16:06 +0900)
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
examples/generate.c
src/flac.c
src/ogg_vorbis.c

index f4ec6c4..60f55e3 100644 (file)
@@ -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
index 884e8d7..44cb6f2 100644 (file)
@@ -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) ;
index d2c5cdd..6bd8aae 100644 (file)
@@ -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       <FLAC/stream_decoder.h>
 #include       <FLAC/stream_encoder.h>
index 78acd38..2dad604 100644 (file)
 
 #if HAVE_EXTERNAL_XIPH_LIBS
 
+
 #include <ogg/ogg.h>
 #include <vorbis/codec.h>
+
+#ifdef __TIZEN__
+#include <dlfcn.h> /* for dlopen */
+#else
 #include <vorbis/vorbisenc.h>
+#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 */