summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Yves Avenard <jyavenard@mythtv.org>2010-11-22 04:36:37 (GMT)
committer Jean-Yves Avenard <jyavenard@mythtv.org>2010-11-22 04:36:37 (GMT)
commit9741adc7f9485ddd8f6b805075fbb5ea965d29c2 (patch)
treeb9bf603a2aa2a43665ce6ec5ac73ad20602e2b5e
parentca3ea9c009d59ea944f764f806482192e74f0dd9 (diff)
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
-rw-r--r--mythtv/libs/libmyth/audiooutputalsa.cpp75
-rw-r--r--mythtv/libs/libmyth/audiooutputalsa.h5
2 files changed, 43 insertions, 37 deletions
diff --git a/mythtv/libs/libmyth/audiooutputalsa.cpp b/mythtv/libs/libmyth/audiooutputalsa.cpp
index 2d5377d..a63b77b 100644
--- a/mythtv/libs/libmyth/audiooutputalsa.cpp
+++ b/mythtv/libs/libmyth/audiooutputalsa.cpp
@@ -33,11 +33,11 @@ using namespace std;
AudioOutputALSA::AudioOutputALSA(const AudioSettings &settings) :
AudioOutputBase(settings),
pcm_handle(NULL),
- numbadioctls(0),
pbufsize(-1),
m_card(-1),
m_device(-1),
- m_subdevice(-1)
+ m_subdevice(-1),
+ m_autopassthrough(false)
{
m_mixer.handle = NULL;
m_mixer.elem = NULL;
@@ -45,6 +45,7 @@ AudioOutputALSA::AudioOutputALSA(const AudioSettings &settings) :
// Set everything up
if (passthru_device == "auto")
{
+ m_autopassthrough = true;
passthru_device = main_device;
/* to set the non-audio bit, use AES0=6 */
@@ -98,6 +99,32 @@ AudioOutputALSA::~AudioOutputALSA()
KillAudio();
}
+int AudioOutputALSA::TryOpenDevice(int open_mode, int try_ac3)
+{
+ QString real_device;
+ QByteArray dev_ba;
+ int err = -1;
+
+ if (try_ac3)
+ {
+ dev_ba = passthru_device.toAscii();
+ err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
+ SND_PCM_STREAM_PLAYBACK, open_mode);
+ m_lastdevice = passthru_device;
+ if (!m_autopassthrough)
+ return err;
+ }
+ if (!try_ac3 || err < 0)
+ {
+ // passthru open failed, retry default device
+ dev_ba = main_device.toAscii();
+ err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
+ SND_PCM_STREAM_PLAYBACK, open_mode);
+ m_lastdevice = main_device;
+ }
+ return err;
+}
+
int AudioOutputALSA::GetPCMInfo(int &card, int &device, int &subdevice)
{
// Check for saved values
@@ -235,8 +262,6 @@ AudioOutputSettings* AudioOutputALSA::GetOutputSettings()
int rate;
int err;
- QString real_device = (passthru || enc) ? passthru_device : main_device;
-
AudioOutputSettings *settings = new AudioOutputSettings();
if (pcm_handle)
@@ -244,11 +269,10 @@ AudioOutputSettings* AudioOutputALSA::GetOutputSettings()
snd_pcm_close(pcm_handle);
pcm_handle = NULL;
}
- QByteArray dev_ba = real_device.toAscii();
- if((err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
- SND_PCM_STREAM_PLAYBACK, OPEN_FLAGS)) < 0)
+
+ if((err = TryOpenDevice(OPEN_FLAGS, passthru || enc)) < 0)
{
- AERROR(QString("snd_pcm_open(\"%1\")").arg(real_device));
+ AERROR(QString("snd_pcm_open(\"%1\")").arg(m_lastdevice));
delete settings;
return NULL;
}
@@ -258,11 +282,9 @@ AudioOutputSettings* AudioOutputALSA::GetOutputSettings()
if ((err = snd_pcm_hw_params_any(pcm_handle, params)) < 0)
{
snd_pcm_close(pcm_handle);
- if((err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
- SND_PCM_STREAM_PLAYBACK, OPEN_FLAGS&FILTER_FLAGS
- )) < 0)
+ if((err = TryOpenDevice(OPEN_FLAGS&FILTER_FLAGS, passthru || enc)) < 0)
{
- AERROR(QString("snd_pcm_open(\"%1\")").arg(real_device));
+ AERROR(QString("snd_pcm_open(\"%1\")").arg(m_lastdevice));
delete settings;
return NULL;
}
@@ -308,6 +330,9 @@ AudioOutputSettings* AudioOutputALSA::GetOutputSettings()
QMap<QString, QString> *alsadevs = GetALSADevices("pcm");
while(1)
{
+ QString real_device = (((passthru || enc) && !m_autopassthrough) ?
+ passthru_device : main_device);
+
QString desc = alsadevs->value(real_device);
settings->setPassthrough(1); // yes passthrough
@@ -345,35 +370,13 @@ bool AudioOutputALSA::OpenDevice()
snd_pcm_format_t format;
uint buffer_time, period_time;
int err;
- QString real_device;
if (pcm_handle != NULL)
CloseDevice();
- numbadioctls = 0;
-
- if (passthru || enc)
- {
- real_device = passthru_device;
- }
- else
- {
- real_device = main_device;
- }
-
- QByteArray dev_ba = real_device.toAscii();
- err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
- SND_PCM_STREAM_PLAYBACK, 0);
- if ((passthru || enc) && err < 0)
- {
- // passthru open failed, retry default device
- dev_ba = main_device.toAscii();
- err = snd_pcm_open(&pcm_handle, dev_ba.constData(),
- SND_PCM_STREAM_PLAYBACK, 0);
- }
- if (err < 0)
+ if ((err = TryOpenDevice(0, passthru || enc)) < 0)
{
- AERROR(QString("snd_pcm_open(%1)").arg(real_device));
+ AERROR(QString("snd_pcm_open2(\"%1\")").arg(m_lastdevice));
if (pcm_handle)
CloseDevice();
return false;
diff --git a/mythtv/libs/libmyth/audiooutputalsa.h b/mythtv/libs/libmyth/audiooutputalsa.h
index ea2f7ed..4ac5759 100644
--- a/mythtv/libs/libmyth/audiooutputalsa.h
+++ b/mythtv/libs/libmyth/audiooutputalsa.h
@@ -31,6 +31,7 @@ class AudioOutputALSA : public AudioOutputBase
AudioOutputSettings* GetOutputSettings(void);
private:
+ int TryOpenDevice(int open_mode, int try_ac3);
int GetPCMInfo(int &card, int &device, int &subdevice);
bool SetPreallocBufferSize(int size);
bool IncPreallocBufferSize(int buffer_time);
@@ -42,12 +43,14 @@ class AudioOutputALSA : public AudioOutputBase
private:
snd_pcm_t *pcm_handle;
- int numbadioctls;
int pbufsize;
int m_card, m_device, m_subdevice;
QMutex killAudioLock;
snd_pcm_sframes_t (*pcm_write_func)(snd_pcm_t*, const void*,
snd_pcm_uframes_t);
+ bool m_autopassthrough;
+ QString m_lastdevice;
+
struct {
QString device;
QString control;