Base: Fix some formatting

This commit is contained in:
tt2468 2022-02-16 13:30:10 -08:00
parent 66c14dced5
commit db2ffa569a
9 changed files with 224 additions and 224 deletions

View File

@ -135,12 +135,12 @@ void EventHandler::ConnectSourceSignals(obs_source_t *source) // Applies to inpu
signal_handler_connect(sh, "mute", HandleInputMuteStateChanged, this); signal_handler_connect(sh, "mute", HandleInputMuteStateChanged, this);
signal_handler_connect(sh, "volume", HandleInputVolumeChanged, this); signal_handler_connect(sh, "volume", HandleInputVolumeChanged, this);
signal_handler_connect(sh, "audio_balance", HandleInputAudioBalanceChanged, this); signal_handler_connect(sh, "audio_balance", HandleInputAudioBalanceChanged, this);
signal_handler_connect(sh, "audio_sync", HandleInputAudioSyncOffsetChanged, this); signal_handler_connect(sh, "audio_sync", HandleInputAudioSyncOffsetChanged, this);
signal_handler_connect(sh, "audio_mixers", HandleInputAudioTracksChanged, this); signal_handler_connect(sh, "audio_mixers", HandleInputAudioTracksChanged, this);
signal_handler_connect(sh, "audio_monitoring", HandleInputAudioMonitorTypeChanged, this); signal_handler_connect(sh, "audio_monitoring", HandleInputAudioMonitorTypeChanged, this);
signal_handler_connect(sh, "filter_add", HandleSourceFilterCreated, this); signal_handler_connect(sh, "filter_add", HandleSourceFilterCreated, this);
signal_handler_connect(sh, "filter_remove", HandleSourceFilterRemoved, this); signal_handler_connect(sh, "filter_remove", HandleSourceFilterRemoved, this);
signal_handler_connect(sh, "reorder_filters", HandleSourceFilterListReindexed, this); signal_handler_connect(sh, "reorder_filters", HandleSourceFilterListReindexed, this);
if (sourceType == OBS_SOURCE_TYPE_INPUT) { if (sourceType == OBS_SOURCE_TYPE_INPUT) {
signal_handler_connect(sh, "media_started", HandleMediaInputPlaybackStarted, this); signal_handler_connect(sh, "media_started", HandleMediaInputPlaybackStarted, this);
@ -191,9 +191,9 @@ void EventHandler::DisconnectSourceSignals(obs_source_t *source)
signal_handler_disconnect(sh, "media_stopped", SourceMediaStopMultiHandler, this); signal_handler_disconnect(sh, "media_stopped", SourceMediaStopMultiHandler, this);
signal_handler_disconnect(sh, "media_next", SourceMediaNextMultiHandler, this); signal_handler_disconnect(sh, "media_next", SourceMediaNextMultiHandler, this);
signal_handler_disconnect(sh, "media_previous", SourceMediaPreviousMultiHandler, this); signal_handler_disconnect(sh, "media_previous", SourceMediaPreviousMultiHandler, this);
signal_handler_disconnect(sh, "filter_add", HandleSourceFilterCreated, this); signal_handler_disconnect(sh, "filter_add", HandleSourceFilterCreated, this);
signal_handler_disconnect(sh, "filter_remove", HandleSourceFilterRemoved, this); signal_handler_disconnect(sh, "filter_remove", HandleSourceFilterRemoved, this);
signal_handler_disconnect(sh, "reorder_filters", HandleSourceFilterListReindexed, this); signal_handler_disconnect(sh, "reorder_filters", HandleSourceFilterListReindexed, this);
// Scenes // Scenes
signal_handler_disconnect(sh, "item_add", HandleSceneItemCreated, this); signal_handler_disconnect(sh, "item_add", HandleSceneItemCreated, this);
@ -207,26 +207,26 @@ void EventHandler::DisconnectSourceSignals(obs_source_t *source)
void EventHandler::ConnectFilterSignals(obs_source_t *filter) void EventHandler::ConnectFilterSignals(obs_source_t *filter)
{ {
if (!filter || obs_source_removed(filter)) if (!filter || obs_source_removed(filter))
return; return;
DisconnectFilterSignals(filter); DisconnectFilterSignals(filter);
signal_handler_t* sh = obs_source_get_signal_handler(filter); signal_handler_t* sh = obs_source_get_signal_handler(filter);
signal_handler_connect(sh, "enable", HandleSourceFilterEnableStateChanged, this); signal_handler_connect(sh, "enable", HandleSourceFilterEnableStateChanged, this);
signal_handler_connect(sh, "rename", HandleSourceFilterNameChanged, this); signal_handler_connect(sh, "rename", HandleSourceFilterNameChanged, this);
} }
void EventHandler::DisconnectFilterSignals(obs_source_t *filter) void EventHandler::DisconnectFilterSignals(obs_source_t *filter)
{ {
if (!filter) if (!filter)
return; return;
signal_handler_t* sh = obs_source_get_signal_handler(filter); signal_handler_t* sh = obs_source_get_signal_handler(filter);
signal_handler_disconnect(sh, "enable", HandleSourceFilterEnableStateChanged, this); signal_handler_disconnect(sh, "enable", HandleSourceFilterEnableStateChanged, this);
signal_handler_disconnect(sh, "rename", HandleSourceFilterNameChanged, this); signal_handler_disconnect(sh, "rename", HandleSourceFilterNameChanged, this);
} }
void EventHandler::OnFrontendEvent(enum obs_frontend_event event, void *private_data) void EventHandler::OnFrontendEvent(enum obs_frontend_event event, void *private_data)

View File

@ -141,9 +141,9 @@ class EventHandler
void HandleMediaInputActionTriggered(obs_source_t *source, ObsMediaInputAction action); void HandleMediaInputActionTriggered(obs_source_t *source, ObsMediaInputAction action);
// Filters // Filters
static void HandleSourceFilterNameChanged(void *param, calldata_t *data); // Direct callback static void HandleSourceFilterNameChanged(void *param, calldata_t *data); // Direct callback
static void HandleSourceFilterCreated(void *param, calldata_t *data); // Direct callback static void HandleSourceFilterCreated(void *param, calldata_t *data); // Direct callback
static void HandleSourceFilterRemoved(void *param, calldata_t *data); // Direct callback static void HandleSourceFilterRemoved(void *param, calldata_t *data); // Direct callback
static void HandleSourceFilterListReindexed(void *param, calldata_t *data); // Direct callback static void HandleSourceFilterListReindexed(void *param, calldata_t *data); // Direct callback
static void HandleSourceFilterEnableStateChanged(void *param, calldata_t *data); // Direct callback static void HandleSourceFilterEnableStateChanged(void *param, calldata_t *data); // Direct callback
}; };

View File

@ -39,28 +39,28 @@ with this program. If not, see <https://www.gnu.org/licenses/>
*/ */
void EventHandler::HandleSourceFilterCreated(void *param, calldata_t *data) void EventHandler::HandleSourceFilterCreated(void *param, calldata_t *data)
{ {
auto eventHandler = static_cast<EventHandler*>(param); auto eventHandler = static_cast<EventHandler*>(param);
obs_source_t *source = GetCalldataPointer<obs_source_t>(data, "source"); obs_source_t *source = GetCalldataPointer<obs_source_t>(data, "source");
obs_source_t *filter = GetCalldataPointer<obs_source_t>(data, "filter"); obs_source_t *filter = GetCalldataPointer<obs_source_t>(data, "filter");
if (!(source && filter)) if (!(source && filter))
return; return;
eventHandler->ConnectFilterSignals(filter); eventHandler->ConnectFilterSignals(filter);
std::string filterKind = obs_source_get_id(filter); std::string filterKind = obs_source_get_id(filter);
OBSDataAutoRelease filterSettings = obs_source_get_settings(filter); OBSDataAutoRelease filterSettings = obs_source_get_settings(filter);
OBSDataAutoRelease defaultFilterSettings = obs_get_source_defaults(filterKind.c_str()); OBSDataAutoRelease defaultFilterSettings = obs_get_source_defaults(filterKind.c_str());
json eventData; json eventData;
eventData["sourceName"] = obs_source_get_name(source); eventData["sourceName"] = obs_source_get_name(source);
eventData["filterName"] = obs_source_get_name(filter); eventData["filterName"] = obs_source_get_name(filter);
eventData["filterKind"] = filterKind; eventData["filterKind"] = filterKind;
eventData["filterIndex"] = Utils::Obs::NumberHelper::GetSourceFilterIndex(source, filter); eventData["filterIndex"] = Utils::Obs::NumberHelper::GetSourceFilterIndex(source, filter);
eventData["filterSettings"] = Utils::Json::ObsDataToJson(filterSettings); eventData["filterSettings"] = Utils::Json::ObsDataToJson(filterSettings);
eventData["defaultFilterSettings"] = Utils::Json::ObsDataToJson(defaultFilterSettings, true); eventData["defaultFilterSettings"] = Utils::Json::ObsDataToJson(defaultFilterSettings, true);
eventHandler->BroadcastEvent(EventSubscription::Filters, "SourceFilterCreated", eventData); eventHandler->BroadcastEvent(EventSubscription::Filters, "SourceFilterCreated", eventData);
} }
/** /**
@ -79,27 +79,27 @@ void EventHandler::HandleSourceFilterCreated(void *param, calldata_t *data)
*/ */
void EventHandler::HandleSourceFilterRemoved(void *param, calldata_t *data) void EventHandler::HandleSourceFilterRemoved(void *param, calldata_t *data)
{ {
auto eventHandler = static_cast<EventHandler*>(param); auto eventHandler = static_cast<EventHandler*>(param);
obs_source_t *source = GetCalldataPointer<obs_source_t>(data, "source"); obs_source_t *source = GetCalldataPointer<obs_source_t>(data, "source");
obs_source_t *filter = GetCalldataPointer<obs_source_t>(data, "filter"); obs_source_t *filter = GetCalldataPointer<obs_source_t>(data, "filter");
if (!(source && filter)) if (!(source && filter))
return; return;
eventHandler->DisconnectFilterSignals(filter); eventHandler->DisconnectFilterSignals(filter);
json eventData; json eventData;
eventData["sourceName"] = obs_source_get_name(source); eventData["sourceName"] = obs_source_get_name(source);
eventData["filterName"] = obs_source_get_name(filter); eventData["filterName"] = obs_source_get_name(filter);
eventHandler->BroadcastEvent(EventSubscription::Filters, "SourceFilterRemoved", eventData); eventHandler->BroadcastEvent(EventSubscription::Filters, "SourceFilterRemoved", eventData);
} }
/** /**
* A source's filter list has been reindexed. * A source's filter list has been reindexed.
* *
* @dataField sourceName | String | Name of the source * @dataField sourceName | String | Name of the source
* @dataField filters | Array<Object> | Array of filter objects * @dataField filters | Array<Object> | Array of filter objects
* *
* @eventType SourceFilterListReindexed * @eventType SourceFilterListReindexed
* @eventSubscription Filters * @eventSubscription Filters
@ -111,16 +111,16 @@ void EventHandler::HandleSourceFilterRemoved(void *param, calldata_t *data)
*/ */
void EventHandler::HandleSourceFilterListReindexed(void *param, calldata_t *data) void EventHandler::HandleSourceFilterListReindexed(void *param, calldata_t *data)
{ {
auto eventHandler = static_cast<EventHandler*>(param); auto eventHandler = static_cast<EventHandler*>(param);
obs_source_t *source = GetCalldataPointer<obs_source_t>(data, "source"); obs_source_t *source = GetCalldataPointer<obs_source_t>(data, "source");
if (!source) if (!source)
return; return;
json eventData; json eventData;
eventData["sourceName"] = obs_source_get_name(source); eventData["sourceName"] = obs_source_get_name(source);
eventData["filters"] = Utils::Obs::ArrayHelper::GetSourceFilterList(source); eventData["filters"] = Utils::Obs::ArrayHelper::GetSourceFilterList(source);
eventHandler->BroadcastEvent(EventSubscription::Filters, "SourceFilterListReindexed", eventData); eventHandler->BroadcastEvent(EventSubscription::Filters, "SourceFilterListReindexed", eventData);
} }
/** /**
@ -140,24 +140,24 @@ void EventHandler::HandleSourceFilterListReindexed(void *param, calldata_t *data
*/ */
void EventHandler::HandleSourceFilterEnableStateChanged(void *param, calldata_t *data) void EventHandler::HandleSourceFilterEnableStateChanged(void *param, calldata_t *data)
{ {
auto eventHandler = static_cast<EventHandler*>(param); auto eventHandler = static_cast<EventHandler*>(param);
obs_source_t *filter = GetCalldataPointer<obs_source_t>(data, "source"); obs_source_t *filter = GetCalldataPointer<obs_source_t>(data, "source");
if (!filter) if (!filter)
return; return;
// Not OBSSourceAutoRelease as get_parent doesn't increment refcount // Not OBSSourceAutoRelease as get_parent doesn't increment refcount
obs_source_t *source = obs_filter_get_parent(filter); obs_source_t *source = obs_filter_get_parent(filter);
if (!source) if (!source)
return; return;
bool filterEnabled = calldata_bool(data, "enabled"); bool filterEnabled = calldata_bool(data, "enabled");
json eventData; json eventData;
eventData["sourceName"] = obs_source_get_name(source); eventData["sourceName"] = obs_source_get_name(source);
eventData["filterName"] = obs_source_get_name(filter); eventData["filterName"] = obs_source_get_name(filter);
eventData["filterEnabled"] = filterEnabled; eventData["filterEnabled"] = filterEnabled;
eventHandler->BroadcastEvent(EventSubscription::Filters, "SourceFilterEnableStateChanged", eventData); eventHandler->BroadcastEvent(EventSubscription::Filters, "SourceFilterEnableStateChanged", eventData);
} }
/** /**
@ -177,15 +177,15 @@ void EventHandler::HandleSourceFilterEnableStateChanged(void *param, calldata_t
*/ */
void EventHandler::HandleSourceFilterNameChanged(void *param, calldata_t *data) void EventHandler::HandleSourceFilterNameChanged(void *param, calldata_t *data)
{ {
auto eventHandler = static_cast<EventHandler*>(param); auto eventHandler = static_cast<EventHandler*>(param);
obs_source_t *filter = GetCalldataPointer<obs_source_t>(data, "source"); obs_source_t *filter = GetCalldataPointer<obs_source_t>(data, "source");
if (!filter) if (!filter)
return; return;
json eventData; json eventData;
eventData["sourceName"] = obs_source_get_name(obs_filter_get_parent(filter)); eventData["sourceName"] = obs_source_get_name(obs_filter_get_parent(filter));
eventData["oldFilterName"] = calldata_string(data, "prev_name"); eventData["oldFilterName"] = calldata_string(data, "prev_name");
eventData["filterName"] = calldata_string(data, "new_name"); eventData["filterName"] = calldata_string(data, "new_name");
eventHandler->BroadcastEvent(EventSubscription::Filters, "SourceFilterNameChanged", eventData); eventHandler->BroadcastEvent(EventSubscription::Filters, "SourceFilterNameChanged", eventData);
} }

View File

@ -111,14 +111,14 @@ const std::unordered_map<std::string, RequestMethodHandler> RequestHandler::_han
{"SetTBarPosition", &RequestHandler::SetTBarPosition}, {"SetTBarPosition", &RequestHandler::SetTBarPosition},
// Filters // Filters
{"GetSourceFilterList", &RequestHandler::GetSourceFilterList}, {"GetSourceFilterList", &RequestHandler::GetSourceFilterList},
{"GetSourceFilterDefaultSettings", &RequestHandler::GetSourceFilterDefaultSettings}, {"GetSourceFilterDefaultSettings", &RequestHandler::GetSourceFilterDefaultSettings},
{"CreateSourceFilter", &RequestHandler::CreateSourceFilter}, {"CreateSourceFilter", &RequestHandler::CreateSourceFilter},
{"RemoveSourceFilter", &RequestHandler::RemoveSourceFilter}, {"RemoveSourceFilter", &RequestHandler::RemoveSourceFilter},
{"GetSourceFilter", &RequestHandler::GetSourceFilter}, {"GetSourceFilter", &RequestHandler::GetSourceFilter},
{"SetSourceFilterIndex", &RequestHandler::SetSourceFilterIndex}, {"SetSourceFilterIndex", &RequestHandler::SetSourceFilterIndex},
{"SetSourceFilterSettings", &RequestHandler::SetSourceFilterSettings}, {"SetSourceFilterSettings", &RequestHandler::SetSourceFilterSettings},
{"SetSourceFilterEnabled", &RequestHandler::SetSourceFilterEnabled}, {"SetSourceFilterEnabled", &RequestHandler::SetSourceFilterEnabled},
// Scene Items // Scene Items
{"GetSceneItemList", &RequestHandler::GetSceneItemList}, {"GetSceneItemList", &RequestHandler::GetSceneItemList},

View File

@ -129,14 +129,14 @@ class RequestHandler {
RequestResult SetTBarPosition(const Request&); RequestResult SetTBarPosition(const Request&);
// Filters // Filters
RequestResult GetSourceFilterList(const Request&); RequestResult GetSourceFilterList(const Request&);
RequestResult GetSourceFilterDefaultSettings(const Request&); RequestResult GetSourceFilterDefaultSettings(const Request&);
RequestResult CreateSourceFilter(const Request&); RequestResult CreateSourceFilter(const Request&);
RequestResult RemoveSourceFilter(const Request&); RequestResult RemoveSourceFilter(const Request&);
RequestResult GetSourceFilter(const Request&); RequestResult GetSourceFilter(const Request&);
RequestResult SetSourceFilterIndex(const Request&); RequestResult SetSourceFilterIndex(const Request&);
RequestResult SetSourceFilterSettings(const Request&); RequestResult SetSourceFilterSettings(const Request&);
RequestResult SetSourceFilterEnabled(const Request&); RequestResult SetSourceFilterEnabled(const Request&);
// Scene Items // Scene Items
RequestResult GetSceneItemList(const Request&); RequestResult GetSceneItemList(const Request&);

View File

@ -35,16 +35,16 @@ with this program. If not, see <https://www.gnu.org/licenses/>
*/ */
RequestResult RequestHandler::GetSourceFilterList(const Request& request) RequestResult RequestHandler::GetSourceFilterList(const Request& request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSourceAutoRelease source = request.ValidateSource("sourceName", statusCode, comment); OBSSourceAutoRelease source = request.ValidateSource("sourceName", statusCode, comment);
if(!source) if(!source)
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
json responseData; json responseData;
responseData["filters"] = Utils::Obs::ArrayHelper::GetSourceFilterList(source); responseData["filters"] = Utils::Obs::ArrayHelper::GetSourceFilterList(source);
return RequestResult::Success(responseData); return RequestResult::Success(responseData);
} }
/** /**
@ -63,23 +63,23 @@ RequestResult RequestHandler::GetSourceFilterList(const Request& request)
*/ */
RequestResult RequestHandler::GetSourceFilterDefaultSettings(const Request& request) RequestResult RequestHandler::GetSourceFilterDefaultSettings(const Request& request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
if (!request.ValidateString("filterKind", statusCode, comment)) if (!request.ValidateString("filterKind", statusCode, comment))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
std::string filterKind = request.RequestData["filterKind"]; std::string filterKind = request.RequestData["filterKind"];
auto kinds = Utils::Obs::ArrayHelper::GetFilterKindList(); auto kinds = Utils::Obs::ArrayHelper::GetFilterKindList();
if (std::find(kinds.begin(), kinds.end(), filterKind) == kinds.end()) if (std::find(kinds.begin(), kinds.end(), filterKind) == kinds.end())
return RequestResult::Error(RequestStatus::InvalidFilterKind); return RequestResult::Error(RequestStatus::InvalidFilterKind);
OBSDataAutoRelease defaultSettings = obs_get_source_defaults(filterKind.c_str()); OBSDataAutoRelease defaultSettings = obs_get_source_defaults(filterKind.c_str());
if (!defaultSettings) if (!defaultSettings)
return RequestResult::Error(RequestStatus::InvalidFilterKind); return RequestResult::Error(RequestStatus::InvalidFilterKind);
json responseData; json responseData;
responseData["defaultFilterSettings"] = Utils::Json::ObsDataToJson(defaultSettings, true); responseData["defaultFilterSettings"] = Utils::Json::ObsDataToJson(defaultSettings, true);
return RequestResult::Success(responseData); return RequestResult::Success(responseData);
} }
/** /**
@ -88,7 +88,7 @@ RequestResult RequestHandler::GetSourceFilterDefaultSettings(const Request& requ
* @requestField sourceName | String | Name of the source to add the filter to * @requestField sourceName | String | Name of the source to add the filter to
* @requestField filterName | String | Name of the new filter to be created * @requestField filterName | String | Name of the new filter to be created
* @requestField filterKind | String | The kind of filter to be created * @requestField filterKind | String | The kind of filter to be created
* @requestField ?filterSettings | Object | Settings object to initialize the filter with | Default settings used * @requestField ?filterSettings | Object | Settings object to initialize the filter with | Default settings used
* *
* @requestType CreateSourceFilter * @requestType CreateSourceFilter
* @complexity 3 * @complexity 3
@ -99,37 +99,37 @@ RequestResult RequestHandler::GetSourceFilterDefaultSettings(const Request& requ
*/ */
RequestResult RequestHandler::CreateSourceFilter(const Request& request) RequestResult RequestHandler::CreateSourceFilter(const Request& request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSourceAutoRelease source = request.ValidateSource("sourceName", statusCode, comment); OBSSourceAutoRelease source = request.ValidateSource("sourceName", statusCode, comment);
if (!(source && request.ValidateString("filterName", statusCode, comment) && request.ValidateString("filterKind", statusCode, comment))) if (!(source && request.ValidateString("filterName", statusCode, comment) && request.ValidateString("filterKind", statusCode, comment)))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
std::string filterName = request.RequestData["filterName"]; std::string filterName = request.RequestData["filterName"];
OBSSourceAutoRelease existingFilter = obs_source_get_filter_by_name(source, filterName.c_str()); OBSSourceAutoRelease existingFilter = obs_source_get_filter_by_name(source, filterName.c_str());
if (existingFilter) if (existingFilter)
return RequestResult::Error(RequestStatus::ResourceAlreadyExists, "A filter already exists by that name."); return RequestResult::Error(RequestStatus::ResourceAlreadyExists, "A filter already exists by that name.");
std::string filterKind = request.RequestData["filterKind"]; std::string filterKind = request.RequestData["filterKind"];
auto kinds = Utils::Obs::ArrayHelper::GetFilterKindList(); auto kinds = Utils::Obs::ArrayHelper::GetFilterKindList();
if (std::find(kinds.begin(), kinds.end(), filterKind) == kinds.end()) if (std::find(kinds.begin(), kinds.end(), filterKind) == kinds.end())
return RequestResult::Error(RequestStatus::InvalidFilterKind, "Your specified filter kind is not supported by OBS. Check that any necessary plugins are loaded."); return RequestResult::Error(RequestStatus::InvalidFilterKind, "Your specified filter kind is not supported by OBS. Check that any necessary plugins are loaded.");
OBSDataAutoRelease filterSettings = nullptr; OBSDataAutoRelease filterSettings = nullptr;
if (request.Contains("filterSettings")) { if (request.Contains("filterSettings")) {
if (!request.ValidateOptionalObject("filterSettings", statusCode, comment, true)) if (!request.ValidateOptionalObject("filterSettings", statusCode, comment, true))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
filterSettings = Utils::Json::JsonToObsData(request.RequestData["filterSettings"]); filterSettings = Utils::Json::JsonToObsData(request.RequestData["filterSettings"]);
} }
OBSSourceAutoRelease filter = Utils::Obs::ActionHelper::CreateSourceFilter(source, filterName, filterKind, filterSettings); OBSSourceAutoRelease filter = Utils::Obs::ActionHelper::CreateSourceFilter(source, filterName, filterKind, filterSettings);
if(!filter) if(!filter)
return RequestResult::Error(RequestStatus::ResourceCreationFailed, "Creation of the filter failed."); return RequestResult::Error(RequestStatus::ResourceCreationFailed, "Creation of the filter failed.");
return RequestResult::Success(); return RequestResult::Success();
} }
/** /**
@ -147,15 +147,15 @@ RequestResult RequestHandler::CreateSourceFilter(const Request& request)
*/ */
RequestResult RequestHandler::RemoveSourceFilter(const Request& request) RequestResult RequestHandler::RemoveSourceFilter(const Request& request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
FilterPair pair = request.ValidateFilter("sourceName", "filterName", statusCode, comment); FilterPair pair = request.ValidateFilter("sourceName", "filterName", statusCode, comment);
if (!pair.filter) if (!pair.filter)
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
obs_source_filter_remove(pair.source, pair.filter); obs_source_filter_remove(pair.source, pair.filter);
return RequestResult::Success(); return RequestResult::Success();
} }
/** /**
@ -211,17 +211,17 @@ RequestResult RequestHandler::GetSourceFilter(const Request& request)
*/ */
RequestResult RequestHandler::SetSourceFilterIndex(const Request& request) RequestResult RequestHandler::SetSourceFilterIndex(const Request& request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
FilterPair pair = request.ValidateFilter("sourceName", "filterName", statusCode, comment); FilterPair pair = request.ValidateFilter("sourceName", "filterName", statusCode, comment);
if (!(pair.filter && request.ValidateNumber("filterIndex", statusCode, comment, 0, 8192))) if (!(pair.filter && request.ValidateNumber("filterIndex", statusCode, comment, 0, 8192)))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
int filterIndex = request.RequestData["filterIndex"]; int filterIndex = request.RequestData["filterIndex"];
Utils::Obs::ActionHelper::SetSourceFilterIndex(pair.source, pair.filter, filterIndex); Utils::Obs::ActionHelper::SetSourceFilterIndex(pair.source, pair.filter, filterIndex);
return RequestResult::Success(); return RequestResult::Success();
} }
/** /**
@ -241,34 +241,34 @@ RequestResult RequestHandler::SetSourceFilterIndex(const Request& request)
*/ */
RequestResult RequestHandler::SetSourceFilterSettings(const Request& request) RequestResult RequestHandler::SetSourceFilterSettings(const Request& request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
FilterPair pair = request.ValidateFilter("sourceName", "filterName", statusCode, comment); FilterPair pair = request.ValidateFilter("sourceName", "filterName", statusCode, comment);
if (!(pair.filter && request.ValidateObject("filterSettings", statusCode, comment, true))) if (!(pair.filter && request.ValidateObject("filterSettings", statusCode, comment, true)))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
// Almost identical to SetInputSettings // Almost identical to SetInputSettings
bool overlay = true; bool overlay = true;
if (request.Contains("overlay")) { if (request.Contains("overlay")) {
if (!request.ValidateOptionalBoolean("overlay", statusCode, comment)) if (!request.ValidateOptionalBoolean("overlay", statusCode, comment))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
overlay = request.RequestData["overlay"]; overlay = request.RequestData["overlay"];
} }
OBSDataAutoRelease newSettings = Utils::Json::JsonToObsData(request.RequestData["filterSettings"]); OBSDataAutoRelease newSettings = Utils::Json::JsonToObsData(request.RequestData["filterSettings"]);
if (!newSettings) if (!newSettings)
return RequestResult::Error(RequestStatus::RequestProcessingFailed, "An internal data conversion operation failed. Please report this!"); return RequestResult::Error(RequestStatus::RequestProcessingFailed, "An internal data conversion operation failed. Please report this!");
if (overlay) if (overlay)
obs_source_update(pair.filter, newSettings); obs_source_update(pair.filter, newSettings);
else else
obs_source_reset_settings(pair.filter, newSettings); obs_source_reset_settings(pair.filter, newSettings);
obs_source_update_properties(pair.filter); obs_source_update_properties(pair.filter);
return RequestResult::Success(); return RequestResult::Success();
} }
/** /**
@ -287,15 +287,15 @@ RequestResult RequestHandler::SetSourceFilterSettings(const Request& request)
*/ */
RequestResult RequestHandler::SetSourceFilterEnabled(const Request& request) RequestResult RequestHandler::SetSourceFilterEnabled(const Request& request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
FilterPair pair = request.ValidateFilter("sourceName", "filterName", statusCode, comment); FilterPair pair = request.ValidateFilter("sourceName", "filterName", statusCode, comment);
if (!(pair.filter && request.ValidateBoolean("filterEnabled", statusCode, comment))) if (!(pair.filter && request.ValidateBoolean("filterEnabled", statusCode, comment)))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
bool filterEnabled = request.RequestData["filterEnabled"]; bool filterEnabled = request.RequestData["filterEnabled"];
obs_source_set_enabled(pair.filter, filterEnabled); obs_source_set_enabled(pair.filter, filterEnabled);
return RequestResult::Success(); return RequestResult::Success();
} }

View File

@ -193,8 +193,8 @@ namespace Utils {
std::vector<json> GetListPropertyItems(obs_property_t *property); std::vector<json> GetListPropertyItems(obs_property_t *property);
std::vector<std::string> GetTransitionKindList(); std::vector<std::string> GetTransitionKindList();
std::vector<json> GetSceneTransitionList(); std::vector<json> GetSceneTransitionList();
std::vector<json> GetSourceFilterList(obs_source_t *source); std::vector<json> GetSourceFilterList(obs_source_t *source);
std::vector<std::string> GetFilterKindList(); std::vector<std::string> GetFilterKindList();
} }
namespace ObjectHelper { namespace ObjectHelper {
@ -211,8 +211,8 @@ namespace Utils {
namespace ActionHelper { namespace ActionHelper {
obs_sceneitem_t *CreateSceneItem(obs_source_t *source, obs_scene_t *scene, bool sceneItemEnabled = true, obs_transform_info *sceneItemTransform = nullptr, obs_sceneitem_crop *sceneItemCrop = nullptr); // Increments ref. Use OBSSceneItemAutoRelease obs_sceneitem_t *CreateSceneItem(obs_source_t *source, obs_scene_t *scene, bool sceneItemEnabled = true, obs_transform_info *sceneItemTransform = nullptr, obs_sceneitem_crop *sceneItemCrop = nullptr); // Increments ref. Use OBSSceneItemAutoRelease
obs_sceneitem_t *CreateInput(std::string inputName, std::string inputKind, obs_data_t *inputSettings, obs_scene_t *scene, bool sceneItemEnabled = true); // Increments ref. Use OBSSceneItemAutoRelease obs_sceneitem_t *CreateInput(std::string inputName, std::string inputKind, obs_data_t *inputSettings, obs_scene_t *scene, bool sceneItemEnabled = true); // Increments ref. Use OBSSceneItemAutoRelease
obs_source_t *CreateSourceFilter(obs_source_t *source, std::string filterName, std::string filterKind, obs_data_t *filterSettings); // Increments source ref. Use OBSSourceAutoRelease obs_source_t *CreateSourceFilter(obs_source_t *source, std::string filterName, std::string filterKind, obs_data_t *filterSettings); // Increments source ref. Use OBSSourceAutoRelease
void SetSourceFilterIndex(obs_source_t *source, obs_source_t *filter, size_t index); void SetSourceFilterIndex(obs_source_t *source, obs_source_t *filter, size_t index);
} }
} }
} }

View File

@ -90,27 +90,27 @@ obs_sceneitem_t *Utils::Obs::ActionHelper::CreateInput(std::string inputName, st
obs_source_t *Utils::Obs::ActionHelper::CreateSourceFilter(obs_source_t *source, std::string filterName, std::string filterKind, obs_data_t *filterSettings) obs_source_t *Utils::Obs::ActionHelper::CreateSourceFilter(obs_source_t *source, std::string filterName, std::string filterKind, obs_data_t *filterSettings)
{ {
obs_source_t *filter = obs_source_create_private(filterKind.c_str(), filterName.c_str(), filterSettings); obs_source_t *filter = obs_source_create_private(filterKind.c_str(), filterName.c_str(), filterSettings);
if (!filter) if (!filter)
return nullptr; return nullptr;
obs_source_filter_add(source, filter); obs_source_filter_add(source, filter);
return filter; return filter;
} }
void Utils::Obs::ActionHelper::SetSourceFilterIndex(obs_source_t *source, obs_source_t *filter, size_t index) void Utils::Obs::ActionHelper::SetSourceFilterIndex(obs_source_t *source, obs_source_t *filter, size_t index)
{ {
size_t currentIndex = Utils::Obs::NumberHelper::GetSourceFilterIndex(source, filter); size_t currentIndex = Utils::Obs::NumberHelper::GetSourceFilterIndex(source, filter);
obs_order_movement direction = index > currentIndex ? OBS_ORDER_MOVE_DOWN : OBS_ORDER_MOVE_UP; obs_order_movement direction = index > currentIndex ? OBS_ORDER_MOVE_DOWN : OBS_ORDER_MOVE_UP;
while(currentIndex != index) { while(currentIndex != index) {
obs_source_filter_set_order(source, filter, direction); obs_source_filter_set_order(source, filter, direction);
if (direction == OBS_ORDER_MOVE_DOWN) if (direction == OBS_ORDER_MOVE_DOWN)
currentIndex++; currentIndex++;
else else
currentIndex--; currentIndex--;
} }
} }

View File

@ -279,35 +279,35 @@ std::vector<json> Utils::Obs::ArrayHelper::GetSceneTransitionList()
std::vector<std::string> Utils::Obs::ArrayHelper::GetFilterKindList() std::vector<std::string> Utils::Obs::ArrayHelper::GetFilterKindList()
{ {
std::vector<std::string> ret; std::vector<std::string> ret;
size_t idx = 0; size_t idx = 0;
const char *kind; const char *kind;
while(obs_enum_filter_types(idx++, &kind)) while(obs_enum_filter_types(idx++, &kind))
ret.push_back(kind); ret.push_back(kind);
return ret; return ret;
} }
std::vector<json> Utils::Obs::ArrayHelper::GetSourceFilterList(obs_source_t *source) std::vector<json> Utils::Obs::ArrayHelper::GetSourceFilterList(obs_source_t *source)
{ {
std::vector<json> filters; std::vector<json> filters;
auto enumFilters = [](obs_source_t *, obs_source_t *filter, void *param) { auto enumFilters = [](obs_source_t *, obs_source_t *filter, void *param) {
auto filters = reinterpret_cast<std::vector<json>*>(param); auto filters = reinterpret_cast<std::vector<json>*>(param);
json filterJson; json filterJson;
filterJson["filterEnabled"] = obs_source_enabled(filter); filterJson["filterEnabled"] = obs_source_enabled(filter);
filterJson["filterIndex"] = filters->size(); filterJson["filterIndex"] = filters->size();
filterJson["filterKind"] = obs_source_get_id(filter); filterJson["filterKind"] = obs_source_get_id(filter);
filterJson["filterName"] = obs_source_get_name(filter); filterJson["filterName"] = obs_source_get_name(filter);
OBSDataAutoRelease filterSettings = obs_source_get_settings(filter); OBSDataAutoRelease filterSettings = obs_source_get_settings(filter);
filterJson["filterSettings"] = Utils::Json::ObsDataToJson(filterSettings); filterJson["filterSettings"] = Utils::Json::ObsDataToJson(filterSettings);
filters->push_back(filterJson); filters->push_back(filterJson);
}; };
obs_source_enum_filters(source, enumFilters, &filters); obs_source_enum_filters(source, enumFilters, &filters);
return filters; return filters;
} }