Add a way to get default settings

- Implement a means of obtaining default settings for an
   input/output/encoder.  obs_source_defaults for example will return
   the default settings for a particular source type.

 - Because C++ doesn't have designated initializers, use functions in
   the WASAPI plugin to register the sources instead.
This commit is contained in:
jp9000 2014-03-07 06:55:21 -07:00
parent e88ee06310
commit 7d48dbb1dc
11 changed files with 122 additions and 41 deletions

View File

@ -88,6 +88,19 @@ void obs_encoder_destroy(obs_encoder_t encoder)
}
}
obs_data_t obs_encoder_defaults(const char *id)
{
const struct obs_encoder_info *info = get_encoder_info(id);
if (info) {
obs_data_t settings = obs_data_create();
if (info->defaults)
info->defaults(settings);
return settings;
}
return NULL;
}
obs_properties_t obs_encoder_properties(const char *id, const char *locale)
{
const struct obs_encoder_info *ei = get_encoder_info(id);

View File

@ -134,6 +134,13 @@ struct obs_encoder_info {
/* ----------------------------------------------------------------- */
/* Optional implementation */
/**
* Gets the default settings for this encoder
*
* @param[out] settings Data to assign default settings to
*/
void (*defaults)(obs_data_t settings);
/**
* Gets the property information of this encoder
*

View File

@ -1,5 +1,5 @@
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
Copyright (C) 2013-2014 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -93,6 +93,19 @@ bool obs_output_active(obs_output_t output)
return (output != NULL) ? output->info.active(output) : false;
}
obs_data_t obs_output_defaults(const char *id)
{
const struct obs_output_info *info = find_output(id);
if (info) {
obs_data_t settings = obs_data_create();
if (info->defaults)
info->defaults(settings);
return settings;
}
return NULL;
}
obs_properties_t obs_output_properties(const char *id, const char *locale)
{
const struct obs_output_info *info = find_output(id);

View File

@ -34,6 +34,8 @@ struct obs_output_info {
/* optional */
void (*update)(void *data, obs_data_t settings);
void (*defaults)(obs_data_t settings);
obs_properties_t (*properties)(const char *locale);
void (*pause)(void *data);

View File

@ -298,6 +298,19 @@ bool obs_source_removed(obs_source_t source)
return source ? source->removed : true;
}
obs_data_t obs_source_settings(enum obs_source_type type, const char *id)
{
const struct obs_source_info *info = get_source_info(type, id);
if (info) {
obs_data_t settings = obs_data_create();
if (info->defaults)
info->defaults(settings);
return settings;
}
return NULL;
}
obs_properties_t obs_source_properties(enum obs_source_type type,
const char *id, const char *locale)
{

View File

@ -135,6 +135,13 @@ struct obs_source_info {
/* ----------------------------------------------------------------- */
/* Optional implementation */
/**
* Gets the default settings for this source
*
* @param[out] settings Data to assign default settings to
*/
void (*defaults)(obs_data_t settings);
/**
* Gets the property information of this source
*

View File

@ -434,13 +434,13 @@ EXPORT bool obs_source_removed(obs_source_t source);
/**
* Retrieves flags that specify what type of data the source presents/modifies.
*
* SOURCE_VIDEO if it presents/modifies video_frame
* SOURCE_ASYNC if the video is asynchronous.
* SOURCE_AUDIO if it presents/modifies audio (always async)
*/
EXPORT uint32_t obs_source_get_output_flags(obs_source_t source);
/** Gets the default settings for a source type */
EXPORT obs_data_t obs_source_defaults(enum obs_source_type type,
const char *id);
/** Returns the property list, if any. Free with obs_properties_destroy */
EXPORT obs_properties_t obs_source_properties(enum obs_source_type type,
const char *id, const char *locale);
@ -658,6 +658,9 @@ EXPORT void obs_output_stop(obs_output_t output);
/** Returns whether the output is active */
EXPORT bool obs_output_active(obs_output_t output);
/** Gets the default settings for an output type */
EXPORT obs_data_t obs_output_defaults(const char *id);
/** Returns the property list, if any. Free with obs_properties_destroy */
EXPORT obs_properties_t obs_output_properties(const char *id,
const char *locale);
@ -698,8 +701,11 @@ EXPORT void obs_encoder_stop(obs_encoder_t encoder,
void (*new_packet)(void *param, struct encoder_packet *packet),
void *param);
/** Gets the default settings for an encoder type */
EXPORT obs_data_t obs_encoder_defaults(const char *id);
/** Returns the property list, if any. Free with obs_properties_destroy */
EXPORT obs_properties_t obs_output_properties(const char *id,
EXPORT obs_properties_t obs_encoder_properties(const char *id,
const char *locale);
EXPORT void obs_encoder_update(obs_encoder_t encoder, obs_data_t settings);

View File

@ -664,13 +664,16 @@ static void coreaudio_destroy(void *data)
}
}
static void coreaudio_defaults(obs_data_t settings)
{
obs_data_set_default_string(settings, "device_id", "default");
}
static void *coreaudio_create(obs_data_t settings, obs_source_t source,
bool input)
{
struct coreaudio_data *ca = bzalloc(sizeof(struct coreaudio_data));
obs_data_set_default_string(settings, "device_id", "default");
if (event_init(&ca->exit_event, EVENT_TYPE_MANUAL) != 0) {
blog(LOG_WARNING, "[coreaudio_create] failed to create "
"semephore: %d", errno);
@ -745,6 +748,7 @@ struct obs_source_info coreaudio_input_capture_info = {
.getname = coreaudio_input_getname,
.create = coreaudio_create_input_capture,
.destroy = coreaudio_destroy,
.defaults = coreaudio_defaults,
.properties = coreaudio_output_properties
};
@ -755,5 +759,6 @@ struct obs_source_info coreaudio_output_capture_info = {
.getname = coreaudio_output_getname,
.create = coreaudio_create_output_capture,
.destroy = coreaudio_destroy,
.defaults = coreaudio_defaults,
.properties = coreaudio_input_properties
};

View File

@ -101,6 +101,13 @@ static void monitor_capture_destroy(void *data)
bfree(capture);
}
static void monitor_capture_defaults(obs_data_t settings)
{
obs_data_set_default_int(settings, "monitor", 0);
obs_data_set_default_bool(settings, "capture_cursor", true);
obs_data_set_default_bool(settings, "compatibility", false);
}
static void *monitor_capture_create(obs_data_t settings, obs_source_t source)
{
struct monitor_capture *capture;
@ -112,9 +119,7 @@ static void *monitor_capture_create(obs_data_t settings, obs_source_t source)
capture = bzalloc(sizeof(struct monitor_capture));
capture->opaque_effect = opaque_effect;
obs_data_set_default_int(settings, "monitor", 0);
obs_data_set_default_bool(settings, "capture_cursor", true);
obs_data_set_default_bool(settings, "compatibility", false);
monitor_capture_defaults(settings);
update_settings(capture, settings);
return capture;
@ -142,6 +147,7 @@ struct obs_source_info monitor_capture_info = {
.getname = monitor_capture_getname,
.create = monitor_capture_create,
.destroy = monitor_capture_destroy,
.defaults = monitor_capture_defaults,
.video_render = monitor_capture_render,
.video_tick = monitor_capture_tick
};

View File

@ -2,12 +2,12 @@
OBS_DECLARE_MODULE()
extern struct obs_source_info wasapiInput;
extern struct obs_source_info wasapiOutput;
void RegisterWASAPIInput();
void RegisterWASAPIOutput();
bool obs_module_load(uint32_t libobs_ver)
{
obs_register_source(&wasapiInput);
obs_register_source(&wasapiOutput);
RegisterWASAPIInput();
RegisterWASAPIOutput();
return true;
}

View File

@ -9,6 +9,8 @@
using namespace std;
static void GetWASAPIDefaults(obs_data_t settings);
#define KSAUDIO_SPEAKER_4POINT1 (KSAUDIO_SPEAKER_QUAD|SPEAKER_LOW_FREQUENCY)
#define KSAUDIO_SPEAKER_2POINT1 (KSAUDIO_SPEAKER_STEREO|SPEAKER_LOW_FREQUENCY)
@ -69,8 +71,7 @@ WASAPISource::WASAPISource(obs_data_t settings, obs_source_t source_,
source (source_),
isInputDevice (input)
{
obs_data_set_default_string(settings, "device_id", "default");
obs_data_set_default_bool(settings, "use_device_timing", true);
GetWASAPIDefaults(settings);
UpdateSettings(settings);
stopSignal = CreateEvent(nullptr, true, false, nullptr);
@ -392,6 +393,12 @@ static const char *GetWASAPIOutputName(const char *locale)
return "Audio Output Capture (WASAPI)";
}
static void GetWASAPIDefaults(obs_data_t settings)
{
obs_data_set_default_string(settings, "device_id", "default");
obs_data_set_default_bool(settings, "use_device_timing", true);
}
static void *CreateWASAPISource(obs_data_t settings, obs_source_t source,
bool input)
{
@ -456,28 +463,30 @@ static obs_properties_t GetWASAPIPropertiesOutput(const char *locale)
return GetWASAPIProperties(locale, false);
}
struct obs_source_info wasapiInput {
"wasapi_input_capture",
OBS_SOURCE_TYPE_INPUT,
OBS_SOURCE_AUDIO,
GetWASAPIInputName,
CreateWASAPIInput,
DestroyWASAPISource,
GetWASAPIPropertiesInput,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
};
void RegisterWASAPIInput()
{
obs_source_info info = {};
info.id = "wasapi_input_capture";
info.type = OBS_SOURCE_TYPE_INPUT;
info.output_flags = OBS_SOURCE_AUDIO;
info.getname = GetWASAPIInputName;
info.create = CreateWASAPIInput;
info.destroy = DestroyWASAPISource;
info.defaults = GetWASAPIDefaults;
info.properties = GetWASAPIPropertiesInput;
obs_register_source(&info);
}
struct obs_source_info wasapiOutput {
"wasapi_output_capture",
OBS_SOURCE_TYPE_INPUT,
OBS_SOURCE_AUDIO,
GetWASAPIOutputName,
CreateWASAPIOutput,
DestroyWASAPISource,
GetWASAPIPropertiesOutput,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
};
void RegisterWASAPIOutput()
{
obs_source_info info = {};
info.id = "wasapi_output_capture";
info.type = OBS_SOURCE_TYPE_INPUT;
info.output_flags = OBS_SOURCE_AUDIO;
info.getname = GetWASAPIOutputName;
info.create = CreateWASAPIOutput;
info.destroy = DestroyWASAPISource;
info.defaults = GetWASAPIDefaults;
info.properties = GetWASAPIPropertiesOutput;
obs_register_source(&info);
}