Changeset 9741adc7f in mythtv


Ignore:
Timestamp:
Nov 22, 2010, 4:36:37 AM (14 years ago)
Author:
Jean-Yves Avenard <jyavenard@…>
Branches:
devel/2020-player, devel/ffmpeg-resync, devel/gpu-commflag, fixes/0.25, fixes/0.26, fixes/0.27, fixes/0.28, fixes/29, fixes/30, fixes/31, github-templates, master
Children:
18fdd004ee
Parents:
ca3ea9c009
Message:

Simplify code when opening ALSA device and trying to setup digital passthrough. Remove unused private member in ALSA class

git-svn-id: http://svn.mythtv.org/svn/trunk@27317 7dbf422c-18fa-0310-86e9-fd20926502f2

Location:
mythtv/libs/libmyth
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • mythtv/libs/libmyth/audiooutputalsa.cpp

    rca3ea9c009 r9741adc7f  
    3434    AudioOutputBase(settings),
    3535    pcm_handle(NULL),
    36     numbadioctls(0),
    3736    pbufsize(-1),
    3837    m_card(-1),
    3938    m_device(-1),
    40     m_subdevice(-1)
     39    m_subdevice(-1),
     40    m_autopassthrough(false)
    4141{
    4242    m_mixer.handle = NULL;
     
    4646    if (passthru_device == "auto")
    4747    {
     48        m_autopassthrough = true;
    4849        passthru_device = main_device;
    4950
     
    99100}
    100101
     102int AudioOutputALSA::TryOpenDevice(int open_mode, int try_ac3)
     103{
     104    QString real_device;
     105    QByteArray dev_ba;
     106    int err = -1;
     107
     108    if (try_ac3)
     109    {
     110        dev_ba = passthru_device.toAscii();
     111        err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
     112                           SND_PCM_STREAM_PLAYBACK, open_mode);
     113        m_lastdevice = passthru_device;
     114        if (!m_autopassthrough)
     115            return err;
     116    }
     117    if (!try_ac3 || err < 0)
     118    {
     119        // passthru open failed, retry default device
     120        dev_ba = main_device.toAscii();
     121        err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
     122                           SND_PCM_STREAM_PLAYBACK, open_mode);
     123        m_lastdevice = main_device;
     124    }
     125    return err;
     126}
     127
    101128int AudioOutputALSA::GetPCMInfo(int &card, int &device, int &subdevice)
    102129{
     
    236263    int err;
    237264
    238     QString real_device = (passthru || enc) ? passthru_device : main_device;
    239 
    240265    AudioOutputSettings *settings = new AudioOutputSettings();
    241266
     
    245270        pcm_handle = NULL;
    246271    }
    247     QByteArray dev_ba = real_device.toAscii();
    248     if((err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
    249                            SND_PCM_STREAM_PLAYBACK, OPEN_FLAGS)) < 0)
    250     {
    251         AERROR(QString("snd_pcm_open(\"%1\")").arg(real_device));
     272
     273    if((err = TryOpenDevice(OPEN_FLAGS, passthru || enc)) < 0)
     274    {
     275        AERROR(QString("snd_pcm_open(\"%1\")").arg(m_lastdevice));
    252276        delete settings;
    253277        return NULL;
     
    259283    {
    260284        snd_pcm_close(pcm_handle);
    261         if((err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
    262                                SND_PCM_STREAM_PLAYBACK, OPEN_FLAGS&FILTER_FLAGS
    263                                )) < 0)
    264         {
    265             AERROR(QString("snd_pcm_open(\"%1\")").arg(real_device));
     285        if((err = TryOpenDevice(OPEN_FLAGS&FILTER_FLAGS, passthru || enc)) < 0)
     286        {
     287            AERROR(QString("snd_pcm_open(\"%1\")").arg(m_lastdevice));
    266288            delete settings;
    267289            return NULL;
     
    309331    while(1)
    310332    {
     333        QString real_device = (((passthru || enc) && !m_autopassthrough) ?
     334                               passthru_device : main_device);
     335
    311336        QString desc = alsadevs->value(real_device);
    312337
     
    346371    uint buffer_time, period_time;
    347372    int err;
    348     QString real_device;
    349373
    350374    if (pcm_handle != NULL)
    351375        CloseDevice();
    352376
    353     numbadioctls = 0;
    354 
    355     if (passthru || enc)
    356     {
    357         real_device = passthru_device;       
    358     }
    359     else
    360     {
    361         real_device = main_device;
    362     }
    363 
    364     QByteArray dev_ba = real_device.toAscii();
    365     err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
    366                        SND_PCM_STREAM_PLAYBACK, 0);
    367     if ((passthru || enc) && err < 0)
    368     {
    369         // passthru open failed, retry default device
    370         dev_ba = main_device.toAscii();
    371         err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
    372                            SND_PCM_STREAM_PLAYBACK, 0);
    373     }
    374     if (err < 0)
    375     {
    376         AERROR(QString("snd_pcm_open(%1)").arg(real_device));
     377    if ((err = TryOpenDevice(0, passthru || enc)) < 0)   
     378    {
     379        AERROR(QString("snd_pcm_open2(\"%1\")").arg(m_lastdevice));
    377380        if (pcm_handle)
    378381            CloseDevice();
  • mythtv/libs/libmyth/audiooutputalsa.h

    rca3ea9c009 r9741adc7f  
    3232
    3333  private:
     34    int TryOpenDevice(int open_mode, int try_ac3);
    3435    int GetPCMInfo(int &card, int &device, int &subdevice);
    3536    bool SetPreallocBufferSize(int size);
     
    4344  private:
    4445    snd_pcm_t   *pcm_handle;
    45     int          numbadioctls;
    4646    int          pbufsize;
    4747    int          m_card, m_device, m_subdevice;
     
    4949    snd_pcm_sframes_t (*pcm_write_func)(snd_pcm_t*, const void*,
    5050                                        snd_pcm_uframes_t);
     51    bool         m_autopassthrough;
     52    QString      m_lastdevice;
     53
    5154    struct {
    5255        QString            device;
Note: See TracChangeset for help on using the changeset viewer.