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
This commit is contained in:
tt2468 2021-05-14 03:59:00 -07:00
parent becf604fc3
commit 9077ac911d
7 changed files with 70 additions and 13 deletions

View File

@ -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

View File

@ -239,9 +239,6 @@ void EventHandler::SourceDestroyedMultiHandler(void *param, calldata_t *data)
{
auto eventHandler = reinterpret_cast<EventHandler*>(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<obs_source_t>(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

View File

@ -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);
};

View File

@ -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);
}

View File

@ -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);
}

View File

@ -25,7 +25,7 @@ std::vector<std::string> 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<json> Utils::Obs::ListHelper::GetSceneList()
std::vector<json> 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<json> Utils::Obs::ListHelper::GetSceneList()
return ret;
}
std::vector<json> Utils::Obs::ListHelper::GetTransitionList()
{
obs_frontend_source_list transitionList = {};
obs_frontend_get_transitions(&transitionList);
std::vector<json> 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;
}

View File

@ -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<std::string> GetSceneCollectionList();
std::vector<std::string> GetProfileList();
std::vector<json> GetSceneList();
std::vector<json> GetTransitionList();
}
}
}