diff options
author | Lennart Poettering <lennart@poettering.net> | 2009-01-16 22:01:45 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2009-01-16 22:01:45 +0100 |
commit | b2b2eb1ee7e30de651b9fb2cbc04329e21b1eb68 (patch) | |
tree | b85c06ac94a236d3f9c1edef2c4c80cce7633579 /src/modules/alsa | |
parent | 5793f93350dd8f29b7bc97eb1ad38873e4ecebde (diff) |
remvoe a bit of duplicate code
Diffstat (limited to 'src/modules/alsa')
-rw-r--r-- | src/modules/alsa/alsa-util.c | 78 | ||||
-rw-r--r-- | src/modules/alsa/alsa-util.h | 3 | ||||
-rw-r--r-- | src/modules/alsa/module-alsa-sink.c | 2 | ||||
-rw-r--r-- | src/modules/alsa/module-alsa-source.c | 2 |
4 files changed, 30 insertions, 55 deletions
diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c index 04d23e0e..5fabf644 100644 --- a/src/modules/alsa/alsa-util.c +++ b/src/modules/alsa/alsa-util.c @@ -622,72 +622,45 @@ snd_pcm_t *pa_alsa_open_by_device_id( i = 0; for (;;) { - pa_sample_spec try_ss; - pa_bool_t reformat; if ((direction > 0) == channel_map_superset(&device_table[i].map, map)) { + pa_sample_spec try_ss; + pa_log_debug("Checking for %s (%s)", device_table[i].name, device_table[i].alsa_name); d = pa_sprintf_malloc("%s:%s", device_table[i].alsa_name, dev_id); - reformat = FALSE; - for (;;) { - pa_log_debug("Trying %s %s SND_PCM_NO_AUTO_FORMAT ...", d, reformat ? "without" : "with"); - - /* We don't pass SND_PCM_NONBLOCK here, since alsa-lib <= - * 1.0.17a would then ignore the SND_PCM_NO_xxx - * flags. Instead we enable nonblock mode afterwards via - * snd_pcm_nonblock(). Also see - * http://mailman.alsa-project.org/pipermail/alsa-devel/2008-August/010258.html */ - - if ((err = snd_pcm_open(&pcm_handle, d, mode, - /* SND_PCM_NONBLOCK| */ - SND_PCM_NO_AUTO_RESAMPLE| - SND_PCM_NO_AUTO_CHANNELS| - (reformat ? 0 : SND_PCM_NO_AUTO_FORMAT))) < 0) { - pa_log_info("Couldn't open PCM device %s: %s", d, snd_strerror(err)); - break; - } - - try_ss.channels = device_table[i].map.channels; - try_ss.rate = ss->rate; - try_ss.format = ss->format; - - if ((err = pa_alsa_set_hw_params(pcm_handle, &try_ss, nfrags, period_size, tsched_size, use_mmap, use_tsched, TRUE)) < 0) { - - if (!reformat) { - reformat = TRUE; - snd_pcm_close(pcm_handle); - continue; - } - - if (!pa_startswith(d, "plug:") && !pa_startswith(d, "plughw:")) { - char *t; - - t = pa_sprintf_malloc("plug:%s", d); - pa_xfree(d); - d = t; + try_ss.channels = device_table[i].map.channels; + try_ss.rate = ss->rate; + try_ss.format = ss->format; + + pcm_handle = pa_alsa_open_by_device_string( + d, + dev, + &try_ss, + map, + mode, + nfrags, + period_size, + tsched_size, + use_mmap, + use_tsched, + TRUE); - reformat = FALSE; - - snd_pcm_close(pcm_handle); - continue; - } + pa_xfree(d); - pa_log_info("PCM device %s refused our hw parameters: %s", d, snd_strerror(err)); - snd_pcm_close(pcm_handle); - break; - } + if (pcm_handle) { *ss = try_ss; *map = device_table[i].map; pa_assert(map->channels == ss->channels); - *dev = d; + if (config_description) *config_description = device_table[i].description; if (config_name) *config_name = device_table[i].name; + return pcm_handle; } @@ -742,7 +715,7 @@ snd_pcm_t *pa_alsa_open_by_device_id( d = pa_sprintf_malloc("hw:%s", dev_id); pa_log_debug("Trying %s as last resort...", d); - pcm_handle = pa_alsa_open_by_device_string(d, dev, ss, map, mode, nfrags, period_size, tsched_size, use_mmap, use_tsched); + pcm_handle = pa_alsa_open_by_device_string(d, dev, ss, map, mode, nfrags, period_size, tsched_size, use_mmap, use_tsched, FALSE); pa_xfree(d); if (pcm_handle) { @@ -763,7 +736,8 @@ snd_pcm_t *pa_alsa_open_by_device_string( snd_pcm_uframes_t *period_size, snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, - pa_bool_t *use_tsched) { + pa_bool_t *use_tsched, + pa_bool_t require_exact_channel_number) { int err; char *d; @@ -798,7 +772,7 @@ snd_pcm_t *pa_alsa_open_by_device_string( return NULL; } - if ((err = pa_alsa_set_hw_params(pcm_handle, ss, nfrags, period_size, tsched_size, use_mmap, use_tsched, FALSE)) < 0) { + if ((err = pa_alsa_set_hw_params(pcm_handle, ss, nfrags, period_size, tsched_size, use_mmap, use_tsched, require_exact_channel_number)) < 0) { if (!reformat) { reformat = TRUE; diff --git a/src/modules/alsa/alsa-util.h b/src/modules/alsa/alsa-util.h index ce5f0eb6..51de2856 100644 --- a/src/modules/alsa/alsa-util.h +++ b/src/modules/alsa/alsa-util.h @@ -78,7 +78,8 @@ snd_pcm_t *pa_alsa_open_by_device_string( snd_pcm_uframes_t *period_size, snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, - pa_bool_t *use_tsched); + pa_bool_t *use_tsched, + pa_bool_t require_exact_channel_number); int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel_map, snd_mixer_selem_channel_id_t mixer_map[], pa_bool_t playback); diff --git a/src/modules/alsa/module-alsa-sink.c b/src/modules/alsa/module-alsa-sink.c index dfa20557..977d7e4b 100644 --- a/src/modules/alsa/module-alsa-sink.c +++ b/src/modules/alsa/module-alsa-sink.c @@ -1351,7 +1351,7 @@ int pa__init(pa_module*m) { &ss, &map, SND_PCM_STREAM_PLAYBACK, &nfrags, &period_frames, tsched_frames, - &b, &d))) + &b, &d, FALSE))) goto fail; } diff --git a/src/modules/alsa/module-alsa-source.c b/src/modules/alsa/module-alsa-source.c index f89b6e2e..5ad76018 100644 --- a/src/modules/alsa/module-alsa-source.c +++ b/src/modules/alsa/module-alsa-source.c @@ -1179,7 +1179,7 @@ int pa__init(pa_module*m) { &ss, &map, SND_PCM_STREAM_CAPTURE, &nfrags, &period_frames, tsched_frames, - &b, &d))) + &b, &d, FALSE))) goto fail; } |