diff --git a/src/common/droid-util.c b/src/common/droid-util.c index af371b6..280e218 100644 --- a/src/common/droid-util.c +++ b/src/common/droid-util.c @@ -393,8 +393,8 @@ static bool parse_formats(const char *fn, const unsigned ln, return check_and_log(fn, ln, "formats", count, str, unknown, false); } -static int parse_channels(const char *fn, const unsigned ln, - const char *str, bool in_output, audio_channel_mask_t *channels) { +static bool parse_channels(const char *fn, const unsigned ln, + const char *str, bool in_output, audio_channel_mask_t *channels) { int count; char *unknown = NULL; @@ -1934,13 +1934,19 @@ static bool stream_config_fill(audio_devices_t devices, audio_format_t hal_audio_format = 0; audio_channel_mask_t hal_channel_mask = 0; bool voicecall_record = false; + bool output = true; pa_assert(sample_spec); pa_assert(channel_map); pa_assert(config); #if AUDIO_API_VERSION_MAJ >= 2 - devices &= ~AUDIO_DEVICE_BIT_IN; + if (devices & AUDIO_DEVICE_BIT_IN) { + output = false; + devices &= ~AUDIO_DEVICE_BIT_IN; + } +#else + output = !(devices & AUDIO_DEVICE_IN_ALL); #endif if (devices & AUDIO_DEVICE_IN_VOICE_CALL) @@ -1951,24 +1957,19 @@ static bool stream_config_fill(audio_devices_t devices, goto fail; } - if (devices & AUDIO_DEVICE_IN_ALL) { - for (int i = 0; i < channel_map->channels; i++) { - audio_channel_mask_t c; - if (!pa_convert_input_channel(channel_map->map[i], CONV_FROM_PA, &c)) { - pa_log("Failed to convert channel map."); - goto fail; - } - hal_channel_mask |= c; - } - } else { - for (int i = 0; i < channel_map->channels; i++) { - audio_channel_mask_t c; - if (!pa_convert_output_channel(channel_map->map[i], CONV_FROM_PA, &c)) { - pa_log("Failed to convert channel map."); - goto fail; - } - hal_channel_mask |= c; + for (int i = 0; i < channel_map->channels; i++) { + bool found; + audio_channel_mask_t c; + + found = output ? pa_convert_output_channel(channel_map->map[i], CONV_FROM_PA, &c) + : pa_convert_input_channel(channel_map->map[i], CONV_FROM_PA, &c); + + if (!found) { + pa_log("Failed to convert %s channel map.", output ? "output" : "input"); + goto fail; } + + hal_channel_mask |= c; } if (voicecall_record) { diff --git a/src/droid/droid-sink.c b/src/droid/droid-sink.c index 1db912d..c82ca30 100644 --- a/src/droid/droid-sink.c +++ b/src/droid/droid-sink.c @@ -1177,8 +1177,8 @@ pa_sink *pa_droid_sink_new(pa_module *m, } /* Default routing */ - dev_out = am->output->module->global_config ? am->output->module->global_config->default_output_device - : u->hw_module->config->global_config->default_output_device; + dev_out = (am && am->output->module->global_config) ? am->output->module->global_config->default_output_device + : u->hw_module->config->global_config->default_output_device; if ((tmp = pa_modargs_get_value(ma, "output_devices", NULL))) { audio_devices_t tmp_dev;