From 7d48dbb1dc563af9fc072070f2b1e0fa1801452c Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 7 Mar 2014 06:55:21 -0700 Subject: [PATCH] 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. --- libobs/obs-encoder.c | 13 ++++++ libobs/obs-encoder.h | 7 +++ libobs/obs-output.c | 15 ++++++- libobs/obs-output.h | 2 + libobs/obs-source.c | 13 ++++++ libobs/obs-source.h | 7 +++ libobs/obs.h | 16 ++++--- plugins/mac-capture/mac-audio.c | 9 +++- plugins/win-capture/monitor-capture.c | 12 ++++-- plugins/win-wasapi/plugin-main.cpp | 8 ++-- plugins/win-wasapi/win-wasapi.cpp | 61 +++++++++++++++------------ 11 files changed, 122 insertions(+), 41 deletions(-) diff --git a/libobs/obs-encoder.c b/libobs/obs-encoder.c index c50290ff2..cd25fa482 100644 --- a/libobs/obs-encoder.c +++ b/libobs/obs-encoder.c @@ -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); diff --git a/libobs/obs-encoder.h b/libobs/obs-encoder.h index 9d333d90e..f5747a945 100644 --- a/libobs/obs-encoder.h +++ b/libobs/obs-encoder.h @@ -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 * diff --git a/libobs/obs-output.c b/libobs/obs-output.c index f73613854..22c57d06f 100644 --- a/libobs/obs-output.c +++ b/libobs/obs-output.c @@ -1,5 +1,5 @@ /****************************************************************************** - Copyright (C) 2013 by Hugh Bailey + Copyright (C) 2013-2014 by Hugh Bailey 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); diff --git a/libobs/obs-output.h b/libobs/obs-output.h index ef1a66ae6..5f6924f55 100644 --- a/libobs/obs-output.h +++ b/libobs/obs-output.h @@ -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); diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 1a416638d..b158e97b9 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -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) { diff --git a/libobs/obs-source.h b/libobs/obs-source.h index 904cf3635..a87d802b5 100644 --- a/libobs/obs-source.h +++ b/libobs/obs-source.h @@ -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 * diff --git a/libobs/obs.h b/libobs/obs.h index 153d4a83d..d831252c1 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -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); diff --git a/plugins/mac-capture/mac-audio.c b/plugins/mac-capture/mac-audio.c index 9693433d1..00bebe338 100644 --- a/plugins/mac-capture/mac-audio.c +++ b/plugins/mac-capture/mac-audio.c @@ -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 }; diff --git a/plugins/win-capture/monitor-capture.c b/plugins/win-capture/monitor-capture.c index 6ba27ae6c..eb579e11b 100644 --- a/plugins/win-capture/monitor-capture.c +++ b/plugins/win-capture/monitor-capture.c @@ -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 }; diff --git a/plugins/win-wasapi/plugin-main.cpp b/plugins/win-wasapi/plugin-main.cpp index c8ac6ac79..36de337e6 100644 --- a/plugins/win-wasapi/plugin-main.cpp +++ b/plugins/win-wasapi/plugin-main.cpp @@ -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; } diff --git a/plugins/win-wasapi/win-wasapi.cpp b/plugins/win-wasapi/win-wasapi.cpp index 8957036d1..d13f3d0a0 100644 --- a/plugins/win-wasapi/win-wasapi.cpp +++ b/plugins/win-wasapi/win-wasapi.cpp @@ -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); +}