From 9077ac911d7057f39faaaaad985e75a511b4f698 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Fri, 14 May 2021 03:59:00 -0700 Subject: [PATCH] EventHandler: Add some transition stuff Transitions in OBS are implemented badly. Not sure what will reasonably be possible with them. I'll probably save implementing them for last --- CMakeLists.txt | 1 + src/eventhandler/EventHandler.cpp | 6 ++-- src/eventhandler/EventHandler.h | 5 +++ src/eventhandler/EventHandler_Inputs.cpp | 1 - src/eventhandler/EventHandler_Transitions.cpp | 27 ++++++++++++++++ src/utils/Obs.cpp | 32 +++++++++++++++---- src/utils/Utils.h | 11 +++++-- 7 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 src/eventhandler/EventHandler_Transitions.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ea3e2b6..711111f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,7 @@ set(obs-websocket_SOURCES src/eventhandler/EventHandler_Config.cpp src/eventhandler/EventHandler_Scenes.cpp src/eventhandler/EventHandler_Inputs.cpp + src/eventhandler/EventHandler_Transitions.cpp src/requesthandler/RequestHandler.cpp src/requesthandler/RequestHandler_General.cpp src/requesthandler/rpc/Request.cpp diff --git a/src/eventhandler/EventHandler.cpp b/src/eventhandler/EventHandler.cpp index 5b6aeb05..45fa79ba 100644 --- a/src/eventhandler/EventHandler.cpp +++ b/src/eventhandler/EventHandler.cpp @@ -239,9 +239,6 @@ void EventHandler::SourceDestroyedMultiHandler(void *param, calldata_t *data) { auto eventHandler = reinterpret_cast(param); - if (!eventHandler->_obsLoaded.load()) - return; - // We can't use any smart types because releasing the source will cause infinite recursion obs_source_t *source = GetCalldataPointer(data, "source"); if (!source) @@ -250,6 +247,9 @@ void EventHandler::SourceDestroyedMultiHandler(void *param, calldata_t *data) // Disconnect all signals from the source eventHandler->DisconnectSourceSignals(source); + if (!eventHandler->_obsLoaded.load()) + return; + switch (obs_source_get_type(source)) { case OBS_SOURCE_TYPE_INPUT: eventHandler->HandleInputRemoved(source); // We have to call `InputRemoved` with source_destroy because source_removed is not called when a source is *only* destroyed diff --git a/src/eventhandler/EventHandler.h b/src/eventhandler/EventHandler.h index dee30907..23712d15 100644 --- a/src/eventhandler/EventHandler.h +++ b/src/eventhandler/EventHandler.h @@ -71,4 +71,9 @@ class EventHandler static void HandleInputVolumeChanged(void *param, calldata_t *data); // Direct callback static void HandleInputAudioSyncOffsetChanged(void *param, calldata_t *data); // Direct callback static void HandleInputAudioTracksChanged(void *param, calldata_t *data); // Direct callback + + // Transitions + void HandleTransitionCreated(obs_source_t *source); + void HandleTransitionRemoved(obs_source_t *source); + void HandleTransitionNameChanged(obs_source_t *source, std::string oldTransitionName, std::string transitionName); }; diff --git a/src/eventhandler/EventHandler_Inputs.cpp b/src/eventhandler/EventHandler_Inputs.cpp index e4ea203c..d924349d 100644 --- a/src/eventhandler/EventHandler_Inputs.cpp +++ b/src/eventhandler/EventHandler_Inputs.cpp @@ -20,7 +20,6 @@ void EventHandler::HandleInputRemoved(obs_source_t *source) { json eventData; eventData["inputName"] = obs_source_get_name(source); - eventData["inputKind"] = obs_source_get_id(source); _webSocketServer->BroadcastEvent(EventSubscription::Inputs, "InputRemoved", eventData); } diff --git a/src/eventhandler/EventHandler_Transitions.cpp b/src/eventhandler/EventHandler_Transitions.cpp new file mode 100644 index 00000000..a1471272 --- /dev/null +++ b/src/eventhandler/EventHandler_Transitions.cpp @@ -0,0 +1,27 @@ +#include "EventHandler.h" + +#include "../plugin-macros.generated.h" + +void EventHandler::HandleTransitionCreated(obs_source_t *source) +{ + json eventData; + eventData["transitionName"] = obs_source_get_name(source); + eventData["transitionKind"] = obs_source_get_id(source); + eventData["transitionFixed"] = obs_transition_fixed(source); + _webSocketServer->BroadcastEvent(EventSubscription::Transitions, "TransitionCreated", eventData); +} + +void EventHandler::HandleTransitionRemoved(obs_source_t *source) +{ + json eventData; + eventData["transitionName"] = obs_source_get_name(source); + _webSocketServer->BroadcastEvent(EventSubscription::Transitions, "TransitionRemoved", eventData); +} + +void EventHandler::HandleTransitionNameChanged(obs_source_t *source, std::string oldTransitionName, std::string transitionName) +{ + json eventData; + eventData["oldTransitionName"] = oldTransitionName; + eventData["transitionName"] = transitionName; + _webSocketServer->BroadcastEvent(EventSubscription::Transitions, "TransitionNameChanged", eventData); +} diff --git a/src/utils/Obs.cpp b/src/utils/Obs.cpp index 483e7e01..82645911 100644 --- a/src/utils/Obs.cpp +++ b/src/utils/Obs.cpp @@ -25,7 +25,7 @@ std::vector ConvertStringArray(char **array) return ret; } -std::string Utils::Obs::DataHelper::GetSourceTypeString(obs_source_t *source) +std::string Utils::Obs::StringHelper::GetSourceTypeString(obs_source_t *source) { obs_source_type sourceType = obs_source_get_type(source); @@ -38,9 +38,9 @@ std::string Utils::Obs::DataHelper::GetSourceTypeString(obs_source_t *source) } } -std::string Utils::Obs::DataHelper::GetSourceMonitorTypeString(obs_source_t *source) +std::string Utils::Obs::StringHelper::GetInputMonitorTypeString(obs_source_t *input) { - obs_monitoring_type monitorType = obs_source_get_monitoring_type(source); + obs_monitoring_type monitorType = obs_source_get_monitoring_type(input); switch (monitorType) { default: @@ -50,9 +50,9 @@ std::string Utils::Obs::DataHelper::GetSourceMonitorTypeString(obs_source_t *sou } } -std::string Utils::Obs::DataHelper::GetSourceMediaStateString(obs_source_t *source) +std::string Utils::Obs::StringHelper::GetMediaInputStateString(obs_source_t *input) { - obs_media_state mediaState = obs_source_media_get_state(source); + obs_media_state mediaState = obs_source_media_get_state(input); switch (mediaState) { default: @@ -90,8 +90,8 @@ std::vector Utils::Obs::ListHelper::GetSceneList() std::vector ret; for (size_t i = 0; i < sceneList.sources.num; i++) { - json sceneJson; obs_source_t *scene = sceneList.sources.array[i]; + json sceneJson; sceneJson["sceneName"] = obs_source_get_name(scene); sceneJson["sceneIndex"] = i; ret.push_back(sceneJson); @@ -101,3 +101,23 @@ std::vector Utils::Obs::ListHelper::GetSceneList() return ret; } + +std::vector Utils::Obs::ListHelper::GetTransitionList() +{ + obs_frontend_source_list transitionList = {}; + obs_frontend_get_transitions(&transitionList); + + std::vector ret; + for (size_t i = 0; i < transitionList.sources.num; i++) { + obs_source_t *transition = transitionList.sources.array[i]; + json transitionJson; + transitionJson["transitionName"] = obs_source_get_name(transition); + transitionJson["transitionKind"] = obs_source_get_id(transition); + transitionJson["transitionFixed"] = obs_transition_fixed(transition); + ret.push_back(transitionJson); + } + + obs_frontend_source_list_free(&transitionList); + + return ret; +} diff --git a/src/utils/Utils.h b/src/utils/Utils.h index 280bda2e..701472e2 100644 --- a/src/utils/Utils.h +++ b/src/utils/Utils.h @@ -27,16 +27,21 @@ namespace Utils { } namespace Obs { - namespace DataHelper { + namespace StringHelper { std::string GetSourceTypeString(obs_source_t *source); - std::string GetSourceMonitorTypeString(obs_source_t *source); - std::string GetSourceMediaStateString(obs_source_t *source); + std::string GetInputMonitorTypeString(obs_source_t *input); + std::string GetMediaInputStateString(obs_source_t *input); + } + + namespace DataHelper { + ; } namespace ListHelper { std::vector GetSceneCollectionList(); std::vector GetProfileList(); std::vector GetSceneList(); + std::vector GetTransitionList(); } } }