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.
master
fryshorts 2014-04-28 20:44:01 +02:00
parent bbda252e2d
commit 30a688e942
3 changed files with 57 additions and 7 deletions

View File

@ -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
};

View File

@ -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
*