Requests: Fix GetSourceDefaultSettings indentation and docs

This commit is contained in:
tt2468 2021-01-19 18:23:54 -08:00
parent ffb34c3fd4
commit 488a57e2de
4 changed files with 44 additions and 43 deletions

View File

@ -917,41 +917,41 @@ struct obs_data_item { // Used for OBSDataGetDefaults
size_t data_size; size_t data_size;
size_t default_len; size_t default_len;
size_t default_size; size_t default_size;
size_t autoselect_size; size_t autoselect_size;
size_t capacity; size_t capacity;
}; };
obs_data_t *Utils::OBSDataGetDefaults(obs_data_t *data) obs_data_t *Utils::OBSDataGetDefaults(obs_data_t *data)
{ {
obs_data_t *returnData = obs_data_create(); obs_data_t *returnData = obs_data_create();
obs_data_item_t *item = NULL; obs_data_item_t *item = NULL;
for (item = obs_data_first(data); item; obs_data_item_next(&item)) { for (item = obs_data_first(data); item; obs_data_item_next(&item)) {
enum obs_data_type type = obs_data_item_gettype(item); enum obs_data_type type = obs_data_item_gettype(item);
const char *name = (char *)item + sizeof(struct obs_data_item); const char *name = (char *)item + sizeof(struct obs_data_item);
if (type == OBS_DATA_STRING) { if (type == OBS_DATA_STRING) {
const char *val = obs_data_item_get_string(item); const char *val = obs_data_item_get_string(item);
obs_data_set_string(returnData, name, val); obs_data_set_string(returnData, name, val);
} else if (type == OBS_DATA_NUMBER) { } else if (type == OBS_DATA_NUMBER) {
enum obs_data_number_type type = obs_data_item_numtype(item); enum obs_data_number_type type = obs_data_item_numtype(item);
if (type == OBS_DATA_NUM_INT) { if (type == OBS_DATA_NUM_INT) {
long long val = obs_data_item_get_int(item); long long val = obs_data_item_get_int(item);
obs_data_set_int(returnData, name, val); obs_data_set_int(returnData, name, val);
} else { } else {
double val = obs_data_item_get_double(item); double val = obs_data_item_get_double(item);
obs_data_set_double(returnData, name, val); obs_data_set_double(returnData, name, val);
} }
} else if (type == OBS_DATA_BOOLEAN) { } else if (type == OBS_DATA_BOOLEAN) {
bool val = obs_data_item_get_bool(item); bool val = obs_data_item_get_bool(item);
obs_data_set_bool(returnData, name, val); obs_data_set_bool(returnData, name, val);
} else if (type == OBS_DATA_OBJECT) { } else if (type == OBS_DATA_OBJECT) {
OBSDataAutoRelease obj = obs_data_item_get_obj(item); OBSDataAutoRelease obj = obs_data_item_get_obj(item);
obs_data_set_obj(returnData, name, obj); obs_data_set_obj(returnData, name, obj);
} else if (type == OBS_DATA_ARRAY) { } else if (type == OBS_DATA_ARRAY) {
OBSDataArrayAutoRelease array = obs_data_item_get_array(item); OBSDataArrayAutoRelease array = obs_data_item_get_array(item);
obs_data_set_array(returnData, name, array); obs_data_set_array(returnData, name, array);
} }
} }
return returnData; return returnData;
} }

View File

@ -88,12 +88,12 @@ namespace Utils {
const char* GetCurrentRecordingFilename(); const char* GetCurrentRecordingFilename();
QString nsToTimestamp(uint64_t ns); QString nsToTimestamp(uint64_t ns);
struct AddSourceData { struct AddSourceData {
obs_source_t *source; obs_source_t *source;
obs_sceneitem_t *sceneItem; obs_sceneitem_t *sceneItem;
bool setVisible; bool setVisible;
}; };
void AddSourceHelper(void *_data, obs_scene_t *scene); void AddSourceHelper(void *_data, obs_scene_t *scene);
obs_data_t *OBSDataGetDefaults(obs_data_t *data); obs_data_t *OBSDataGetDefaults(obs_data_t *data);
}; };

View File

@ -118,7 +118,7 @@ const QHash<QString, RpcMethodHandler> WSRequestHandler::messageMap{
{ "SetSourceSettings", &WSRequestHandler::SetSourceSettings }, { "SetSourceSettings", &WSRequestHandler::SetSourceSettings },
{ "GetAudioMonitorType", &WSRequestHandler::GetAudioMonitorType }, { "GetAudioMonitorType", &WSRequestHandler::GetAudioMonitorType },
{ "SetAudioMonitorType", &WSRequestHandler::SetAudioMonitorType }, { "SetAudioMonitorType", &WSRequestHandler::SetAudioMonitorType },
{ "GetSourceDefaultSettings", &WSRequestHandler::GetSourceDefaultSettings }, { "GetSourceDefaultSettings", &WSRequestHandler::GetSourceDefaultSettings },
{ "TakeSourceScreenshot", &WSRequestHandler::TakeSourceScreenshot }, { "TakeSourceScreenshot", &WSRequestHandler::TakeSourceScreenshot },
{ "GetSourceFilters", &WSRequestHandler::GetSourceFilters }, { "GetSourceFilters", &WSRequestHandler::GetSourceFilters },

View File

@ -1684,6 +1684,8 @@ RpcResponse WSRequestHandler::SetAudioMonitorType(const RpcRequest& request)
* *
* @param {String} `sourceKind` Source name. * @param {String} `sourceKind` Source name.
* *
* @return {Object} `defaultSettings` Settings object for source.
*
* @api requests * @api requests
* @name GetSourceDefaultSettings * @name GetSourceDefaultSettings
* @category sources * @category sources
@ -1695,22 +1697,21 @@ RpcResponse WSRequestHandler::GetSourceDefaultSettings(const RpcRequest& request
return request.failed("missing request parameters"); return request.failed("missing request parameters");
} }
QString sourceKind = obs_data_get_string(request.parameters(), "sourceKind"); QString sourceKind = obs_data_get_string(request.parameters(), "sourceKind");
if (sourceKind.isEmpty()) {
return request.failed("invalid request parameters");
}
if (sourceKind.isEmpty()) { OBSDataAutoRelease defaultData = obs_get_source_defaults(sourceKind.toUtf8());
return request.failed("invalid request parameters"); if (!defaultData) {
} return request.failed("invalid sourceKind");
}
OBSDataAutoRelease defaultData = obs_get_source_defaults(sourceKind.toUtf8()); OBSDataAutoRelease defaultSettings = Utils::OBSDataGetDefaults(defaultData);
if (!defaultData) {
return request.failed("invalid sourceKind");
}
OBSDataAutoRelease defaultSettings = Utils::OBSDataGetDefaults(defaultData); OBSDataAutoRelease response = obs_data_create();
obs_data_set_obj(response, "defaultSettings", defaultSettings);
OBSDataAutoRelease response = obs_data_create(); return request.success(response);
obs_data_set_obj(response, "defaultSettings", defaultSettings);
return request.success(response);
} }
/** /**