Ticket #8148: dlopen-libmp3lame.patch

File dlopen-libmp3lame.patch, 13.9 KB (added by Andres Mejia <mcitadel@…>, 16 years ago)

Patch to support using libmp3lame via dlopen

  • configure

    Implement support to use libmp3lame via dlopen
    ==========================================================================
    a b  
    141141                           Supported bindings: perl, python
    142142                           comma-separated list
    143143  --python=PATH            Force a specific python executable to use [$python_default]
     144  --enable-dlopen-libmp3lame enable libmp3lame use via dlopen [autodetect]
    144145EOF
    145146
    146147#following is ffmpeg's configure help text
     
    13381339    dvdv
    13391340    opengl
    13401341    vdpau
     1342    dlopen_libmp3lame
    13411343'
    13421344
    13431345CMDLINE_SELECT="
     
    20202022            fi
    20212023        done
    20222024    ;;
     2025    --enable-dlopen-libmp3lame)
     2026      dlopen_libmp3lame="yes"
     2027    ;;
     2028    --disable-dlopen-libmp3lame)
     2029      dlopen_libmp3lame="no"
     2030    ;;
    20232031    --disable-devices) disable $INDEV_LIST $OUTDEV_LIST
    20242032    ;;
    20252033    --enable-debug=*) debuglevel="$optval"
     
    37703778enabled freetype2 ||
    37713779    die "ERROR! You must have FreeType installed to compile MythTV."
    37723780
    3773 enabled lamemp3 && check_lib2 lame/lame.h lame_init -lmp3lame -lm ||
    3774     die "ERROR! You must have the Lame MP3 encoding library installed to compile MythTV."
     3781# libmp3lame probe
     3782if test -z "$dlopen_libmp3lame" || test x"$dlopen_libmp3lame" = x"yes"; then
     3783  { check_header lame/lame.h &&
     3784    enable dlopen_libmp3lame
     3785  } || disable dlopen_libmp3lame
     3786else
     3787  disable dlopen_libmp3lame
     3788fi
     3789
     3790if disabled dlopen_libmp3lame; then
     3791  enabled lamemp3 && check_lib2 lame/lame.h lame_init -lmp3lame -lm ||
     3792    die "ERROR! You must have the Lame MP3 encoding library or header installed to compile MythTV."
     3793fi
    37753794
    37763795if $(pkg-config --atleast-version 4.4.0 QtWebKit) ; then
    37773796    enable qtwebkit
     
    42514270echo "# Bindings"
    42524271echo "bindings_perl             ${bindings_perl-no}"
    42534272echo "bindings_python           ${bindings_python-no}"
     4273echo "dlopen libmp3lame         ${dlopen_libmp3lame-no}"
    42544274echo ""
    42554275
    42564276MYTH_CONFIG_H=libs/libmythdb/mythconfig.h
     
    45644584  echo "CONFIG_OPENGL_LIBS=-lGL -lGLU" >> $MYTH_CONFIG_MAK
    45654585fi
    45664586
     4587if enabled dlopen_libmp3lame; then
     4588  echo "#define CONFIG_DLOPEN_LIBMP3LAME 1" >>$TMPH
     4589fi
     4590
    45674591if test x"$CCONFIG" != x"" ; then
    45684592  echo "CCONFIG=$CCONFIG" >> $MYTH_CONFIG_MAK
    45694593  echo "#define MYTH_BUILD_CONFIG \"$CCONFIG\"" >>$TMPH
  • new file libs/libmythtv/myth_mp3.h

    - +  
     1#ifndef MYTH_MP3_H
     2#define MYTH_MP3_H
     3
     4#ifdef MMX
     5#undef MMX
     6#define MMXBLAH
     7#endif
     8#include <lame/lame.h>
     9#ifdef MMXBLAH
     10#define MMX
     11#undef MMXBLAH
     12#endif
     13
     14typedef struct {
     15    void *handle;
     16    int CDECL (*lame_close)(lame_global_flags *);
     17    lame_global_flags * CDECL (*lame_init)(void);
     18    int CDECL (*lame_set_bWriteVbrTag)(lame_global_flags *, int);
     19    int CDECL (*lame_set_quality)(lame_global_flags *, int);
     20    int CDECL (*lame_set_compression_ratio)(lame_global_flags *, float);
     21    int CDECL (*lame_set_mode)(lame_global_flags *, MPEG_mode);
     22    int CDECL (*lame_set_num_channels)(lame_global_flags *, int);
     23    int CDECL (*lame_set_in_samplerate)(lame_global_flags *, int);
     24    int CDECL (*lame_init_params)(lame_global_flags *);
     25    int CDECL (*lame_encode_buffer_interleaved)(lame_global_flags*,short int*,int,
     26                                                unsigned char*,int);
     27    int CDECL (*lame_encode_buffer)(lame_global_flags*,const short int*,
     28                                    const short int*,const int,unsigned char*,
     29                                    const int);
     30    int CDECL (*lame_encode_flush_nogap)(lame_global_flags*,unsigned char*,int);
     31} MythMP3Context;
     32
     33class MythMP3
     34{
     35  public:
     36    MythMP3();
     37    ~MythMP3();
     38    bool IsInitilized();
     39    int CDECL lame_close(lame_global_flags *);
     40    lame_global_flags * CDECL lame_init(void);
     41    int CDECL lame_set_bWriteVbrTag(lame_global_flags *, int);
     42    int CDECL lame_set_quality(lame_global_flags *, int);
     43    int CDECL lame_set_compression_ratio(lame_global_flags *, float);
     44    int CDECL lame_set_mode(lame_global_flags *, MPEG_mode);
     45    int CDECL lame_set_num_channels(lame_global_flags *, int);
     46    int CDECL lame_set_in_samplerate(lame_global_flags *, int);
     47    int CDECL lame_init_params(lame_global_flags *);
     48    int CDECL lame_encode_buffer_interleaved(
     49            lame_global_flags*  gfp,
     50            short int           pcm[],
     51            int                 num_samples,
     52            unsigned char*      mp3buf,
     53            int                 mp3buf_size);
     54    int CDECL lame_encode_buffer(
     55            lame_global_flags*  gfp,
     56            const short int     buffer_l [],
     57            const short int     buffer_r [],
     58            const int           nsamples,
     59            unsigned char*      mp3buf,
     60            const int           mp3buf_size);
     61    int CDECL lame_encode_flush_nogap(
     62            lame_global_flags *  gfp,
     63            unsigned char*       mp3buf,
     64            int                  size);
     65  private:
     66    MythMP3Context *s;
     67};
     68
     69#endif
  • libs/libmythtv/libmythtv.pro

    a b  
    5252using_mheg: LIBS += -L../libmythfreemheg -lmythfreemheg-$$LIBVERSION
    5353using_live: LIBS += -L../libmythlivemedia -lmythlivemedia-$$LIBVERSION
    5454using_hdhomerun: LIBS += -L../libmythhdhomerun -lmythhdhomerun-$$LIBVERSION
    55 using_backend: LIBS += -lmp3lame
     55using_backend:!using_dlopen_libmp3lame LIBS += -lmp3lame
    5656LIBS += -lz $$EXTRA_LIBS $$QMAKE_LIBS_DYNLOAD
    5757
    5858TARGETDEPS += ../libmyth/libmyth-$${MYTH_SHLIB_EXT}
     
    432432    using_ffmpeg_threads:DEFINES += USING_FFMPEG_THREADS
    433433    HEADERS += NuppelVideoRecorder.h       fifowriter.h        audioinput.h
    434434    SOURCES += NuppelVideoRecorder.cpp     fifowriter.cpp      audioinput.cpp
     435    HEADERS += myth_mp3.h
     436    SOURCES += myth_mp3.cpp
     437    LIBS += -ldl
    435438    using_alsa {
    436439        HEADERS += audioinputalsa.h
    437440        SOURCES += audioinputalsa.cpp
  • libs/libmythtv/NuppelVideoRecorder.cpp

    a b  
    190190    if (mp3buf)
    191191        delete [] mp3buf;
    192192    if (gf)
    193         lame_close(gf);
     193        myth_mp3.lame_close(gf);
    194194    if (strm)
    195195        delete [] strm;
    196196    if (audio_device)
     
    717717
    718718    if (compressaudio)
    719719    {
    720         gf = lame_init();
    721         lame_set_bWriteVbrTag(gf, 0);
    722         lame_set_quality(gf, mp3quality);
    723         lame_set_compression_ratio(gf, 11);
    724         lame_set_mode(gf, audio_channels == 2 ? STEREO : MONO);
    725         lame_set_num_channels(gf, audio_channels);
    726         lame_set_in_samplerate(gf, audio_samplerate);
    727         if ((tmp = lame_init_params(gf)) != 0)
     720        gf = myth_mp3.lame_init();
     721        myth_mp3.lame_set_bWriteVbrTag(gf, 0);
     722        myth_mp3.lame_set_quality(gf, mp3quality);
     723        myth_mp3.lame_set_compression_ratio(gf, 11);
     724        myth_mp3.lame_set_mode(gf, audio_channels == 2 ? STEREO : MONO);
     725        myth_mp3.lame_set_num_channels(gf, audio_channels);
     726        myth_mp3.lame_set_in_samplerate(gf, audio_samplerate);
     727        if ((tmp = myth_mp3.lame_init_params(gf)) != 0)
    728728        {
    729729            VERBOSE(VB_IMPORTANT, LOC_ERR +
    730                     QString("AudioInit(): lame_init_params error %1").arg(tmp));
     730                    QString("AudioInit(): myth_mp3.lame_init_params error %1").arg(tmp));
    731731            compressaudio = false;
    732732        }
    733733
     
    31943194
    31953195        if (audio_channels == 2)
    31963196        {
    3197             lameret = lame_encode_buffer_interleaved(
     3197            lameret = myth_mp3.lame_encode_buffer_interleaved(
    31983198                gf, (short int*) buf, sample_cnt,
    31993199                (unsigned char*) mp3buf, mp3buf_size);
    32003200        }
    32013201        else
    32023202        {
    3203             lameret = lame_encode_buffer(
     3203            lameret = myth_mp3.lame_encode_buffer(
    32043204                gf, (short int*) buf, (short int*) buf, sample_cnt,
    32053205                (unsigned char*) mp3buf, mp3buf_size);
    32063206        }
     
    32133213        }
    32143214        compressedsize = lameret;
    32153215
    3216         lameret = lame_encode_flush_nogap(gf, (unsigned char *)mp3gapless,
     3216        lameret = myth_mp3.lame_encode_flush_nogap(gf, (unsigned char *)mp3gapless,
    32173217                                          7200);
    32183218        if (lameret < 0)
    32193219        {
  • new file libs/libmythtv/myth_mp3.cpp

    - +  
     1extern "C" {
     2#include <dlfcn.h>
     3}
     4#include "mythconfig.h"
     5#include "myth_mp3.h"
     6
     7#if (defined __APPLE__)
     8#define LIBMP3LAME "libmp3lame.dylib"
     9#else
     10#define LIBMP3LAME "libmp3lame.so.0"
     11#endif
     12
     13MythMP3::MythMP3()
     14{
     15#ifndef CONFIG_DLOPEN_LIBMP3LAME
     16    s = NULL;
     17#else
     18    /* use the initializer function to initilize the libmp3lame library */
     19    const char* const libmp3lame = LIBMP3LAME;
     20    s->handle = dlopen(libmp3lame, RTLD_LOCAL | RTLD_LAZY);
     21    if (!s->handle)
     22        return;
     23    const char* err = 0;
     24#define TOSTRING(s) #s
     25#define init_sym(a, b) do {                                      \
     26        const char* n = TOSTRING(lame_##b);                      \
     27        if (!err && !(s->lame_##b = (a)dlsym(s->handle, n))) {   \
     28            err = n;                                             \
     29        }                                                        \
     30    } while(0)
     31    /* resolve function calls */
     32    init_sym(int CDECL (*)(lame_global_flags*), close);
     33    init_sym(lame_global_flags * CDECL (*)(void), init);
     34    init_sym(int CDECL (*)(lame_global_flags*, int), set_bWriteVbrTag);
     35    init_sym(int CDECL (*)(lame_global_flags*, int), set_quality);
     36    init_sym(int CDECL (*)(lame_global_flags*, float), set_compression_ratio);
     37    init_sym(int CDECL (*)(lame_global_flags*, MPEG_mode), set_mode);
     38    init_sym(int CDECL (*)(lame_global_flags*, int), set_num_channels);
     39    init_sym(int CDECL (*)(lame_global_flags*, int), set_in_samplerate);
     40    init_sym(int CDECL (*)(lame_global_flags*), init_params);
     41    init_sym(int CDECL (*)(lame_global_flags*,short int*,int,unsigned char*,
     42                           int),
     43             encode_buffer_interleaved);
     44    init_sym(int CDECL (*)(lame_global_flags*,const short int*,const short int*,
     45                           const int,unsigned char*,const int),
     46             encode_buffer);
     47    init_sym(int CDECL (*)(lame_global_flags*,unsigned char*,int),
     48             encode_flush_nogap);
     49    if (err)
     50    {
     51        dlclose(s->handle);
     52        s->handle = NULL;
     53        return;
     54    }
     55#endif /* CONFIG_DLOPEN_LIBMP3LAME */
     56}
     57
     58MythMP3::~MythMP3()
     59{
     60#ifdef CONFIG_DLOPEN_LIBMP3LAME
     61    dlclose(s->handle);
     62#endif
     63}
     64
     65bool MythMP3::IsInitilized()
     66{
     67#ifndef CONFIG_DLOPEN_LIBMP3LAME
     68    return true;
     69#else
     70    return (s->handle != NULL);
     71#endif
     72}
     73
     74/* libmp3lame calls */
     75lame_global_flags * CDECL MythMP3::lame_init(void)
     76{
     77#ifndef CONFIG_DLOPEN_LIBMP3LAME
     78    return ::lame_init();
     79#else
     80    return (*s->lame_init)();
     81#endif
     82}
     83
     84int CDECL MythMP3::lame_close(lame_global_flags *a)
     85{
     86#ifndef CONFIG_DLOPEN_LIBMP3LAME
     87    return ::lame_close(a);
     88#else
     89    return (*s->lame_close)(a);
     90#endif
     91}
     92
     93int CDECL MythMP3::lame_set_bWriteVbrTag(lame_global_flags *a, int b)
     94{
     95#ifndef CONFIG_DLOPEN_LIBMP3LAME
     96    return ::lame_set_bWriteVbrTag(a,b);
     97#else
     98    return (*s->lame_set_bWriteVbrTag)(a,b);
     99#endif
     100}
     101
     102int CDECL MythMP3::lame_set_quality(lame_global_flags *a, int b)
     103{
     104#ifndef CONFIG_DLOPEN_LIBMP3LAME
     105    return ::lame_set_quality(a,b);
     106#else
     107    return (*s->lame_set_quality)(a,b);
     108#endif
     109}
     110
     111int CDECL MythMP3::lame_set_compression_ratio(lame_global_flags *a, float b)
     112{
     113#ifndef CONFIG_DLOPEN_LIBMP3LAME
     114    return ::lame_set_compression_ratio(a,b);
     115#else
     116    return (*s->lame_set_compression_ratio)(a,b);
     117#endif
     118}
     119
     120int CDECL MythMP3::lame_set_mode(lame_global_flags *a, MPEG_mode b)
     121{
     122#ifndef CONFIG_DLOPEN_LIBMP3LAME
     123    return ::lame_set_mode(a,b);
     124#else
     125    return (*s->lame_set_mode)(a,b);
     126#endif
     127}
     128
     129int CDECL MythMP3::lame_set_num_channels(lame_global_flags *a, int b)
     130{
     131#ifndef CONFIG_DLOPEN_LIBMP3LAME
     132    return ::lame_set_num_channels(a,b);
     133#else
     134    return (*s->lame_set_num_channels)(a,b);
     135#endif
     136}
     137
     138int CDECL MythMP3::lame_set_in_samplerate(lame_global_flags *a , int b)
     139{
     140#ifndef CONFIG_DLOPEN_LIBMP3LAME
     141    return ::lame_set_in_samplerate(a,b);
     142#else
     143    return (*s->lame_set_in_samplerate)(a,b);
     144#endif
     145}
     146
     147int CDECL MythMP3::lame_init_params(lame_global_flags *a)
     148{
     149#ifndef CONFIG_DLOPEN_LIBMP3LAME
     150    return ::lame_init_params(a);
     151#else
     152    return (*s->lame_init_params)(a);
     153#endif
     154}
     155
     156int CDECL MythMP3::lame_encode_buffer_interleaved(
     157        lame_global_flags*  gfp,
     158        short int           pcm[],
     159        int                 num_samples,
     160        unsigned char*      mp3buf,
     161        int                 mp3buf_size)
     162{
     163#ifndef CONFIG_DLOPEN_LIBMP3LAME
     164    return ::lame_encode_buffer_interleaved(gfp,pcm,num_samples,mp3buf,
     165                                            mp3buf_size);
     166#else
     167    return (*s->lame_encode_buffer_interleaved)(gfp,pcm,num_samples,mp3buf,
     168                                                mp3buf_size);
     169#endif
     170}
     171
     172int CDECL MythMP3::lame_encode_buffer (
     173        lame_global_flags*  gfp,
     174        const short int     buffer_l [],
     175        const short int     buffer_r [],
     176        const int           nsamples,
     177        unsigned char*      mp3buf,
     178        const int           mp3buf_size)
     179{
     180#ifndef CONFIG_DLOPEN_LIBMP3LAME
     181    return ::lame_encode_buffer(gfp,buffer_l,buffer_r,nsamples,mp3buf,
     182                                mp3buf_size);
     183#else
     184    return (*s->lame_encode_buffer)(gfp,buffer_l,buffer_r,nsamples,mp3buf,
     185                                    mp3buf_size);
     186#endif
     187}
     188
     189int CDECL MythMP3::lame_encode_flush_nogap(
     190        lame_global_flags *  gfp,
     191        unsigned char*       mp3buf,
     192        int                  size)
     193{
     194#ifndef CONFIG_DLOPEN_LIBMP3LAME
     195    return ::lame_encode_flush_nogap(gfp,mp3buf,size);
     196#else
     197    return (*s->lame_encode_flush_nogap)(gfp,mp3buf,size);
     198#endif
     199}
  • libs/libmythtv/NuppelVideoRecorder.h

    a b  
    3535
    3636#include "mythexp.h"
    3737
     38#include "myth_mp3.h"
     39
    3840struct video_audio;
    3941struct VBIData;
    4042struct cc;
     
    287289
    288290    bool go7007;
    289291    bool resetcapture;
     292
     293    MythMP3 myth_mp3;
    290294};
    291295
    292296#endif