summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2009-06-24 14:59:03 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2009-06-24 14:59:03 +0800
commit4b5d87b983ea3d0b915e56456f90c6318be7a712 (patch)
tree01fafc2c825fcd3ec0216ea25e52fb14fe0b7c31 /src
parentf0f2626c1a67b47435362cd012de27d7cf1db075 (diff)
AlsaDevice: rework reopening pcm device logical.
Diffstat (limited to 'src')
-rw-r--r--src/device_alsa.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/device_alsa.cpp b/src/device_alsa.cpp
index 548be0a..035531a 100644
--- a/src/device_alsa.cpp
+++ b/src/device_alsa.cpp
@@ -221,6 +221,15 @@ namespace audiere {
char* sample_buf;
int retry = 0;
+ // reopen a pcm
+ if (m_pcm_handle) {
+ m_pcm_handle = openDevice(m_pcm_name, m_rate);
+ if (!m_pcm_handle) {
+ usleep(100);
+ return;
+ }
+ }
+
sample_buf = m_buffer;
sample_len = m_buffer_size / 4;
@@ -230,13 +239,10 @@ namespace audiere {
if (ret == -EAGAIN) {
snd_pcm_wait(m_pcm_handle, 100);
if (++retry > 50) {
- fprintf(stderr, "audiere: snd_pcm_writei doesn't work anymore, try to reopen a new pcm.\n");
+ fprintf(stderr, "audiere: snd_pcm_writei doesn't work anymore, reopening pcm.\n");
snd_pcm_close(m_pcm_handle);
-
- retry = 0;
- m_pcm_handle = openDevice(m_pcm_name, m_rate);
- if (!m_pcm_handle)
- break;
+ m_pcm_handle = 0;
+ break;
}
} else if (ret == -ESTRPIPE) {
do {