requesthandler: Add private source settings get/set requests

It was requested via Discord to be able to modify the private settings
of any private source, since that functionality is used by some client
software to store stateful data. As private settings are in territory
that no normal user should ever tread into, these requests will be left
undocumented.
This commit is contained in:
tt2468 2022-01-01 17:43:26 -08:00
parent 8f2d266dec
commit 6a2d5968ad
4 changed files with 40 additions and 2 deletions

View File

@ -56,6 +56,8 @@ const std::unordered_map<std::string, RequestMethodHandler> RequestHandler::_han
{"GetSourceActive", &RequestHandler::GetSourceActive}, {"GetSourceActive", &RequestHandler::GetSourceActive},
{"GetSourceScreenshot", &RequestHandler::GetSourceScreenshot}, {"GetSourceScreenshot", &RequestHandler::GetSourceScreenshot},
{"SaveSourceScreenshot", &RequestHandler::SaveSourceScreenshot}, {"SaveSourceScreenshot", &RequestHandler::SaveSourceScreenshot},
{"GetSourcePrivateSettings", &RequestHandler::GetSourcePrivateSettings},
{"SetSourcePrivateSettings", &RequestHandler::SetSourcePrivateSettings},
// Scenes // Scenes
{"GetSceneList", &RequestHandler::GetSceneList}, {"GetSceneList", &RequestHandler::GetSceneList},

View File

@ -74,6 +74,8 @@ class RequestHandler {
RequestResult GetSourceActive(const Request&); RequestResult GetSourceActive(const Request&);
RequestResult GetSourceScreenshot(const Request&); RequestResult GetSourceScreenshot(const Request&);
RequestResult SaveSourceScreenshot(const Request&); RequestResult SaveSourceScreenshot(const Request&);
RequestResult GetSourcePrivateSettings(const Request&);
RequestResult SetSourcePrivateSettings(const Request&);
// Scenes // Scenes
RequestResult GetSceneList(const Request&); RequestResult GetSceneList(const Request&);

View File

@ -675,8 +675,6 @@ RequestResult RequestHandler::GetSceneItemBlendMode(const Request& request)
return RequestResult::Success(responseData); return RequestResult::Success(responseData);
} }
/** /**
* Sets the blend mode of a scene item. * Sets the blend mode of a scene item.
* *

View File

@ -312,3 +312,39 @@ RequestResult RequestHandler::SaveSourceScreenshot(const Request& request)
return RequestResult::Success(); return RequestResult::Success();
} }
// Intentionally undocumented
RequestResult RequestHandler::GetSourcePrivateSettings(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
OBSSourceAutoRelease source = request.ValidateSource("sourceName", statusCode, comment);
if (!source)
return RequestResult::Error(statusCode, comment);
OBSDataAutoRelease privateSettings = obs_source_get_private_settings(source);
json responseData;
responseData["sourceSettings"] = Utils::Json::ObsDataToJson(privateSettings);
return RequestResult::Success(responseData);
}
// Intentionally undocumented
RequestResult RequestHandler::SetSourcePrivateSettings(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
OBSSourceAutoRelease source = request.ValidateSource("sourceName", statusCode, comment);
if (!source || !request.ValidateObject("sourceSettings", statusCode, comment))
return RequestResult::Error(statusCode, comment);
OBSDataAutoRelease privateSettings = obs_source_get_private_settings(source);
OBSDataAutoRelease newSettings = Utils::Json::JsonToObsData(request.RequestData["sourceSettings"]);
// Always overlays to prevent destroying internal source data unintentionally
obs_data_apply(privateSettings, newSettings);
return RequestResult::Success();
}