diff -Nurp -x '*~' -x '*.orig' -x '*.rej' mythtv-13107/configure mythtv-13107-f/configure --- mythtv-13107/configure 2006-08-28 19:18:08.000000000 +0300 +++ mythtv-13107-f/configure 2007-03-22 23:00:30.000000000 +0200 @@ -104,6 +104,7 @@ show_help(){ #echo " --disable-decoders disables all decoders" #echo " --disable-muxers disables all muxers" #echo " --disable-demuxers disables all demuxers" + echo " --disable-lame disable LAME MP3 support" echo " --disable-lirc disable lirc support (Infrared Remotes)" echo " --disable-joystick-menu disable joystick menu" echo " --disable-firewire disable support for FireWire cable boxes" @@ -396,6 +397,7 @@ ivtv="yes" ivtv_header="no" dvb="no" dvb_path="/usr/include" +lamemp3="yes" lirc="yes" appleremote="no" joystick_menu="yes" @@ -1088,6 +1090,10 @@ for opt do ;; --disable-ivtv-sys-header) ivtv_header="no" ;; + --enable-lame) lamemp3="yes" + ;; + --disable-lame) lamemp3="no" + ;; --enable-lirc) lirc="yes" ;; --disable-lirc) lirc="no" @@ -2336,16 +2342,19 @@ if test x"$dvb" = x"yes" ; then fi fi -lamemp3="no" -if has_library libmp3lame ; then - if has_header lame/lame.h ; then - lamemp3="yes" +if test x"$lamemp3" = x"yes"; then + if ! has_library libmp3lame || ! has_header lame/lame.h ; then + echo "You must have the Lame MP3 encoding library installed to compile Myth." + exit 255 + fi +else + if ! has_library libmad || ! has_header mad.h ; then + echo "You must have the libmad MP3 decoding library installed to compile" + echo "Myth without Lame MP3 encoding support." + exit 255 + else + echo "Myth will be built without MP3 encoding support!" fi -fi - -if test x"$lamemp3" = x"no" ; then - echo "You must have the Lame MP3 encoding library installed to compile Myth." - exit -1 fi #test for lirc client libraries @@ -3343,6 +3352,14 @@ if test x"$freebox_box" = x"yes" ; then CONFIG_DEFINES="$CONFIG_DEFINES USING_FREEBOX" fi +if test x"$lamemp3" = x"yes" ; then + CCONFIG="$CCONFIG using_lame" + echo "CONFIG_MP3_LIBS=-lmp3lame" >> $MYTH_CONFIG_MAK +else + CCONFIG="$CCONFIG using_mad" + echo "CONFIG_MP3_LIBS=-lmad" >> $MYTH_CONFIG_MAK +fi + if test x"$lirc" = x"yes" ; then CCONFIG="$CCONFIG using_lirc" echo "CONFIG_LIRC_LIBS=-llirc_client" >> $MYTH_CONFIG_MAK diff -Nurp -x '*~' -x '*.orig' -x '*.rej' mythtv-13107/libs/libmythtv/libmythtv.pro mythtv-13107-f/libs/libmythtv/libmythtv.pro --- mythtv-13107/libs/libmythtv/libmythtv.pro 2006-07-18 15:35:04.000000000 +0300 +++ mythtv-13107-f/libs/libmythtv/libmythtv.pro 2007-03-22 22:59:14.000000000 +0200 @@ -233,6 +233,8 @@ using_frontend { using_ivtv:HEADERS += ivtvdecoder.h using_ivtv:SOURCES += ivtvdecoder.cpp + using_lame:DEFINES += LAME + # On screen display (video output overlay) HEADERS += osd.h osdtypes.h HEADERS += osdsurface.h osdlistbtntype.h diff -Nurp -x '*~' -x '*.orig' -x '*.rej' mythtv-13107/libs/libmythtv/nuppeldecoder.cpp mythtv-13107-f/libs/libmythtv/nuppeldecoder.cpp --- mythtv-13107/libs/libmythtv/nuppeldecoder.cpp 2006-09-05 01:01:20.000000000 +0300 +++ mythtv-13107-f/libs/libmythtv/nuppeldecoder.cpp 2007-03-22 22:59:13.000000000 +0200 @@ -30,7 +30,10 @@ using namespace std; NuppelDecoder::NuppelDecoder(NuppelVideoPlayer *parent, ProgramInfo *pginfo) : DecoderBase(parent, pginfo), - gf(0), rtjd(0), video_width(0), video_height(0), video_size(0), +#ifdef LAME + gf(0), +#endif + rtjd(0), video_width(0), video_height(0), video_size(0), video_frame_rate(0.0f), audio_samplerate(44100), #ifdef WORDS_BIGENDIAN audio_bits_per_sample(0), @@ -56,10 +59,26 @@ NuppelDecoder::NuppelDecoder(NuppelVideo getrawframes = false; getrawvideo = false; +#ifdef LAME gf = lame_init(); lame_set_decode_only(gf, 1); lame_decode_init(); lame_init_params(gf); +#else + mad_stream_init(&madstream); + mad_frame_init(&madframe); + mad_synth_init(&madsynth); +/* large enough to hold two audio frames */ +#define MAD_BUFFER_SIZE (5*8192) + madbuffer = new unsigned char[MAD_BUFFER_SIZE]; + if (!madbuffer) + { + VERBOSE(VB_IMPORTANT, "NuppelDecoder: allocating mad buffer failed, " + "aborting"); + errored = true; + return; + } +#endif rtjd = new RTjpeg(); int format = RTJ_YUV420; @@ -80,8 +99,16 @@ NuppelDecoder::NuppelDecoder(NuppelVideo NuppelDecoder::~NuppelDecoder() { +#ifdef LAME if (gf) lame_close(gf); +#else + mad_stream_finish(&madstream); + mad_frame_finish(&madframe); + mad_synth_finish(&madsynth); + if (madbuffer) + delete [] madbuffer; +#endif if (rtjd) delete rtjd; if (ffmpeg_extradata) @@ -916,6 +943,27 @@ void NuppelDecoder::ClearStoredData() } } +#ifndef LAME +/* Libmad outputs 32bit samples instead of 16bit ones as expected by + AddAudioData(), so we have to scale. This is the simple scale() function + from the minimad.c example which is Copyright (C) 2000-2004 Underbit + Technologies, Inc. and licensed under GPL. */ +short int NuppelDecoder::MadScale(mad_fixed_t sample) +{ + /* round */ + sample += (1L << (MAD_F_FRACBITS - 16)); + + /* clip */ + if (sample >= MAD_F_ONE) + sample = MAD_F_ONE - 1; + else if (sample < -MAD_F_ONE) + sample = -MAD_F_ONE; + + /* quantize */ + return sample >> (MAD_F_FRACBITS + 1 - 16); +} +#endif + // avignore = 0 : get audio and video // = 1 : video only // = -1 : neither, just parse @@ -1116,11 +1164,11 @@ bool NuppelDecoder::GetFrame(int avignor if (getrawframes) StoreRawData(strm); - int lameret = 0; short int pcmlbuffer[audio_samplerate * 4]; short int pcmrbuffer[audio_samplerate * 4]; int packetlen = frameheader.packetlength; - +#ifdef LAME + int lameret = 0; do { lameret = lame_decode(strm, packetlen, pcmlbuffer, @@ -1139,6 +1187,53 @@ bool NuppelDecoder::GetFrame(int avignor } packetlen = 0; } while (lameret > 0); +#else + size_t madremain = 0; + if (madstream.next_frame) + { + madremain = madstream.bufend - madstream.next_frame; + memmove(madbuffer, madstream.next_frame, madremain); + } + + if (packetlen + madremain > MAD_BUFFER_SIZE) + { + VERBOSE(VB_IMPORTANT, QString("mad buffer too small (%1 " + "vs. %2), exiting").arg(MAD_BUFFER_SIZE). + arg(packetlen + madremain)); + errored = true; + return false; + } + + memcpy(madbuffer + madremain, strm, packetlen); + mad_stream_buffer(&madstream, madbuffer, + packetlen + madremain); + + while (true) + { + if (mad_frame_decode(&madframe, &madstream)) + { + if (!MAD_RECOVERABLE(madstream.error)) + break; + continue; + } + mad_synth_frame(&madsynth, &madframe); + + for (int samplenr = 0; samplenr < madsynth.pcm.length; + samplenr++) + { + pcmlbuffer[samplenr] = + MadScale(madsynth.pcm.samples[0][samplenr]); + if (madsynth.pcm.channels == 2) + pcmrbuffer[samplenr] = + MadScale(madsynth.pcm.samples[1][samplenr]); + else + pcmrbuffer[samplenr] = pcmlbuffer[samplenr]; + } + + GetNVP()->AddAudioData(pcmlbuffer, pcmrbuffer, + madsynth.pcm.length, frameheader.timecode); + } +#endif } else { diff -Nurp -x '*~' -x '*.orig' -x '*.rej' mythtv-13107/libs/libmythtv/nuppeldecoder.h mythtv-13107-f/libs/libmythtv/nuppeldecoder.h --- mythtv-13107/libs/libmythtv/nuppeldecoder.h 2006-03-03 11:45:51.000000000 +0200 +++ mythtv-13107-f/libs/libmythtv/nuppeldecoder.h 2007-03-22 22:59:14.000000000 +0200 @@ -8,6 +8,7 @@ #include "format.h" #include "decoderbase.h" +#ifdef LAME #ifdef MMX #undef MMX #define MMXBLAH @@ -16,6 +17,9 @@ #ifdef MMXBLAH #define MMX #endif +#else +#include <mad.h> +#endif #include "RTjpegN.h" @@ -73,13 +77,24 @@ class NuppelDecoder : public DecoderBase void SeekReset(long long newKey = 0, uint skipFrames = 0, bool needFlush = false, bool discardFrames = false); +#ifndef LAME + short int MadScale(mad_fixed_t sample); +#endif + friend int get_nuppel_buffer(struct AVCodecContext *c, AVFrame *pic); friend void release_nuppel_buffer(struct AVCodecContext *c, AVFrame *pic); struct rtfileheader fileheader; struct rtframeheader frameheader; +#ifdef LAME lame_global_flags *gf; +#else + struct mad_stream madstream; + struct mad_frame madframe; + struct mad_synth madsynth; + unsigned char *madbuffer; +#endif RTjpeg *rtjd; int video_width, video_height, video_size; diff -Nurp -x '*~' -x '*.orig' -x '*.rej' mythtv-13107/libs/libmythtv/NuppelVideoRecorder.cpp mythtv-13107-f/libs/libmythtv/NuppelVideoRecorder.cpp --- mythtv-13107/libs/libmythtv/NuppelVideoRecorder.cpp 2007-03-03 08:25:06.000000000 +0200 +++ mythtv-13107-f/libs/libmythtv/NuppelVideoRecorder.cpp 2007-03-22 23:02:02.000000000 +0200 @@ -64,7 +64,11 @@ NuppelVideoRecorder::NuppelVideoRecorder pid = pid2 = 0; inputchannel = 1; compression = 1; +#ifdef LAME compressaudio = 1; +#else + compressaudio = 0; +#endif usebttv = 1; w = 352; h = 240; @@ -76,11 +80,14 @@ NuppelVideoRecorder::NuppelVideoRecorder framerate_multiplier = 1.0; height_multiplier = 1.0; +#ifdef LAME + mp3buf = NULL; mp3quality = 3; gf = NULL; +#endif + rtjc = NULL; strm = NULL; - mp3buf = NULL; transcoding = false; @@ -176,10 +183,12 @@ NuppelVideoRecorder::~NuppelVideoRecorde } if (rtjc) delete rtjc; +#ifdef LAME if (mp3buf) delete [] mp3buf; if (gf) lame_close(gf); +#endif if (strm) delete [] strm; if (fd >= 0) @@ -290,8 +299,10 @@ void NuppelVideoRecorder::SetOption(cons hmjpg_vdecimation = value; else if (opt == "audiocompression") compressaudio = value; +#ifdef LAME else if (opt == "mp3quality") mp3quality = value; +#endif else if (opt == "samplerate") audio_samplerate = value; else if (opt == "audioframesize") @@ -368,13 +379,16 @@ void NuppelVideoRecorder::SetOptionsFrom } setting = profile->byName("audiocodec")->getValue(); +#ifdef LAME if (setting == "MP3") { SetOption("audiocompression", 1); SetIntOption(profile, "mp3quality"); SetIntOption(profile, "samplerate"); } - else if (setting == "Uncompressed") + else +#endif + if (setting == "Uncompressed") { SetOption("audiocompression", 0); SetIntOption(profile, "samplerate"); @@ -684,6 +698,7 @@ int NuppelVideoRecorder::AudioInit(bool if (compressaudio) { +#ifdef LAME gf = lame_init(); lame_set_bWriteVbrTag(gf, 0); lame_set_quality(gf, mp3quality); @@ -702,9 +717,17 @@ int NuppelVideoRecorder::AudioInit(bool VERBOSE(VB_IMPORTANT, "NVR: AudioInit(): lame support requires 16bit audio"); compressaudio = false; } +#else + VERBOSE(VB_IMPORTANT, "NVR: AudioInit(): support for LAME MP3 " + "compression not enabled, disabling"); + compressaudio = false; +#endif } + +#ifdef LAME mp3buf_size = (int)(1.25 * 16384 + 7200); mp3buf = new char[mp3buf_size]; +#endif return 0; } @@ -1909,6 +1932,7 @@ void NuppelVideoRecorder::WriteHeader(vo moredata.rtjpeg_chroma_filter = M2; } +#ifdef LAME if (compressaudio) { moredata.audio_fourcc = MKTAG('L', 'A', 'M', 'E'); @@ -1916,6 +1940,7 @@ void NuppelVideoRecorder::WriteHeader(vo moredata.audio_quality = mp3quality; } else +#endif { moredata.audio_fourcc = MKTAG('R', 'A', 'W', 'A'); } @@ -3161,6 +3186,7 @@ void NuppelVideoRecorder::WriteAudio(uns } } +#ifdef LAME if (compressaudio) { char mp3gapless[7200]; @@ -3217,6 +3243,7 @@ void NuppelVideoRecorder::WriteAudio(uns audiobytes += audio_buffer_size; } else +#endif { frameheader.comptype = '0'; // uncompressed audio frameheader.packetlength = audio_buffer_size; diff -Nurp -x '*~' -x '*.orig' -x '*.rej' mythtv-13107/libs/libmythtv/NuppelVideoRecorder.h mythtv-13107-f/libs/libmythtv/NuppelVideoRecorder.h --- mythtv-13107/libs/libmythtv/NuppelVideoRecorder.h 2006-07-16 10:36:00.000000000 +0300 +++ mythtv-13107-f/libs/libmythtv/NuppelVideoRecorder.h 2007-03-22 22:59:14.000000000 +0200 @@ -5,6 +5,8 @@ #include <sys/time.h> #include <time.h> #include <pthread.h> + +#ifdef LAME #ifdef MMX #undef MMX #define MMXBLAH @@ -13,6 +15,7 @@ #ifdef MMXBLAH #define MMX #endif +#endif #include "filter.h" #include "minilzo.h" @@ -162,10 +165,12 @@ class NuppelVideoRecorder : public Recor bool transcoding; +#ifdef LAME int mp3quality; char *mp3buf; int mp3buf_size; lame_global_flags *gf; +#endif RTjpeg *rtjc; diff -Nurp -x '*~' -x '*.orig' -x '*.rej' mythtv-13107/libs/libmythtv/recordingprofile.cpp mythtv-13107-f/libs/libmythtv/recordingprofile.cpp --- mythtv-13107/libs/libmythtv/recordingprofile.cpp 2006-09-06 02:52:38.000000000 +0300 +++ mythtv-13107-f/libs/libmythtv/recordingprofile.cpp 2007-03-22 23:02:51.000000000 +0200 @@ -69,6 +69,7 @@ public: }; }; +#ifdef LAME class MP3Quality: public CodecParam, public SliderSetting { public: MP3Quality(const RecordingProfile& parent): @@ -81,6 +82,7 @@ public: "numbers) requires more CPU.")); }; }; +#endif class BTTVVolume: public CodecParam, public SliderSetting { public: @@ -232,12 +234,16 @@ public: addChild(codecName); setTrigger(codecName); - ConfigurationGroup* params = new VerticalConfigurationGroup(false); + ConfigurationGroup* params; + +#ifdef LAME + params = new VerticalConfigurationGroup(false); params->setLabel("MP3"); params->addChild(new SampleRate(parent)); params->addChild(new MP3Quality(parent)); params->addChild(new BTTVVolume(parent)); addTarget("MP3", params); +#endif params = new VerticalConfigurationGroup(false); params->setLabel("MPEG-2 Hardware Encoder"); @@ -262,13 +268,17 @@ public: else { // V4L, TRANSCODE (and any undefined types) +#ifdef LAME codecName->addSelection("MP3"); +#endif codecName->addSelection("Uncompressed"); } } else { +#ifdef LAME codecName->addSelection("MP3"); +#endif codecName->addSelection("Uncompressed"); codecName->addSelection("MPEG-2 Hardware Encoder"); } diff -Nurp -x '*~' -x '*.orig' -x '*.rej' mythtv-13107/settings.pro mythtv-13107-f/settings.pro --- mythtv-13107/settings.pro 2006-08-28 23:47:26.000000000 +0300 +++ mythtv-13107-f/settings.pro 2007-03-22 23:03:53.000000000 +0200 @@ -72,7 +72,8 @@ LOCAL_LIBDIR_OGL = } QMAKE_LIBDIR_OPENGL = -EXTRA_LIBS = -lfreetype -lmp3lame +EXTRA_LIBS = -lfreetype +EXTRA_LIBS += $$CONFIG_MP3_LIBS EXTRA_LIBS += $$CONFIG_AUDIO_OSS_LIBS EXTRA_LIBS += $$CONFIG_AUDIO_ALSA_LIBS EXTRA_LIBS += $$CONFIG_AUDIO_ARTS_LIBS