Ticket #5900: audioencoding-fixes-5.patch

File audioencoding-fixes-5.patch, 86.4 KB (added by foobum@…, 15 years ago)
  • 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..d3b695e 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,
     360    m_output = AudioOutput::OpenAudio(adevice, pdevice, 16, 2, 44100,
    359361                                    AUDIOOUTPUT_MUSIC, true, false);
    360362    m_output->setBufferSize(256 * 1024);
    361363    m_output->SetBlocking(false);
  • mythplugins/mythmusic/mythmusic/playbackbox.cpp

    diff --git a/mythplugins/mythmusic/mythmusic/playbackbox.cpp b/mythplugins/mythmusic/mythmusic/playbackbox.cpp
    index b3a8f61..b9885cb 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() 
    11751177    }
    11761178}
    11771179
     1180void PlaybackBoxMusic::toggleUpmix()
     1181{
     1182    if (gPlayer->getOutput())
     1183        gPlayer->getOutput()->ToggleUpmix();
     1184}
     1185   
     1186
    11781187void PlaybackBoxMusic::showProgressBar()
    11791188{
    11801189    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);
  • mythtv/libs/libmyth/audiooutput.h

    diff --git a/mythtv/libs/libmyth/audiooutput.h b/mythtv/libs/libmyth/audiooutput.h
    index 7d65a51..b88c29f 100644
    a b class MPUBLIC AudioOutput : public VolumeBase, public OutputListeners 
    3434    virtual void Reconfigure(int audio_bits,
    3535                             int audio_channels,
    3636                             int audio_samplerate,
    37                              bool audio_passthru,
    38                              void* audio_codec = NULL) = 0;
     37                             bool audio_passthru) = 0;
    3938   
    4039    virtual void SetStretchFactor(float factor);
    4140    virtual float GetStretchFactor(void) { return 1.0f; }
     41    virtual bool ToggleUpmix(void) = 0;
    4242
    4343    // do AddSamples calls block?
    4444    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..b4bfc96 100644
    a b AudioOutputALSA::AudioOutputALSA( 
    3535AudioOutputALSA::~AudioOutputALSA()
    3636{
    3737    KillAudio();
     38    SetIECStatus(true);
     39}
     40
     41void AudioOutputALSA::SetIECStatus(bool audio) {
     42   
     43    snd_ctl_t *ctl;
     44    const char *spdif_str = SND_CTL_NAME_IEC958("", PLAYBACK, DEFAULT);
     45    int spdif_index = -1;
     46    snd_ctl_elem_list_t *clist;
     47    snd_ctl_elem_id_t *cid;
     48    snd_ctl_elem_value_t *cval;
     49    snd_aes_iec958_t iec958;
     50    int cidx, controls;
     51
     52    VERBOSE(VB_AUDIO, QString("Setting IEC958 status: %1")
     53                      .arg(audio ? "audio" : "non-audio"));
     54   
     55    snd_ctl_open(&ctl, "default", 0);
     56    snd_ctl_elem_list_alloca(&clist);
     57    snd_ctl_elem_list(ctl, clist);
     58    snd_ctl_elem_list_alloc_space(clist, snd_ctl_elem_list_get_count(clist));
     59    snd_ctl_elem_list(ctl, clist);
     60    controls = snd_ctl_elem_list_get_used(clist);
     61    for (cidx = 0; cidx < controls; cidx++)
     62    {
     63        if (!strcmp(snd_ctl_elem_list_get_name(clist, cidx), spdif_str))
     64            if (spdif_index < 0 ||
     65                snd_ctl_elem_list_get_index(clist, cidx) == (uint)spdif_index)
     66                    break;
     67    }
     68    snd_ctl_elem_id_alloca(&cid);
     69    snd_ctl_elem_list_get_id(clist, cidx, cid);
     70    snd_ctl_elem_value_alloca(&cval);
     71    snd_ctl_elem_value_set_id(cval, cid);
     72    snd_ctl_elem_read(ctl,cval);
     73    snd_ctl_elem_value_get_iec958(cval, &iec958);
     74   
     75    if (!audio)
     76        iec958.status[0] |= IEC958_AES0_NONAUDIO;
     77    else
     78        iec958.status[0] &= ~IEC958_AES0_NONAUDIO;
     79
     80    snd_ctl_elem_value_set_iec958(cval, &iec958);
     81    snd_ctl_elem_write(ctl, cval);
     82
    3883}
    3984
    4085bool AudioOutputALSA::OpenDevice()
    bool AudioOutputALSA::OpenDevice() 
    4287    snd_pcm_format_t format;
    4388    unsigned int buffer_time, period_time;
    4489    int err;
     90    QString real_device;
    4591
    4692    if (pcm_handle != NULL)
    4793        CloseDevice();
    4894
    4995    pcm_handle = NULL;
    5096    numbadioctls = 0;
    51 
    52     QString real_device = (audio_passthru) ?
    53         audio_passthru_device : audio_main_device;
     97   
     98    if (audio_passthru || audio_enc)
     99    {
     100        real_device = audio_passthru_device;
     101        SetIECStatus(false);
     102    }
     103    else
     104    {
     105        real_device = audio_main_device;
     106        SetIECStatus(true);
     107    }
    54108
    55109    VERBOSE(VB_GENERAL, QString("Opening ALSA audio device '%1'.")
    56110            .arg(real_device));
  • mythtv/libs/libmyth/audiooutputalsa.h

    diff --git a/mythtv/libs/libmyth/audiooutputalsa.h b/mythtv/libs/libmyth/audiooutputalsa.h
    index 79c923b..1c68f7d 100644
    a b class AudioOutputALSA : public AudioOutputBase 
    3737    virtual inline int getBufferedOnSoundcard(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/audiooutputbase.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputbase.cpp b/mythtv/libs/libmyth/audiooutputbase.cpp
    index 883136d..5bb127c 100644
    a b AudioOutputBase::AudioOutputBase( 
    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    allow_ac3_passthru = gContext->GetNumSetting("AC3PassThru", false);
     91    src_quality = gContext->GetNumSetting("SRCQuality", 2);
    8792
    8893    // You need to call Reconfigure from your concrete class.
    8994    // Reconfigure(laudio_bits,       laudio_channels,
    void AudioOutputBase::SetStretchFactorLocked(float laudio_stretchfactor) 
    124129            VERBOSE(VB_GENERAL, LOC + QString("Using time stretch %1")
    125130                                        .arg(audio_stretchfactor));
    126131            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             }
     132            pSoundStretch->setSampleRate(audio_samplerate);
     133            pSoundStretch->setChannels(upmixer ?
     134                configured_audio_channels : source_audio_channels);
    161135
    162136            pSoundStretch->setTempo(audio_stretchfactor);
    163137            pSoundStretch->setSetting(SETTING_SEQUENCE_MS, 35);
    void AudioOutputBase::SetStretchFactorLocked(float laudio_stretchfactor) 
    165139            // dont need these with only tempo change
    166140            //pSoundStretch->setPitch(1.0);
    167141            //pSoundStretch->setRate(1.0);
    168 
    169142            //pSoundStretch->setSetting(SETTING_USE_QUICKSEEK, true);
    170143            //pSoundStretch->setSetting(SETTING_USE_AA_FILTER, false);
    171144        }
    float AudioOutputBase::GetStretchFactor(void) 
    184157    return audio_stretchfactor;
    185158}
    186159
     160bool AudioOutputBase::ToggleUpmix(void)
     161{
     162    if (audio_passthru)
     163        return false;
     164    if (configured_audio_channels == 6)
     165        configured_audio_channels = 2;
     166    else
     167        configured_audio_channels = 6;
     168   
     169    Reconfigure(audio_bits, source_audio_channels,
     170        source_audio_samplerate, audio_passthru);
     171    return (configured_audio_channels == 6);
     172}
     173
    187174void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels,
    188                                   int laudio_samplerate, bool laudio_passthru,
    189                                   void *laudio_codec)
     175                                  int laudio_samplerate, bool laudio_passthru)
    190176{
    191     int codec_id = CODEC_ID_NONE;
    192     int lcodec_id = CODEC_ID_NONE;
    193     int lcchannels = 0;
    194     int cchannels = 0;
    195177    int lsource_audio_channels = laudio_channels;
    196178    bool lneeds_upmix = false;
    197 
    198     if (laudio_codec)
    199     {
    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;
    206     }
    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))
     179    bool laudio_reenc = false;
     180   
     181    // Are we perhaps reencoding a (previously) timestretched bitstream?
     182    if (laudio_channels > 2 && !laudio_passthru)
     183        laudio_reenc = true;
     184 
     185    // Enough channels? Upmix if not
     186    if (laudio_channels < configured_audio_channels && !laudio_passthru)
    216187    {
    217188        laudio_channels = configured_audio_channels;
    218189        lneeds_upmix = true;
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    225196        laudio_samplerate == audio_samplerate && !need_resampler &&
    226197        laudio_passthru == audio_passthru &&
    227198        lneeds_upmix == needs_upmix &&
    228         lcodec_id == codec_id && lcchannels == cchannels);
     199        laudio_reenc == audio_reenc);
    229200    bool upmix_deps =
    230201        (lsource_audio_channels == source_audio_channels);
    231202    if (general_deps && upmix_deps)
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    252223    waud = raud = 0;
    253224    audio_actually_paused = false;
    254225   
    255     bool redo_stretch = (pSoundStretch && audio_channels != laudio_channels);
    256226    audio_channels = laudio_channels;
    257227    source_audio_channels = lsource_audio_channels;
    258228    audio_bits = laudio_bits;
    259     audio_samplerate = laudio_samplerate;
    260     audio_codec = (AVCodecContext*)laudio_codec;
     229    source_audio_samplerate = audio_samplerate = laudio_samplerate;
     230    audio_reenc = laudio_reenc;
    261231    audio_passthru = laudio_passthru;
    262232    needs_upmix = lneeds_upmix;
    263233
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    268238        Error("AudioOutput only supports 8 or 16bit audio.");
    269239        return;
    270240    }
    271     audio_bytes_per_sample = audio_channels * audio_bits / 8;
    272     source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8;
    273241   
    274242    need_resampler = false;
    275243    killaudio = false;
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    278246    internal_vol = gContext->GetNumSetting("MythControlsVolume", 0);
    279247   
    280248    numlowbuffer = 0;
     249   
     250    // Encode to AC-3 if not passing thru, there's more than 2 channels
     251    // and we're allowed to passthru AC-3
     252    // This won't reencode timestretched 2ch AC-3 but there's no point doing so
     253    if (!audio_passthru && audio_channels > 2 && allow_ac3_passthru)
     254    {
     255        VERBOSE(VB_AUDIO, LOC + "Creating AC-3 Encoder");
     256        int srate = src_quality == 0 ? audio_samplerate : 48000;
     257        encoder = new AudioOutputDigitalEncoder();
     258        if (!encoder->Init(CODEC_ID_AC3, 448000, srate,
     259                           audio_channels, audio_reenc))
     260        {
     261            VERBOSE(VB_AUDIO, LOC + "Can't create AC-3 encoder");
     262            delete encoder;
     263            encoder = NULL;
     264        }
     265       
     266        audio_enc = true;
     267    }       
     268   
     269    if(audio_passthru || audio_enc)
     270        // AC-3 output - soundcard expects a 2ch 48k stream
     271        audio_channels = 2;
     272   
     273    audio_bytes_per_sample = audio_channels * audio_bits / 8;
     274    source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8;
    281275
     276    // Always resample to 48k - many cards can't do anything else
     277    // and ALSA will do it with linear interpolation (yuk) if we don't anyway
     278    if (src_quality != 0 && audio_samplerate != 48000)
     279    {
     280        int error;
     281        audio_samplerate = 48000;
     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, 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   
    282301    VERBOSE(VB_GENERAL, QString("Opening audio device '%1'. ch %2(%3) sr %4")
    283302            .arg(audio_main_device).arg(audio_channels)
    284303            .arg(source_audio_channels).arg(audio_samplerate));
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    314333    current_seconds = -1;
    315334    source_bitrate = -1;
    316335
    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 
    340336    if (needs_upmix)
    341337    {
    342         VERBOSE(VB_AUDIO, LOC + QString("create upmixer"));
    343338        if (configured_audio_channels == 6)
    344339        {
    345340            surround_mode = gContext->GetNumSetting("AudioUpmixType", 2);
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    351346            (FreeSurround::SurroundMode)surround_mode);
    352347
    353348        VERBOSE(VB_AUDIO, LOC +
    354                 QString("create upmixer done with surround mode %1")
     349                QString("Create upmixer done with surround mode %1")
    355350                .arg(surround_mode));
    356351    }
    357352
    358353    VERBOSE(VB_AUDIO, LOC + QString("Audio Stretch Factor: %1")
    359354            .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"));
    363355
    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     }
     356    SetStretchFactorLocked(old_audio_stretchfactor);
    412357
    413358    // Setup visualisations, zero the visualisations buffers
    414359    prepareVisuals();
    void AudioOutputBase::KillAudio() 
    455400    VERBOSE(VB_AUDIO, LOC + "Killing AudioOutputDSP");
    456401    killaudio = true;
    457402    StopOutputThread();
     403   
     404    pthread_mutex_lock(&audio_buflock);
    458405
    459406    // Close resampler?
    460407    if (src_ctx)
     408    {
    461409        src_delete(src_ctx);
     410        src_ctx = NULL;
     411    }
     412               
    462413    need_resampler = false;
    463414
    464415    // close sound stretcher
    void AudioOutputBase::KillAudio() 
    466417    {
    467418        delete pSoundStretch;
    468419        pSoundStretch = NULL;
     420        old_audio_stretchfactor = audio_stretchfactor;
     421        audio_stretchfactor = 1.0;
    469422    }
    470423
    471424    if (encoder)
    void AudioOutputBase::KillAudio() 
    480433        upmixer = NULL;
    481434    }
    482435    needs_upmix = false;
     436    audio_enc = false;
    483437
    484438    CloseDevice();
    485439
     440    pthread_mutex_unlock(&audio_buflock);
    486441    killAudioLock.unlock();
    487442}
    488443
    int AudioOutputBase::GetAudiotime(void) 
    591546    ret += (now.tv_usec - audiotime_updated.tv_usec) / 1000;
    592547    ret = (long long)(ret * audio_stretchfactor);
    593548
    594 #if 1
    595549    VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    596550            QString("GetAudiotime now=%1.%2, set=%3.%4, ret=%5, audt=%6 sf=%7")
    597551            .arg(now.tv_sec).arg(now.tv_usec)
    int AudioOutputBase::GetAudiotime(void) 
    600554            .arg(audiotime)
    601555            .arg(audio_stretchfactor)
    602556           );
    603 #endif
    604557
    605558    ret += audiotime;
    606559
    void AudioOutputBase::SetAudiotime(void) 
    638591 
    639592    soundcard_buffer = getBufferedOnSoundcard(); // bytes
    640593    totalbuffer = audiolen(false) + soundcard_buffer;
    641  
     594
    642595    // include algorithmic latencies
    643596    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
    650597        totalbuffer += (int)((pSoundStretch->numUnprocessedSamples() *
    651598                              audio_bytes_per_sample) / audio_stretchfactor);
    652     }
    653599
    654600    if (upmixer && needs_upmix)
    655     {
    656601        totalbuffer += upmixer->sampleLatency() * audio_bytes_per_sample;
    657     }
     602
     603    if (encoder)
     604        totalbuffer += encoder->Buffered();
    658605
    659606    audiotime = audbuf_timecode - (int)(totalbuffer * 100000.0 /
    660607                                   (audio_bytes_per_sample * effdspstretched));
    661608 
    662609    gettimeofday(&audiotime_updated, NULL);
    663 #if 1
     610   
    664611    VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    665612            QString("SetAudiotime set=%1.%2, audt=%3 atc=%4 "
    666613                    "tb=%5 sb=%6 eds=%7 abps=%8 sf=%9")
    void AudioOutputBase::SetAudiotime(void) 
    672619            .arg(effdspstretched)
    673620            .arg(audio_bytes_per_sample)
    674621            .arg(audio_stretchfactor));
    675 #endif
    676622
    677623    pthread_mutex_unlock(&avsync_lock);
    678624    pthread_mutex_unlock(&audio_buflock);
    bool AudioOutputBase::AddSamples(char *buffers[], int samples, 
    686632    int abps = (encoder) ?
    687633        encoder->audio_bytes_per_sample : audio_bytes_per_sample;
    688634    int len = samples * abps;
    689 
     635 
    690636    // Check we have enough space to write the data
    691637    if (need_resampler && src_ctx)
    692638        len = (int)ceilf(float(len) * src_data.src_ratio);
    bool AudioOutputBase::AddSamples(char *buffers[], int samples, 
    708654
    709655        return false; // would overflow
    710656    }
     657   
     658    pthread_mutex_lock(&audio_buflock);
    711659
    712660    // resample input if necessary
    713661    if (need_resampler && src_ctx)
    bool AudioOutputBase::AddSamples(char *buffers[], int samples, 
    741689        // Call our function to do the work
    742690        _AddSamples(buffers, false, samples, timecode);
    743691    }
     692   
     693    pthread_mutex_unlock(&audio_buflock);
    744694
    745695    return true;
    746696}
    bool AudioOutputBase::AddSamples(char *buffer, int samples, long long timecode) 
    753703    int abps = (encoder) ?
    754704        encoder->audio_bytes_per_sample : audio_bytes_per_sample;
    755705    int len = samples * abps;
     706 
     707    // Give original samples to mythmusic visualisation
     708    dispatchVisual((unsigned char *)buffer, len, timecode,
     709                   source_audio_channels, audio_bits);
    756710
    757711    // Check we have enough space to write the data
    758712    if (need_resampler && src_ctx)
    bool AudioOutputBase::AddSamples(char *buffer, int samples, long long timecode) 
    776730                .arg(timecode));
    777731        return false; // would overflow
    778732    }
     733   
     734    pthread_mutex_lock(&audio_buflock);
    779735
    780736    // resample input if necessary
    781737    if (need_resampler && src_ctx)
    bool AudioOutputBase::AddSamples(char *buffer, int samples, long long timecode) 
    804760        // Call our function to do the work
    805761        _AddSamples(buffer, true, samples, timecode);
    806762    }
     763   
     764    pthread_mutex_unlock(&audio_buflock);
    807765
    808766    return true;
    809767}
    int AudioOutputBase::WaitForFreeSpace(int samples) 
    836794            if (src_ctx)
    837795            {
    838796                int error = src_reset(src_ctx);
    839                 if (error)
     797                if (error)
     798                {
    840799                    VERBOSE(VB_IMPORTANT, LOC_ERR + QString(
    841800                            "Error occured while resetting resampler: %1")
    842801                            .arg(src_strerror(error)));
     802                    src_ctx = NULL;
     803                }
    843804            }
    844805        }
    845806    }
    int AudioOutputBase::WaitForFreeSpace(int samples) 
    849810void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples,
    850811                                  long long timecode)
    851812{
    852     pthread_mutex_lock(&audio_buflock);
    853 
    854813    int len; // = samples * audio_bytes_per_sample;
    855814    int audio_bytes = audio_bits / 8;
    856815    int org_waud = waud;
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    867826            .arg(samples * abps)
    868827            .arg(AUDBUFSIZE-afree).arg(afree).arg(timecode)
    869828            .arg(needs_upmix));
     829
     830    len = WaitForFreeSpace(samples);
    870831   
    871832    if (upmixer && needs_upmix)
    872833    {
    873834        int out_samples = 0;
     835        org_waud = waud;
    874836        int step = (interleaved)?source_audio_channels:1;
    875         len = WaitForFreeSpace(samples);    // test
     837       
    876838        for (int itemp = 0; itemp < samples; )
    877839        {
    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);
    881840            if (audio_bytes == 2)
    882841            {
    883842                itemp += upmixer->putSamples(
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    894853                    source_audio_channels,
    895854                    (interleaved) ? 0 : samples);
    896855            }
    897             pthread_mutex_lock(&audio_buflock);
    898856
    899857            int copy_samples = upmixer->numSamples();
    900858            if (copy_samples)
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    913871                        (short*)(audiobuffer), (copy_samples - bdiff_samples));
    914872                }
    915873                else
    916                 {
    917874                    upmixer->receiveSamples(
    918875                        (short*)(audiobuffer + org_waud), copy_samples);
    919                 }
     876               
    920877                org_waud = (org_waud + copy_len) % AUDBUFSIZE;
    921878            }
    922879        }
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    928885    }
    929886    else
    930887    {
    931         len = WaitForFreeSpace(samples);
    932 
    933888        if (interleaved)
    934889        {
    935890            char *mybuf = (char*)buffer;
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    964919            }
    965920        }
    966921    }
    967 
    968     if (samples > 0)
     922   
     923    if (samples <= 0)
     924        return;
     925   
     926    if (pSoundStretch)
    969927    {
    970         if (pSoundStretch)
     928        // does not change the timecode, only the number of samples
     929        // back to orig pos
     930        org_waud = waud;
     931        int bdiff = AUDBUFSIZE - org_waud;
     932        int nSamplesToEnd = bdiff/abps;
     933        if (bdiff < len)
    971934        {
     935            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
     936                                      (audiobuffer +
     937                                       org_waud), nSamplesToEnd);
     938            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer,
     939                                      (len - bdiff) / abps);
     940        }
     941        else
     942            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
     943                                      (audiobuffer + org_waud),
     944                                      len / abps);
    972945
    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);
    991             }
    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                 }
     946        int nSamples = pSoundStretch->numSamples();
     947        len = WaitForFreeSpace(nSamples);
     948       
     949        while ((nSamples = pSoundStretch->numSamples()))
     950        {
     951            if (nSamples > nSamplesToEnd)
     952                nSamples = nSamplesToEnd;
     953           
     954            nSamples = pSoundStretch->receiveSamples(
     955                (soundtouch::SAMPLETYPE*)
     956                (audiobuffer + org_waud), nSamples
     957            );
     958           
     959            if (nSamples == nSamplesToEnd) {
     960                org_waud = 0;
     961                nSamplesToEnd = AUDBUFSIZE/abps;
    1039962            }
    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);
     963            else {
     964                org_waud += nSamples * abps;
     965                nSamplesToEnd -= nSamples;
    1071966            }
     967           
    1072968        }
     969       
     970    }
    1073971
    1074         waud = org_waud;
    1075         lastaudiolen = audiolen(false);
     972    // Encode to AC-3?
     973    if (encoder)
     974    {
     975       
     976        org_waud = waud;
     977        int bdiff = AUDBUFSIZE - org_waud;
     978        int to_get = 0;
    1076979
    1077         if (timecode < 0)
     980        if (bdiff < len)
    1078981        {
    1079             // mythmusic doesn't give timestamps..
    1080             timecode = (int)((samples_buffered * 100000.0) / effdsp);
     982            encoder->Encode(audiobuffer + org_waud, bdiff);
     983            to_get = encoder->Encode(audiobuffer, len - bdiff);
    1081984        }
     985        else
     986            to_get = encoder->Encode(audiobuffer + org_waud, len);
    1082987       
    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)
     988        if (to_get > 0)
    1092989        {
    1093             dispatchVisual((unsigned char *)buffer, len, timecode,
    1094                            source_audio_channels, audio_bits);
     990           
     991            if (to_get >= bdiff)
     992            {
     993                encoder->GetFrames(audiobuffer + org_waud, bdiff);
     994                to_get -= bdiff;
     995                org_waud = 0;
     996            }
     997            if (to_get > 0)
     998                encoder->GetFrames(audiobuffer + org_waud, to_get);
     999
     1000            org_waud += to_get;
     1001
    10951002        }
     1003
    10961004    }
    10971005
    1098     pthread_mutex_unlock(&audio_buflock);
     1006    waud = org_waud;
     1007    lastaudiolen = audiolen(false);
     1008
     1009    if (timecode < 0)
     1010        // mythmusic doesn't give timestamps..
     1011        timecode = (int)((samples_buffered * 100000.0) / effdsp);
     1012   
     1013    samples_buffered += samples;
     1014   
     1015    /* we want the time at the end -- but the file format stores
     1016       time at the start of the chunk. */
     1017    // even with timestretch, timecode is still calculated from original
     1018    // sample count
     1019    audbuf_timecode = timecode + (int)((samples * 100000.0) / effdsp);
     1020
    10991021}
    11001022
    11011023void AudioOutputBase::Status()
  • mythtv/libs/libmyth/audiooutputbase.h

    diff --git a/mythtv/libs/libmyth/audiooutputbase.h b/mythtv/libs/libmyth/audiooutputbase.h
    index d60c687..3a2e9e9 100644
    a b class AudioOutputBase : public AudioOutput 
    4848    virtual void Reconfigure(int   audio_bits,
    4949                             int   audio_channels,
    5050                             int   audio_samplerate,
    51                              bool  audio_passthru,
    52                              void *audio_codec = NULL);
     51                             bool  audio_passthru);
    5352   
    5453    // do AddSamples calls block?
    5554    virtual void SetBlocking(bool blocking);
    class AudioOutputBase : public AudioOutput 
    5958
    6059    virtual void SetStretchFactor(float factor);
    6160    virtual float GetStretchFactor(void);
     61    virtual bool ToggleUpmix(void);
    6262
    6363    virtual void Reset(void);
    6464
    class AudioOutputBase : public AudioOutput 
    139139    QString audio_passthru_device;
    140140
    141141    bool audio_passthru;
     142    bool audio_enc;
     143    bool audio_reenc;
    142144
    143145    float audio_stretchfactor;
    144     AVCodecContext *audio_codec;
    145146    AudioOutputSource source;
    146147
    147148    bool killaudio;
    class AudioOutputBase : public AudioOutput 
    151152    bool buffer_output_data_for_use; //  used by AudioOutputNULL
    152153   
    153154    int configured_audio_channels;
     155    int src_quality;
    154156
    155157 private:
    156158    // resampler
    class AudioOutputBase : public AudioOutput 
    167169    FreeSurround              *upmixer;
    168170
    169171    int source_audio_channels;
     172    int source_audio_samplerate;
    170173    int source_audio_bytes_per_sample;
    171174    bool needs_upmix;
    172175    int surround_mode;
     176    bool allow_ac3_passthru;
     177    float old_audio_stretchfactor;
    173178
    174179    bool blocking; // do AddSamples calls block?
    175180
  • mythtv/libs/libmyth/audiooutputdigitalencoder.cpp

    diff --git a/mythtv/libs/libmyth/audiooutputdigitalencoder.cpp b/mythtv/libs/libmyth/audiooutputdigitalencoder.cpp
    index 40c4acb..5bd2c01 100644
    a b extern "C" { 
    2727
    2828AudioOutputDigitalEncoder::AudioOutputDigitalEncoder(void) :
    2929    av_context(NULL),
    30     outbuf(NULL),
    31     outbuf_size(0),
    32     frame_buffer(NULL),
    33     one_frame_bytes(0)
     30    outbuflen(0),
     31    inbuflen(0),
     32    one_frame_bytes(0),
     33    reorder(true)
    3434{
    3535}
    3636
    void AudioOutputDigitalEncoder::Dispose() 
    4747        av_free(av_context);
    4848        av_context = NULL;
    4949    }
    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     }
    6450}
    6551
    6652//CODEC_ID_AC3
    6753bool AudioOutputDigitalEncoder::Init(
    68     CodecID codec_id, int bitrate, int samplerate, int channels)
     54    CodecID codec_id, int bitrate, int samplerate, int channels, bool reencoding)
    6955{
    7056    AVCodec *codec;
    7157    int ret;
    7258
    73     VERBOSE(VB_AUDIO, LOC + QString("Init codecid=%1, br=%2, sr=%3, ch=%4")
     59    VERBOSE(VB_AUDIO, LOC + QString("Init codecid=%1, br=%2, sr=%3, ch=%4 re=%5")
    7460            .arg(codec_id_string(codec_id))
    7561            .arg(bitrate)
    7662            .arg(samplerate)
    77             .arg(channels));
    78 
    79     //codec = avcodec_find_encoder(codec_id);
     63            .arg(channels)
     64            .arg(reencoding));
     65   
     66    reorder = !reencoding;
     67
     68    // We need to do this when called from mythmusic
     69    avcodec_init();
     70    avcodec_register_all();
    8071    // always AC3 as there is no DTS encoder at the moment 2005/1/9
    8172    codec = avcodec_find_encoder(CODEC_ID_AC3);
    8273    if (!codec)
    bool AudioOutputDigitalEncoder::Init( 
    10596    audio_bytes_per_sample = bytes_per_frame;
    10697    one_frame_bytes = bytes_per_frame * av_context->frame_size;
    10798
    108     outbuf_size = 16384;    // ok for AC3 but DTS?
    109     outbuf = new char [outbuf_size];
    11099    VERBOSE(VB_AUDIO, QString("DigitalEncoder::Init fs=%1, bpf=%2 ofb=%3")
    111100            .arg(av_context->frame_size)
    112101            .arg(bytes_per_frame)
    typedef struct { 
    256245
    257246} AESHeader;
    258247
     248
     249void reorder_6ch_ac3(void *buf, unsigned int len) {
     250    unsigned short *src = (unsigned short *)buf;
     251    unsigned short tmp;
     252    unsigned int samples = len >> 1;
     253
     254    for (uint i = 0; i < samples; i += 6) {
     255        tmp = src[i+4];
     256        src[i+4] = src[i+3];
     257        src[i+3] = src[i+2];
     258        src[i+2] = src[i+1];
     259        src[i+1] = tmp;
     260    }
     261}
     262
    259263static int encode_frame(
    260264        bool dts,
    261265        unsigned char *data,
    262         size_t &len)
     266        size_t enc_len)
    263267{
    264     size_t enc_len;
    265268    int flags, sample_rate, bit_rate;
    266269
    267270    // we don't do any length/crc validation of the AC3 frame here; presumably
    static int encode_frame( 
    273276    // anything with a bad CRC...
    274277
    275278    uint nr_samples = 0, block_len;
     279   
    276280    if (dts)
    277281    {
    278282        enc_len = dts_syncinfo(data+8, &flags, &sample_rate, &bit_rate);
    static int encode_frame( 
    293297#endif
    294298    }
    295299
    296     if (enc_len == 0 || enc_len > len)
    297     {
    298         int l = len;
    299         len = 0;
    300         return l;
    301     }
    302 
    303300    enc_len = min((uint)enc_len, block_len - 8);
    304 
     301   
    305302    //uint32_t x = *(uint32_t*)(data+8);
    306303    // in place swab
    307304    swab((const char *)data + 8, (char *)data + 8, enc_len);
    static int encode_frame( 
    348345                break;
    349346        }
    350347    }
    351     data[5] = 0x00;
     348    data[5] = 0;
    352349    data[6] = (enc_len << 3) & 0xFF;
    353350    data[7] = (enc_len >> 5) & 0xFF;
    354351    memset(data + 8 + enc_len, 0, block_len - 8 - enc_len);
    355     len = block_len;
    356352
    357353    return enc_len;
    358354}
    359355
    360 // must have exactly 1 frames worth of data
    361 size_t AudioOutputDigitalEncoder::Encode(short *buff)
     356size_t AudioOutputDigitalEncoder::Encode(void *buf, int len)
    362357{
    363     int encsize = 0;
    364358    size_t outsize = 0;
    365359 
    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);
     360    int fs = FrameSize();
     361    memcpy(inbuf+inbuflen, buf, len);
     362    inbuflen += len;
     363    int frames = inbuflen / fs;
    369364
    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);
     365    while (frames--)
     366    {
     367        if (reorder)
     368            reorder_6ch_ac3(inbuf, fs);
     369       
     370        // put data in the correct spot for encode frame
     371        outsize = avcodec_encode_audio(
     372            av_context, ((uchar*)outbuf) + outbuflen + 8, OUTBUFSIZE - 8, (short int *)inbuf);
     373
     374        encode_frame(
     375            /*av_context->codec_id==CODEC_ID_DTS*/ false,
     376            (unsigned char*)outbuf + outbuflen, outsize
     377        );
     378
     379        outbuflen += MAX_AC3_FRAME_SIZE;
     380        inbuflen -= fs;
     381        memmove(inbuf, inbuf+fs, inbuflen);
     382    }
    376383
    377     VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    378             QString("DigitalEncoder::Encode len1=%1 len2=%2 finallen=%3")
    379                 .arg(tmpsize).arg(encsize).arg(outsize));
     384    return outbuflen;
     385}
    380386
    381     return outsize;
     387void AudioOutputDigitalEncoder::GetFrames(void *ptr, int maxlen)
     388{
     389    int len = (maxlen < outbuflen ? maxlen : outbuflen);
     390    memcpy(ptr, outbuf, len);
     391    outbuflen -= len;
     392    memmove(outbuf, outbuf+len, outbuflen);
    382393}
  • mythtv/libs/libmyth/audiooutputdigitalencoder.h

    diff --git a/mythtv/libs/libmyth/audiooutputdigitalencoder.h b/mythtv/libs/libmyth/audiooutputdigitalencoder.h
    index 8a4689a..47e19af 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, bool reencoding);
    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;
     35    bool            reorder;
    3136};
    3237
    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 
    4138#endif
  • mythtv/libs/libmythfreesurround/el_processor.cpp

    diff --git a/mythtv/libs/libmythfreesurround/el_processor.cpp b/mythtv/libs/libmythfreesurround/el_processor.cpp
    index 8f24737..1cf0dc8 100644
    a b typedef std::complex<float> cfloat; 
    4040
    4141const float PI = 3.141592654;
    4242const 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
     43const float center_level = 0.5*sqrt(0.5);
    5444
    5545// private implementation of the surround decoder
    5646class decoder_impl {
    public: 
    9888            outbuf[c].resize(N);
    9989            filter[c].resize(N);
    10090        }
    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         }
    10891        sample_rate(48000);
    10992        // generate the window function (square root of hann, b/c it is applied before and after the transform)
    11093        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);
     94        for (unsigned k=0;k<N;k++)
     95            wnd[k] = sqrt(0.5*(1-cos(2*PI*k/N))/N);
    11496        current_buf = 0;
    11597        // set the default coefficients
    11698        surround_coefficients(0.8165,0.5774);
    public: 
    192174    // set lfe filter params
    193175    void sample_rate(unsigned int srate) {
    194176        // lfe filter is just straight through band limited
    195         unsigned int cutoff = (250*N)/srate;
     177        unsigned int cutoff = (30*N)/srate;
    196178        for (unsigned f=0;f<=halfN;f++) {           
    197             if ((f>=2) && (f<cutoff))
    198                 filter[5][f] = 1.0;
     179            if (f<cutoff)
     180                filter[5][f] = 0.5*sqrt(0.5);
    199181            else
    200182                filter[5][f] = 0.0;
    201183        }
    public: 
    214196        E = (o+v)*n; F = (o+u)*n; G = (o-v)*n;  H = (o-u)*n;
    215197    }
    216198
    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 
    223199    // set the phase shifting mode
    224200    void phase_mode(unsigned mode) {
    225201        const float modes[4][2] = {{0,0},{0,PI},{PI,0},{-PI/2,PI/2}};
    private: 
    290266
    291267        // 2. compare amplitude and phase of each DFT bin and produce the X/Y coordinates in the sound field
    292268        //    but dont do DC or N/2 component
    293         for (unsigned f=2;f<halfN;f++) {           
     269        for (unsigned f=0;f<halfN;f++) {           
    294270            // get left/right amplitudes/phases
    295271            float ampL = amplitude(dftL[f]), ampR = amplitude(dftR[f]);
    296272            float phaseL = phase(dftL[f]), phaseR = phase(dftR[f]);
    private: 
    305281            phaseDiff = abs(phaseDiff);
    306282
    307283            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 
    343284                // --- this is the fancy new linear mode ---
    344285
    345286                // get sound field x/y position
    private: 
    597538    float surround_high,surround_low;  // high and low surround mixing coefficient (e.g. 0.8165/0.5774)
    598539    float surround_balance;            // the xfs balance that follows from the coeffs
    599540    float surround_level;              // gain for the surround channels (follows from the coeffs
    600     float master_gain;                 // gain for all channels
    601541    float phase_offsetL, phase_offsetR;// phase shifts to be applied to the rear channels
    602542    float front_separation;            // front stereo separation
    603543    float rear_separation;             // rear stereo separation
    void fsurround_decoder::flush() { impl->flush(); } 
    625565
    626566void fsurround_decoder::surround_coefficients(float a, float b) { impl->surround_coefficients(a,b); }
    627567
    628 void fsurround_decoder::gain(float gain) { impl->surround_gain(gain); }
    629 
    630568void fsurround_decoder::phase_mode(unsigned mode) { impl->phase_mode(mode); }
    631569
    632570void 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/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 d61ec62..d409409 100644
    a b NuppelVideoPlayer::NuppelVideoPlayer(QString inUseID, const ProgramInfo *info) 
    209209      audio_passthru_device(QString::null),
    210210      audio_channels(2),            audio_bits(-1),
    211211      audio_samplerate(44100),      audio_stretchfactor(1.0f),
    212       audio_codec(NULL),
    213212      // Picture-in-Picture
    214213      pipplayer(NULL), setpipplayer(NULL), needsetpipplayer(false),
    215214      // Preview window support
    QString NuppelVideoPlayer::ReinitAudio(void) 
    804803    if (audioOutput)
    805804    {
    806805        audioOutput->Reconfigure(audio_bits, audio_channels,
    807                                  audio_samplerate, audio_passthru,
    808                                  audio_codec);
     806                                 audio_samplerate, audio_passthru);
     807        if (audio_passthru)
     808            audio_channels = 2;
    809809        errMsg = audioOutput->GetError();
    810810        if (!errMsg.isEmpty())
    811811            audioOutput->SetStretchFactor(audio_stretchfactor);
    void NuppelVideoPlayer::SetAudioParams(int bps, int channels, 
    37183718    audio_passthru = passthru;
    37193719}
    37203720
    3721 void NuppelVideoPlayer::SetAudioCodec(void *ac)
    3722 {
    3723     audio_codec = ac;
    3724 }
    3725 
    37263721void NuppelVideoPlayer::SetEffDsp(int dsprate)
    37273722{
    37283723    if (audioOutput)
  • mythtv/libs/libmythtv/NuppelVideoPlayer.h

    diff --git a/mythtv/libs/libmythtv/NuppelVideoPlayer.h b/mythtv/libs/libmythtv/NuppelVideoPlayer.h
    index 5f3d2ac..a6d2d7a 100644
    a b class MPUBLIC NuppelVideoPlayer : public CC608Reader, public CC708Reader 
    685685    int      audio_bits;
    686686    int      audio_samplerate;
    687687    float    audio_stretchfactor;
    688     void    *audio_codec;
    689688    bool     audio_passthru;
    690689
    691690    // Picture-in-Picture
  • mythtv/libs/libmythtv/avformatdecoder.cpp

    diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
    index ead8ebf..6bbd577 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::AutoSelectAudioTrack(void) 
    28292829    {
    28302830        int idx = atracks[i].av_stream_index;
    28312831        AVCodecContext *codec_ctx = ic->streams[idx]->codec;
    2832         bool do_ac3_passthru = (allow_ac3_passthru && !transcoding &&
    2833                                 !disable_passthru &&
    2834                                 (codec_ctx->codec_id == CODEC_ID_AC3));
    2835         bool do_dts_passthru = (allow_dts_passthru && !transcoding &&
    2836                                 !disable_passthru &&
    2837                                 (codec_ctx->codec_id == CODEC_ID_DTS));
    28382832        AudioInfo item(codec_ctx->codec_id,
    28392833                       codec_ctx->sample_rate, codec_ctx->channels,
    2840                        do_ac3_passthru || do_dts_passthru);
     2834                       DoPassThrough(codec_ctx));
    28412835        VERBOSE(VB_AUDIO, LOC + " * " + item.toString());
    28422836    }
    28432837#endif
    static void extract_mono_channel(uint channel, AudioInfo *audioInfo, 
    29712965bool AvFormatDecoder::GetFrame(int onlyvideo)
    29722966{
    29732967    AVPacket *pkt = NULL;
     2968    AC3HeaderInfo hdr;
    29742969    int len;
    29752970    unsigned char *ptr;
    29762971    int data_size = 0;
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    31573152        pts = 0;
    31583153
    31593154        AVStream *curstream = ic->streams[pkt->stream_index];
     3155        AVCodecContext *ctx = curstream->codec;
    31603156
    31613157        if (pkt->dts != (int64_t)AV_NOPTS_VALUE)
    31623158            pts = (long long)(av_q2d(curstream->time_base) * pkt->dts * 1000);
    31633159
    31643160        if (ringBuffer->isDVD() &&
    3165             curstream->codec->codec_type == CODEC_TYPE_VIDEO)
     3161            ctx->codec_type == CODEC_TYPE_VIDEO)
    31663162        {
    31673163            MpegPreProcessPkt(curstream, pkt);
    31683164
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    31903186
    31913187            if (!d->HasMPEG2Dec())
    31923188            {
    3193                 int current_width = curstream->codec->width;
     3189                int current_width = ctx->width;
    31943190                int video_width = GetNVP()->GetVideoSize().width();
    31953191                if (dvd_xvmc_enabled && GetNVP() && GetNVP()->getVideoOutput())
    31963192                {
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    32313227        }
    32323228
    32333229        if (storevideoframes &&
    3234             curstream->codec->codec_type == CODEC_TYPE_VIDEO)
     3230            ctx->codec_type == CODEC_TYPE_VIDEO)
    32353231        {
    32363232            av_dup_packet(pkt);
    32373233            storedPackets.append(pkt);
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    32393235            continue;
    32403236        }
    32413237
    3242         if (len > 0 && curstream->codec->codec_type == CODEC_TYPE_VIDEO &&
     3238        if (len > 0 && ctx->codec_type == CODEC_TYPE_VIDEO &&
    32433239            pkt->stream_index == selectedVideoIndex)
    32443240        {
    3245             AVCodecContext *context = curstream->codec;
    32463241
    3247             if (context->codec_id == CODEC_ID_MPEG1VIDEO ||
    3248                 context->codec_id == CODEC_ID_MPEG2VIDEO ||
    3249                 context->codec_id == CODEC_ID_MPEG2VIDEO_XVMC ||
    3250                 context->codec_id == CODEC_ID_MPEG2VIDEO_XVMC_VLD)
     3242            if (ctx->codec_id == CODEC_ID_MPEG1VIDEO ||
     3243                ctx->codec_id == CODEC_ID_MPEG2VIDEO ||
     3244                ctx->codec_id == CODEC_ID_MPEG2VIDEO_XVMC ||
     3245                ctx->codec_id == CODEC_ID_MPEG2VIDEO_XVMC_VLD)
    32513246            {
    32523247                if (!ringBuffer->isDVD())
    32533248                    MpegPreProcessPkt(curstream, pkt);
    32543249            }
    3255             else if (context->codec_id == CODEC_ID_H264)
     3250            else if (ctx->codec_id == CODEC_ID_H264)
    32563251            {
    32573252                H264PreProcessPkt(curstream, pkt);
    32583253            }
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    32983293        }
    32993294
    33003295        if (len > 0 &&
    3301             curstream->codec->codec_type == CODEC_TYPE_DATA &&
    3302             curstream->codec->codec_id   == CODEC_ID_MPEG2VBI)
     3296            ctx->codec_type == CODEC_TYPE_DATA &&
     3297            ctx->codec_id   == CODEC_ID_MPEG2VBI)
    33033298        {
    33043299            ProcessVBIDataPacket(curstream, pkt);
    33053300
    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_DVB_VBI)
     3306            ctx->codec_type == CODEC_TYPE_DATA &&
     3307            ctx->codec_id   == CODEC_ID_DVB_VBI)
    33133308        {
    33143309            ProcessDVBDataPacket(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_DSMCC_B)
     3316            ctx->codec_type == CODEC_TYPE_DATA &&
     3317            ctx->codec_id   == CODEC_ID_DSMCC_B)
    33233318        {
    33243319            ProcessDSMCCPacket(curstream, pkt);
    33253320
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    33393334        }
    33403335
    33413336        // we don't care about other data streams
    3342         if (curstream->codec->codec_type == CODEC_TYPE_DATA)
     3337        if (ctx->codec_type == CODEC_TYPE_DATA)
    33433338        {
    33443339            av_free_packet(pkt);
    33453340            continue;
    33463341        }
    33473342
    3348         if (!curstream->codec->codec)
     3343        if (!ctx->codec)
    33493344        {
    33503345            VERBOSE(VB_PLAYBACK, LOC +
    33513346                    QString("No codec for stream index %1, type(%2) id(%3:%4)")
    33523347                    .arg(pkt->stream_index)
    3353                     .arg(codec_type_string(curstream->codec->codec_type))
    3354                     .arg(codec_id_string(curstream->codec->codec_id))
    3355                     .arg(curstream->codec->codec_id));
     3348                    .arg(codec_type_string(ctx->codec_type))
     3349                    .arg(codec_id_string(ctx->codec_id))
     3350                    .arg(ctx->codec_id));
    33563351            av_free_packet(pkt);
    33573352            continue;
    33583353        }
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    33613356        have_err = false;
    33623357
    33633358        avcodeclock.lock();
    3364         int ctype  = curstream->codec->codec_type;
     3359        int ctype  = ctx->codec_type;
    33653360        int audIdx = selectedTrack[kTrackTypeAudio].av_stream_index;
    33663361        int audSubIdx = selectedTrack[kTrackTypeAudio].av_substream_index;
    33673362        int subIdx = selectedTrack[kTrackTypeSubtitle].av_stream_index;
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    33863381
    33873382                    // detect switches between stereo and dual languages
    33883383                    bool wasDual = audSubIdx != -1;
    3389                     bool isDual = curstream->codec->avcodec_dual_language;
     3384                    bool isDual = ctx->avcodec_dual_language;
    33903385                    if ((wasDual && !isDual) || (!wasDual &&  isDual))
    33913386                    {
    33923387                        SetupAudioStreamSubIndexes(audIdx);
    33933388                        reselectAudioTrack = true;
    33943389                    }                           
    33953390
    3396                     bool do_ac3_passthru =
    3397                         (allow_ac3_passthru && !transcoding &&
    3398                          (curstream->codec->codec_id == CODEC_ID_AC3));
    3399                     bool do_dts_passthru =
    3400                         (allow_dts_passthru && !transcoding &&
    3401                          (curstream->codec->codec_id == CODEC_ID_DTS));
    3402                     bool using_passthru = do_ac3_passthru || do_dts_passthru;
    3403 
    34043391                    // detect channels on streams that need
    34053392                    // to be decoded before we can know this
    34063393                    bool already_decoded = false;
    3407                     if (!curstream->codec->channels)
     3394                    if (!ctx->channels)
    34083395                    {
    34093396                        QMutexLocker locker(&avcodeclock);
    34103397                        VERBOSE(VB_IMPORTANT, LOC +
    34113398                                QString("Setting channels to %1")
    34123399                                .arg(audioOut.channels));
    34133400
    3414                         if (using_passthru)
     3401                        if (DoPassThrough(ctx))
    34153402                        {
    34163403                            // for passthru let it select the max number
    34173404                            // of channels
    3418                             curstream->codec->channels = 0;
    3419                             curstream->codec->request_channels = 0;
     3405                            ctx->channels = 0;
     3406                            ctx->request_channels = 0;
    34203407                        }
    34213408                        else
    34223409                        {
    3423                             curstream->codec->channels = audioOut.channels;
    3424                             curstream->codec->request_channels =
     3410                            ctx->channels = audioOut.channels;
     3411                            ctx->request_channels =
    34253412                                audioOut.channels;
    34263413                        }
    34273414                        ret = avcodec_decode_audio(
    3428                             curstream->codec, audioSamples,
     3415                            ctx, audioSamples,
    34293416                            &data_size, ptr, len);
    34303417                        already_decoded = true;
    34313418
    3432                         reselectAudioTrack |= curstream->codec->channels;
     3419                        reselectAudioTrack |= ctx->channels;
     3420                    }
     3421
     3422                    if (ctx->codec_id == CODEC_ID_AC3 &&
     3423                        !ff_ac3_parse_header(ptr, &hdr))
     3424                    {
     3425                        if (hdr.channels != last_ac3_channels)
     3426                        {
     3427                            last_ac3_channels = ctx->channels = hdr.channels;
     3428                            SetupAudioStream();
     3429                        }
    34333430                    }
    34343431
    34353432                    if (reselectAudioTrack)
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    34453442                            .av_stream_index;
    34463443                        audSubIdx = selectedTrack[kTrackTypeAudio]
    34473444                            .av_substream_index;
     3445                        ctx = curstream->codec;
    34483446                    }
    34493447
    34503448                    if (firstloop && pkt->pts != (int64_t)AV_NOPTS_VALUE)
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    34763474                    if (audioOut.do_passthru)
    34773475                    {
    34783476                        data_size = pkt->size;
    3479                         bool dts = CODEC_ID_DTS == curstream->codec->codec_id;
     3477                        bool dts = CODEC_ID_DTS == ctx->codec_id;
    34803478                        ret = encode_frame(dts, ptr, len,
    34813479                                           audioSamples, data_size);
    34823480                    }
    34833481                    else
    34843482                    {
    3485                         AVCodecContext *ctx = curstream->codec;
    3486 
    34873483                        if ((ctx->channels == 0) ||
    34883484                            (ctx->channels > audioOut.channels))
    34893485                        {
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    34923488
    34933489                        if (!already_decoded)
    34943490                        {
    3495                             curstream->codec->request_channels =
    3496                                 audioOut.channels;
     3491                            ctx->request_channels = audioOut.channels;
    34973492                            ret = avcodec_decode_audio(
    34983493                                ctx, audioSamples, &data_size, ptr, len);
    34993494                        }
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    35103505                            audIdx = -1;
    35113506                            AutoSelectAudioTrack();
    35123507                            data_size = 0;
     3508                            ctx = curstream->codec;
    35133509                        }
    35143510                    }
    35153511                    avcodeclock.unlock();
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    35273523
    35283524                    // calc for next frame
    35293525                    lastapts += (long long)((double)(data_size * 1000) /
    3530                                 (curstream->codec->channels * 2) /
    3531                                 curstream->codec->sample_rate);
     3526                                (ctx->channels * 2) / ctx->sample_rate);
    35323527
    35333528                    VERBOSE(VB_PLAYBACK|VB_TIMESTAMP,
    35343529                            LOC + QString("audio timecode %1 %2 %3 %4")
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    35883583                        continue;
    35893584                    }
    35903585
    3591                     AVCodecContext *context = curstream->codec;
    35923586                    AVFrame mpa_pic;
    35933587                    bzero(&mpa_pic, sizeof(AVFrame));
    35943588
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    36033597                            // HACK
    36043598                            while (!gotpicture && count < 5)
    36053599                            {
    3606                                 ret = d->DecodeMPEG2Video(context, &mpa_pic,
     3600                                ret = d->DecodeMPEG2Video(ctx, &mpa_pic,
    36073601                                                  &gotpicture, ptr, len);
    36083602                                count++;
    36093603                            }
    36103604                        }
    36113605                        else
    36123606                        {
    3613                             ret = d->DecodeMPEG2Video(context, &mpa_pic,
     3607                            ret = d->DecodeMPEG2Video(ctx, &mpa_pic,
    36143608                                                &gotpicture, ptr, len);
    36153609                        }
    36163610                    }
    36173611                    else
    36183612                    {
    3619                         ret = avcodec_decode_video(context, &mpa_pic,
     3613                        ret = avcodec_decode_video(ctx, &mpa_pic,
    36203614                                                   &gotpicture, ptr, len);
    36213615                        // Reparse it to not drop the DVD still frame
    36223616                        if (decodeStillFrame)
    3623                             ret = avcodec_decode_video(context, &mpa_pic,
     3617                            ret = avcodec_decode_video(ctx, &mpa_pic,
    36243618                                                        &gotpicture, ptr, len);
    36253619                    }
    36263620                    avcodeclock.unlock();
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    36873681
    36883682                        img_convert(&tmppicture, PIX_FMT_YUV420P,
    36893683                                    (AVPicture *)&mpa_pic,
    3690                                     context->pix_fmt,
    3691                                     context->width,
    3692                                     context->height);
     3684                                    ctx->pix_fmt,
     3685                                    ctx->width,
     3686                                    ctx->height);
    36933687
    36943688                        if (xf)
    36953689                        {
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    37123706                        (temppts + 10000 > lastvpts || temppts < 0))
    37133707                    {
    37143708                        temppts = lastvpts;
    3715                         temppts += (long long)(1000 * av_q2d(context->time_base));
     3709                        temppts += (long long)(1000 * av_q2d(ctx->time_base));
    37163710                        // MPEG2 frames can be repeated, update pts accordingly
    37173711                        temppts += (long long)(mpa_pic.repeat_pict * 500
    3718                                       * av_q2d(curstream->codec->time_base));
     3712                                      * av_q2d(ctx->time_base));
    37193713                    }
    37203714
    37213715                    VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC +
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    37513745                    picframe->frameNumber = framesPlayed;
    37523746                    GetNVP()->ReleaseNextVideoFrame(picframe, temppts);
    37533747                    if (d->HasMPEG2Dec() && mpa_pic.data[3])
    3754                         context->release_buffer(context, &mpa_pic);
     3748                        ctx->release_buffer(ctx, &mpa_pic);
    37553749
    37563750                    decoded_video_frame = picframe;
    37573751                    gotvideo = 1;
    bool AvFormatDecoder::GetFrame(int onlyvideo) 
    38103804                }
    38113805                default:
    38123806                {
    3813                     AVCodecContext *enc = curstream->codec;
    38143807                    VERBOSE(VB_IMPORTANT, LOC_ERR +
    38153808                            QString("Decoding - id(%1) type(%2)")
    3816                             .arg(codec_id_string(enc->codec_id))
    3817                             .arg(codec_type_string(enc->codec_type)));
     3809                            .arg(codec_id_string(ctx->codec_id))
     3810                            .arg(codec_type_string(ctx->codec_type)));
    38183811                    have_err = true;
    38193812                    break;
    38203813                }
    void AvFormatDecoder::SetDisablePassThrough(bool disable) 
    39593952    }
    39603953}
    39613954
     3955bool AvFormatDecoder::DoPassThrough(const AVCodecContext *ctx)
     3956{
     3957    bool passthru = false;
     3958
     3959    if (ctx->codec_id == CODEC_ID_AC3)
     3960        passthru = allow_ac3_passthru &&
     3961                   ctx->channels >= (int)max_channels;
     3962    else if (ctx->codec_id == CODEC_ID_DTS)
     3963        passthru = allow_dts_passthru;
     3964   
     3965    passthru &= !transcoding && !disable_passthru;
     3966    // Don't know any cards that support spdif clocked at < 44100
     3967    // Some US cable transmissions have 2ch 32k AC-3 streams
     3968    passthru &= ctx->sample_rate >= 44100;
     3969
     3970    return passthru;
     3971}
     3972
     3973
    39623974/** \fn AvFormatDecoder::SetupAudioStream(void)
    39633975 *  \brief Reinitializes audio if it needs to be reinitialized.
    39643976 *
    bool AvFormatDecoder::SetupAudioStream(void) 
    39723984    AVStream *curstream = NULL;
    39733985    AVCodecContext *codec_ctx = NULL;
    39743986    AudioInfo old_in  = audioIn;
    3975     AudioInfo old_out = audioOut;
    39763987    bool using_passthru = false;
    39773988
    39783989    if ((currentTrack[kTrackTypeAudio] >= 0) &&
    bool AvFormatDecoder::SetupAudioStream(void) 
    39843995        assert(curstream);
    39853996        assert(curstream->codec);
    39863997        codec_ctx = curstream->codec;       
    3987         bool do_ac3_passthru = (allow_ac3_passthru && !transcoding &&
    3988                                 (codec_ctx->codec_id == CODEC_ID_AC3));
    3989         bool do_dts_passthru = (allow_dts_passthru && !transcoding &&
    3990                                 (codec_ctx->codec_id == CODEC_ID_DTS));
    3991         using_passthru = do_ac3_passthru || do_dts_passthru;
    3992         info = AudioInfo(codec_ctx->codec_id,
    3993                          codec_ctx->sample_rate, codec_ctx->channels,
    3994                          using_passthru && !disable_passthru);
     3998        using_passthru = DoPassThrough(codec_ctx);
     3999        info = AudioInfo(codec_ctx->codec_id, codec_ctx->sample_rate,
     4000                         codec_ctx->channels, using_passthru);
    39954001    }
    39964002
    39974003    if (info == audioIn)
    bool AvFormatDecoder::SetupAudioStream(void) 
    40024008            QString("audio track #%1").arg(currentTrack[kTrackTypeAudio]+1));
    40034009
    40044010    audioOut = audioIn = info;
    4005     if (using_passthru)
    4006     {
    4007         // A passthru stream looks like a 48KHz 2ch (@ 16bit) to the sound card
    4008         AudioInfo digInfo = audioOut;
    4009         if (!disable_passthru)
    4010         {
    4011             digInfo.channels    = 2;
    4012             digInfo.sample_rate = 48000;
    4013             digInfo.sample_size = 4;
    4014         }
    4015         if (audioOut.channels > (int) max_channels)
    4016         {
    4017             audioOut.channels = (int) max_channels;
    4018             audioOut.sample_size = audioOut.channels * 2;
    4019             codec_ctx->channels = audioOut.channels;
    4020         }
    4021         VERBOSE(VB_AUDIO, LOC + "Audio format changed digital passthrough " +
    4022                 QString("%1\n\t\t\tfrom %2 ; %3\n\t\t\tto   %4 ; %5")
    4023                 .arg(digInfo.toString())
    4024                 .arg(old_in.toString()).arg(old_out.toString())
    4025                 .arg(audioIn.toString()).arg(audioOut.toString()));
    4026 
    4027         if (digInfo.sample_rate > 0)
    4028             GetNVP()->SetEffDsp(digInfo.sample_rate * 100);
    4029 
    4030         GetNVP()->SetAudioParams(digInfo.bps(), digInfo.channels,
    4031                                  digInfo.sample_rate, audioIn.do_passthru);
    4032         // allow the audio stuff to reencode
    4033         GetNVP()->SetAudioCodec(codec_ctx);
    4034         GetNVP()->ReinitAudio();
    4035         return true;
    4036     }
    4037     else
     4011
     4012    if (!using_passthru && audioOut.channels > (int)max_channels)
    40384013    {
    4039         if (audioOut.channels > (int) max_channels)
    4040         {
    4041             audioOut.channels = (int) max_channels;
    4042             audioOut.sample_size = audioOut.channels * 2;
    4043             codec_ctx->channels = audioOut.channels;
    4044         }
     4014        audioOut.channels = (int)max_channels;
     4015        audioOut.sample_size = audioOut.channels * 2;
     4016        codec_ctx->channels = audioOut.channels;
    40454017    }
    4046 
     4018   
    40474019    VERBOSE(VB_AUDIO, LOC + "Audio format changed " +
    4048             QString("\n\t\t\tfrom %1 ; %2\n\t\t\tto   %3 ; %4")
    4049             .arg(old_in.toString()).arg(old_out.toString())
    4050             .arg(audioIn.toString()).arg(audioOut.toString()));
     4020            QString("\n\t\t\tfrom %1 to %2")
     4021            .arg(old_in.toString()).arg(audioOut.toString()));
    40514022
    40524023    if (audioOut.sample_rate > 0)
    40534024        GetNVP()->SetEffDsp(audioOut.sample_rate * 100);
    40544025
    40554026    GetNVP()->SetAudioParams(audioOut.bps(), audioOut.channels,
    40564027                             audioOut.sample_rate,
    4057                              audioIn.do_passthru);
     4028                             audioOut.do_passthru);
    40584029
    4059     // allow the audio stuff to reencode
    4060     GetNVP()->SetAudioCodec(using_passthru?codec_ctx:NULL);
    40614030    QString errMsg = GetNVP()->ReinitAudio();
    4062     bool audiook = errMsg.isEmpty();
    40634031
    40644032    return true;
    40654033}
  • 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/tv_play.cpp

    diff --git a/mythtv/libs/libmythtv/tv_play.cpp b/mythtv/libs/libmythtv/tv_play.cpp
    index de06d06..d990434 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) 
    73007319
    73017320        ChangeTimeStretch(0, !floatRead);   // just display
    73027321    }
     7322    else if (action == "TOGGLEUPMIX")
     7323        ToggleUpmix();
    73037324    else if (action.left(11) == "SELECTSCAN_")
    73047325        activenvp->SetScanType((FrameScanType) action.right(1).toInt());
    73057326    else if (action.left(15) == "TOGGLEAUDIOSYNC")
    void TV::BuildOSDTreeMenu(void) 
    75477568    subitem = new OSDGenericTree(item, tr("1.5X"), "ADJUSTSTRETCH1.5",
    75487569                                 (speedX100 == 150) ? 1 : 0, NULL,
    75497570                                 "STRETCHGROUP");
     7571   
     7572    item = new OSDGenericTree(treeMenu, tr("Toggle Upmixer"), "TOGGLEUPMIX");
    75507573
    75517574    // add scan mode override settings to menu
    75527575    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..78d21b7 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->addSelection(QObject::tr("Disabled"), "0");
     127    gc->setHelpText(
     128            QObject::tr(
     129                "Set the quality of audio sample rate conversion. "
     130                "This only affects non 48000Hz PCM audio. "
     131                "All three options offer a worst-case SNR of 97dB. "
     132                "'Best' at a bandwidth of 97%. "
     133                "'Medium' at a bandwidth of 90%. "
     134                "'Fastest' at a bandwidth of 80%. "
     135                "Set 'Disabled' only if you know what you are doing . "));
     136    return gc;
     137}
     138
    119139static HostComboBox *PassThroughOutputDevice()
    120140{
    121141    HostComboBox *gc = new HostComboBox("PassThruOutputDevice", true);
    class AudioSettings : public TriggeredConfigurationGroup 
    33073327         agrp->addChild(MaxAudioChannels());
    33083328         agrp->addChild(AudioUpmixType());
    33093329         addChild(agrp);
     3330         
     3331         HorizontalConfigurationGroup *agrp1 =
     3332             new HorizontalConfigurationGroup(false, false, true, true);
     3333         agrp1->addChild(SRCQuality());
     3334         addChild(agrp1);
    33103335
    33113336         VerticalConfigurationGroup *vgrp1 =
    33123337             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..c6adf51 100644
    a b class AudioReencodeBuffer : public AudioOutput 
    5555
    5656    // reconfigure sound out for new params
    5757    virtual void Reconfigure(int audio_bits, int audio_channels,
    58                              int audio_samplerate, bool audio_passthru,
    59                              void *audio_codec = NULL)
     58                             int audio_samplerate, bool audio_passthru)
    6059    {
    6160        (void)audio_samplerate;
    6261        (void)audio_passthru;
    63         (void)audio_codec;
    6462
    6563        ClearError();
    6664        bits = audio_bits;
    class AudioReencodeBuffer : public AudioOutput 
    218216        // Do nothing
    219217        return MUTE_OFF;
    220218    }
     219    virtual bool ToggleUpmix(void)
     220    {
     221        // Do nothing
     222        return false;
     223    }
    221224
    222225    //  These are pure virtual in AudioOutput, but we don't need them here
    223226    virtual void bufferOutputData(bool){ return; }