From 30a688e94261a177c8c42115ace27b4ed88c2a9b Mon Sep 17 00:00:00 2001 From: fryshorts Date: Mon, 28 Apr 2014 20:44:01 +0200 Subject: [PATCH] Implement defaults functions The defaults functions will now return the default device for the input/output as provided by pulseaudio. The default output device is the monitor of the default sink. --- plugins/linux-pulseaudio/pulse-input.c | 58 ++++++++++++++++++++++-- plugins/linux-pulseaudio/pulse-wrapper.c | 2 +- plugins/linux-pulseaudio/pulse-wrapper.h | 4 +- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/plugins/linux-pulseaudio/pulse-input.c b/plugins/linux-pulseaudio/pulse-input.c index 852e0c377..96951e5e6 100644 --- a/plugins/linux-pulseaudio/pulse-input.c +++ b/plugins/linux-pulseaudio/pulse-input.c @@ -298,12 +298,62 @@ static obs_properties_t pulse_output_properties(const char *locale) return pulse_properties(locale, false); } +/** + * Server info callback + */ +static void pulse_input_device(pa_context *c, const pa_server_info *i, + void *userdata) +{ + UNUSED_PARAMETER(c); + obs_data_t settings = (obs_data_t) userdata; + + obs_data_set_default_string(settings, "device_id", + i->default_source_name); + blog(LOG_DEBUG, "pulse-input: Default input device: '%s'", + i->default_source_name); + + pulse_signal(0); +} + +static void pulse_output_device(pa_context *c, const pa_server_info *i, + void *userdata) +{ + UNUSED_PARAMETER(c); + obs_data_t settings = (obs_data_t) userdata; + + char *monitor = bzalloc(strlen(i->default_sink_name) + 9); + strcat(monitor, i->default_sink_name); + strcat(monitor, ".monitor"); + + obs_data_set_default_string(settings, "device_id", monitor); + blog(LOG_DEBUG, "pulse-input: Default output device: '%s'", monitor); + bfree(monitor); + + pulse_signal(0); +} + /** * Get plugin defaults */ -static void pulse_defaults(obs_data_t settings) +static void pulse_defaults(obs_data_t settings, bool input) { - obs_data_set_default_string(settings, "device_id", "default"); + pulse_init(); + + pa_server_info_cb_t cb = (input) + ? pulse_input_device : pulse_output_device; + pulse_get_server_info(cb, (void *) settings); + + pulse_unref(); +} + +static void pulse_input_defaults(obs_data_t settings) +{ + return pulse_defaults(settings, true); +} + +static void pulse_output_defaults(obs_data_t settings) +{ + return pulse_defaults(settings, false); } /** @@ -391,7 +441,7 @@ struct obs_source_info pulse_input_capture = { .create = pulse_create, .destroy = pulse_destroy, .update = pulse_update, - .defaults = pulse_defaults, + .defaults = pulse_input_defaults, .properties = pulse_input_properties }; @@ -403,6 +453,6 @@ struct obs_source_info pulse_output_capture = { .create = pulse_create, .destroy = pulse_destroy, .update = pulse_update, - .defaults = pulse_defaults, + .defaults = pulse_output_defaults, .properties = pulse_output_properties }; diff --git a/plugins/linux-pulseaudio/pulse-wrapper.c b/plugins/linux-pulseaudio/pulse-wrapper.c index a491c1879..2f33709f7 100644 --- a/plugins/linux-pulseaudio/pulse-wrapper.c +++ b/plugins/linux-pulseaudio/pulse-wrapper.c @@ -86,7 +86,7 @@ static void pulse_init_context() static int_fast32_t pulse_context_ready() { pulse_lock(); - + if (!PA_CONTEXT_IS_GOOD(pa_context_get_state(pulse_context))) { pulse_unlock(); return -1; diff --git a/plugins/linux-pulseaudio/pulse-wrapper.h b/plugins/linux-pulseaudio/pulse-wrapper.h index e9db5a5da..493fc3de8 100644 --- a/plugins/linux-pulseaudio/pulse-wrapper.h +++ b/plugins/linux-pulseaudio/pulse-wrapper.h @@ -83,7 +83,7 @@ void pulse_accept(); * Request source information * * The function will block until the operation was executed and the mainloop - * called the provided callback functions. + * called the provided callback function. * * @return negative on error * @@ -97,7 +97,7 @@ int_fast32_t pulse_get_source_info_list(pa_source_info_cb_t cb, void *userdata); * Request server information * * The function will block until the operation was executed and the mainloop - * called the provided callback functions + * called the provided callback function. * * @return negative on error *