Ticket #5900: audioencoding-fixes-7.patch

File audioencoding-fixes-7.patch, 131.5 KB (added by foobum@…, 15 years ago)

against r20844

  • mfd/mfd/plugins/audio/audio.cpp

    diff --git a/mfd/mfd/plugins/audio/audio.cpp b/mfd/mfd/plugins/audio/audio.cpp
    index b2026bc..102c8bc 100644
    a b AudioPlugin::AudioPlugin(MFD *owner, int identity) 
    4545    //  thr RTSP streamer can use to get PCM bits to send out.
    4646    //
    4747
    48     output = AudioOutput::OpenAudio("NULL", "default", 16, 2, 44100,
    49                                     AUDIOOUTPUT_MUSIC, true, false );
     48    output = AudioOutput::OpenAudio("NULL", "default", 16, 2, CODEC_ID_NONE,
     49                                    44100, AUDIOOUTPUT_MUSIC, true, false );
    5050    output->bufferOutputData(true);
    5151    output->setBufferSize(output_buffer_size * 1024);
    5252    output->SetBlocking(false);
    bool AudioPlugin::playUrl(QUrl url, int collection_id) 
    517517#else
    518518            QString adevice = gContext->GetSetting("AudioDevice");
    519519            // TODO: Error checking that device is opened correctly!
    520             output = AudioOutput::OpenAudio(adevice, "default", 16, 2, 44100,
     520            output = AudioOutput::OpenAudio(adevice, "default", 16, 2,
     521                                            CODEC_ID_NONE, 44100,
    521522                                            AUDIOOUTPUT_MUSIC, true, false );
    522523            output->setBufferSize(output_buffer_size * 1024);
    523524            output->SetBlocking(false);
  • mfd/mfd/plugins/speakers/rtspin.cpp

    diff --git a/mfd/mfd/plugins/speakers/rtspin.cpp b/mfd/mfd/plugins/speakers/rtspin.cpp
    index c6e9e9f..1703676 100644
    a b RtspIn::RtspIn( 
    8080        }
    8181    }
    8282
    83     audio_output = AudioOutput::OpenAudio(adevice, "default", 16, 2, 44100,
     83    audio_output = AudioOutput::OpenAudio(adevice, "default", 16, 2,
     84                                          CODEC_ID_NONE, 44100,
    8485                                          AUDIOOUTPUT_MUSIC, false);
    8586    audio_output->setBufferSize(256 * 1024);
    8687    audio_output->SetBlocking(false);
  • mythplugins/mythmusic/mythmusic/aacdecoder.cpp

    diff --git a/mythplugins/mythmusic/mythmusic/aacdecoder.cpp b/mythplugins/mythmusic/mythmusic/aacdecoder.cpp
    index 4e350d3..6d0b11f 100644
    a b  
    2828#include "metaiomp4.h"
    2929
    3030#include <mythtv/mythcontext.h>
     31#include <mythtv/ffmpeg/avcodec.h>
    3132
    3233//
    3334//  C style callbacks (jump right back into the aacDecoder object)
    bool aacDecoder::initializeMP4() 
    384385
    385386    if (output())
    386387    {
    387         output()->Reconfigure(16, channels, sample_rate,
     388        output()->Reconfigure(16, channels, CODEC_ID_AAC, sample_rate,
    388389                              false /* AC3/DTS pass through */);
    389390        output()->SetSourceBitrate(bitrate);
    390391    }
  • mythplugins/mythmusic/mythmusic/avfdecoder.cpp

    diff --git a/mythplugins/mythmusic/mythmusic/avfdecoder.cpp b/mythplugins/mythmusic/mythmusic/avfdecoder.cpp
    index d4b7598..ff3fe59 100644
    a b bool avfDecoder::initialize() 
    184184
    185185    if (output())
    186186    {
    187         output()->Reconfigure(16, audio_dec->channels, audio_dec->sample_rate,
     187        output()->Reconfigure(16, audio_dec->channels, audio_dec->codec_id,
     188                              audio_dec->sample_rate,
    188189                              false /* AC3/DTS pass through */);
    189190        output()->SetSourceBitrate(audio_dec->bit_rate);
    190191    }
  • mythplugins/mythmusic/mythmusic/cddecoder.cpp

    diff --git a/mythplugins/mythmusic/mythmusic/cddecoder.cpp b/mythplugins/mythmusic/mythmusic/cddecoder.cpp
    index 19f85b1..cf22083 100644
    a b using namespace std; 
    1414
    1515#include <mythtv/mythcontext.h>
    1616#include <mythtv/mythmediamonitor.h>
     17#include <mythtv/ffmpeg/avcodec.h>
    1718
    1819CdDecoder::CdDecoder(const QString &file, DecoderFactory *d, QIODevice *i,
    1920                     AudioOutput *o)
    bool CdDecoder::initialize() 
    136137
    137138    if (output())
    138139    {
    139         output()->Reconfigure(16, chan, freq, false /* AC3/DTS passthru */);
     140        output()->Reconfigure(16, chan, CODEC_ID_PCM_S16LE, freq,
     141                              false /* AC3/DTS passthru */);
    140142        output()->SetSourceBitrate(44100 * 2 * 16);
    141143    }
    142144
  • mythplugins/mythmusic/mythmusic/flacdecoder.cpp

    diff --git a/mythplugins/mythmusic/mythmusic/flacdecoder.cpp b/mythplugins/mythmusic/mythmusic/flacdecoder.cpp
    index 9c891e1..d893ab5 100644
    a b using namespace std; 
    1414
    1515#include <mythtv/mythconfig.h>
    1616#include <mythtv/mythcontext.h>
     17#include <mythtv/ffmpeg/avcodec.h>
    1718
    1819#include <qtimer.h>
    1920
    void FlacDecoder::setFlacMetadata(const FLAC__StreamMetadata *metadata) 
    150151   
    151152    if (output())
    152153    {
    153         output()->Reconfigure(bitspersample, chan,
     154        output()->Reconfigure(bitspersample, chan, CODEC_ID_FLAC,
    154155                              freq, false /* AC3/DTS pass through */);
    155156        output()->SetSourceBitrate(44100 * 2 * 16);
    156157    }
  • mythplugins/mythmusic/mythmusic/maddecoder.cpp

    diff --git a/mythplugins/mythmusic/mythmusic/maddecoder.cpp b/mythplugins/mythmusic/mythmusic/maddecoder.cpp
    index bd0c1fe..cc30fb3 100644
    a b using namespace std; 
    1717
    1818#include <mythtv/mythconfig.h>
    1919#include <mythtv/mythcontext.h>
     20#include <mythtv/ffmpeg/avcodec.h>
    2021
    2122#define XING_MAGIC     (('X' << 24) | ('i' << 16) | ('n' << 8) | 'g')
    2223
    bool MadDecoder::initialize() 
    111112
    112113    if (output())
    113114    {
    114         output()->Reconfigure(16, channels, freq, false /*AC3/DTS passthru*/);
     115        output()->Reconfigure(16, channels, CODEC_ID_MP3, freq,
     116                              false /*AC3/DTS passthru*/);
    115117        output()->SetSourceBitrate(bitrate);
    116118    }
    117119
    enum mad_flow MadDecoder::madOutput() 
    479481        {
    480482            freq = newfreq;
    481483            channels = newchannels;
    482             output()->Reconfigure(16, channels, freq, false /*AC3/DTS passthru*/);
     484            output()->Reconfigure(16, channels, CODEC_ID_MP3, freq,
     485                                  false /*AC3/DTS passthru*/);
    483486        }
    484487        if (newbitrate != bitrate)
    485488        {
  • mythplugins/mythmusic/mythmusic/main.cpp

    diff --git a/mythplugins/mythmusic/mythmusic/main.cpp b/mythplugins/mythmusic/mythmusic/main.cpp
    index 0ab4b45..490aab3 100644
    a b void setupKeys(void) 
    378378    REG_KEY("Music", "VOLUMEDOWN", "Volume down",       "[,{,F10,Volume Down");
    379379    REG_KEY("Music", "VOLUMEUP",   "Volume up",         "],},F11,Volume Up");
    380380    REG_KEY("Music", "MUTE",       "Mute",              "|,\\,F9,Volume Mute");
     381    REG_KEY("Music", "TOGGLEUPMIX","Toggle upmixer",             "Ctrl+U");
    381382    REG_KEY("Music", "CYCLEVIS",   "Cycle visualizer mode",      "6");
    382383    REG_KEY("Music", "BLANKSCR",   "Blank screen",               "5");
    383384    REG_KEY("Music", "THMBUP",     "Increase rating",            "9");
  • mythplugins/mythmusic/mythmusic/musicplayer.cpp

    diff --git a/mythplugins/mythmusic/mythmusic/musicplayer.cpp b/mythplugins/mythmusic/mythmusic/musicplayer.cpp
    index ba0793d..92a4a49 100644
    a b void MusicPlayer::stopDecoder(void) 
    347347
    348348void MusicPlayer::openOutputDevice(void)
    349349{
    350     QString adevice;
     350    QString adevice, pdevice;
    351351
    352352    if (gContext->GetSetting("MusicAudioDevice") == "default")
    353353        adevice = gContext->GetSetting("AudioOutputDevice");
    354354    else
    355355        adevice = gContext->GetSetting("MusicAudioDevice");
    356356
     357    pdevice = gContext->GetSetting("PassThruOutputDevice");
     358
    357359    // TODO: Error checking that device is opened correctly!
    358     m_output = AudioOutput::OpenAudio(adevice, "default", 16, 2, 44100,
    359                                     AUDIOOUTPUT_MUSIC, true, false);
     360    m_output = AudioOutput::OpenAudio(adevice, pdevice, 16, 2,
     361                                      0, 44100,
     362                                      AUDIOOUTPUT_MUSIC, true, false);
     363
    360364    m_output->setBufferSize(256 * 1024);
    361365    m_output->SetBlocking(false);
    362366
  • mythplugins/mythmusic/mythmusic/playbackbox.cpp

    diff --git a/mythplugins/mythmusic/mythmusic/playbackbox.cpp b/mythplugins/mythmusic/mythmusic/playbackbox.cpp
    index 57c38a9..cc230c5 100644
    a b void PlaybackBoxMusic::keyPressEvent(QKeyEvent *e) 
    358358            changeSpeed(true);
    359359        else if (action == "MUTE")
    360360            toggleMute();
     361        else if (action == "TOGGLEUPMIX")
     362            toggleUpmix();
    361363        else if (action == "MENU" && visualizer_status != 2)
    362364        {
    363365            menufilters = false;
    void PlaybackBoxMusic::toggleMute() 
    11781180    }
    11791181}
    11801182
     1183void PlaybackBoxMusic::toggleUpmix()
     1184{
     1185    if (gPlayer->getOutput())
     1186        gPlayer->getOutput()->ToggleUpmix();
     1187}
     1188   
     1189
    11811190void PlaybackBoxMusic::showProgressBar()
    11821191{
    11831192    if (progress_bar)
  • mythplugins/mythmusic/mythmusic/playbackbox.h

    diff --git a/mythplugins/mythmusic/mythmusic/playbackbox.h b/mythplugins/mythmusic/mythmusic/playbackbox.h
    index 038ad97..2950d0b 100644
    a b class PlaybackBoxMusic : public MythThemedDialog 
    6969    void changeVolume(bool up_or_down);
    7070    void changeSpeed(bool up_or_down);
    7171    void toggleMute();
     72    void toggleUpmix();
    7273    void resetTimer();
    7374    void hideVolume(){showVolume(false);}
    7475    void showVolume(bool on_or_off);
  • mythplugins/mythmusic/mythmusic/vorbisdecoder.cpp

    diff --git a/mythplugins/mythmusic/mythmusic/vorbisdecoder.cpp b/mythplugins/mythmusic/mythmusic/vorbisdecoder.cpp
    index 1dc90a8..702de6d 100644
    a b using namespace std; 
    1414
    1515#include <mythtv/mythconfig.h>
    1616#include <mythtv/mythcontext.h>
     17#include <mythtv/ffmpeg/avcodec.h>
    1718
    1819// static functions for OggVorbis
    1920
    bool VorbisDecoder::initialize() 
    187188
    188189    if (output())
    189190    {
    190         output()->Reconfigure(16, chan, freq, false /*AC3/DTS pass through*/);
     191        output()->Reconfigure(16, chan, CODEC_ID_VORBIS, freq,
     192                              false /*AC3/DTS pass through*/);
    191193        output()->SetSourceBitrate(bitrate);
    192194    }
    193195
  • mythplugins/mythphone/mythphone/audiodrv.cpp

    diff --git a/mythplugins/mythphone/mythphone/audiodrv.cpp b/mythplugins/mythphone/mythphone/audiodrv.cpp
    index 20662b8..048ac33 100644
    a b void mythAudioDriver::Open() 
    835835        cerr << "Cannot have matching spk and mic devices in this mode, should have chosen OSS mode\n";
    836836    else
    837837    {
    838         mythOutput = AudioOutput::OpenAudio(spkDevice, "default", 16, 1, 8000,
     838        mythOutput = AudioOutput::OpenAudio(spkDevice, "default", 16, 1,
     839                                            CODEC_ID_NONE, 8000,
    839840                                            AUDIOOUTPUT_TELEPHONY, true,
    840841                                            false /* AC3/DTS pass through */);
    841842        if (mythOutput)
  • mythplugins/mythphone/mythphone/tone.cpp

    diff --git a/mythplugins/mythphone/mythphone/tone.cpp b/mythplugins/mythphone/mythphone/tone.cpp
    index 9056ab1..76f3c96 100644
    a b void Tone::OpenSpeaker(QString devName) 
    305305        return;
    306306
    307307#else
    308     mythOutput = AudioOutput::OpenAudio(devName, "default", 16, 1, 8000,
     308    mythOutput = AudioOutput::OpenAudio(devName, "default", 16, 1,
     309                                        CODEC_ID_NONE, 8000,
    309310                                        AUDIOOUTPUT_TELEPHONY, true,
    310311                                        false /* AC3/DTS pass through */);
    311312    if (mythOutput)
  • mythtv/libs/libavcodec/ac3dec.c

    diff --git a/mythtv/libs/libavcodec/ac3dec.c b/mythtv/libs/libavcodec/ac3dec.c
    index 76c6284..1b4d996 100644
    a b static const uint8_t ac3_default_coeffs[8][5][2] = { 
    121121    { { 1, 0 }, { 3, 3 }, { 0, 1 }, { 4, 0 }, { 0, 4 }, },
    122122};
    123123
     124static const int channel_map[6] = { 0, 2, 3, 4, 1, 5 };
     125
    124126/* override ac3.h to include coupling channel */
    125127#undef AC3_MAX_CHANNELS
    126128#define AC3_MAX_CHANNELS 7
    static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, 
    11741176            *data_size = 0;
    11751177            return ctx->frame_size;
    11761178        }
    1177         for (i = 0; i < 256; i++)
    1178             for (ch = 0; ch < ctx->out_channels; ch++)
    1179                 *(out_samples++) = ctx->int_output[ch][i];
     1179        if (ctx->out_channels == 6) {
     1180            for (i = 0; i < 256; i++)
     1181               for (ch = 0; ch < ctx->out_channels; ch++)
     1182                    *(out_samples++) = ctx->int_output[channel_map[ch]][i];
     1183        }   
     1184        else {
     1185            for (i = 0; i < 256; i++)
     1186                for (ch = 0; ch < ctx->out_channels; ch++)
     1187                    *(out_samples++) = ctx->int_output[ch][i];
     1188        }
    11801189    }
    11811190    *data_size = NB_BLOCKS * 256 * avctx->channels * sizeof (int16_t);
    11821191    return ctx->frame_size;
  • mythtv/libs/libavcodec/dca.c

    diff --git a/mythtv/libs/libavcodec/dca.c b/mythtv/libs/libavcodec/dca.c
    index b3803ad..af974f0 100644
    a b static BitAlloc dca_smpl_bitalloc[11]; ///< samples VLCs 
    8787/** Pre-calculated cosine modulation coefs for the QMF */
    8888static float cos_mod[544];
    8989
     90static const int channel_map[6] = { 1, 2, 3, 4, 0, 5 };
     91
    9092static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx)
    9193{
    9294    return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) + ba->offset;
    static int dca_decode_frame(AVCodecContext * avctx, 
    11891191        dca_decode_block(s);
    11901192        s->dsp.float_to_int16(s->tsamples, s->samples, 256 * channels);
    11911193        /* interleave samples */
    1192         for (j = 0; j < 256; j++) {
    1193             for (k = 0; k < channels; k++)
    1194                 samples[k] = s->tsamples[j + k * 256];
    1195             samples += channels;
     1194        if (channels == 6) {
     1195            for (j = 0; j < 256; j++) {
     1196                for (k = 0; k < channels; k++)
     1197                    samples[k] = s->tsamples[j + channel_map[k] * 256];
     1198                samples += channels;
     1199            }
     1200        }
     1201        else {
     1202            for (j = 0; j < 256; j++) {
     1203                for (k = 0; k < channels; k++)
     1204                    samples[k] = s->tsamples[j + k * 256];
     1205                samples += channels;
     1206            }
    11961207        }
    11971208        *data_size += 256 * sizeof(int16_t) * channels;
    11981209    }
  • mythtv/libs/libmyth/audiooutput.cpp

    diff --git a/mythtv/libs/libmyth/audiooutput.cpp b/mythtv/libs/libmyth/audiooutput.cpp
    index 1eab657..dbd6618 100644
    a b using namespace std; 
    3434AudioOutput *AudioOutput::OpenAudio(QString main_device,
    3535                                    QString passthru_device,
    3636                                    int audio_bits,
    37                                     int audio_channels, int audio_samplerate,
     37                                    int audio_channels,
     38                                    int audio_codec,
     39                                    int audio_samplerate,
    3840                                    AudioOutputSource source,
    3941                                    bool set_initial_vol, bool audio_passthru)
    4042{
    AudioOutput *AudioOutput::OpenAudio(QString main_device, 
    4648#ifdef USE_ALSA
    4749        return new AudioOutputALSA(main_device.remove(0, 5),
    4850                                   passthru_device.remove(0, 5), audio_bits,
    49                                    audio_channels, audio_samplerate, source,
     51                                   audio_channels, audio_codec,
     52                                   audio_samplerate, source,
    5053                                   set_initial_vol, audio_passthru);
    5154#else
    5255        VERBOSE(VB_IMPORTANT, "Audio output device is set to an ALSA device "
    AudioOutput *AudioOutput::OpenAudio(QString main_device, 
    5760    else if (main_device.startsWith("NULL"))
    5861    {
    5962        return new AudioOutputNULL(main_device, passthru_device, audio_bits,
    60                                    audio_channels, audio_samplerate, source,
     63                                   audio_channels, audio_codec,
     64                                   audio_samplerate, source,
    6165                                   set_initial_vol, audio_passthru);
    6266    }
    6367    else if (main_device.startsWith("ARTS:"))
    AudioOutput *AudioOutput::OpenAudio(QString main_device, 
    6569#ifdef USE_ARTS
    6670        return new AudioOutputARTS(main_device.remove(0, 5),
    6771                                   passthru_device.remove(0, 5), audio_bits,
    68                                    audio_channels, audio_samplerate, source,
     72                                   audio_channels, audio_codec,
     73                                   audio_samplerate, source,
    6974                                   set_initial_vol, audio_passthru);
    7075#else
    7176        VERBOSE(VB_IMPORTANT, "Audio output device is set to an ARTS device "
    AudioOutput *AudioOutput::OpenAudio(QString main_device, 
    7883#ifdef USE_JACK
    7984        return new AudioOutputJACK(main_device.remove(0, 5),
    8085                                   passthru_device.remove(0, 5), audio_bits,
    81                                    audio_channels, audio_samplerate, source,
     86                                   audio_channels, audio_codec,
     87                                   audio_samplerate, source,
    8288                                   set_initial_vol, audio_passthru);
    8389#else
    8490        VERBOSE(VB_IMPORTANT, "Audio output device is set to a JACK device "
    AudioOutput *AudioOutput::OpenAudio(QString main_device, 
    9096    {
    9197#ifdef USING_DIRECTX
    9298        return new AudioOutputDX(main_device, passthru_device, audio_bits,
    93                                  audio_channels, audio_samplerate, source,
     99                                 audio_channels, audio_codec,
     100                                 audio_samplerate, source,
    94101                                 set_initial_vol, audio_passthru);
    95102#else
    96103        VERBOSE(VB_IMPORTANT, "Audio output device is set to DirectX device "
    AudioOutput *AudioOutput::OpenAudio(QString main_device, 
    102109    {
    103110#ifdef USING_WINAUDIO
    104111        return new AudioOutputWin(main_device, passthru_device, audio_bits,
    105                                   audio_channels, audio_samplerate, source,
     112                                  audio_channels, audio_codec,
     113                                  audio_samplerate, source,
    106114                                  set_initial_vol, audio_passthru);
    107115#else
    108116        VERBOSE(VB_IMPORTANT, "Audio output device is set to a Windows device "
    AudioOutput *AudioOutput::OpenAudio(QString main_device, 
    113121#if defined(USING_OSS)
    114122    else
    115123        return new AudioOutputOSS(main_device, passthru_device, audio_bits,
    116                                   audio_channels, audio_samplerate, source,
     124                                  audio_channels, audio_codec,
     125                                  audio_samplerate, source,
    117126                                  set_initial_vol, audio_passthru);
    118127#elif defined(CONFIG_DARWIN)
    119128    else
    120129        return new AudioOutputCA(main_device, passthru_device, audio_bits,
    121                                  audio_channels, audio_samplerate, source,
     130                                 audio_channels, audio_codec,
     131                                 audio_samplerate, source,
    122132                                 set_initial_vol, audio_passthru);
    123133#endif
    124134
  • mythtv/libs/libmyth/audiooutput.h

    diff --git a/mythtv/libs/libmyth/audiooutput.h b/mythtv/libs/libmyth/audiooutput.h
    index 7d65a51..1de4f96 100644
    a b class MPUBLIC AudioOutput : public VolumeBase, public OutputListeners 
    1919 public:
    2020    // opens one of the concrete subclasses
    2121    static AudioOutput *OpenAudio(QString audiodevice, QString passthrudevice,
    22                                   int audio_bits,
    23                                   int audio_channels, int audio_samplerate,
     22                                  int audio_bits, int audio_channels,
     23                                  int audio_codec, int audio_samplerate,
    2424                                  AudioOutputSource source,
    2525                                  bool set_initial_vol, bool audio_passthru);
    2626
    class MPUBLIC AudioOutput : public VolumeBase, public OutputListeners 
    3333    // reconfigure sound out for new params
    3434    virtual void Reconfigure(int audio_bits,
    3535                             int audio_channels,
     36                             int audio_codec,
    3637                             int audio_samplerate,
    37                              bool audio_passthru,
    38                              void* audio_codec = NULL) = 0;
     38                             bool audio_passthru) = 0;
    3939   
    4040    virtual void SetStretchFactor(float factor);
    4141    virtual float GetStretchFactor(void) { return 1.0f; }
     42    virtual bool ToggleUpmix(void) = 0;
    4243
    4344    // do AddSamples calls block?
    4445    virtual void SetBlocking(bool blocking) = 0;
  • mythtv/libs/libmyth/audiooutputalsa.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputalsa.cpp b/mythtv/libs/libmyth/audiooutputalsa.cpp
    index ba86f3b..dd5bad9 100644
    a b using namespace std; 
    1616AudioOutputALSA::AudioOutputALSA(
    1717    QString laudio_main_device, QString           laudio_passthru_device,
    1818    int     laudio_bits,        int               laudio_channels,
    19     int     laudio_samplerate,  AudioOutputSource lsource,
    20     bool    lset_initial_vol,   bool              laudio_passthru) :
     19    int     laudio_codec,       int               laudio_samplerate, 
     20    AudioOutputSource lsource,  bool              lset_initial_vol,   
     21    bool              laudio_passthru) :
    2122    AudioOutputBase(laudio_main_device, laudio_passthru_device,
    2223                    laudio_bits,        laudio_channels,
    2324                    laudio_samplerate,  lsource,
    AudioOutputALSA::AudioOutputALSA( 
    2829    playback_vol_min(0),          playback_vol_max(1)
    2930{
    3031    // Set everything up
    31     Reconfigure(laudio_bits,       laudio_channels,
     32    Reconfigure(laudio_bits,       laudio_channels,     laudio_codec,
    3233                laudio_samplerate, laudio_passthru);
    3334}
    3435
    3536AudioOutputALSA::~AudioOutputALSA()
    3637{
    3738    KillAudio();
     39    SetIECStatus(true);
     40}
     41
     42void AudioOutputALSA::SetIECStatus(bool audio) {
     43   
     44    snd_ctl_t *ctl;
     45    const char *spdif_str = SND_CTL_NAME_IEC958("", PLAYBACK, DEFAULT);
     46    int spdif_index = -1;
     47    snd_ctl_elem_list_t *clist;
     48    snd_ctl_elem_id_t *cid;
     49    snd_ctl_elem_value_t *cval;
     50    snd_aes_iec958_t iec958;
     51    int cidx, controls;
     52
     53    VERBOSE(VB_AUDIO, QString("Setting IEC958 status: %1")
     54                      .arg(audio ? "audio" : "non-audio"));
     55   
     56    snd_ctl_open(&ctl, "default", 0);
     57    snd_ctl_elem_list_alloca(&clist);
     58    snd_ctl_elem_list(ctl, clist);
     59    snd_ctl_elem_list_alloc_space(clist, snd_ctl_elem_list_get_count(clist));
     60    snd_ctl_elem_list(ctl, clist);
     61    controls = snd_ctl_elem_list_get_used(clist);
     62    for (cidx = 0; cidx < controls; cidx++)
     63    {
     64        if (!strcmp(snd_ctl_elem_list_get_name(clist, cidx), spdif_str))
     65            if (spdif_index < 0 ||
     66                snd_ctl_elem_list_get_index(clist, cidx) == (uint)spdif_index)
     67                    break;
     68    }
     69
     70    if (cidx >= controls)
     71        return;
     72
     73    snd_ctl_elem_id_alloca(&cid);
     74    snd_ctl_elem_list_get_id(clist, cidx, cid);
     75    snd_ctl_elem_value_alloca(&cval);
     76    snd_ctl_elem_value_set_id(cval, cid);
     77    snd_ctl_elem_read(ctl,cval);
     78    snd_ctl_elem_value_get_iec958(cval, &iec958);
     79   
     80    if (!audio)
     81        iec958.status[0] |= IEC958_AES0_NONAUDIO;
     82    else
     83        iec958.status[0] &= ~IEC958_AES0_NONAUDIO;
     84
     85    snd_ctl_elem_value_set_iec958(cval, &iec958);
     86    snd_ctl_elem_write(ctl, cval);
     87
     88}
     89
     90vector<int> AudioOutputALSA::GetSupportedRates()
     91{
     92    snd_pcm_hw_params_t *params;
     93    int err;
     94    const int srates[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000 };
     95    vector<int> rates(srates, srates + sizeof(srates) / sizeof(int) );
     96    QString real_device;
     97   
     98    if (audio_passthru || audio_enc)
     99        real_device = audio_passthru_device;
     100    else
     101        real_device = audio_main_device;
     102
     103    if((err = snd_pcm_open(&pcm_handle, real_device,
     104                           SND_PCM_STREAM_PLAYBACK,
     105                           SND_PCM_NONBLOCK|SND_PCM_NO_AUTO_RESAMPLE)) < 0)
     106    {
     107        Error(QString("snd_pcm_open(%1): %2")
     108              .arg(real_device).arg(snd_strerror(err)));
     109
     110        if (pcm_handle)
     111        {
     112            snd_pcm_close(pcm_handle);
     113            pcm_handle = NULL;
     114        }
     115        rates.clear();
     116        return rates;
     117    }
     118   
     119    snd_pcm_hw_params_alloca(&params);
     120
     121    if ((err = snd_pcm_hw_params_any(pcm_handle, params)) < 0)
     122    {
     123        Error(QString("Broken configuration for playback; no configurations"
     124              " available: %1").arg(snd_strerror(err)));
     125        snd_pcm_close(pcm_handle);
     126        pcm_handle = NULL;
     127        rates.clear();
     128        return rates;
     129    }
     130   
     131    vector<int>::iterator it;
     132
     133    for (it = rates.begin(); it < rates.end(); it++)
     134        if(snd_pcm_hw_params_test_rate(pcm_handle, params, *it, 0) < 0)
     135            rates.erase(it--);
     136   
     137    snd_pcm_close(pcm_handle);
     138    pcm_handle = NULL;
     139
     140    return rates;
    38141}
    39142
    40143bool AudioOutputALSA::OpenDevice()
    bool AudioOutputALSA::OpenDevice() 
    42145    snd_pcm_format_t format;
    43146    unsigned int buffer_time, period_time;
    44147    int err;
     148    QString real_device;
    45149
    46150    if (pcm_handle != NULL)
    47151        CloseDevice();
    48152
    49153    pcm_handle = NULL;
    50154    numbadioctls = 0;
    51 
    52     QString real_device = (audio_passthru) ?
    53         audio_passthru_device : audio_main_device;
     155   
     156    if (audio_passthru || audio_enc)
     157    {
     158        real_device = audio_passthru_device;
     159        SetIECStatus(false);
     160    }
     161    else
     162    {
     163        real_device = audio_main_device;
     164        SetIECStatus(true);
     165    }
    54166
    55167    VERBOSE(VB_GENERAL, QString("Opening ALSA audio device '%1'.")
    56168            .arg(real_device));
    bool AudioOutputALSA::OpenDevice() 
    63175        Error(QString("snd_pcm_open(%1): %2")
    64176              .arg(real_device).arg(snd_strerror(err)));
    65177
    66         if (pcm_handle)
    67             CloseDevice();
     178        CloseDevice();
    68179        return false;
    69180    }
    70181
  • mythtv/libs/libmyth/audiooutputalsa.h

    diff --git a/mythtv/libs/libmyth/audiooutputalsa.h b/mythtv/libs/libmyth/audiooutputalsa.h
    index 79c923b..3f3440a 100644
    a b class AudioOutputALSA : public AudioOutputBase 
    1717{
    1818  public:
    1919    AudioOutputALSA(QString laudio_main_device, QString laudio_passthru_device,
    20                     int laudio_bits,
    21                     int laudio_channels, int laudio_samplerate,
    22                     AudioOutputSource source,
    23                     bool set_initial_vol, bool laudio_passthru);
     20                    int laudio_bits, int laudio_channels,
     21                    int laudio_codec, int laudio_samplerate,
     22                    AudioOutputSource source, bool set_initial_vol,
     23                    bool laudio_passthru);
    2424    virtual ~AudioOutputALSA();
    2525
    2626    // Volume control
    2727    virtual int GetVolumeChannel(int channel); // Returns 0-100
    2828    virtual void SetVolumeChannel(int channel, int volume); // range 0-100 for vol
    29 
    3029   
    3130  protected:
    3231    // You need to implement the following functions
    class AudioOutputALSA : public AudioOutputBase 
    3534    virtual void WriteAudio(unsigned char *aubuf, int size);
    3635    virtual inline int getSpaceOnSoundcard(void);
    3736    virtual inline int getBufferedOnSoundcard(void);
     37    vector<int> GetSupportedRates(void);
    3838
    3939  private:
     40    void SetIECStatus(bool audio);
    4041    inline int SetParameters(snd_pcm_t *handle,
    4142                             snd_pcm_format_t format, unsigned int channels,
    4243                             unsigned int rate, unsigned int buffer_time,
  • mythtv/libs/libmyth/audiooutputarts.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputarts.cpp b/mythtv/libs/libmyth/audiooutputarts.cpp
    index a257c6b..d7626f2 100644
    a b using namespace std; 
    1010AudioOutputARTS::AudioOutputARTS(
    1111    QString laudio_main_device,     QString laudio_passthru_device,
    1212    int     laudio_bits,            int     laudio_channels,
    13     int     laudio_samplerate,      AudioOutputSource lsource,
    14     bool    lset_initial_vol,       bool    laudio_passthru) :
     13    int     laudio_codec,           int     laudio_samplerate,
     14    AudioOutputSource lsource,      bool    lset_initial_vol,
     15    bool    laudio_passthru) :
    1516    AudioOutputBase(laudio_main_device, laudio_passthru_device,
    1617                    laudio_bits,        laudio_channels,
    1718                    laudio_samplerate,  lsource,
    AudioOutputARTS::AudioOutputARTS( 
    1920    pcm_handle(NULL), buff_size(-1), can_hw_pause(false)
    2021{
    2122    // Set everything up
    22     Reconfigure(laudio_bits,       laudio_channels,
     23    Reconfigure(laudio_bits,       laudio_channels,     laudio_codec,
    2324                laudio_samplerate, laudio_passthru);
    2425}
    2526
  • mythtv/libs/libmyth/audiooutputarts.h

    diff --git a/mythtv/libs/libmyth/audiooutputarts.h b/mythtv/libs/libmyth/audiooutputarts.h
    index ee65be3..d731c31 100644
    a b class AudioOutputARTS : public AudioOutputBase 
    1515{
    1616  public:
    1717     AudioOutputARTS(QString main_device, QString passthru_device,
    18                      int audio_bits,
    19                      int audio_channels, int audio_samplerate,
     18                     int audio_bits, int audio_channels,
     19                     int audio_codec, int audio_samplerate,
    2020                     AudioOutputSource source,
    2121                     bool set_initial_vol, bool laudio_passthru);
    2222     virtual ~AudioOutputARTS();
    class AudioOutputARTS : public AudioOutputBase 
    3333    virtual void WriteAudio(unsigned char *aubuf, int size);
    3434    virtual inline int getSpaceOnSoundcard(void);
    3535    virtual inline int getBufferedOnSoundcard(void);
    36 
    37      
     36    virtual vector<int> GetSupportedRates(void)
     37        { vector<int> rates; return rates; }
    3838
    3939  private:
    4040    arts_stream_t pcm_handle;
  • mythtv/libs/libmyth/audiooutputbase.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputbase.cpp b/mythtv/libs/libmyth/audiooutputbase.cpp
    index 883136d..2cb54ea 100644
    a b AudioOutputBase::AudioOutputBase( 
    3030    bool    lset_initial_vol,      bool              /*laudio_passthru*/) :
    3131
    3232    effdsp(0),                  effdspstretched(0),
    33     audio_channels(-1),         audio_bytes_per_sample(0),
    34     audio_bits(-1),             audio_samplerate(-1),
    35     audio_buffer_unused(0),
     33    audio_channels(-1),         audio_codec(CODEC_ID_NONE),
     34    audio_bytes_per_sample(0),  audio_bits(-1),
     35    audio_samplerate(-1),       audio_buffer_unused(0),
    3636    fragment_size(0),           soundcard_buffer_size(0),
    3737
    3838    audio_main_device(QDeepCopy<QString>(laudio_main_device)),
    3939    audio_passthru_device(QDeepCopy<QString>(laudio_passthru_device)),
    40     audio_passthru(false),      audio_stretchfactor(1.0f),
     40    audio_passthru(false),      audio_enc(false),
     41    audio_reenc(false),         audio_stretchfactor(1.0f),
    4142
    42     audio_codec(NULL),
    4343    source(lsource),            killaudio(false),
    4444
    4545    pauseaudio(false),          audio_actually_paused(false),
    AudioOutputBase::AudioOutputBase( 
    5454    pSoundStretch(NULL),       
    5555    encoder(NULL),
    5656    upmixer(NULL),
     57
    5758    source_audio_channels(-1),
     59    source_audio_samplerate(0),
    5860    source_audio_bytes_per_sample(0),
    5961    needs_upmix(false),
    6062    surround_mode(FreeSurround::SurroundModePassive),
     63    old_audio_stretchfactor(1.0),
    6164
    6265    blocking(false),
    6366
    AudioOutputBase::AudioOutputBase( 
    8487    memset(&audiotime_updated, 0, sizeof(audiotime_updated));
    8588    memset(audiobuffer,        0, sizeof(char)  * AUDBUFSIZE);
    8689    configured_audio_channels = gContext->GetNumSetting("MaxChannels", 2);
     90    orig_config_channels = configured_audio_channels;
     91    allow_ac3_passthru = gContext->GetNumSetting("AC3PassThru", false);
     92    src_quality = gContext->GetNumSetting("SRCQuality", 2);
    8793
    8894    // You need to call Reconfigure from your concrete class.
    8995    // Reconfigure(laudio_bits,       laudio_channels,
    void AudioOutputBase::SetStretchFactorLocked(float laudio_stretchfactor) 
    124130            VERBOSE(VB_GENERAL, LOC + QString("Using time stretch %1")
    125131                                        .arg(audio_stretchfactor));
    126132            pSoundStretch = new soundtouch::SoundTouch();
    127             if (audio_codec)
    128             {
    129                 if (!encoder)
    130                 {
    131                     VERBOSE(VB_AUDIO, LOC +
    132                             QString("Creating Encoder for codec %1 origfs %2")
    133                             .arg(audio_codec->codec_id)
    134                             .arg(audio_codec->frame_size));
    135 
    136                     encoder = new AudioOutputDigitalEncoder();
    137                     if (!encoder->Init(audio_codec->codec_id,
    138                                 audio_codec->bit_rate,
    139                                 audio_codec->sample_rate,
    140                                 audio_codec->channels
    141                                 ))
    142                     {
    143                         // eeks
    144                         delete encoder;
    145                         encoder = NULL;
    146                         VERBOSE(VB_AUDIO, LOC +
    147                                 QString("Failed to Create Encoder"));
    148                     }
    149                 }
    150             }
    151             if (audio_codec && encoder)
    152             {
    153                 pSoundStretch->setSampleRate(audio_codec->sample_rate);
    154                 pSoundStretch->setChannels(audio_codec->channels);
    155             }
    156             else
    157             {
    158                 pSoundStretch->setSampleRate(audio_samplerate);
    159                 pSoundStretch->setChannels(audio_channels);
    160             }
     133            pSoundStretch->setSampleRate(audio_samplerate);
     134            pSoundStretch->setChannels(upmixer ?
     135                configured_audio_channels : source_audio_channels);
    161136
    162137            pSoundStretch->setTempo(audio_stretchfactor);
    163138            pSoundStretch->setSetting(SETTING_SEQUENCE_MS, 35);
    void AudioOutputBase::SetStretchFactorLocked(float laudio_stretchfactor) 
    165140            // dont need these with only tempo change
    166141            //pSoundStretch->setPitch(1.0);
    167142            //pSoundStretch->setRate(1.0);
    168 
    169143            //pSoundStretch->setSetting(SETTING_USE_QUICKSEEK, true);
    170144            //pSoundStretch->setSetting(SETTING_USE_AA_FILTER, false);
    171145        }
    float AudioOutputBase::GetStretchFactor(void) 
    184158    return audio_stretchfactor;
    185159}
    186160
     161bool AudioOutputBase::ToggleUpmix(void)
     162{
     163    if (orig_config_channels == 2 || source_audio_channels > 2 ||
     164        audio_passthru)
     165        return false;
     166
     167    if (configured_audio_channels == 6)
     168        configured_audio_channels = 2;
     169    else
     170        configured_audio_channels = 6;
     171   
     172    Reconfigure(audio_bits, source_audio_channels, audio_codec,
     173        source_audio_samplerate, audio_passthru);
     174    return (configured_audio_channels == 6);
     175}
     176
    187177void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels,
    188                                   int laudio_samplerate, bool laudio_passthru,
    189                                   void *laudio_codec)
     178                                  int laudio_codec, int laudio_samplerate,
     179                                  bool laudio_passthru)
    190180{
    191     int codec_id = CODEC_ID_NONE;
    192     int lcodec_id = CODEC_ID_NONE;
    193     int lcchannels = 0;
    194     int cchannels = 0;
    195181    int lsource_audio_channels = laudio_channels;
    196182    bool lneeds_upmix = false;
    197 
    198     if (laudio_codec)
     183    bool laudio_reenc = false;
     184   
     185    // Are we reencoding a timestretched / softvol'd bitstream?
     186    if ((laudio_codec == CODEC_ID_AC3 || laudio_codec == CODEC_ID_DTS) &&
     187        !laudio_passthru && allow_ac3_passthru)
    199188    {
    200         lcodec_id = ((AVCodecContext*)laudio_codec)->codec_id;
    201         laudio_bits = 16;
    202         laudio_channels = 2;
    203         lsource_audio_channels = laudio_channels;
    204         laudio_samplerate = 48000;
    205         lcchannels = ((AVCodecContext*)laudio_codec)->channels;
     189        VERBOSE(VB_AUDIO,LOC + "Reencoding decoded AC3/DTS to AC3");
     190        laudio_reenc = true;
    206191    }
    207 
    208     if (audio_codec)
    209     {
    210         codec_id = audio_codec->codec_id;
    211         cchannels = ((AVCodecContext*)audio_codec)->channels;
    212     }
    213 
    214     if ((configured_audio_channels == 6) &&
    215         !(laudio_codec || audio_codec))
     192    // Enough channels? Upmix if not
     193    if (laudio_channels < configured_audio_channels && !laudio_passthru)
    216194    {
    217195        laudio_channels = configured_audio_channels;
    218196        lneeds_upmix = true;
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    225203        laudio_samplerate == audio_samplerate && !need_resampler &&
    226204        laudio_passthru == audio_passthru &&
    227205        lneeds_upmix == needs_upmix &&
    228         lcodec_id == codec_id && lcchannels == cchannels);
     206        laudio_reenc == audio_reenc);
    229207    bool upmix_deps =
    230208        (lsource_audio_channels == source_audio_channels);
    231209    if (general_deps && upmix_deps)
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    252230    waud = raud = 0;
    253231    audio_actually_paused = false;
    254232   
    255     bool redo_stretch = (pSoundStretch && audio_channels != laudio_channels);
    256233    audio_channels = laudio_channels;
     234    audio_codec = laudio_codec;
    257235    source_audio_channels = lsource_audio_channels;
    258236    audio_bits = laudio_bits;
    259     audio_samplerate = laudio_samplerate;
    260     audio_codec = (AVCodecContext*)laudio_codec;
     237    source_audio_samplerate = audio_samplerate = laudio_samplerate;
     238    audio_reenc = laudio_reenc;
    261239    audio_passthru = laudio_passthru;
    262240    needs_upmix = lneeds_upmix;
    263241
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    268246        Error("AudioOutput only supports 8 or 16bit audio.");
    269247        return;
    270248    }
    271     audio_bytes_per_sample = audio_channels * audio_bits / 8;
    272     source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8;
    273    
     249
     250    VERBOSE(VB_AUDIO, LOC + QString("Original audio format was %1")
     251                            .arg(codec_id_string((CodecID)audio_codec)));
     252
    274253    need_resampler = false;
    275254    killaudio = false;
    276255    pauseaudio = false;
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    278257    internal_vol = gContext->GetNumSetting("MythControlsVolume", 0);
    279258   
    280259    numlowbuffer = 0;
     260   
     261    // Find out what sample rates we can output (if output layer supports it)
     262    vector<int> rates = GetSupportedRates();
     263    vector<int>::iterator it;
     264    bool resample = true;
     265
     266    for (it = rates.begin(); it < rates.end(); it++)
     267    {
     268        VERBOSE(VB_AUDIO, LOC + QString("Sample rate %1 is supported")
     269                                .arg(*it));
     270        if (*it == audio_samplerate)
     271            resample = false;
     272    }
     273
     274    // Assume 48k if we can't get supported rates
     275    if (rates.empty())
     276        rates.push_back(48000);
     277
     278    if (resample)
     279    {
     280        int error;
     281        audio_samplerate = *(rates.end());
     282        VERBOSE(VB_GENERAL, LOC + QString("Using resampler. From: %1 to %2")
     283            .arg(laudio_samplerate).arg(audio_samplerate));
     284        src_ctx = src_new(3-src_quality, source_audio_channels, &error);
     285        if (error)
     286        {
     287            Error(QString("Error creating resampler, the error was: %1")
     288                  .arg(src_strerror(error)) );
     289            pthread_mutex_unlock(&avsync_lock);
     290            pthread_mutex_unlock(&audio_buflock);
     291            src_ctx = NULL;
     292            return;
     293        }
     294        src_data.src_ratio = (double) audio_samplerate / laudio_samplerate;
     295        src_data.data_in = src_in;
     296        src_data.data_out = src_out;
     297        src_data.output_frames = 16384*6;
     298        need_resampler = true;
     299    }
     300   
     301    // Encode to AC-3 if not passing thru, there's more than 2 channels
     302    // and we're allowed to passthru AC-3
     303    if (
     304        !audio_passthru && allow_ac3_passthru &&
     305        (audio_channels > 2 || audio_reenc) 
     306       )
     307    {
     308        VERBOSE(VB_AUDIO, LOC + "Creating AC-3 Encoder");
     309        encoder = new AudioOutputDigitalEncoder();
     310        if (
     311            !encoder->Init(
     312                CODEC_ID_AC3, 448000, audio_samplerate, audio_channels
     313            )
     314           )
     315        {
     316            VERBOSE(VB_AUDIO, LOC + "Can't create AC-3 encoder");
     317            delete encoder;
     318            encoder = NULL;
     319        }
     320       
     321        audio_enc = true;
     322    }       
     323   
     324    if(audio_passthru || audio_enc)
     325        // bitstream output - soundcard expects a 2ch 48k stream
     326        audio_channels = 2;
     327   
     328    audio_bytes_per_sample = audio_channels * audio_bits / 8;
     329    source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8;
    281330
    282331    VERBOSE(VB_GENERAL, QString("Opening audio device '%1'. ch %2(%3) sr %4")
    283332            .arg(audio_main_device).arg(audio_channels)
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    314363    current_seconds = -1;
    315364    source_bitrate = -1;
    316365
    317     // NOTE: this won't do anything as above samplerate vars are set equal
    318     // Check if we need the resampler
    319     if (audio_samplerate != laudio_samplerate)
    320     {
    321         int error;
    322         VERBOSE(VB_GENERAL, LOC + QString("Using resampler. From: %1 to %2")
    323                                .arg(laudio_samplerate).arg(audio_samplerate));
    324         src_ctx = src_new (SRC_SINC_BEST_QUALITY, audio_channels, &error);
    325         if (error)
    326         {
    327             Error(QString("Error creating resampler, the error was: %1")
    328                   .arg(src_strerror(error)) );
    329             pthread_mutex_unlock(&avsync_lock);
    330             pthread_mutex_unlock(&audio_buflock);
    331             return;
    332         }
    333         src_data.src_ratio = (double) audio_samplerate / laudio_samplerate;
    334         src_data.data_in = src_in;
    335         src_data.data_out = src_out;
    336         src_data.output_frames = 16384*6;
    337         need_resampler = true;
    338     }
    339 
    340366    if (needs_upmix)
    341367    {
    342         VERBOSE(VB_AUDIO, LOC + QString("create upmixer"));
    343368        if (configured_audio_channels == 6)
    344         {
    345369            surround_mode = gContext->GetNumSetting("AudioUpmixType", 2);
    346         }
    347370
    348371        upmixer = new FreeSurround(
    349372            audio_samplerate,
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    351374            (FreeSurround::SurroundMode)surround_mode);
    352375
    353376        VERBOSE(VB_AUDIO, LOC +
    354                 QString("create upmixer done with surround mode %1")
     377                QString("Create upmixer done with surround mode %1")
    355378                .arg(surround_mode));
    356379    }
    357380
    358381    VERBOSE(VB_AUDIO, LOC + QString("Audio Stretch Factor: %1")
    359382            .arg(audio_stretchfactor));
    360     VERBOSE(VB_AUDIO, QString("Audio Codec Used: %1")
    361             .arg((audio_codec) ?
    362                  codec_id_string(audio_codec->codec_id) : "not set"));
    363383
    364     if (redo_stretch)
    365     {
    366         float laudio_stretchfactor = audio_stretchfactor;
    367         delete pSoundStretch;
    368         pSoundStretch = NULL;
    369         audio_stretchfactor = 0.0f;
    370         SetStretchFactorLocked(laudio_stretchfactor);
    371     }
    372     else
    373     {
    374         SetStretchFactorLocked(audio_stretchfactor);
    375         if (pSoundStretch)
    376         {
    377             // if its passthru then we need to reencode
    378             if (audio_codec)
    379             {
    380                 if (!encoder)
    381                 {
    382                     VERBOSE(VB_AUDIO, LOC +
    383                             QString("Creating Encoder for codec %1")
    384                             .arg(audio_codec->codec_id));
    385 
    386                     encoder = new AudioOutputDigitalEncoder();
    387                     if (!encoder->Init(audio_codec->codec_id,
    388                                 audio_codec->bit_rate,
    389                                 audio_codec->sample_rate,
    390                                 audio_codec->channels
    391                                 ))
    392                     {
    393                         // eeks
    394                         delete encoder;
    395                         encoder = NULL;
    396                         VERBOSE(VB_AUDIO, LOC + "Failed to Create Encoder");
    397                     }
    398                 }
    399             }
    400             if (audio_codec && encoder)
    401             {
    402                 pSoundStretch->setSampleRate(audio_codec->sample_rate);
    403                 pSoundStretch->setChannels(audio_codec->channels);
    404             }
    405             else
    406             {
    407                 pSoundStretch->setSampleRate(audio_samplerate);
    408                 pSoundStretch->setChannels(audio_channels);
    409             }
    410         }
    411     }
     384    SetStretchFactorLocked(old_audio_stretchfactor);
    412385
    413386    // Setup visualisations, zero the visualisations buffers
    414387    prepareVisuals();
    void AudioOutputBase::StopOutputThread(void) 
    451424void AudioOutputBase::KillAudio()
    452425{
    453426    killAudioLock.lock();
    454 
    455427    VERBOSE(VB_AUDIO, LOC + "Killing AudioOutputDSP");
    456428    killaudio = true;
    457429    StopOutputThread();
     430   
     431    pthread_mutex_lock(&audio_buflock);
    458432
    459433    // Close resampler?
    460434    if (src_ctx)
     435    {
    461436        src_delete(src_ctx);
     437        src_ctx = NULL;
     438    }
     439               
    462440    need_resampler = false;
    463441
    464442    // close sound stretcher
    void AudioOutputBase::KillAudio() 
    466444    {
    467445        delete pSoundStretch;
    468446        pSoundStretch = NULL;
     447        old_audio_stretchfactor = audio_stretchfactor;
     448        audio_stretchfactor = 1.0;
    469449    }
    470450
    471451    if (encoder)
    void AudioOutputBase::KillAudio() 
    480460        upmixer = NULL;
    481461    }
    482462    needs_upmix = false;
     463    audio_enc = false;
    483464
    484465    CloseDevice();
    485466
     467    pthread_mutex_unlock(&audio_buflock);
    486468    killAudioLock.unlock();
    487469}
    488470
    int AudioOutputBase::GetAudiotime(void) 
    591573    ret += (now.tv_usec - audiotime_updated.tv_usec) / 1000;
    592574    ret = (long long)(ret * audio_stretchfactor);
    593575
    594 #if 1
    595576    VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    596577            QString("GetAudiotime now=%1.%2, set=%3.%4, ret=%5, audt=%6 sf=%7")
    597578            .arg(now.tv_sec).arg(now.tv_usec)
    int AudioOutputBase::GetAudiotime(void) 
    600581            .arg(audiotime)
    601582            .arg(audio_stretchfactor)
    602583           );
    603 #endif
    604584
    605585    ret += audiotime;
    606586
    void AudioOutputBase::SetAudiotime(void) 
    638618 
    639619    soundcard_buffer = getBufferedOnSoundcard(); // bytes
    640620    totalbuffer = audiolen(false) + soundcard_buffer;
    641  
     621
    642622    // include algorithmic latencies
    643623    if (pSoundStretch)
    644     {
    645         // add the effect of any unused but processed samples,
    646         // AC3 reencode does this
    647         totalbuffer += (int)(pSoundStretch->numSamples() *
    648                              audio_bytes_per_sample);
    649         // add the effect of unprocessed samples in time stretch algo
    650624        totalbuffer += (int)((pSoundStretch->numUnprocessedSamples() *
    651625                              audio_bytes_per_sample) / audio_stretchfactor);
    652     }
    653626
    654627    if (upmixer && needs_upmix)
    655     {
    656628        totalbuffer += upmixer->sampleLatency() * audio_bytes_per_sample;
    657     }
     629
     630    if (encoder)
     631        totalbuffer += encoder->Buffered();
    658632
    659633    audiotime = audbuf_timecode - (int)(totalbuffer * 100000.0 /
    660634                                   (audio_bytes_per_sample * effdspstretched));
    661635 
    662636    gettimeofday(&audiotime_updated, NULL);
    663 #if 1
     637   
    664638    VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    665639            QString("SetAudiotime set=%1.%2, audt=%3 atc=%4 "
    666640                    "tb=%5 sb=%6 eds=%7 abps=%8 sf=%9")
    void AudioOutputBase::SetAudiotime(void) 
    672646            .arg(effdspstretched)
    673647            .arg(audio_bytes_per_sample)
    674648            .arg(audio_stretchfactor));
    675 #endif
    676649
    677650    pthread_mutex_unlock(&avsync_lock);
    678651    pthread_mutex_unlock(&audio_buflock);
    bool AudioOutputBase::AddSamples(char *buffers[], int samples, 
    686659    int abps = (encoder) ?
    687660        encoder->audio_bytes_per_sample : audio_bytes_per_sample;
    688661    int len = samples * abps;
    689 
     662 
    690663    // Check we have enough space to write the data
    691664    if (need_resampler && src_ctx)
    692665        len = (int)ceilf(float(len) * src_data.src_ratio);
    bool AudioOutputBase::AddSamples(char *buffers[], int samples, 
    708681
    709682        return false; // would overflow
    710683    }
     684   
     685    pthread_mutex_lock(&audio_buflock);
    711686
    712687    // resample input if necessary
    713688    if (need_resampler && src_ctx)
    bool AudioOutputBase::AddSamples(char *buffers[], int samples, 
    741716        // Call our function to do the work
    742717        _AddSamples(buffers, false, samples, timecode);
    743718    }
     719   
     720    pthread_mutex_unlock(&audio_buflock);
    744721
    745722    return true;
    746723}
    bool AudioOutputBase::AddSamples(char *buffer, int samples, long long timecode) 
    753730    int abps = (encoder) ?
    754731        encoder->audio_bytes_per_sample : audio_bytes_per_sample;
    755732    int len = samples * abps;
     733 
     734    // Give original samples to mythmusic visualisation
     735    dispatchVisual((unsigned char *)buffer, len, timecode,
     736                   source_audio_channels, audio_bits);
    756737
    757738    // Check we have enough space to write the data
    758739    if (need_resampler && src_ctx)
    bool AudioOutputBase::AddSamples(char *buffer, int samples, long long timecode) 
    776757                .arg(timecode));
    777758        return false; // would overflow
    778759    }
     760   
     761    pthread_mutex_lock(&audio_buflock);
    779762
    780763    // resample input if necessary
    781764    if (need_resampler && src_ctx)
    bool AudioOutputBase::AddSamples(char *buffer, int samples, long long timecode) 
    804787        // Call our function to do the work
    805788        _AddSamples(buffer, true, samples, timecode);
    806789    }
     790   
     791    pthread_mutex_unlock(&audio_buflock);
    807792
    808793    return true;
    809794}
    int AudioOutputBase::WaitForFreeSpace(int samples) 
    836821            if (src_ctx)
    837822            {
    838823                int error = src_reset(src_ctx);
    839                 if (error)
     824                if (error)
     825                {
    840826                    VERBOSE(VB_IMPORTANT, LOC_ERR + QString(
    841827                            "Error occured while resetting resampler: %1")
    842828                            .arg(src_strerror(error)));
     829                    src_ctx = NULL;
     830                }
    843831            }
    844832        }
    845833    }
    int AudioOutputBase::WaitForFreeSpace(int samples) 
    849837void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples,
    850838                                  long long timecode)
    851839{
    852     pthread_mutex_lock(&audio_buflock);
    853 
    854840    int len; // = samples * audio_bytes_per_sample;
    855841    int audio_bytes = audio_bits / 8;
    856842    int org_waud = waud;
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    867853            .arg(samples * abps)
    868854            .arg(AUDBUFSIZE-afree).arg(afree).arg(timecode)
    869855            .arg(needs_upmix));
     856
     857    len = WaitForFreeSpace(samples);
    870858   
    871859    if (upmixer && needs_upmix)
    872860    {
    873861        int out_samples = 0;
     862        org_waud = waud;
    874863        int step = (interleaved)?source_audio_channels:1;
    875         len = WaitForFreeSpace(samples);    // test
     864       
    876865        for (int itemp = 0; itemp < samples; )
    877866        {
    878             // just in case it does a processing cycle, release the lock
    879             // to allow the output loop to do output
    880             pthread_mutex_unlock(&audio_buflock);
    881867            if (audio_bytes == 2)
    882868            {
    883869                itemp += upmixer->putSamples(
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    894880                    source_audio_channels,
    895881                    (interleaved) ? 0 : samples);
    896882            }
    897             pthread_mutex_lock(&audio_buflock);
    898883
    899884            int copy_samples = upmixer->numSamples();
    900885            if (copy_samples)
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    913898                        (short*)(audiobuffer), (copy_samples - bdiff_samples));
    914899                }
    915900                else
    916                 {
    917901                    upmixer->receiveSamples(
    918902                        (short*)(audiobuffer + org_waud), copy_samples);
    919                 }
     903               
    920904                org_waud = (org_waud + copy_len) % AUDBUFSIZE;
    921905            }
    922906        }
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    928912    }
    929913    else
    930914    {
    931         len = WaitForFreeSpace(samples);
    932 
    933915        if (interleaved)
    934916        {
    935917            char *mybuf = (char*)buffer;
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    964946            }
    965947        }
    966948    }
    967 
    968     if (samples > 0)
     949   
     950    if (samples <= 0)
     951        return;
     952   
     953    if (pSoundStretch)
    969954    {
    970         if (pSoundStretch)
     955        // does not change the timecode, only the number of samples
     956        // back to orig pos
     957        org_waud = waud;
     958        int bdiff = AUDBUFSIZE - org_waud;
     959        int nSamplesToEnd = bdiff/abps;
     960        if (bdiff < len)
    971961        {
     962            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
     963                                      (audiobuffer +
     964                                       org_waud), nSamplesToEnd);
     965            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer,
     966                                      (len - bdiff) / abps);
     967        }
     968        else
     969            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
     970                                      (audiobuffer + org_waud),
     971                                      len / abps);
    972972
    973             // does not change the timecode, only the number of samples
    974             // back to orig pos
    975             org_waud = waud;
    976             int bdiff = AUDBUFSIZE - org_waud;
    977             int nSamplesToEnd = bdiff/abps;
    978             if (bdiff < len)
    979             {
    980                 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
    981                                           (audiobuffer +
    982                                            org_waud), nSamplesToEnd);
    983                 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer,
    984                                           (len - bdiff) / abps);
    985             }
    986             else
    987             {
    988                 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
    989                                           (audiobuffer + org_waud),
    990                                           len / abps);
     973        int nSamples = pSoundStretch->numSamples();
     974        len = WaitForFreeSpace(nSamples);
     975       
     976        while ((nSamples = pSoundStretch->numSamples()))
     977        {
     978            if (nSamples > nSamplesToEnd)
     979                nSamples = nSamplesToEnd;
     980           
     981            nSamples = pSoundStretch->receiveSamples(
     982                (soundtouch::SAMPLETYPE*)
     983                (audiobuffer + org_waud), nSamples
     984            );
     985           
     986            if (nSamples == nSamplesToEnd) {
     987                org_waud = 0;
     988                nSamplesToEnd = AUDBUFSIZE/abps;
    991989            }
    992 
    993             if (encoder)
    994             {
    995                 // pull out a packet's worth and reencode it until we
    996                 // don't have enough for any more packets
    997                 soundtouch::SAMPLETYPE *temp_buff =
    998                     (soundtouch::SAMPLETYPE*)encoder->GetFrameBuffer();
    999                 size_t frameSize = encoder->FrameSize()/abps;
    1000 
    1001                 VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    1002                         QString("_AddSamples Enc sfs=%1 bfs=%2 sss=%3")
    1003                         .arg(frameSize)
    1004                         .arg(encoder->FrameSize())
    1005                         .arg(pSoundStretch->numSamples()));
    1006 
    1007                 // process the same number of samples as it creates
    1008                 // a full encoded buffer just like before
    1009                 while (pSoundStretch->numSamples() >= frameSize)
    1010                 {
    1011                     int got = pSoundStretch->receiveSamples(
    1012                         temp_buff, frameSize);
    1013                     int amount = encoder->Encode(temp_buff);
    1014 
    1015                     VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    1016                             QString("_AddSamples Enc bytes=%1 got=%2 left=%3")
    1017                             .arg(amount)
    1018                             .arg(got)
    1019                             .arg(pSoundStretch->numSamples()));
    1020 
    1021                     if (!amount)
    1022                         continue;
    1023 
    1024                     //len = WaitForFreeSpace(amount);
    1025                     char *ob = encoder->GetOutBuff();
    1026                     if (amount >= bdiff)
    1027                     {
    1028                         memcpy(audiobuffer + org_waud, ob, bdiff);
    1029                         ob += bdiff;
    1030                         amount -= bdiff;
    1031                         org_waud = 0;
    1032                     }
    1033                     if (amount > 0)
    1034                         memcpy(audiobuffer + org_waud, ob, amount);
    1035 
    1036                     bdiff = AUDBUFSIZE - amount;
    1037                     org_waud += amount;
    1038                 }
    1039             }
    1040             else
    1041             {
    1042                 int newLen = 0;
    1043                 int nSamples;
    1044                 len = WaitForFreeSpace(pSoundStretch->numSamples() *
    1045                                        audio_bytes_per_sample);
    1046                 do
    1047                 {
    1048                     int samplesToGet = len/audio_bytes_per_sample;
    1049                     if (samplesToGet > nSamplesToEnd)
    1050                     {
    1051                         samplesToGet = nSamplesToEnd;   
    1052                     }
    1053 
    1054                     nSamples = pSoundStretch->receiveSamples(
    1055                         (soundtouch::SAMPLETYPE*)
    1056                         (audiobuffer + org_waud), samplesToGet);
    1057                     if (nSamples == nSamplesToEnd)
    1058                     {
    1059                         org_waud = 0;
    1060                         nSamplesToEnd = AUDBUFSIZE/audio_bytes_per_sample;
    1061                     }
    1062                     else
    1063                     {
    1064                         org_waud += nSamples * audio_bytes_per_sample;
    1065                         nSamplesToEnd -= nSamples;
    1066                     }
    1067 
    1068                     newLen += nSamples * audio_bytes_per_sample;
    1069                     len -= nSamples * audio_bytes_per_sample;
    1070                 } while (nSamples > 0);
     990            else {
     991                org_waud += nSamples * abps;
     992                nSamplesToEnd -= nSamples;
    1071993            }
     994           
    1072995        }
     996       
     997    }
    1073998
    1074         waud = org_waud;
    1075         lastaudiolen = audiolen(false);
     999    // Encode to AC-3?
     1000    if (encoder)
     1001    {
     1002       
     1003        org_waud = waud;
     1004        int bdiff = AUDBUFSIZE - org_waud;
     1005        int to_get = 0;
    10761006
    1077         if (timecode < 0)
     1007        if (bdiff < len)
    10781008        {
    1079             // mythmusic doesn't give timestamps..
    1080             timecode = (int)((samples_buffered * 100000.0) / effdsp);
     1009            encoder->Encode(audiobuffer + org_waud, bdiff);
     1010            to_get = encoder->Encode(audiobuffer, len - bdiff);
    10811011        }
     1012        else
     1013            to_get = encoder->Encode(audiobuffer + org_waud, len);
    10821014       
    1083         samples_buffered += samples;
    1084        
    1085         /* we want the time at the end -- but the file format stores
    1086            time at the start of the chunk. */
    1087         // even with timestretch, timecode is still calculated from original
    1088         // sample count
    1089         audbuf_timecode = timecode + (int)((samples * 100000.0) / effdsp);
    1090 
    1091         if (interleaved)
     1015        if (to_get > 0)
    10921016        {
    1093             dispatchVisual((unsigned char *)buffer, len, timecode,
    1094                            source_audio_channels, audio_bits);
     1017           
     1018            if (to_get >= bdiff)
     1019            {
     1020                encoder->GetFrames(audiobuffer + org_waud, bdiff);
     1021                to_get -= bdiff;
     1022                org_waud = 0;
     1023            }
     1024            if (to_get > 0)
     1025                encoder->GetFrames(audiobuffer + org_waud, to_get);
     1026
     1027            org_waud += to_get;
     1028
    10951029        }
     1030
    10961031    }
    10971032
    1098     pthread_mutex_unlock(&audio_buflock);
     1033    waud = org_waud;
     1034    lastaudiolen = audiolen(false);
     1035
     1036    if (timecode < 0)
     1037        // mythmusic doesn't give timestamps..
     1038        timecode = (int)((samples_buffered * 100000.0) / effdsp);
     1039   
     1040    samples_buffered += samples;
     1041   
     1042    /* we want the time at the end -- but the file format stores
     1043       time at the start of the chunk. */
     1044    // even with timestretch, timecode is still calculated from original
     1045    // sample count
     1046    audbuf_timecode = timecode + (int)((samples * 100000.0) / effdsp);
     1047
    10991048}
    11001049
    11011050void AudioOutputBase::Status()
  • mythtv/libs/libmyth/audiooutputbase.h

    diff --git a/mythtv/libs/libmyth/audiooutputbase.h b/mythtv/libs/libmyth/audiooutputbase.h
    index d60c687..bdf808c 100644
    a b class AudioOutputBase : public AudioOutput 
    4747    // reconfigure sound out for new params
    4848    virtual void Reconfigure(int   audio_bits,
    4949                             int   audio_channels,
     50                             int   audio_codec,
    5051                             int   audio_samplerate,
    51                              bool  audio_passthru,
    52                              void *audio_codec = NULL);
     52                             bool  audio_passthru);
    5353   
    5454    // do AddSamples calls block?
    5555    virtual void SetBlocking(bool blocking);
    class AudioOutputBase : public AudioOutput 
    5959
    6060    virtual void SetStretchFactor(float factor);
    6161    virtual float GetStretchFactor(void);
     62    virtual bool ToggleUpmix(void);
    6263
    6364    virtual void Reset(void);
    6465
    class AudioOutputBase : public AudioOutput 
    9798    virtual int getBufferedOnSoundcard(void) = 0;
    9899    virtual int GetVolumeChannel(int channel) = 0; // Returns 0-100
    99100    virtual void SetVolumeChannel(int channel, int volume) = 0; // range 0-100 for vol
     101    virtual vector<int> GetSupportedRates(void) = 0;
    100102
    101103    // The following functions may be overridden, but don't need to be
    102104    virtual bool StartOutputThread(void);
    class AudioOutputBase : public AudioOutput 
    129131
    130132    // Basic details about the audio stream
    131133    int audio_channels;
     134    int audio_codec;
    132135    int audio_bytes_per_sample;
    133136    int audio_bits;
    134137    int audio_samplerate;
    class AudioOutputBase : public AudioOutput 
    139142    QString audio_passthru_device;
    140143
    141144    bool audio_passthru;
     145    bool audio_enc;
     146    bool audio_reenc;
    142147
    143148    float audio_stretchfactor;
    144     AVCodecContext *audio_codec;
    145149    AudioOutputSource source;
    146150
    147151    bool killaudio;
    class AudioOutputBase : public AudioOutput 
    151155    bool buffer_output_data_for_use; //  used by AudioOutputNULL
    152156   
    153157    int configured_audio_channels;
     158    int orig_config_channels;
     159    int src_quality;
    154160
    155161 private:
    156162    // resampler
    class AudioOutputBase : public AudioOutput 
    167173    FreeSurround              *upmixer;
    168174
    169175    int source_audio_channels;
     176    int source_audio_samplerate;
    170177    int source_audio_bytes_per_sample;
    171178    bool needs_upmix;
    172179    int surround_mode;
     180    bool allow_ac3_passthru;
     181    float old_audio_stretchfactor;
    173182
    174183    bool blocking; // do AddSamples calls block?
    175184
  • mythtv/libs/libmyth/audiooutputca.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputca.cpp b/mythtv/libs/libmyth/audiooutputca.cpp
    index c90e967..0e10fc0 100644
    a b static OSStatus RenderCallbackSPDIF(AudioDeviceID inDevice, 
    114114AudioOutputCA::AudioOutputCA(QString laudio_main_device,
    115115                             QString laudio_passthru_device,
    116116                             int laudio_bits, int laudio_channels,
    117                              int laudio_samplerate,
     117                             int laudio_codec, int laudio_samplerate,
    118118                             AudioOutputSource lsource,
    119119                             bool lset_initial_vol, bool laudio_passthru)
    120120    : AudioOutputBase(laudio_main_device, laudio_passthru_device,
    AudioOutputCA::AudioOutputCA(QString laudio_main_device, 
    123123                      lset_initial_vol,   laudio_passthru),
    124124      d(new CoreAudioData(this))
    125125{
    126     Reconfigure(laudio_bits, laudio_channels,
     126    Reconfigure(laudio_bits, laudio_channels, laudio_codec
    127127                laudio_samplerate, laudio_passthru);
    128128}
    129129
  • mythtv/libs/libmyth/audiooutputca.h

    diff --git a/mythtv/libs/libmyth/audiooutputca.h b/mythtv/libs/libmyth/audiooutputca.h
    index 2fa8920..d5c9464 100644
    a b class AudioOutputCA : public AudioOutputBase 
    2020public:
    2121    AudioOutputCA(QString laudio_main_device,
    2222                  QString laudio_passthru_device,
    23                   int laudio_bits,
    24                   int laudio_channels, int laudio_samplerate,
     23                  int laudio_bits, int laudio_channels,
     24                  int laudio_codec, int laudio_samplerate,
    2525                  AudioOutputSource lsource,
    2626                  bool lset_initial_vol, bool laudio_passthru);
    2727    virtual ~AudioOutputCA();
    protected: 
    5757   
    5858    virtual bool StartOutputThread(void) { return true; }
    5959    virtual void StopOutputThread(void) {}
     60    virtual vector<int> GetSupportedRates(void)
     61        { vector<int> rates; return rates; }
    6062
    6163private:
    6264
  • mythtv/libs/libmyth/audiooutputdigitalencoder.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputdigitalencoder.cpp b/mythtv/libs/libmyth/audiooutputdigitalencoder.cpp
    index 40c4acb..a349cc3 100644
    a b extern "C" { 
    2727
    2828AudioOutputDigitalEncoder::AudioOutputDigitalEncoder(void) :
    2929    av_context(NULL),
    30     outbuf(NULL),
    31     outbuf_size(0),
    32     frame_buffer(NULL),
     30    outbuflen(0),
     31    inbuflen(0),
    3332    one_frame_bytes(0)
    3433{
    3534}
    void AudioOutputDigitalEncoder::Dispose() 
    4746        av_free(av_context);
    4847        av_context = NULL;
    4948    }
    50 
    51     if (outbuf)
    52     {
    53         delete [] outbuf;
    54         outbuf = NULL;
    55         outbuf_size = 0;
    56     }
    57 
    58     if (frame_buffer)
    59     {
    60         delete [] frame_buffer;
    61         frame_buffer = NULL;
    62         one_frame_bytes = 0;
    63     }
    6449}
    6550
    6651//CODEC_ID_AC3
    6752bool AudioOutputDigitalEncoder::Init(
    68     CodecID codec_id, int bitrate, int samplerate, int channels)
     53    CodecID codec_id, int bitrate, int samplerate, int channels
     54    )
    6955{
    7056    AVCodec *codec;
    7157    int ret;
    bool AudioOutputDigitalEncoder::Init( 
    7561            .arg(bitrate)
    7662            .arg(samplerate)
    7763            .arg(channels));
    78 
    79     //codec = avcodec_find_encoder(codec_id);
     64   
     65    // We need to do this when called from mythmusic
     66    avcodec_init();
     67    avcodec_register_all();
    8068    // always AC3 as there is no DTS encoder at the moment 2005/1/9
    8169    codec = avcodec_find_encoder(CODEC_ID_AC3);
    8270    if (!codec)
    bool AudioOutputDigitalEncoder::Init( 
    10593    audio_bytes_per_sample = bytes_per_frame;
    10694    one_frame_bytes = bytes_per_frame * av_context->frame_size;
    10795
    108     outbuf_size = 16384;    // ok for AC3 but DTS?
    109     outbuf = new char [outbuf_size];
    11096    VERBOSE(VB_AUDIO, QString("DigitalEncoder::Init fs=%1, bpf=%2 ofb=%3")
    11197            .arg(av_context->frame_size)
    11298            .arg(bytes_per_frame)
    typedef struct { 
    256242
    257243} AESHeader;
    258244
     245
     246void reorder_6ch_ac3(void *buf, unsigned int len) {
     247    unsigned short *src = (unsigned short *)buf;
     248    unsigned short tmp;
     249    unsigned int samples = len >> 1;
     250
     251    for (uint i = 0; i < samples; i += 6) {
     252        tmp = src[i+4];
     253        src[i+4] = src[i+3];
     254        src[i+3] = src[i+2];
     255        src[i+2] = src[i+1];
     256        src[i+1] = tmp;
     257    }
     258}
     259
    259260static int encode_frame(
    260261        bool dts,
    261262        unsigned char *data,
    262         size_t &len)
     263        size_t enc_len)
    263264{
    264     size_t enc_len;
    265265    int flags, sample_rate, bit_rate;
    266266
    267267    // we don't do any length/crc validation of the AC3 frame here; presumably
    static int encode_frame( 
    273273    // anything with a bad CRC...
    274274
    275275    uint nr_samples = 0, block_len;
     276   
    276277    if (dts)
    277278    {
    278279        enc_len = dts_syncinfo(data+8, &flags, &sample_rate, &bit_rate);
    static int encode_frame( 
    293294#endif
    294295    }
    295296
    296     if (enc_len == 0 || enc_len > len)
    297     {
    298         int l = len;
    299         len = 0;
    300         return l;
    301     }
    302 
    303297    enc_len = min((uint)enc_len, block_len - 8);
    304 
     298   
    305299    //uint32_t x = *(uint32_t*)(data+8);
    306300    // in place swab
    307301    swab((const char *)data + 8, (char *)data + 8, enc_len);
    static int encode_frame( 
    348342                break;
    349343        }
    350344    }
    351     data[5] = 0x00;
     345    data[5] = 0;
    352346    data[6] = (enc_len << 3) & 0xFF;
    353347    data[7] = (enc_len >> 5) & 0xFF;
    354348    memset(data + 8 + enc_len, 0, block_len - 8 - enc_len);
    355     len = block_len;
    356349
    357350    return enc_len;
    358351}
    359352
    360 // must have exactly 1 frames worth of data
    361 size_t AudioOutputDigitalEncoder::Encode(short *buff)
     353size_t AudioOutputDigitalEncoder::Encode(void *buf, int len)
    362354{
    363     int encsize = 0;
    364355    size_t outsize = 0;
    365356 
    366     // put data in the correct spot for encode frame
    367     outsize = avcodec_encode_audio(
    368         av_context, ((uchar*)outbuf) + 8, outbuf_size - 8, buff);
     357    int fs = FrameSize();
     358    memcpy(inbuf+inbuflen, buf, len);
     359    inbuflen += len;
     360    int frames = inbuflen / fs;
    369361
    370     size_t tmpsize = outsize;
    371 
    372     outsize = MAX_AC3_FRAME_SIZE;
    373     encsize = encode_frame(
    374         /*av_context->codec_id==CODEC_ID_DTS*/ false,
    375         (unsigned char*)outbuf, outsize);
     362    while (frames--)
     363    {
     364        reorder_6ch_ac3(inbuf, fs);
     365       
     366        // put data in the correct spot for encode frame
     367        outsize = avcodec_encode_audio(
     368            av_context, ((uchar*)outbuf) + outbuflen + 8, OUTBUFSIZE - 8, (short int *)inbuf);
     369
     370        encode_frame(
     371            /*av_context->codec_id==CODEC_ID_DTS*/ false,
     372            (unsigned char*)outbuf + outbuflen, outsize
     373        );
     374
     375        outbuflen += MAX_AC3_FRAME_SIZE;
     376        inbuflen -= fs;
     377        memmove(inbuf, inbuf+fs, inbuflen);
     378    }
    376379
    377     VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    378             QString("DigitalEncoder::Encode len1=%1 len2=%2 finallen=%3")
    379                 .arg(tmpsize).arg(encsize).arg(outsize));
     380    return outbuflen;
     381}
    380382
    381     return outsize;
     383void AudioOutputDigitalEncoder::GetFrames(void *ptr, int maxlen)
     384{
     385    int len = (maxlen < outbuflen ? maxlen : outbuflen);
     386    memcpy(ptr, outbuf, len);
     387    outbuflen -= len;
     388    memmove(outbuf, outbuf+len, outbuflen);
    382389}
  • mythtv/libs/libmyth/audiooutputdigitalencoder.h

    diff --git a/mythtv/libs/libmyth/audiooutputdigitalencoder.h b/mythtv/libs/libmyth/audiooutputdigitalencoder.h
    index 8a4689a..0a9f122 100644
    a b extern "C" { 
    55#include "libavcodec/avcodec.h"
    66};
    77
     8#define INBUFSIZE 131072
     9#define OUTBUFSIZE 98304
     10
    811class AudioOutputDigitalEncoder
    912{
    1013  public:
    1114    AudioOutputDigitalEncoder(void);
    1215    ~AudioOutputDigitalEncoder();
    1316
    14     bool   Init(CodecID codec_id, int bitrate, int samplerate, int channels);
     17    bool   Init(CodecID codec_id, int bitrate, int samplerate,
     18                int channels);
    1519    void   Dispose(void);
    16     size_t Encode(short * buff);
    17 
    18     inline char *GetFrameBuffer(void);
     20    size_t Encode(void *buf, int len);
     21    void   GetFrames(void *ptr, int maxlen);
    1922    size_t FrameSize(void)  const { return one_frame_bytes; }
    20     char  *GetOutBuff(void) const { return outbuf;          }
     23    int    Buffered(void) const { return inbuflen; }
    2124
    2225  public:
    2326    size_t audio_bytes_per_sample;
    2427
    2528  private:
    2629    AVCodecContext *av_context;
    27     char           *outbuf;
    28     int             outbuf_size;
    29     char           *frame_buffer;
     30    char            outbuf[OUTBUFSIZE];
     31    char            inbuf[INBUFSIZE];
     32    int             outbuflen;
     33    int             inbuflen;
    3034    size_t          one_frame_bytes;
    3135};
    3236
    33 inline char *AudioOutputDigitalEncoder::GetFrameBuffer(void)
    34 {
    35     if (!frame_buffer && av_context)
    36         frame_buffer = new char [one_frame_bytes];
    37 
    38     return frame_buffer;
    39 }
    40 
    4137#endif
  • mythtv/libs/libmyth/audiooutputdx.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputdx.cpp b/mythtv/libs/libmyth/audiooutputdx.cpp
    index adbbc4f..dad9197 100644
    a b DEFINE_GUID( _KSDATAFORMAT_SUBTYPE_DOLBY_AC3_SPDIF, WAVE_FORMAT_DOLBY_AC3_SPDIF, 
    9898AudioOutputDX::AudioOutputDX(
    9999    QString laudio_main_device,  QString           laudio_passthru_device,
    100100    int     laudio_bits,         int               laudio_channels,
    101     int     laudio_samplerate,   AudioOutputSource lsource,
    102     bool    lset_initial_vol,    bool              laudio_passthru) :
     101    int     laudio_codec,        int               laudio_samplerate,
     102    AudioOutputSource lsource,   bool              lset_initial_vol,
     103    bool    laudio_passthru) :
    103104    AudioOutputBase(laudio_main_device, laudio_passthru_device,
    104105                    laudio_bits,        laudio_channels,
    105106                    laudio_samplerate,  lsource,
    AudioOutputDX::AudioOutputDX( 
    121122{
    122123    InitDirectSound();
    123124   
    124     Reconfigure(laudio_bits,       laudio_channels,
     125    Reconfigure(laudio_bits,       laudio_channels,     laudio_codec
    125126                laudio_samplerate, laudio_passthru);
    126127}
    127128
  • mythtv/libs/libmyth/audiooutputdx.h

    diff --git a/mythtv/libs/libmyth/audiooutputdx.h b/mythtv/libs/libmyth/audiooutputdx.h
    index 00978b4..d975c46 100644
    a b class AudioOutputDX : public AudioOutputBase 
    1919public:
    2020    AudioOutputDX(QString laudio_main_device,
    2121                  QString laudio_passthru_device,
    22                   int laudio_bits,
    23                   int laudio_channels, int laudio_samplerate,
     22                  int laudio_bits, int laudio_channels,
     23                  int laudio_codec, int laudio_samplerate,
    2424                  AudioOutputSource lsource,
    2525                  bool lset_initial_vol, bool laudio_passthru);
    2626    virtual ~AudioOutputDX();
    public: 
    5656    // Volume control
    5757    virtual int GetVolumeChannel(int channel); // Returns 0-100
    5858    virtual void SetVolumeChannel(int channel, int volume); // range 0-100 for vol
     59    virtual vector<int> GetSupportedRates(void)
     60        { vector<int> rates; return rates; }
    5961
    6062 private:
    6163    HINSTANCE dsound_dll;      /* handle of the opened dsound dll */
  • mythtv/libs/libmyth/audiooutputjack.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputjack.cpp b/mythtv/libs/libmyth/audiooutputjack.cpp
    index f1c62bb..c89a7f9 100644
    a b extern "C" 
    2424AudioOutputJACK::AudioOutputJACK(
    2525    QString laudio_main_device, QString           laudio_passthru_device,
    2626    int     laudio_bits,        int               laudio_channels,
    27     int     laudio_samplerate,  AudioOutputSource lsource,
    28     bool    lset_initial_vol,   bool              laudio_passthru) :
     27    int     laudio_codec,       int               laudio_samplerate,
     28    AudioOutputSource lsource,  bool              lset_initial_vol,
     29    bool    laudio_passthru) :
    2930    AudioOutputBase(laudio_main_device, laudio_passthru_device,
    3031                    laudio_bits,        laudio_channels,
    3132                    laudio_samplerate,  lsource,
    AudioOutputJACK::AudioOutputJACK( 
    3637    JACK_Init();
    3738
    3839    // Set everything up
    39     Reconfigure(laudio_bits, laudio_channels,
     40    Reconfigure(laudio_bits, laudio_channels, laudio_codec
    4041                laudio_samplerate, laudio_passthru);
    4142}
    4243
     44vector<int> AudioOutputJACK::GetSupportedRates()
     45{
     46    const int srates[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000 };
     47    vector<int> rates(srates, srates + sizeof(srates) / sizeof(int) );
     48    unsigned long jack_port_flags = 0;
     49    unsigned int jack_port_name_count = 1;
     50    const char *jack_port_name = audio_main_device.ascii();
     51    int err = -1;
     52    audioid = -1;
     53    vector<int>::iterator it;
     54
     55    for (it = rates.begin(); it < rates.end(); it++)
     56    {
     57        err = JACK_OpenEx(&audioid, 16, (unsigned long *)it,
     58                          2, 2, &jack_port_name, jack_port_name_count,
     59                          jack_port_flags);
     60       
     61        if (err == 1)
     62        {
     63            Error(QString("Error connecting to jackd: %1. Is it running?")
     64                  .arg(audio_main_device));
     65            rates.clear();
     66            return rates;
     67        }
     68        else if (err == 2)
     69            rates.erase(it--);
     70
     71        JACK_Close(audioid);
     72        audioid = -1;
     73       
     74    }
     75 
     76    return rates;
     77}
     78
    4379AudioOutputJACK::~AudioOutputJACK()
    4480{
    4581    // Close down all audio stuff
    4682    KillAudio();
    4783}
    4884
     85
    4986bool AudioOutputJACK::OpenDevice()
    5087{
    5188    MythTimer timer;
  • mythtv/libs/libmyth/audiooutputjack.h

    diff --git a/mythtv/libs/libmyth/audiooutputjack.h b/mythtv/libs/libmyth/audiooutputjack.h
    index 19ce22a..a0b5b4a 100644
    a b class AudioOutputJACK : public AudioOutputBase 
    1414  public:
    1515    AudioOutputJACK(QString laudio_main_device,
    1616                    QString laudio_passthru_device,
    17                     int laudio_bits,
    18                     int laudio_channels, int laudio_samplerate,
     17                    int laudio_bits, int laudio_channels,
     18                    int laudio_codec, int laudio_samplerate,
    1919                    AudioOutputSource lsource,
    2020                    bool lset_initial_vol, bool laudio_passthru);
    2121    virtual ~AudioOutputJACK();
    class AudioOutputJACK : public AudioOutputBase 
    3232    virtual void WriteAudio(unsigned char *aubuf, int size);
    3333    virtual inline int getSpaceOnSoundcard(void);
    3434    virtual inline int getBufferedOnSoundcard(void);
     35    virtual vector<int> GetSupportedRates(void);
    3536
    3637  private:
    3738
  • mythtv/libs/libmyth/audiooutputnull.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputnull.cpp b/mythtv/libs/libmyth/audiooutputnull.cpp
    index 190364b..4a79730 100644
    a b using namespace std; 
    1919
    2020#include "mythcontext.h"
    2121#include "audiooutputnull.h"
     22#include "avcodec.h"
    2223
    2324AudioOutputNULL::AudioOutputNULL(
    2425    QString laudio_main_device, QString           laudio_passthru_device,
    2526    int     laudio_bits,        int               laudio_channels,
    26     int     laudio_samplerate,  AudioOutputSource lsource,
    27     bool    lset_initial_vol,   bool              laudio_passthru) :
     27    int     laudio_codec,       int               laudio_samplerate,
     28    AudioOutputSource lsource,  bool              lset_initial_vol,
     29    bool              laudio_passthru) :
    2830    AudioOutputBase(laudio_main_device, laudio_passthru_device,
    2931                    laudio_bits,        laudio_channels,
    3032                    laudio_samplerate,  lsource,
    AudioOutputNULL::AudioOutputNULL( 
    3739{
    3840    bzero(pcm_output_buffer, sizeof(char) * NULLAUDIO_OUTPUT_BUFFER_SIZE);
    3941
    40     Reconfigure(laudio_bits,       laudio_channels,
     42    Reconfigure(laudio_bits,       laudio_channels,     laudio_codec,
    4143                laudio_samplerate, laudio_passthru);
    4244}
    4345
  • mythtv/libs/libmyth/audiooutputnull.h

    diff --git a/mythtv/libs/libmyth/audiooutputnull.h b/mythtv/libs/libmyth/audiooutputnull.h
    index acaa17a..d7b3c8f 100644
    a b class AudioOutputNULL : public AudioOutputBase 
    2626public:
    2727    AudioOutputNULL(QString laudio_main_device,
    2828                    QString laudio_passthru_device,
    29                     int laudio_bits,
    30                     int laudio_channels, int laudio_samplerate,
     29                    int laudio_bits, int laudio_channels,
     30                    int laudio_codec, int laudio_samplerate,
    3131                    AudioOutputSource lsource,
    3232                    bool lset_initial_vol, bool laudio_passthru);
    3333    virtual ~AudioOutputNULL();
    protected: 
    4848    virtual void WriteAudio(unsigned char *aubuf, int size);
    4949    virtual inline int getSpaceOnSoundcard(void);
    5050    virtual inline int getBufferedOnSoundcard(void);
     51    virtual vector<int> GetSupportedRates(void)
     52        { vector<int> rates; return rates; }
    5153
    5254private:
    5355
  • mythtv/libs/libmyth/audiooutputoss.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputoss.cpp b/mythtv/libs/libmyth/audiooutputoss.cpp
    index 3436579..0f67c6a 100644
    a b using namespace std; 
    2323
    2424#include "mythcontext.h"
    2525#include "audiooutputoss.h"
     26#include "avcodec.h"
    2627#include "util.h"
    2728
    2829AudioOutputOSS::AudioOutputOSS(
    2930    QString laudio_main_device, QString           laudio_passthru_device,
    3031    int     laudio_bits,        int               laudio_channels,
    31     int     laudio_samplerate,  AudioOutputSource lsource,
    32     bool    lset_initial_vol,   bool              laudio_passthru) :
     32    int     laudio_codec,       int               laudio_samplerate,
     33    AudioOutputSource lsource,  bool              lset_initial_vol, 
     34    bool    laudio_passthru) :
    3335    AudioOutputBase(laudio_main_device, laudio_passthru_device,
    3436                    laudio_bits,        laudio_channels,
    3537                    laudio_samplerate,  lsource,
    AudioOutputOSS::AudioOutputOSS( 
    3840    mixerfd(-1), control(SOUND_MIXER_VOLUME)
    3941{
    4042    // Set everything up
    41     Reconfigure(laudio_bits,       laudio_channels,
     43    Reconfigure(laudio_bits,       laudio_channels,     laudio_codec,
    4244                laudio_samplerate, laudio_passthru);
    4345}
    4446
    AudioOutputOSS::~AudioOutputOSS() 
    4749    KillAudio();
    4850}
    4951
     52vector<int> AudioOutputOSS::GetSupportedRates()
     53{
     54    const int srates[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000 };
     55    vector<int> rates(srates, srates + sizeof(srates) / sizeof(int) );
     56    audiofd = open(audio_main_device.ascii(), O_WRONLY | O_NONBLOCK);
     57   
     58    if (audiofd < 0)
     59    {
     60        VERBOSE(VB_IMPORTANT, QString("Error opening audio device (%1), the"
     61                " error was: %2").arg(audio_main_device).arg(strerror(errno)));
     62        rates.clear();
     63        return rates;
     64    }
     65   
     66    vector<int>::iterator it;
     67
     68    for (it = rates.begin(); it < rates.end(); it++)
     69        if(ioctl(audiofd, SNDCTL_DSP_SPEED, &audio_samplerate) < 0)
     70            rates.erase(it--);
     71   
     72    close(audiofd);
     73    audiofd = -1;
     74   
     75    return rates;
     76}
     77
    5078bool AudioOutputOSS::OpenDevice()
    5179{
    5280    numbadioctls = 0;
  • mythtv/libs/libmyth/audiooutputoss.h

    diff --git a/mythtv/libs/libmyth/audiooutputoss.h b/mythtv/libs/libmyth/audiooutputoss.h
    index 8efd49d..49bcbb3 100644
    a b class AudioOutputOSS : public AudioOutputBase 
    1414{
    1515public:
    1616    AudioOutputOSS(QString audiodevice, QString passthrudevice,
    17                    int laudio_bits,
    18                    int laudio_channels, int laudio_samplerate,
     17                   int laudio_bits, int laudio_channels,
     18                   int laudio_codec, int laudio_samplerate,
    1919                   AudioOutputSource source, bool set_initial_vol,
    2020                   bool laudio_passthru);
    2121    virtual ~AudioOutputOSS();
    protected: 
    3131    virtual void WriteAudio(unsigned char *aubuf, int size);
    3232    virtual inline int getSpaceOnSoundcard(void);
    3333    virtual inline int getBufferedOnSoundcard(void);
     34    virtual vector<int> GetSupportedRates(void);
    3435
    3536private:
    3637    void VolumeInit(void);
  • mythtv/libs/libmyth/audiooutputwin.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputwin.cpp b/mythtv/libs/libmyth/audiooutputwin.cpp
    index e051605..79e22f5 100644
    a b void CALLBACK AudioOutputWinPrivate::waveOutProc( 
    7474AudioOutputWin::AudioOutputWin(
    7575    QString laudio_main_device,  QString           laudio_passthru_device,
    7676    int     laudio_bits,         int               laudio_channels,
    77     int     laudio_samplerate,   AudioOutputSource lsource,
    78     bool    lset_initial_vol,    bool              laudio_passthru) :
     77    int     laudio_codec,        int               laudio_samplerate,
     78    AudioOutputSource lsource,   bool              lset_initial_vol,
     79    bool    laudio_passthru) :
    7980    AudioOutputBase(laudio_main_device, laudio_passthru_device,
    8081                    laudio_bits,        laudio_channels,
    8182                    laudio_samplerate,  lsource,
    AudioOutputWin::AudioOutputWin( 
    8586    m_CurrentPkt(0),
    8687    m_OutPkts(NULL)
    8788{
    88     Reconfigure(laudio_bits,       laudio_channels,
     89    Reconfigure(laudio_bits,       laudio_channels,     laudio_codec
    8990                laudio_samplerate, laudio_passthru);
    9091
    9192    m_OutPkts = (unsigned char**) calloc(kPacketCnt, sizeof(unsigned char*));
  • mythtv/libs/libmyth/audiooutputwin.h

    diff --git a/mythtv/libs/libmyth/audiooutputwin.h b/mythtv/libs/libmyth/audiooutputwin.h
    index e53a9e8..ea71f99 100644
    a b class AudioOutputWin : public AudioOutputBase 
    1515  public:
    1616    AudioOutputWin(QString laudio_main_device,
    1717                   QString laudio_passthru_device,
    18                    int laudio_bits,
    19                    int laudio_channels, int laudio_samplerate,
     18                   int laudio_bits, int laudio_channels,
     19                   int laudio_codec, int laudio_samplerate,
    2020                   AudioOutputSource lsource,
    2121                   bool lset_initial_vol, bool laudio_passthru);
    2222    virtual ~AudioOutputWin();
    class AudioOutputWin : public AudioOutputBase 
    3131    virtual void WriteAudio(unsigned char *aubuf, int size);
    3232    virtual inline int getSpaceOnSoundcard(void);
    3333    virtual inline int getBufferedOnSoundcard(void);
     34    virtual vector<int> GetSupportedRates(void)
     35        { vector<int> rates; return rates; }
    3436
    3537  protected:
    3638    AudioOutputWinPrivate *m_priv;
  • mythtv/libs/libmythfreesurround/el_processor.cpp

    diff --git a/mythtv/libs/libmythfreesurround/el_processor.cpp b/mythtv/libs/libmythfreesurround/el_processor.cpp
    index 8f24737..cc0dbea 100644
    a b extern "C" { 
    3131typedef FFTSample FFTComplexArray[2];
    3232#endif
    3333
    34 
    3534#ifdef USE_FFTW3
    3635#pragma comment (lib,"libfftw3f-3.lib")
    3736#endif
    typedef std::complex<float> cfloat; 
    4039
    4140const float PI = 3.141592654;
    4241const float epsilon = 0.000001;
    43 //const float center_level = 0.5*sqrt(0.5);   // gain of the center channel
    44 //const float center_level = sqrt(0.5);   // gain of the center channel
    45 const float center_level = 1.0;   // gain of the center channel
    46 //const float center_level = 0.5;   // gain of the center channel
    47 
    48 // should be .6-.7
    49 // but with centerlevel 2x what its supposed to be, we halve 0.68
    50 // to keep center from clipping
    51 //const float window_gain = 0.34;     
    52 //const float window_gain = 0.68;     
    53 const float window_gain = 0.95;     // to prive a bit of margin
     42const float center_level = 0.5*sqrt(0.5);
    5443
    5544// private implementation of the surround decoder
    5645class decoder_impl {
    public: 
    9887            outbuf[c].resize(N);
    9988            filter[c].resize(N);
    10089        }
    101         // DC component of filters is always 0
    102         for (unsigned c=0;c<5;c++)
    103         {
    104             filter[c][0] = 0.0;
    105             filter[c][1] = 0.0;
    106             filter[c][halfN] = 0.0;
    107         }
    10890        sample_rate(48000);
    10991        // generate the window function (square root of hann, b/c it is applied before and after the transform)
    11092        wnd.resize(N);
    111         // dft normalization included in the window for zero cost scaling
    112         // also add a gain factor of *2 due to processing gain in algo (see center_level)
    113         surround_gain(1.0);
     93        for (unsigned k=0;k<N;k++)
     94            wnd[k] = sqrt(0.5*(1-cos(2*PI*k/N))/N);
    11495        current_buf = 0;
    11596        // set the default coefficients
    11697        surround_coefficients(0.8165,0.5774);
    public: 
    192173    // set lfe filter params
    193174    void sample_rate(unsigned int srate) {
    194175        // lfe filter is just straight through band limited
    195         unsigned int cutoff = (250*N)/srate;
     176        unsigned int cutoff = (30*N)/srate;
    196177        for (unsigned f=0;f<=halfN;f++) {           
    197             if ((f>=2) && (f<cutoff))
    198                 filter[5][f] = 1.0;
     178            if (f<cutoff)
     179                filter[5][f] = 0.5*sqrt(0.5);
    199180            else
    200181                filter[5][f] = 0.0;
    201182        }
    public: 
    214195        E = (o+v)*n; F = (o+u)*n; G = (o-v)*n;  H = (o-u)*n;
    215196    }
    216197
    217     void surround_gain(float gain) {
    218         master_gain = gain * window_gain * 0.5 * 0.25;
    219         for (unsigned k=0;k<N;k++)
    220             wnd[k] = sqrt(master_gain*(1-cos(2*PI*k/N))/N);
    221     }
    222 
    223198    // set the phase shifting mode
    224199    void phase_mode(unsigned mode) {
    225200        const float modes[4][2] = {{0,0},{0,PI},{PI,0},{-PI/2,PI/2}};
    private: 
    290265
    291266        // 2. compare amplitude and phase of each DFT bin and produce the X/Y coordinates in the sound field
    292267        //    but dont do DC or N/2 component
    293         for (unsigned f=2;f<halfN;f++) {           
     268        for (unsigned f=0;f<halfN;f++) {           
    294269            // get left/right amplitudes/phases
    295270            float ampL = amplitude(dftL[f]), ampR = amplitude(dftR[f]);
    296271            float phaseL = phase(dftL[f]), phaseR = phase(dftR[f]);
    private: 
    305280            phaseDiff = abs(phaseDiff);
    306281
    307282            if (linear_steering) {
    308 /*              cfloat w = polar(sqrt(ampL*ampL+ampR*ampR), (phaseL+phaseR)/2);
    309                 cfloat lt = cfloat(dftL[f][0],dftL[f][1])/w, rt = cfloat(dftR[f][0],dftR[f][1])/w;              */
    310 //              xfs[f] = -(C*(rt-H) - B*E + F*A + G*(D-lt)) / (G*A - C*E).real();
    311 //              yfs[f] = (rt - (xfs[f]*E+H))/(F+xfs[f]*G);
    312 
    313                 /*
    314                 Problem:
    315                 This assumes that the values are interpolated linearly between the cardinal points.
    316                 But this way we have no chance of knowing the average volume...
    317                 - Can we solve that computing everything under the assumption of normalized volume?
    318                   No. Seemingly not.
    319                 - Maybe we should add w explitcitly into the equation and see if we can solve it...
    320                 */
    321 
    322 
    323                 //cfloat lt(0.5,0),rt(0.5,0);
    324                 //cfloat x(0,0), y(1,0);
    325                 /*cfloat p = (C*(rt-H) - B*E + F*A + G*(D-lt)) / (G*A - C*E);
    326                 cfloat q = B*(rt+H) + F*(D-lt) / (G*A - C*E);
    327                 cfloat s = sqrt(p*p/4.0f - q);
    328                 cfloat x = -p;
    329                 cfloat x1 = -p/2.0f + s;
    330                 cfloat x2 = -p/2.0f - s;
    331                 float x = 0;
    332                 if (x1.real() >= -1 && x1.real() <= 1)
    333                     x = x1.real();
    334                 else if (x2.real() >= -1 && x2.real() <= 1)
    335                     x = x2.real();*/
    336 
    337                 //cfloat yp = (rt - (x*E+H))/(F+x*G);
    338                 //cfloat xp = (lt - (y*B+D))/(A+y*C);
    339 
    340                 /*xfs[f] = x;
    341                 yfs[f] = y.real();*/
    342 
    343283                // --- this is the fancy new linear mode ---
    344284
    345285                // get sound field x/y position
    private: 
    597537    float surround_high,surround_low;  // high and low surround mixing coefficient (e.g. 0.8165/0.5774)
    598538    float surround_balance;            // the xfs balance that follows from the coeffs
    599539    float surround_level;              // gain for the surround channels (follows from the coeffs
    600     float master_gain;                 // gain for all channels
    601540    float phase_offsetL, phase_offsetR;// phase shifts to be applied to the rear channels
    602541    float front_separation;            // front stereo separation
    603542    float rear_separation;             // rear stereo separation
    void fsurround_decoder::flush() { impl->flush(); } 
    625564
    626565void fsurround_decoder::surround_coefficients(float a, float b) { impl->surround_coefficients(a,b); }
    627566
    628 void fsurround_decoder::gain(float gain) { impl->surround_gain(gain); }
    629 
    630567void fsurround_decoder::phase_mode(unsigned mode) { impl->phase_mode(mode); }
    631568
    632569void fsurround_decoder::steering_mode(bool mode) { impl->steering_mode(mode); }
  • mythtv/libs/libmythfreesurround/el_processor.h

    diff --git a/mythtv/libs/libmythfreesurround/el_processor.h b/mythtv/libs/libmythfreesurround/el_processor.h
    index 021786a..26452f6 100644
    a b public: 
    4747        //  a is the coefficient of left rear in left total, b is the coefficient of left rear in right total; the same is true for right.
    4848        void surround_coefficients(float a, float b);
    4949
    50         // override for master surround gain
    51         void gain(float gain);
    52 
    5350        // set the phase shifting mode for decoding
    5451        // 0 = (+0°,+0°)   - music mode
    5552        // 1 = (+0°,+180°) - PowerDVD compatibility
  • mythtv/libs/libmythfreesurround/freesurround.cpp

    diff --git a/mythtv/libs/libmythfreesurround/freesurround.cpp b/mythtv/libs/libmythfreesurround/freesurround.cpp
    index 07fe0d8..85b4e59 100644
    a b using namespace std; 
    6363const unsigned default_block_size = 8192;
    6464// there will be a slider for this in the future
    6565//const float master_gain = 1.0;
    66 //#define MASTER_GAIN * master_gain
     66//#define MASTER_GAIN * master_gain 
    6767#define MASTER_GAIN
    68 //const float master_gain = 1.0/(1<<15);
    69 //const float inv_master_gain = (1<<15);
     68//const float inv_master_gain = 1.0;
    7069//#define INV_MASTER_GAIN * inv_master_gain
    7170#define INV_MASTER_GAIN
    7271
    FreeSurround::FreeSurround(uint srate, bool moviemode, SurroundMode smode) : 
    191190    if (moviemode)
    192191    {
    193192        params.phasemode = 1;
    194         params.center_width = 0;
    195         params.gain = 1.0;
     193        params.center_width = 25;
     194        params.dimension = 0.5;
    196195    }
    197196    else
    198197    {
    199         params.center_width = 70;
    200         // for 50, gain should be about 1.9, c/lr about 2.7
    201         // for 70, gain should be about 3.1, c/lr about 1.5
    202         params.gain = 3.1;
     198        params.center_width = 65;
     199        params.dimension = 0.3;
    203200    }
    204201    switch (surround_mode)
    205202    {
    void FreeSurround::SetParams() 
    235232        decoder->phase_mode(params.phasemode);
    236233        decoder->surround_coefficients(params.coeff_a, params.coeff_b);                         
    237234        decoder->separation(params.front_sep/100.0,params.rear_sep/100.0);
    238         decoder->gain(params.gain);
    239235    }
    240236}
    241237
    FreeSurround::fsurround_params::fsurround_params( 
    249245    phasemode(0),
    250246    steering(1),
    251247    front_sep(100),
    252     rear_sep(100),
    253     gain(1.0)
     248    rear_sep(100)
    254249{
    255250}
    256251
    void FreeSurround::process_block() 
    654649    {
    655650        if (decoder)
    656651        {
    657             // actually these params need only be set when they change... but it doesn't hurt
    658 #if 0
    659             decoder->steering_mode(params.steering);
    660             decoder->phase_mode(params.phasemode);
    661             decoder->surround_coefficients(params.coeff_a, params.coeff_b);                             
    662             decoder->separation(params.front_sep/100.0,params.rear_sep/100.0);
    663 #endif
    664             // decode the bufs->block
    665             //decoder->decode(input,output,params.center_width/100.0,params.dimension/100.0);
    666             //decoder->decode(output,params.center_width/100.0,params.dimension/100.0);
    667652            decoder->decode(params.center_width/100.0,params.dimension/100.0);
    668653        }
    669654    }
  • mythtv/libs/libmythfreesurround/freesurround.h

    diff --git a/mythtv/libs/libmythfreesurround/freesurround.h b/mythtv/libs/libmythfreesurround/freesurround.h
    index 5748864..0f057e3 100644
    a b private: 
    7474        fsurround_params(int32_t center_width=100, int32_t dimension=0);
    7575    } params;
    7676
    77         // additional settings
    78         uint srate;
    79 
    80         // info about the current setup
    81         bool open_;                                     // whether a stream is currently open
    82         bool initialized_;                      // whether the thing is intialized     
    83         //struct buffers *bufs;                         // our buffers
    84         struct int16buffers *int16bufs;         // our buffers
    85         class fsurround_decoder *decoder;       // the surround decoder
     77    // additional settings
     78    uint srate;
     79
     80    // info about the current setup
     81    bool open_;                                 // whether a stream is currently open
     82    bool initialized_;                  // whether the thing is intialized     
     83    //struct buffers *bufs;                             // our buffers
     84    struct int16buffers *int16bufs;             // our buffers
     85    class fsurround_decoder *decoder;   // the surround decoder
    8686    int in_count;               // amount in lt,rt
    8787    int out_count;              // amount in output bufs
    8888    bool processed;             // whether processing is enabled or not for latency calc
  • mythtv/libs/libmythsamplerate/samplerate.c

    diff --git a/mythtv/libs/libmythsamplerate/samplerate.c b/mythtv/libs/libmythsamplerate/samplerate.c
    index d5a5abc..4d74640 100644
    a b src_float_to_short_array (const float *in, short *out, int len) 
    452452        {       len -- ;
    453453
    454454                scaled_value = in [len] * (8.0 * 0x10000000) ;
    455                 if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
     455                if (scaled_value >= (1.0 * 0x7FFFFFFF))
    456456                {       out [len] = 32767 ;
    457457                        continue ;
    458458                        } ;
    459                 if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
     459                if (scaled_value <= (-8.0 * 0x10000000))
    460460                {       out [len] = -32768 ;
    461461                        continue ;
    462462                        } ;
  • mythtv/libs/libmythtv/NuppelVideoPlayer.cpp

    diff --git a/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp b/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp
    index cb660af..a512c26 100644
    a b NuppelVideoPlayer::NuppelVideoPlayer(QString inUseID, const ProgramInfo *info) 
    207207      audioOutput(NULL),
    208208      audio_main_device(QString::null),
    209209      audio_passthru_device(QString::null),
    210       audio_channels(2),            audio_bits(-1),
    211       audio_samplerate(44100),      audio_stretchfactor(1.0f),
    212       audio_codec(NULL),
     210      audio_channels(2),            audio_codec(0),
     211      audio_bits(-1),               audio_samplerate(44100),
     212      audio_stretchfactor(1.0f),
    213213      // Picture-in-Picture
    214214      pipplayer(NULL), setpipplayer(NULL), needsetpipplayer(false),
    215215      // Preview window support
    QString NuppelVideoPlayer::ReinitAudio(void) 
    775775        audioOutput = AudioOutput::OpenAudio(audio_main_device,
    776776                                             audio_passthru_device,
    777777                                             audio_bits, audio_channels,
     778                                             audio_codec,
    778779                                             audio_samplerate,
    779780                                             AUDIOOUTPUT_VIDEO,
    780781                                             setVolume, audio_passthru);
    QString NuppelVideoPlayer::ReinitAudio(void) 
    803804
    804805    if (audioOutput)
    805806    {
    806         audioOutput->Reconfigure(audio_bits, audio_channels,
    807                                  audio_samplerate, audio_passthru,
    808                                  audio_codec);
     807        audioOutput->Reconfigure(audio_bits, audio_channels, audio_codec,
     808                                 audio_samplerate, audio_passthru);
     809        if (audio_passthru)
     810            audio_channels = 2;
    809811        errMsg = audioOutput->GetError();
    810812        if (!errMsg.isEmpty())
    811813            audioOutput->SetStretchFactor(audio_stretchfactor);
    void NuppelVideoPlayer::StartPlaying(void) 
    37093711    }
    37103712}
    37113713
    3712 void NuppelVideoPlayer::SetAudioParams(int bps, int channels,
     3714void NuppelVideoPlayer::SetAudioParams(int bps, int channels, int codec,
    37133715                                       int samplerate, bool passthru)
    37143716{
    37153717    audio_bits = bps;
    37163718    audio_channels = channels;
     3719    audio_codec = codec;
    37173720    audio_samplerate = samplerate;
    37183721    audio_passthru = passthru;
    37193722}
    37203723
    3721 void NuppelVideoPlayer::SetAudioCodec(void *ac)
    3722 {
    3723     audio_codec = ac;
    3724 }
    3725 
    37263724void NuppelVideoPlayer::SetEffDsp(int dsprate)
    37273725{
    37283726    if (audioOutput)
  • mythtv/libs/libmythtv/NuppelVideoPlayer.h

    diff --git a/mythtv/libs/libmythtv/NuppelVideoPlayer.h b/mythtv/libs/libmythtv/NuppelVideoPlayer.h
    index 5f3d2ac..58e4695 100644
    a b class MPUBLIC NuppelVideoPlayer : public CC608Reader, public CC708Reader 
    125125    void SetAudioStretchFactor(float factor)  { audio_stretchfactor = factor; }
    126126    void SetAudioOutput(AudioOutput *ao)      { audioOutput = ao; }
    127127    void SetAudioInfo(const QString &main, const QString &passthru, uint rate);
    128     void SetAudioParams(int bits, int channels, int samplerate, bool passthru);
     128    void SetAudioParams(int bits, int channels, int codec, int samplerate,
     129                        bool passthru);
    129130    void SetEffDsp(int dsprate);
    130131    void SetAudioCodec(void *ac);
    131132
    class MPUBLIC NuppelVideoPlayer : public CC608Reader, public CC708Reader 
    682683    QString  audio_main_device;
    683684    QString  audio_passthru_device;
    684685    int      audio_channels;
     686    int      audio_codec;
    685687    int      audio_bits;
    686688    int      audio_samplerate;
    687689    float    audio_stretchfactor;
    688     void    *audio_codec;
    689690    bool     audio_passthru;
    690691
    691692    // Picture-in-Picture
  • mythtv/libs/libmythtv/avformatdecoder.cpp

    diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
    index f574bca..972f0fd 100644
    a b AvFormatDecoder::AvFormatDecoder(NuppelVideoPlayer *parent, 
    411411      audioSamples(new short int[AVCODEC_MAX_AUDIO_FRAME_SIZE]),
    412412      allow_ac3_passthru(false),    allow_dts_passthru(false),
    413413      disable_passthru(false),      max_channels(2),
    414       dummy_frame(NULL),
     414      last_ac3_channels(0),         dummy_frame(NULL),
    415415      // DVD
    416416      lastdvdtitle(-1),
    417417      decodeStillFrame(false),
    int AvFormatDecoder::ScanStreams(bool novideo) 
    18741874    // waiting on audio.
    18751875    if (GetNVP()->HasAudioIn() && tracks[kTrackTypeAudio].empty())
    18761876    {
    1877         GetNVP()->SetAudioParams(-1, -1, -1, false /* AC3/DTS pass-through */);
     1877        GetNVP()->SetAudioParams(-1, -1, CODEC_ID_NONE, -1, false /* AC3/DTS pass-through */);
    18781878        GetNVP()->ReinitAudio();
    18791879        if (ringBuffer && ringBuffer->isDVD())
    18801880            audioIn = AudioInfo();
    int AvFormatDecoder::AutoSelectAudioTrack(void) 
    28392839    {
    28402840        int idx = atracks[i].av_stream_index;
    28412841        AVCodecContext *codec_ctx = ic->streams[idx]->codec;
    2842         bool do_ac3_passthru = (allow_ac3_passthru && !transcoding &&
    2843                                 !disable_passthru &&
    2844                                 (codec_ctx->codec_id == CODEC_ID_AC3));
    2845         bool do_dts_passthru = (allow_dts_passthru && !transcoding &&
    2846                                 !disable_passthru &&
    2847                                 (codec_ctx->codec_id == CODEC_ID_DTS));
    28482842        AudioInfo item(codec_ctx->codec_id,
    28492843                       codec_ctx->sample_rate, codec_ctx->channels,
    2850                        do_ac3_passthru || do_dts_passthru);
     2844                       DoPassThrough(codec_ctx));
    28512845        VERBOSE(VB_AUDIO, LOC + " * " + item.toString());
    28522846    }
    28532847#endif
    static void extract_mono_channel(uint channel, AudioInfo *audioInfo, 
    29812975bool AvFormatDecoder::GetFrame(int onlyvideo)
    29822976{
    29832977    AVPacket *pkt = NULL;
     2978    AC3HeaderInfo hdr;
    29842979    int len;
    29852980    unsigned char *ptr;
    29862981    int data_size = 0;
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    31673162        pts = 0;
    31683163
    31693164        AVStream *curstream = ic->streams[pkt->stream_index];
     3165        AVCodecContext *ctx = curstream->codec;
    31703166
    31713167        if (pkt->dts != (int64_t)AV_NOPTS_VALUE)
    31723168            pts = (long long)(av_q2d(curstream->time_base) * pkt->dts * 1000);
    31733169
    31743170        if (ringBuffer->isDVD() &&
    3175             curstream->codec->codec_type == CODEC_TYPE_VIDEO)
     3171            ctx->codec_type == CODEC_TYPE_VIDEO)
    31763172        {
    31773173            MpegPreProcessPkt(curstream, pkt);
    31783174
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    32003196
    32013197            if (!d->HasMPEG2Dec())
    32023198            {
    3203                 int current_width = curstream->codec->width;
     3199                int current_width = ctx->width;
    32043200                int video_width = GetNVP()->GetVideoSize().width();
    32053201                if (dvd_xvmc_enabled && GetNVP() && GetNVP()->getVideoOutput())
    32063202                {
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    32413237        }
    32423238
    32433239        if (storevideoframes &&
    3244             curstream->codec->codec_type == CODEC_TYPE_VIDEO)
     3240            ctx->codec_type == CODEC_TYPE_VIDEO)
    32453241        {
    32463242            av_dup_packet(pkt);
    32473243            storedPackets.append(pkt);
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    32493245            continue;
    32503246        }
    32513247
    3252         if (len > 0 && curstream->codec->codec_type == CODEC_TYPE_VIDEO &&
     3248        if (len > 0 && ctx->codec_type == CODEC_TYPE_VIDEO &&
    32533249            pkt->stream_index == selectedVideoIndex)
    32543250        {
    3255             AVCodecContext *context = curstream->codec;
    32563251
    3257             if (context->codec_id == CODEC_ID_MPEG1VIDEO ||
    3258                 context->codec_id == CODEC_ID_MPEG2VIDEO ||
    3259                 context->codec_id == CODEC_ID_MPEG2VIDEO_XVMC ||
    3260                 context->codec_id == CODEC_ID_MPEG2VIDEO_XVMC_VLD)
     3252            if (ctx->codec_id == CODEC_ID_MPEG1VIDEO ||
     3253                ctx->codec_id == CODEC_ID_MPEG2VIDEO ||
     3254                ctx->codec_id == CODEC_ID_MPEG2VIDEO_XVMC ||
     3255                ctx->codec_id == CODEC_ID_MPEG2VIDEO_XVMC_VLD)
    32613256            {
    32623257                if (!ringBuffer->isDVD())
    32633258                    MpegPreProcessPkt(curstream, pkt);
    32643259            }
    3265             else if (context->codec_id == CODEC_ID_H264)
     3260            else if (ctx->codec_id == CODEC_ID_H264)
    32663261            {
    32673262                H264PreProcessPkt(curstream, pkt);
    32683263            }
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    33083303        }
    33093304
    33103305        if (len > 0 &&
    3311             curstream->codec->codec_type == CODEC_TYPE_DATA &&
    3312             curstream->codec->codec_id   == CODEC_ID_MPEG2VBI)
     3306            ctx->codec_type == CODEC_TYPE_DATA &&
     3307            ctx->codec_id   == CODEC_ID_MPEG2VBI)
    33133308        {
    33143309            ProcessVBIDataPacket(curstream, pkt);
    33153310
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    33183313        }
    33193314
    33203315        if (len > 0 &&
    3321             curstream->codec->codec_type == CODEC_TYPE_DATA &&
    3322             curstream->codec->codec_id   == CODEC_ID_DVB_VBI)
     3316            ctx->codec_type == CODEC_TYPE_DATA &&
     3317            ctx->codec_id   == CODEC_ID_DVB_VBI)
    33233318        {
    33243319            ProcessDVBDataPacket(curstream, pkt);
    33253320
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    33283323        }
    33293324
    33303325        if (len > 0 &&
    3331             curstream->codec->codec_type == CODEC_TYPE_DATA &&
    3332             curstream->codec->codec_id   == CODEC_ID_DSMCC_B)
     3326            ctx->codec_type == CODEC_TYPE_DATA &&
     3327            ctx->codec_id   == CODEC_ID_DSMCC_B)
    33333328        {
    33343329            ProcessDSMCCPacket(curstream, pkt);
    33353330
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    33493344        }
    33503345
    33513346        // we don't care about other data streams
    3352         if (curstream->codec->codec_type == CODEC_TYPE_DATA)
     3347        if (ctx->codec_type == CODEC_TYPE_DATA)
    33533348        {
    33543349            av_free_packet(pkt);
    33553350            continue;
    33563351        }
    33573352
    3358         if (!curstream->codec->codec)
     3353        if (!ctx->codec)
    33593354        {
    33603355            VERBOSE(VB_PLAYBACK, LOC +
    33613356                    QString("No codec for stream index %1, type(%2) id(%3:%4)")
    33623357                    .arg(pkt->stream_index)
    3363                     .arg(codec_type_string(curstream->codec->codec_type))
    3364                     .arg(codec_id_string(curstream->codec->codec_id))
    3365                     .arg(curstream->codec->codec_id));
     3358                    .arg(codec_type_string(ctx->codec_type))
     3359                    .arg(codec_id_string(ctx->codec_id))
     3360                    .arg(ctx->codec_id));
    33663361            av_free_packet(pkt);
    33673362            continue;
    33683363        }
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    33713366        have_err = false;
    33723367
    33733368        avcodeclock.lock();
    3374         int ctype  = curstream->codec->codec_type;
     3369        int ctype  = ctx->codec_type;
    33753370        int audIdx = selectedTrack[kTrackTypeAudio].av_stream_index;
    33763371        int audSubIdx = selectedTrack[kTrackTypeAudio].av_substream_index;
    33773372        int subIdx = selectedTrack[kTrackTypeSubtitle].av_stream_index;
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    33963391
    33973392                    // detect switches between stereo and dual languages
    33983393                    bool wasDual = audSubIdx != -1;
    3399                     bool isDual = curstream->codec->avcodec_dual_language;
     3394                    bool isDual = ctx->avcodec_dual_language;
    34003395                    if ((wasDual && !isDual) || (!wasDual &&  isDual))
    34013396                    {
    34023397                        SetupAudioStreamSubIndexes(audIdx);
    34033398                        reselectAudioTrack = true;
    34043399                    }                           
    34053400
    3406                     bool do_ac3_passthru =
    3407                         (allow_ac3_passthru && !transcoding &&
    3408                          (curstream->codec->codec_id == CODEC_ID_AC3));
    3409                     bool do_dts_passthru =
    3410                         (allow_dts_passthru && !transcoding &&
    3411                          (curstream->codec->codec_id == CODEC_ID_DTS));
    3412                     bool using_passthru = do_ac3_passthru || do_dts_passthru;
    3413 
    34143401                    // detect channels on streams that need
    34153402                    // to be decoded before we can know this
    34163403                    bool already_decoded = false;
    3417                     if (!curstream->codec->channels)
     3404                    if (!ctx->channels)
    34183405                    {
    34193406                        QMutexLocker locker(&avcodeclock);
    34203407                        VERBOSE(VB_IMPORTANT, LOC +
    34213408                                QString("Setting channels to %1")
    34223409                                .arg(audioOut.channels));
    34233410
    3424                         if (using_passthru)
     3411                        if (DoPassThrough(ctx))
    34253412                        {
    34263413                            // for passthru let it select the max number
    34273414                            // of channels
    3428                             curstream->codec->channels = 0;
    3429                             curstream->codec->request_channels = 0;
     3415                            ctx->channels = 0;
     3416                            ctx->request_channels = 0;
    34303417                        }
    34313418                        else
    34323419                        {
    3433                             curstream->codec->channels = audioOut.channels;
    3434                             curstream->codec->request_channels =
     3420                            ctx->channels = audioOut.channels;
     3421                            ctx->request_channels =
    34353422                                audioOut.channels;
    34363423                        }
    34373424                        ret = avcodec_decode_audio(
    3438                             curstream->codec, audioSamples,
     3425                            ctx, audioSamples,
    34393426                            &data_size, ptr, len);
    34403427                        already_decoded = true;
    34413428
    3442                         reselectAudioTrack |= curstream->codec->channels;
     3429                        reselectAudioTrack |= ctx->channels;
     3430                    }
     3431
     3432                    if (ctx->codec_id == CODEC_ID_AC3 &&
     3433                        !ff_ac3_parse_header(ptr, &hdr))
     3434                    {
     3435                        if (hdr.channels != last_ac3_channels)
     3436                        {
     3437                            last_ac3_channels = ctx->channels = hdr.channels;
     3438                            SetupAudioStream();
     3439                        }
    34433440                    }
    34443441
    34453442                    if (reselectAudioTrack)
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    34553452                            .av_stream_index;
    34563453                        audSubIdx = selectedTrack[kTrackTypeAudio]
    34573454                            .av_substream_index;
     3455                        ctx = curstream->codec;
    34583456                    }
    34593457
    34603458                    if ((onlyvideo > 0) || (pkt->stream_index != audIdx))
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    34863484                    if (audioOut.do_passthru)
    34873485                    {
    34883486                        data_size = pkt->size;
    3489                         bool dts = CODEC_ID_DTS == curstream->codec->codec_id;
     3487                        bool dts = CODEC_ID_DTS == ctx->codec_id;
    34903488                        ret = encode_frame(dts, ptr, len,
    34913489                                           audioSamples, data_size);
    34923490                    }
    34933491                    else
    34943492                    {
    3495                         AVCodecContext *ctx = curstream->codec;
    3496 
    34973493                        if ((ctx->channels == 0) ||
    34983494                            (ctx->channels > audioOut.channels))
    34993495                        {
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    35023498
    35033499                        if (!already_decoded)
    35043500                        {
    3505                             curstream->codec->request_channels =
    3506                                 audioOut.channels;
     3501                            ctx->request_channels = audioOut.channels;
    35073502                            ret = avcodec_decode_audio(
    35083503                                ctx, audioSamples, &data_size, ptr, len);
    35093504                        }
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    35203515                            audIdx = -1;
    35213516                            AutoSelectAudioTrack();
    35223517                            data_size = 0;
     3518                            ctx = curstream->codec;
    35233519                        }
    35243520                    }
    35253521                    avcodeclock.unlock();
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    35373533
    35383534                    // calc for next frame
    35393535                    lastapts += (long long)((double)(data_size * 1000) /
    3540                                 (curstream->codec->channels * 2) /
    3541                                 curstream->codec->sample_rate);
     3536                                (ctx->channels * 2) / ctx->sample_rate);
    35423537
    35433538                    VERBOSE(VB_PLAYBACK|VB_TIMESTAMP,
    35443539                            LOC + QString("audio timecode %1 %2 %3 %4")
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    35983593                        continue;
    35993594                    }
    36003595
    3601                     AVCodecContext *context = curstream->codec;
    36023596                    AVFrame mpa_pic;
    36033597                    bzero(&mpa_pic, sizeof(AVFrame));
    36043598
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    36133607                            // HACK
    36143608                            while (!gotpicture && count < 5)
    36153609                            {
    3616                                 ret = d->DecodeMPEG2Video(context, &mpa_pic,
     3610                                ret = d->DecodeMPEG2Video(ctx, &mpa_pic,
    36173611                                                  &gotpicture, ptr, len);
    36183612                                count++;
    36193613                            }
    36203614                        }
    36213615                        else
    36223616                        {
    3623                             ret = d->DecodeMPEG2Video(context, &mpa_pic,
     3617                            ret = d->DecodeMPEG2Video(ctx, &mpa_pic,
    36243618                                                &gotpicture, ptr, len);
    36253619                        }
    36263620                    }
    36273621                    else
    36283622                    {
    3629                         ret = avcodec_decode_video(context, &mpa_pic,
     3623                        ret = avcodec_decode_video(ctx, &mpa_pic,
    36303624                                                   &gotpicture, ptr, len);
    36313625                        // Reparse it to not drop the DVD still frame
    36323626                        if (decodeStillFrame)
    3633                             ret = avcodec_decode_video(context, &mpa_pic,
     3627                            ret = avcodec_decode_video(ctx, &mpa_pic,
    36343628                                                        &gotpicture, ptr, len);
    36353629                    }
    36363630                    avcodeclock.unlock();
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    36973691
    36983692                        img_convert(&tmppicture, PIX_FMT_YUV420P,
    36993693                                    (AVPicture *)&mpa_pic,
    3700                                     context->pix_fmt,
    3701                                     context->width,
    3702                                     context->height);
     3694                                    ctx->pix_fmt,
     3695                                    ctx->width,
     3696                                    ctx->height);
    37033697
    37043698                        if (xf)
    37053699                        {
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    37223716                        (temppts + 10000 > lastvpts || temppts < 0))
    37233717                    {
    37243718                        temppts = lastvpts;
    3725                         temppts += (long long)(1000 * av_q2d(context->time_base));
     3719                        temppts += (long long)(1000 * av_q2d(ctx->time_base));
    37263720                        // MPEG2 frames can be repeated, update pts accordingly
    37273721                        temppts += (long long)(mpa_pic.repeat_pict * 500
    3728                                       * av_q2d(curstream->codec->time_base));
     3722                                      * av_q2d(ctx->time_base));
    37293723                    }
    37303724
    37313725                    VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC +
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    37613755                    picframe->frameNumber = framesPlayed;
    37623756                    GetNVP()->ReleaseNextVideoFrame(picframe, temppts);
    37633757                    if (d->HasMPEG2Dec() && mpa_pic.data[3])
    3764                         context->release_buffer(context, &mpa_pic);
     3758                        ctx->release_buffer(ctx, &mpa_pic);
    37653759
    37663760                    decoded_video_frame = picframe;
    37673761                    gotvideo = 1;
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    38203814                }
    38213815                default:
    38223816                {
    3823                     AVCodecContext *enc = curstream->codec;
    38243817                    VERBOSE(VB_IMPORTANT, LOC_ERR +
    38253818                            QString("Decoding - id(%1) type(%2)")
    3826                             .arg(codec_id_string(enc->codec_id))
    3827                             .arg(codec_type_string(enc->codec_type)));
     3819                            .arg(codec_id_string(ctx->codec_id))
     3820                            .arg(codec_type_string(ctx->codec_type)));
    38283821                    have_err = true;
    38293822                    break;
    38303823                }
    void AvFormatDecoder::SetDisablePassThrough(bool disable) 
    39693962    }
    39703963}
    39713964
     3965bool AvFormatDecoder::DoPassThrough(const AVCodecContext *ctx)
     3966{
     3967    bool passthru = false;
     3968
     3969    if (ctx->codec_id == CODEC_ID_AC3)
     3970        passthru = allow_ac3_passthru &&
     3971                   ctx->channels >= (int)max_channels;
     3972    else if (ctx->codec_id == CODEC_ID_DTS)
     3973        passthru = allow_dts_passthru;
     3974   
     3975    passthru &= !transcoding && !disable_passthru;
     3976    // Don't know any cards that support spdif clocked at < 44100
     3977    // Some US cable transmissions have 2ch 32k AC-3 streams
     3978    passthru &= ctx->sample_rate >= 44100;
     3979
     3980    return passthru;
     3981}
     3982
     3983
    39723984/** \fn AvFormatDecoder::SetupAudioStream(void)
    39733985 *  \brief Reinitializes audio if it needs to be reinitialized.
    39743986 *
    bool AvFormatDecoder::SetupAudioStream(void) 
    39823994    AVStream *curstream = NULL;
    39833995    AVCodecContext *codec_ctx = NULL;
    39843996    AudioInfo old_in  = audioIn;
    3985     AudioInfo old_out = audioOut;
    39863997    bool using_passthru = false;
    39873998
    39883999    if ((currentTrack[kTrackTypeAudio] >= 0) &&
    bool AvFormatDecoder::SetupAudioStream(void) 
    39944005        assert(curstream);
    39954006        assert(curstream->codec);
    39964007        codec_ctx = curstream->codec;       
    3997         bool do_ac3_passthru = (allow_ac3_passthru && !transcoding &&
    3998                                 (codec_ctx->codec_id == CODEC_ID_AC3));
    3999         bool do_dts_passthru = (allow_dts_passthru && !transcoding &&
    4000                                 (codec_ctx->codec_id == CODEC_ID_DTS));
    4001         using_passthru = do_ac3_passthru || do_dts_passthru;
    4002         info = AudioInfo(codec_ctx->codec_id,
    4003                          codec_ctx->sample_rate, codec_ctx->channels,
    4004                          using_passthru && !disable_passthru);
     4008        using_passthru = DoPassThrough(codec_ctx);
     4009        info = AudioInfo(codec_ctx->codec_id, codec_ctx->sample_rate,
     4010                         codec_ctx->channels, using_passthru);
    40054011    }
    40064012
    40074013    if (info == audioIn)
    bool AvFormatDecoder::SetupAudioStream(void) 
    40124018            QString("audio track #%1").arg(currentTrack[kTrackTypeAudio]+1));
    40134019
    40144020    audioOut = audioIn = info;
    4015     if (using_passthru)
    4016     {
    4017         // A passthru stream looks like a 48KHz 2ch (@ 16bit) to the sound card
    4018         AudioInfo digInfo = audioOut;
    4019         if (!disable_passthru)
    4020         {
    4021             digInfo.channels    = 2;
    4022             digInfo.sample_rate = 48000;
    4023             digInfo.sample_size = 4;
    4024         }
    4025         if (audioOut.channels > (int) max_channels)
    4026         {
    4027             audioOut.channels = (int) max_channels;
    4028             audioOut.sample_size = audioOut.channels * 2;
    4029             codec_ctx->channels = audioOut.channels;
    4030         }
    4031         VERBOSE(VB_AUDIO, LOC + "Audio format changed digital passthrough " +
    4032                 QString("%1\n\t\t\tfrom %2 ; %3\n\t\t\tto   %4 ; %5")
    4033                 .arg(digInfo.toString())
    4034                 .arg(old_in.toString()).arg(old_out.toString())
    4035                 .arg(audioIn.toString()).arg(audioOut.toString()));
    4036 
    4037         if (digInfo.sample_rate > 0)
    4038             GetNVP()->SetEffDsp(digInfo.sample_rate * 100);
    4039 
    4040         GetNVP()->SetAudioParams(digInfo.bps(), digInfo.channels,
    4041                                  digInfo.sample_rate, audioIn.do_passthru);
    4042         // allow the audio stuff to reencode
    4043         GetNVP()->SetAudioCodec(codec_ctx);
    4044         GetNVP()->ReinitAudio();
    4045         return true;
    4046     }
    4047     else
     4021
     4022    if (!using_passthru && audioOut.channels > (int)max_channels)
    40484023    {
    4049         if (audioOut.channels > (int) max_channels)
    4050         {
    4051             audioOut.channels = (int) max_channels;
    4052             audioOut.sample_size = audioOut.channels * 2;
    4053             codec_ctx->channels = audioOut.channels;
    4054         }
     4024        audioOut.channels = (int)max_channels;
     4025        audioOut.sample_size = audioOut.channels * 2;
     4026        codec_ctx->channels = audioOut.channels;
    40554027    }
    4056 
     4028   
    40574029    VERBOSE(VB_AUDIO, LOC + "Audio format changed " +
    4058             QString("\n\t\t\tfrom %1 ; %2\n\t\t\tto   %3 ; %4")
    4059             .arg(old_in.toString()).arg(old_out.toString())
    4060             .arg(audioIn.toString()).arg(audioOut.toString()));
     4030            QString("\n\t\t\tfrom %1 to %2")
     4031            .arg(old_in.toString()).arg(audioOut.toString()));
    40614032
    40624033    if (audioOut.sample_rate > 0)
    40634034        GetNVP()->SetEffDsp(audioOut.sample_rate * 100);
    40644035
    4065     GetNVP()->SetAudioParams(audioOut.bps(), audioOut.channels,
    4066                              audioOut.sample_rate,
    4067                              audioIn.do_passthru);
     4036    GetNVP()->SetAudioParams(audioOut.bps(), audioOut.channels, 
     4037                             audioOut.codec_id, audioOut.sample_rate,
     4038                             audioOut.do_passthru);
    40684039
    4069     // allow the audio stuff to reencode
    4070     GetNVP()->SetAudioCodec(using_passthru?codec_ctx:NULL);
    40714040    QString errMsg = GetNVP()->ReinitAudio();
    4072     bool audiook = errMsg.isEmpty();
    40734041
    40744042    return true;
    40754043}
  • mythtv/libs/libmythtv/avformatdecoder.h

    diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h
    index 2f4fb43..f008136 100644
    a b class AvFormatDecoder : public DecoderBase 
    196196
    197197    void SeekReset(long long, uint skipFrames, bool doFlush, bool discardFrames);
    198198
     199    bool DoPassThrough(const AVCodecContext *ctx);
    199200    bool SetupAudioStream(void);
    200201    void SetupAudioStreamSubIndexes(int streamIndex);
    201202    void RemoveAudioStreams();
    class AvFormatDecoder : public DecoderBase 
    264265    bool              allow_dts_passthru;
    265266    bool              disable_passthru;
    266267    uint              max_channels;
     268    uint              last_ac3_channels;
    267269
    268270    VideoFrame       *dummy_frame;
    269271
  • mythtv/libs/libmythtv/nuppeldecoder.cpp

    diff --git a/mythtv/libs/libmythtv/nuppeldecoder.cpp b/mythtv/libs/libmythtv/nuppeldecoder.cpp
    index aae2f26..80a5b89 100644
    a b int NuppelDecoder::OpenFile(RingBuffer *rbuffer, bool novideo, 
    479479#endif
    480480        GetNVP()->SetAudioParams(extradata.audio_bits_per_sample,
    481481                                 extradata.audio_channels,
     482                                 CODEC_ID_NONE,
    482483                                 extradata.audio_sample_rate,
    483484                                 false /* AC3/DTS pass through */);
    484485        GetNVP()->ReinitAudio();
  • mythtv/libs/libmythtv/tv_play.cpp

    diff --git a/mythtv/libs/libmythtv/tv_play.cpp b/mythtv/libs/libmythtv/tv_play.cpp
    index e56fbae..5fc504d 100644
    a b void TV::InitKeys(void) 
    348348    REG_KEY("TV Playback", "VOLUMEDOWN", "Volume down", "[,{,F10,Volume Down");
    349349    REG_KEY("TV Playback", "VOLUMEUP",   "Volume up",   "],},F11,Volume Up");
    350350    REG_KEY("TV Playback", "MUTE",       "Mute",        "|,\\,F9,Volume Mute");
     351    REG_KEY("TV Playback", "TOGGLEUPMIX", "Toggle upmixer", "Ctrl+U");
    351352    REG_KEY("TV Playback", "TOGGLEPIPMODE", "Toggle Picture-in-Picture mode",
    352353            "V");
    353354    REG_KEY("TV Playback", "TOGGLEPIPWINDOW", "Toggle active PiP window", "B");
    void TV::InitKeys(void) 
    480481  Teletext     F2,F3,F4,F5,F6,F7,F8
    481482  ITV          F2,F3,F4,F5,F6,F7,F12
    482483
    483   Playback: Ctrl-B,Ctrl-G,Ctrl-Y
     484  Playback: Ctrl-B,Ctrl-G,Ctrl-Y,Ctrl-U
    484485*/
    485486}
    486487
    void TV::ProcessKeypress(QKeyEvent *e) 
    27102711            else if (action == "VOLUMEDOWN" || action == "VOLUMEUP" ||
    27112712                     action == "STRETCHINC" || action == "STRETCHDEC" ||
    27122713                     action == "MUTE"       || action == "TOGGLEASPECT" ||
    2713                      action == "TOGGLEFILL" )
     2714                     action == "TOGGLEFILL" || action == "TOGGLEUPMIX")
    27142715            {
    27152716                passThru = 1;
    27162717                handled = false;
    void TV::ProcessKeypress(QKeyEvent *e) 
    27252726            else
    27262727                handled = false;
    27272728        }
    2728 
     2729       
    27292730        if (!passThru)
    27302731            return;
    27312732    }
    2732 
     2733 
    27332734    if (zoomMode)
    27342735    {
    27352736        int passThru = 0;
    void TV::ProcessKeypress(QKeyEvent *e) 
    27652766            else if (action == "VOLUMEDOWN" || action == "VOLUMEUP" ||
    27662767                     action == "STRETCHINC" || action == "STRETCHDEC" ||
    27672768                     action == "MUTE" || action == "PAUSE" ||
    2768                      action == "CLEAROSD")
     2769                     action == "CLEAROSD" || action == "TOGGLEUPMIX")
    27692770            {
    27702771                passThru = 1;
    27712772                handled = false;
    void TV::ProcessKeypress(QKeyEvent *e) 
    27772778        if (!passThru)
    27782779            return;
    27792780    }
    2780 
     2781   
    27812782    if (dialogname != "" && GetOSD() && GetOSD()->DialogShowing(dialogname))
    27822783    {
    27832784        for (unsigned int i = 0; i < actions.size() && !handled; i++)
    void TV::ProcessKeypress(QKeyEvent *e) 
    30363037                return;
    30373038       }
    30383039    }
    3039              
     3040   
    30403041    for (unsigned int i = 0; i < actions.size() && !handled; i++)
    30413042    {
    30423043        QString action = actions[i];
    void TV::ProcessKeypress(QKeyEvent *e) 
    30703071            ChangeTimeStretch(0);   // just display
    30713072        else if (action == "TOGGLESTRETCH")
    30723073            ToggleTimeStretch();
     3074        else if (action == "TOGGLEUPMIX")
     3075            ToggleUpmix();
    30733076        else if (action == "CYCLECOMMSKIPMODE") {
    30743077            SetAutoCommercialSkip((enum commSkipMode)
    30753078                                  ((autoCommercialSkip + 1) % CommSkipModes));
    void TV::ChangeTimeStretch(int dir, bool allowEdit) 
    60546057    }
    60556058}
    60566059
     6060void TV::ToggleUpmix()
     6061{
     6062    AudioOutput *aud = nvp->getAudioOutput();
     6063    if (!aud)
     6064        return;
     6065    QString text;
     6066    if (aud->ToggleUpmix())
     6067        text = tr("Upmixer On");
     6068    else
     6069        text = tr("Upmixer Off");
     6070   
     6071    if (GetOSD() && !browsemode)
     6072        GetOSD()->SetSettingsText(text, 5);
     6073}
     6074   
     6075
    60576076// dir in 10ms jumps
    60586077void TV::ChangeAudioSync(int dir, bool allowEdit)
    60596078{
    void TV::TreeMenuSelected(OSDListTreeType *tree, OSDGenericTree *item) 
    73027321
    73037322        ChangeTimeStretch(0, !floatRead);   // just display
    73047323    }
     7324    else if (action == "TOGGLEUPMIX")
     7325        ToggleUpmix();
    73057326    else if (action.left(11) == "SELECTSCAN_")
    73067327        activenvp->SetScanType((FrameScanType) action.right(1).toInt());
    73077328    else if (action.left(15) == "TOGGLEAUDIOSYNC")
    void TV::BuildOSDTreeMenu(void) 
    75497570    subitem = new OSDGenericTree(item, tr("1.5X"), "ADJUSTSTRETCH1.5",
    75507571                                 (speedX100 == 150) ? 1 : 0, NULL,
    75517572                                 "STRETCHGROUP");
     7573   
     7574    item = new OSDGenericTree(treeMenu, tr("Toggle Upmixer"), "TOGGLEUPMIX");
    75527575
    75537576    // add scan mode override settings to menu
    75547577    FrameScanType scan_type = kScan_Ignore;
  • mythtv/libs/libmythtv/tv_play.h

    diff --git a/mythtv/libs/libmythtv/tv_play.h b/mythtv/libs/libmythtv/tv_play.h
    index 8aa048b..873da6f 100644
    a b class MPUBLIC TV : public QObject 
    314314    void ChangeSpeed(int direction);
    315315    void ToggleTimeStretch(void);
    316316    void ChangeTimeStretch(int dir, bool allowEdit = true);
     317    void ToggleUpmix(void);
    317318    void ChangeAudioSync(int dir, bool allowEdit = true);
    318319    float StopFFRew(void);
    319320    void ChangeFFRew(int direction);
  • mythtv/programs/mythfrontend/globalsettings.cpp

    diff --git a/mythtv/programs/mythfrontend/globalsettings.cpp b/mythtv/programs/mythfrontend/globalsettings.cpp
    index b1012d1..19ecd0e 100644
    a b static HostComboBox *AudioUpmixType() 
    116116    return gc;
    117117}
    118118
     119static HostComboBox *SRCQuality()
     120{
     121    HostComboBox *gc = new HostComboBox("SRCQuality", false);
     122    gc->setLabel(QObject::tr("Sample Rate Conversion"));
     123    gc->addSelection(QObject::tr("Best"), "3", true); // default
     124    gc->addSelection(QObject::tr("Medium"), "2");
     125    gc->addSelection(QObject::tr("Fastest"), "1");
     126    gc->setHelpText(
     127            QObject::tr(
     128                "Set the quality of audio sample rate conversion. "
     129                "All three options offer a worst-case SNR of 97dB. "
     130                "'Best' at a bandwidth of 97%. "
     131                "'Medium' at a bandwidth of 90%. "
     132                "'Fastest' at a bandwidth of 80%. "));
     133    return gc;
     134}
     135
    119136static HostComboBox *PassThroughOutputDevice()
    120137{
    121138    HostComboBox *gc = new HostComboBox("PassThruOutputDevice", true);
    class AudioSettings : public TriggeredConfigurationGroup 
    33073324         agrp->addChild(MaxAudioChannels());
    33083325         agrp->addChild(AudioUpmixType());
    33093326         addChild(agrp);
     3327         
     3328         HorizontalConfigurationGroup *agrp1 =
     3329             new HorizontalConfigurationGroup(false, false, true, true);
     3330         agrp1->addChild(SRCQuality());
     3331         addChild(agrp1);
    33103332
    33113333         VerticalConfigurationGroup *vgrp1 =
    33123334             new VerticalConfigurationGroup(false, false, true, true);
  • mythtv/programs/mythtranscode/transcode.cpp

    diff --git a/mythtv/programs/mythtranscode/transcode.cpp b/mythtv/programs/mythtranscode/transcode.cpp
    index dde8b09..653f9d4 100644
    a b class AudioReencodeBuffer : public AudioOutput 
    3838    AudioReencodeBuffer(int audio_bits, int audio_channels)
    3939    {
    4040        Reset();
    41         Reconfigure(audio_bits, audio_channels, 0, 0);
     41        Reconfigure(audio_bits, audio_channels, CODEC_ID_NONE, 0, 0);
    4242        bufsize = 512000;
    4343        audiobuffer = new unsigned char[bufsize];
    4444
    class AudioReencodeBuffer : public AudioOutput 
    5454    }
    5555
    5656    // reconfigure sound out for new params
    57     virtual void Reconfigure(int audio_bits, int audio_channels,
    58                              int audio_samplerate, bool audio_passthru,
    59                              void *audio_codec = NULL)
     57    virtual void Reconfigure(int audio_bits, int audio_channels, 
     58                             int audio_codec, int audio_samplerate,
     59                             bool audio_passthru)
    6060    {
    6161        (void)audio_samplerate;
    6262        (void)audio_passthru;
    63         (void)audio_codec;
    6463
    6564        ClearError();
    6665        bits = audio_bits;
    class AudioReencodeBuffer : public AudioOutput 
    218217        // Do nothing
    219218        return MUTE_OFF;
    220219    }
     220    virtual bool ToggleUpmix(void)
     221    {
     222        // Do nothing
     223        return false;
     224    }
    221225
    222226    //  These are pure virtual in AudioOutput, but we don't need them here
    223227    virtual void bufferOutputData(bool){ return; }