diff options
author | Christian Gmeiner <christian.gmeiner@gmail.com> | 2009-02-25 13:09:36 +0100 |
---|---|---|
committer | Christian Gmeiner <christian.gmeiner@gmail.com> | 2009-02-25 13:09:36 +0100 |
commit | da29390ac2d8593434a94f08896ff776e3e9392a (patch) | |
tree | 95bdac749d2dbdb9ee6197dbae4d13739beaef8f /dxr3audio-alsa.c | |
parent | 5344138582d635e9bb24a74c6529bd081430b521 (diff) | |
download | vdr-plugin-dxr3-da29390ac2d8593434a94f08896ff776e3e9392a.tar.gz vdr-plugin-dxr3-da29390ac2d8593434a94f08896ff776e3e9392a.tar.bz2 |
improve audio device handling
- keep track if sound device is open
- use pass-by-reference-to-const instead of pass-by-value (no copying needed)
Diffstat (limited to 'dxr3audio-alsa.c')
-rw-r--r-- | dxr3audio-alsa.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/dxr3audio-alsa.c b/dxr3audio-alsa.c index 87012d5..0e45afb 100644 --- a/dxr3audio-alsa.c +++ b/dxr3audio-alsa.c @@ -26,6 +26,9 @@ using namespace std; void cAudioAlsa::openDevice() { + if (open) + return; + // generate alsa card name int card = cDxr3ConfigData::Instance().GetDxr3Card(); string cardname = "EM8300"; @@ -35,9 +38,6 @@ void cAudioAlsa::openDevice() } string device = "default:CARD=" + cardname; - - releaseDevice(); - dsyslog("[dxr3-audio-alsa] opening device %s", device.c_str()); int err = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0); @@ -45,18 +45,25 @@ void cAudioAlsa::openDevice() esyslog("[dxr3-audio-alsa] Playback open error: %s", snd_strerror(err)); exit(1); } + + open = true; } void cAudioAlsa::releaseDevice() { + if (!open) + return; + if (handle) { snd_pcm_drain(handle); snd_pcm_close(handle); handle = NULL; } + + open = false; } -void cAudioAlsa::setup(SampleContext ctx) +void cAudioAlsa::setup(const SampleContext& ctx) { // look if ctx is different if (curContext.channels == ctx.channels && curContext.samplerate == ctx.samplerate) { @@ -94,7 +101,7 @@ void cAudioAlsa::setup(SampleContext ctx) } // set samplerate - err = snd_pcm_hw_params_set_rate_near(handle, alsa_hwparams, &ctx.samplerate, NULL); + err = snd_pcm_hw_params_set_rate_near(handle, alsa_hwparams, (unsigned int *)&ctx.samplerate, NULL); if (err < 0) { esyslog("[dxr3-audio-alsa] Unable to set samplerate %d: %s", ctx.samplerate, snd_strerror(err)); } |