Ticket #3233: mythtv-nolame.patch

File mythtv-nolame.patch, 14.1 KB (added by anssi.hannula@…, 19 years ago)

Allow building mythtv with libmad instead of lame

  • configure

     
    137137  #echo "  --disable-decoders       disables all decoders"
    138138  #echo "  --disable-muxers         disables all muxers"
    139139  #echo "  --disable-demuxers       disables all demuxers"
     140  echo "  --disable-lame           disable LAME MP3 support"
    140141  echo "  --disable-lirc           disable lirc support (Infrared Remotes)"
    141142  echo "  --disable-joystick-menu  disable joystick menu"
    142143  echo "  --disable-firewire       disable support for FireWire cable boxes"
     
    670671ivtv="yes"
    671672dvb="no"
    672673dvb_path="/usr/include"
     674lamemp3="yes"
    673675lirc="yes"
    674676appleremote="no"
    675677joystick_menu="no"
     
    13921394  ;;
    13931395  --disable-ivtv) ivtv="no"
    13941396  ;;
     1397  --enable-lame) lamemp3="yes"
     1398  ;;
     1399  --disable-lame) lamemp3="no"
     1400  ;;
    13951401  --enable-lirc) lirc="yes"
    13961402  ;;
    13971403  --disable-lirc) lirc="no"
     
    27282734    fi
    27292735fi
    27302736
    2731 lamemp3="no"
    2732 if has_library libmp3lame ; then
    2733     if has_header lame/lame.h ; then
    2734         lamemp3="yes"
     2737if test x"$lamemp3" = x"yes"; then
     2738    if ! has_library libmp3lame || ! has_header lame/lame.h ; then
     2739        echo "You must have the Lame MP3 encoding library installed to compile Myth."
     2740        exit 255
    27352741    fi
     2742else
     2743    if ! has_library libmad || ! has_header mad.h ; then
     2744        echo "You must have the libmad MP3 decoding library installed to compile"
     2745        echo "Myth without Lame MP3 encoding support."
     2746        exit 255
     2747    else
     2748        echo "Myth will be built without MP3 encoding support!"
     2749    fi
    27362750fi
    27372751
    2738 if test x"$lamemp3" = x"no" ; then
    2739     echo "You must have the Lame MP3 encoding library installed to compile Myth."
    2740     exit 255
    2741 fi
    2742 
    27432752#test for lirc client libraries
    27442753if test x"$lirc" = x"yes" ; then
    27452754    lirc="no"
     
    34133422    CCONFIG="$CCONFIG using_iptv using_live"
    34143423fi
    34153424
     3425if test x"$lamemp3" = x"yes" ; then
     3426  CCONFIG="$CCONFIG using_lame"
     3427  echo "#define LAME 1" >> $TMPH
     3428  echo "CONFIG_MP3_LIBS=-lmp3lame" >> $MYTH_CONFIG_MAK
     3429else
     3430  CCONFIG="$CCONFIG using_mad"
     3431  echo "CONFIG_MP3_LIBS=-lmad" >> $MYTH_CONFIG_MAK
     3432fi
     3433
    34163434if test x"$lirc" = x"yes" ; then
    34173435  CCONFIG="$CCONFIG using_lirc"
    34183436  echo "CONFIG_LIRC_LIBS=-llirc_client" >> $MYTH_CONFIG_MAK
  • libs/libmythtv/nuppeldecoder.cpp

     
    3030
    3131NuppelDecoder::NuppelDecoder(NuppelVideoPlayer *parent, ProgramInfo *pginfo)
    3232    : DecoderBase(parent, pginfo),
    33       gf(0), rtjd(0), video_width(0), video_height(0), video_size(0),
     33#ifdef LAME
     34      gf(0),
     35#endif
     36      rtjd(0), video_width(0), video_height(0), video_size(0),
    3437      video_frame_rate(0.0f), audio_samplerate(44100),
    3538#ifdef WORDS_BIGENDIAN
    3639      audio_bits_per_sample(0),
     
    5659    getrawframes = false;
    5760    getrawvideo = false;
    5861
     62#ifdef LAME
    5963    gf = lame_init();
    6064    lame_set_decode_only(gf, 1);
    6165    lame_decode_init();
    6266    lame_init_params(gf);
     67#else
     68    mad_stream_init(&madstream);
     69    mad_frame_init(&madframe);
     70    mad_synth_init(&madsynth);
     71/* large enough to hold two audio frames */
     72#define MAD_BUFFER_SIZE (5*8192)
     73    madbuffer = new unsigned char[MAD_BUFFER_SIZE];
     74    if (!madbuffer)
     75    {
     76        VERBOSE(VB_IMPORTANT, "NuppelDecoder: allocating mad buffer failed, "
     77                                                                "aborting");
     78        errored = true;
     79        return;
     80    }
     81#endif
    6382
    6483    rtjd = new RTjpeg();
    6584    int format = RTJ_YUV420;
     
    8099
    81100NuppelDecoder::~NuppelDecoder()
    82101{
     102#ifdef LAME
    83103    if (gf)
    84104        lame_close(gf);
     105#else
     106    mad_stream_finish(&madstream);
     107    mad_frame_finish(&madframe);
     108    mad_synth_finish(&madsynth);
     109    if (madbuffer)
     110        delete [] madbuffer;
     111#endif
    85112    if (rtjd)
    86113        delete rtjd;
    87114    if (ffmpeg_extradata)
     
    916943    }
    917944}
    918945
     946#ifndef LAME
     947/* Libmad outputs 32bit samples instead of 16bit ones as expected by
     948   AddAudioData(), so we have to scale. This is the simple scale() function
     949   from the minimad.c example which is Copyright (C) 2000-2004 Underbit
     950   Technologies, Inc. and licensed under GPL. */
     951short int NuppelDecoder::MadScale(mad_fixed_t sample)
     952{
     953    /* round */
     954    sample += (1L << (MAD_F_FRACBITS - 16));
     955
     956    /* clip */
     957    if (sample >= MAD_F_ONE)
     958        sample = MAD_F_ONE - 1;
     959    else if (sample < -MAD_F_ONE)
     960        sample = -MAD_F_ONE;
     961
     962     /* quantize */
     963     return sample >> (MAD_F_FRACBITS + 1 - 16);
     964}
     965#endif
     966
    919967// avignore = 0  : get audio and video
    920968//          = 1  : video only
    921969//          = -1 : neither, just parse
     
    11171165                if (getrawframes)
    11181166                    StoreRawData(strm);
    11191167
    1120                 int lameret = 0;
    11211168                short int pcmlbuffer[audio_samplerate * 4];
    11221169                short int pcmrbuffer[audio_samplerate * 4];
    11231170                int packetlen = frameheader.packetlength;
    1124 
     1171#ifdef LAME
     1172                int lameret = 0;
    11251173                do
    11261174                {
    11271175                    lameret = lame_decode(strm, packetlen, pcmlbuffer,
     
    11401188                    }
    11411189                    packetlen = 0;
    11421190                } while (lameret > 0);
     1191#else
     1192                size_t madremain = 0;
     1193                if (madstream.next_frame)
     1194                {
     1195                    madremain = madstream.bufend - madstream.next_frame;
     1196                    memmove(madbuffer, madstream.next_frame, madremain);
     1197                }
     1198
     1199                if (packetlen + madremain > MAD_BUFFER_SIZE)
     1200                {
     1201                    VERBOSE(VB_IMPORTANT, QString("mad buffer too small (%1 "
     1202                                   "vs. %2), exiting").arg(MAD_BUFFER_SIZE).
     1203                                                arg(packetlen + madremain));
     1204                    errored = true;
     1205                    return false;
     1206                }
     1207
     1208                memcpy(madbuffer + madremain, strm, packetlen);
     1209                mad_stream_buffer(&madstream, madbuffer,
     1210                                                     packetlen + madremain);
     1211
     1212                while (true)
     1213                {
     1214                    if (mad_frame_decode(&madframe, &madstream))
     1215                    {
     1216                        if (!MAD_RECOVERABLE(madstream.error))
     1217                            break;
     1218                        continue;
     1219                    }
     1220                    mad_synth_frame(&madsynth, &madframe);
     1221
     1222                    for (int samplenr = 0; samplenr < madsynth.pcm.length;
     1223                                                                  samplenr++)
     1224                    {
     1225                        pcmlbuffer[samplenr] =
     1226                                  MadScale(madsynth.pcm.samples[0][samplenr]);
     1227                        if (madsynth.pcm.channels == 2)
     1228                            pcmrbuffer[samplenr] =
     1229                                  MadScale(madsynth.pcm.samples[1][samplenr]);
     1230                        else
     1231                            pcmrbuffer[samplenr] = pcmlbuffer[samplenr];
     1232                    }
     1233
     1234                    GetNVP()->AddAudioData(pcmlbuffer, pcmrbuffer,
     1235                                  madsynth.pcm.length, frameheader.timecode);
     1236                }
     1237#endif
    11431238            }
    11441239            else
    11451240            {
  • libs/libmythtv/NuppelVideoRecorder.cpp

     
    6464    pid = pid2 = 0;
    6565    inputchannel = 1;
    6666    compression = 1;
     67#ifdef LAME
    6768    compressaudio = 1;
     69#else
     70    compressaudio = 0;
     71#endif
    6872    usebttv = 1;
    6973    w = 352;
    7074    h = 240;
     
    7680    framerate_multiplier = 1.0;
    7781    height_multiplier = 1.0;
    7882
     83#ifdef LAME
     84    mp3buf = NULL;
    7985    mp3quality = 3;
    8086    gf = NULL;
     87#endif
     88
    8189    rtjc = NULL;
    8290    strm = NULL;   
    83     mp3buf = NULL;
    8491
    8592    transcoding = false;
    8693
     
    176183    }
    177184    if (rtjc)
    178185        delete rtjc;
     186#ifdef LAME
    179187    if (mp3buf)
    180188        delete [] mp3buf;
    181189    if (gf)
    182190        lame_close(gf); 
     191#endif
    183192    if (strm)
    184193        delete [] strm;
    185194    if (fd >= 0)
     
    290299        hmjpg_vdecimation = value;
    291300    else if (opt == "audiocompression")
    292301        compressaudio = value;
     302#ifdef LAME
    293303    else if (opt == "mp3quality")
    294304        mp3quality = value;
     305#endif
    295306    else if (opt == "samplerate")
    296307        audio_samplerate = value;
    297308    else if (opt == "audioframesize")
     
    375386    if ((tmp = profile->byName("audiocodec")))
    376387        setting = tmp->getValue();
    377388
     389#ifdef LAME
    378390    if (setting == "MP3")
    379391    {
    380392        SetOption("audiocompression", 1);
    381393        SetIntOption(profile, "mp3quality");
    382394        SetIntOption(profile, "samplerate");
    383395    }
    384     else if (setting == "Uncompressed")
     396    else
     397#endif
     398         if (setting == "Uncompressed")
    385399    {
    386400        SetOption("audiocompression", 0);
    387401        SetIntOption(profile, "samplerate");
     
    697711
    698712    if (compressaudio)
    699713    {
     714#ifdef LAME
    700715        gf = lame_init();
    701716        lame_set_bWriteVbrTag(gf, 0);
    702717        lame_set_quality(gf, mp3quality);
     
    717732                    "AudioInit(): lame support requires 16bit audio");
    718733            compressaudio = false;
    719734        }
     735#else
     736        VERBOSE(VB_IMPORTANT, "NVR: AudioInit(): support for LAME MP3 "
     737                                       "compression not enabled, disabling");
     738        compressaudio = false;
     739#endif
    720740    }
     741
     742#ifdef LAME
    721743    mp3buf_size = (int)(1.25 * 16384 + 7200);
    722744    mp3buf = new char[mp3buf_size];
     745#endif
    723746
    724747    return 0;
    725748}
     
    19351958        moredata.rtjpeg_chroma_filter = M2;
    19361959    }
    19371960
     1961#ifdef LAME
    19381962    if (compressaudio)
    19391963    {
    19401964        moredata.audio_fourcc = FOURCC_LAME;
     
    19421966        moredata.audio_quality = mp3quality;
    19431967    }
    19441968    else
     1969#endif
    19451970    {
    19461971        moredata.audio_fourcc = FOURCC_RAWA;
    19471972    }
     
    31883213        }
    31893214    }
    31903215
     3216#ifdef LAME
    31913217    if (compressaudio)
    31923218    {
    31933219        char mp3gapless[7200];
     
    32443270        audiobytes += audio_buffer_size;
    32453271    }
    32463272    else
     3273#endif
    32473274    {
    32483275        frameheader.comptype = '0'; // uncompressed audio
    32493276        frameheader.packetlength = audio_buffer_size;
  • libs/libmythtv/nuppeldecoder.h

     
    88#include "format.h"
    99#include "decoderbase.h"
    1010
     11#ifdef LAME
    1112#ifdef MMX
    1213#undef MMX
    1314#define MMXBLAH
     
    1617#ifdef MMXBLAH
    1718#define MMX
    1819#endif
     20#else
     21#include <mad.h>
     22#endif
    1923
    2024#include "RTjpegN.h"
    2125
     
    7377    void SeekReset(long long newKey = 0, uint skipFrames = 0,
    7478                   bool needFlush = false, bool discardFrames = false);
    7579
     80#ifndef LAME
     81    short int MadScale(mad_fixed_t sample);
     82#endif
     83
    7684    friend int get_nuppel_buffer(struct AVCodecContext *c, AVFrame *pic);
    7785    friend void release_nuppel_buffer(struct AVCodecContext *c, AVFrame *pic);
    7886
    7987    struct rtfileheader fileheader;
    8088    struct rtframeheader frameheader;
    8189
     90#ifdef LAME
    8291    lame_global_flags *gf;
     92#else
     93    struct mad_stream madstream;
     94    struct mad_frame madframe;
     95    struct mad_synth madsynth;
     96    unsigned char *madbuffer;
     97#endif
    8398    RTjpeg *rtjd;
    8499
    85100    int video_width, video_height, video_size;
  • libs/libmythtv/NuppelVideoRecorder.h

     
    55#include <sys/time.h>
    66#include <time.h>
    77#include <pthread.h>
     8
     9#ifdef LAME
    810#ifdef MMX
    911#undef MMX
    1012#define MMXBLAH
     
    1315#ifdef MMXBLAH
    1416#define MMX
    1517#endif
     18#endif
    1619
    1720#include "filter.h"
    1821#include "minilzo.h"
     
    166169
    167170    bool transcoding;
    168171
     172#ifdef LAME
    169173    int mp3quality;
    170174    char *mp3buf;
    171175    int mp3buf_size;
    172176    lame_global_flags *gf;
     177#endif
    173178
    174179    RTjpeg *rtjc;
    175180
  • libs/libmythtv/recordingprofile.cpp

     
    7878    }
    7979};
    8080
     81#ifdef LAME
    8182class MP3Quality : public SliderSetting, public CodecParamStorage
    8283{
    8384  public:
     
    9293                    "numbers) requires more CPU."));
    9394    };
    9495};
     96#endif
    9597
    9698class BTTVVolume : public SliderSetting, public CodecParamStorage
    9799{
     
    363365        addChild(codecName);
    364366        setTrigger(codecName);
    365367
    366         ConfigurationGroup* params = new VerticalConfigurationGroup(false);
     368        ConfigurationGroup* params;
     369
     370#ifdef LAME
     371        params = new VerticalConfigurationGroup(false);
    367372        params->setLabel("MP3");
    368373        params->addChild(new SampleRate(parent));
    369374        params->addChild(new MP3Quality(parent));
    370375        params->addChild(new BTTVVolume(parent));
    371376        addTarget("MP3", params);
     377#endif
    372378
    373379        params = new VerticalConfigurationGroup(false, false, true, true);
    374380        params->setLabel("MPEG-2 Hardware Encoder");
     
    395401            else
    396402            {
    397403                // V4L, TRANSCODE (and any undefined types)
     404#ifdef LAME
    398405                codecName->addSelection("MP3");
     406#endif
    399407                codecName->addSelection("Uncompressed");
    400408            }
    401409        }
    402410        else
    403411        {
     412#ifdef LAME
    404413            codecName->addSelection("MP3");
     414#endif
    405415            codecName->addSelection("Uncompressed");
    406416            codecName->addSelection("MPEG-2 Hardware Encoder");
    407417        }
  • settings.pro

     
    8888}
    8989QMAKE_LIBDIR_OPENGL =
    9090
    91 EXTRA_LIBS = $$FREETYPE_LIBS -lmp3lame
     91EXTRA_LIBS = $$FREETYPE_LIBS
     92EXTRA_LIBS += $$CONFIG_MP3_LIBS
    9293EXTRA_LIBS += $$CONFIG_AUDIO_OSS_LIBS
    9394EXTRA_LIBS += $$CONFIG_AUDIO_ALSA_LIBS
    9495EXTRA_LIBS += $$CONFIG_AUDIO_ARTS_LIBS