提交 9478624b 编写于 作者: J jp9000

win-wasapi: Use macros instead of strings

Instead of using strings for setting names, use macros.  Macros prevent
mis-spellings, prevent usage of the wrong name, and if you get it wrong,
it will simply fail to compile, helping to ensure that the right setting
value is being used.
上级 9851c061
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
using namespace std; using namespace std;
#define OPT_DEVICE_ID "device_id"
#define OPT_USE_DEVICE_TIMING "use_device_timing"
static void GetWASAPIDefaults(obs_data_t settings); static void GetWASAPIDefaults(obs_data_t settings);
#define KSAUDIO_SPEAKER_4POINT1 (KSAUDIO_SPEAKER_QUAD|SPEAKER_LOW_FREQUENCY) #define KSAUDIO_SPEAKER_4POINT1 (KSAUDIO_SPEAKER_QUAD|SPEAKER_LOW_FREQUENCY)
...@@ -121,14 +124,14 @@ inline WASAPISource::~WASAPISource() ...@@ -121,14 +124,14 @@ inline WASAPISource::~WASAPISource()
void WASAPISource::UpdateSettings(obs_data_t settings) void WASAPISource::UpdateSettings(obs_data_t settings)
{ {
device_id = obs_data_getstring(settings, "device_id"); device_id = obs_data_getstring(settings, OPT_DEVICE_ID);
useDeviceTiming = obs_data_getbool(settings, "useDeviceTiming"); useDeviceTiming = obs_data_getbool(settings, OPT_USE_DEVICE_TIMING);
isDefaultDevice = _strcmpi(device_id.c_str(), "default") == 0; isDefaultDevice = _strcmpi(device_id.c_str(), "default") == 0;
} }
void WASAPISource::Update(obs_data_t settings) void WASAPISource::Update(obs_data_t settings)
{ {
string newDevice = obs_data_getstring(settings, "device_id"); string newDevice = obs_data_getstring(settings, OPT_DEVICE_ID);
bool restart = newDevice.compare(device_id) != 0; bool restart = newDevice.compare(device_id) != 0;
if (restart) if (restart)
...@@ -430,8 +433,8 @@ static const char *GetWASAPIOutputName(void) ...@@ -430,8 +433,8 @@ static const char *GetWASAPIOutputName(void)
static void GetWASAPIDefaults(obs_data_t settings) static void GetWASAPIDefaults(obs_data_t settings)
{ {
obs_data_set_default_string(settings, "device_id", "default"); obs_data_set_default_string(settings, OPT_DEVICE_ID, "default");
obs_data_set_default_bool(settings, "use_device_timing", true); obs_data_set_default_bool(settings, OPT_USE_DEVICE_TIMING, true);
} }
static void *CreateWASAPISource(obs_data_t settings, obs_source_t source, static void *CreateWASAPISource(obs_data_t settings, obs_source_t source,
...@@ -473,7 +476,7 @@ static obs_properties_t GetWASAPIProperties(bool input) ...@@ -473,7 +476,7 @@ static obs_properties_t GetWASAPIProperties(bool input)
/* TODO: translate */ /* TODO: translate */
obs_property_t device_prop = obs_properties_add_list(props, obs_property_t device_prop = obs_properties_add_list(props,
"device_id", "Device", OPT_DEVICE_ID, "Device",
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING); OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
GetWASAPIAudioDevices(devices, input); GetWASAPIAudioDevices(devices, input);
...@@ -488,7 +491,7 @@ static obs_properties_t GetWASAPIProperties(bool input) ...@@ -488,7 +491,7 @@ static obs_properties_t GetWASAPIProperties(bool input)
} }
obs_property_t prop; obs_property_t prop;
prop = obs_properties_add_bool(props, "use_device_timing", prop = obs_properties_add_bool(props, OPT_USE_DEVICE_TIMING,
"Use Device Timing"); "Use Device Timing");
return props; return props;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册