diff options
author | Alex Chronopoulos <[email protected]> | 2019-01-22 10:07:27 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2019-01-22 10:07:27 +0200 |
commit | 9a8e02e7515e7cef01504d0730616be310813b77 (patch) | |
tree | 2e35cfd35b50a72b35265dc12e0aff260cd807b9 /src/cubeb_pulse.c | |
parent | 67d37c16be84fcc469531d4b6f70eae8a2867a66 (diff) | |
download | cubeb-9a8e02e7515e7cef01504d0730616be310813b77.tar.gz cubeb-9a8e02e7515e7cef01504d0730616be310813b77.zip |
pulse: guess default layout when it is not configured (BMO 1518106). (#486)
Diffstat (limited to 'src/cubeb_pulse.c')
-rw-r--r-- | src/cubeb_pulse.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/cubeb_pulse.c b/src/cubeb_pulse.c index 94f842c..8bef42e 100644 --- a/src/cubeb_pulse.c +++ b/src/cubeb_pulse.c @@ -85,6 +85,7 @@ X(pa_context_subscribe) \ X(pa_mainloop_api_once) \ X(pa_get_library_version) \ + X(pa_channel_map_init_auto) \ #define MAKE_TYPEDEF(x) static typeof(x) * cubeb_##x; LIBPULSE_API_VISIT(MAKE_TYPEDEF); @@ -786,6 +787,25 @@ to_pulse_format(cubeb_sample_format format) } } +static cubeb_channel_layout +pulse_default_layout_for_channels(uint32_t ch) +{ + assert (ch > 0 && ch <= 8); + switch (ch) { + case 1: return CUBEB_LAYOUT_MONO; + case 2: return CUBEB_LAYOUT_STEREO; + case 3: return CUBEB_LAYOUT_3F; + case 4: return CUBEB_LAYOUT_QUAD; + case 5: return CUBEB_LAYOUT_3F2; + case 6: return CUBEB_LAYOUT_3F_LFE | + CHANNEL_SIDE_LEFT | CHANNEL_SIDE_RIGHT; + case 7: return CUBEB_LAYOUT_3F3R_LFE; + case 8: return CUBEB_LAYOUT_3F4_LFE; + } + // Never get here! + return CUBEB_LAYOUT_UNDEFINED; +} + static int create_pa_stream(cubeb_stream * stm, pa_stream ** pa_stm, @@ -809,7 +829,16 @@ create_pa_stream(cubeb_stream * stm, ss.channels = stream_params->channels; if (stream_params->layout == CUBEB_LAYOUT_UNDEFINED) { - *pa_stm = WRAP(pa_stream_new)(stm->context->context, stream_name, &ss, NULL); + pa_channel_map cm; + if (stream_params->channels <= 8 && + !pa_channel_map_init_auto(&cm, stream_params->channels, PA_CHANNEL_MAP_DEFAULT)) { + LOG("Layout undefined and PulseAudio's default layout has not been configured, guess one."); + layout_to_channel_map(pulse_default_layout_for_channels(stream_params->channels), &cm); + *pa_stm = WRAP(pa_stream_new)(stm->context->context, stream_name, &ss, &cm); + } else { + LOG("Layout undefined, PulseAudio will use its default."); + *pa_stm = WRAP(pa_stream_new)(stm->context->context, stream_name, &ss, NULL); + } } else { pa_channel_map cm; layout_to_channel_map(stream_params->layout, &cm); |