From 409c270ba2c3cde9cbb78de015a0d69fc3d5e0b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20L?= Date: Mon, 20 May 2019 23:48:49 +0200 Subject: [PATCH 1/2] events: fix TransitionBegin event not triggering --- src/WSEvents.cpp | 35 ++++++++++++++++++++++++++++++++--- src/WSEvents.h | 3 +++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/WSEvents.cpp b/src/WSEvents.cpp index 6922c5392..b25226f60 100644 --- a/src/WSEvents.cpp +++ b/src/WSEvents.cpp @@ -104,6 +104,8 @@ WSEvents::WSEvents(WSServerPtr srv) : heartbeatTimer.start(STATUS_INTERVAL); + hookTransitionBeginEvent(); + // Connect to signals of all existing sources obs_enum_sources([](void* param, obs_source_t* source) { auto self = reinterpret_cast(param); @@ -132,6 +134,8 @@ WSEvents::~WSEvents() { return true; }, this); + unhookTransitionBeginEvent(); + obs_frontend_remove_event_callback(WSEvents::FrontendEventHandler, this); os_cpu_usage_info_destroy(cpuUsageInfo); } @@ -159,6 +163,7 @@ void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private owner->OnTransitionChange(); } else if (event == OBS_FRONTEND_EVENT_TRANSITION_LIST_CHANGED) { + owner->hookTransitionBeginEvent(); owner->OnTransitionListChange(); } else if (event == OBS_FRONTEND_EVENT_PROFILE_CHANGED) { @@ -283,9 +288,6 @@ void WSEvents::connectSourceSignals(obs_source_t* source) { signal_handler_connect(sh, "item_select", OnSceneItemSelected, this); signal_handler_connect(sh, "item_deselect", OnSceneItemDeselected, this); } - if (sourceType == OBS_SOURCE_TYPE_TRANSITION) { - signal_handler_connect(sh, "transition_start", OnTransitionBegin, this); - } } void WSEvents::disconnectSourceSignals(obs_source_t* source) { @@ -318,6 +320,33 @@ void WSEvents::disconnectSourceSignals(obs_source_t* source) { signal_handler_disconnect(sh, "transition_start", OnTransitionBegin, this); } +void WSEvents::hookTransitionBeginEvent() { + obs_frontend_source_list transitions = {}; + obs_frontend_get_transitions(&transitions); + + for (int i = 0; i < transitions.sources.num; i++) { + obs_source_t* transition = transitions.sources.array[i]; + signal_handler_t* sh = obs_source_get_signal_handler(transition); + signal_handler_disconnect(sh, "transition_start", OnTransitionBegin, this); + signal_handler_connect(sh, "transition_start", OnTransitionBegin, this); + } + + obs_frontend_source_list_free(&transitions); +} + +void WSEvents::unhookTransitionBeginEvent() { + obs_frontend_source_list transitions = {}; + obs_frontend_get_transitions(&transitions); + + for (int i = 0; i < transitions.sources.num; i++) { + obs_source_t* transition = transitions.sources.array[i]; + signal_handler_t* sh = obs_source_get_signal_handler(transition); + signal_handler_disconnect(sh, "transition_start", OnTransitionBegin, this); + } + + obs_frontend_source_list_free(&transitions); +} + uint64_t WSEvents::GetStreamingTime() { if (obs_frontend_streaming_active()) return (os_gettime_ns() - _streamStarttime); diff --git a/src/WSEvents.h b/src/WSEvents.h index 9250dc9ee..8a6bbec48 100644 --- a/src/WSEvents.h +++ b/src/WSEvents.h @@ -40,6 +40,9 @@ Q_OBJECT void connectSourceSignals(obs_source_t* source); void disconnectSourceSignals(obs_source_t* source); + void hookTransitionBeginEvent(); + void unhookTransitionBeginEvent(); + uint64_t GetStreamingTime(); const char* GetStreamingTimecode(); uint64_t GetRecordingTime(); From 45dc6447bfb0c73830c8df4c9e7798608d9930e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20L?= Date: Mon, 20 May 2019 23:54:13 +0200 Subject: [PATCH 2/2] events: fix how and when TransitionBegin is hooked --- src/WSEvents.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/WSEvents.cpp b/src/WSEvents.cpp index b25226f60..f2c9e7482 100644 --- a/src/WSEvents.cpp +++ b/src/WSEvents.cpp @@ -104,8 +104,6 @@ WSEvents::WSEvents(WSServerPtr srv) : heartbeatTimer.start(STATUS_INTERVAL); - hookTransitionBeginEvent(); - // Connect to signals of all existing sources obs_enum_sources([](void* param, obs_source_t* source) { auto self = reinterpret_cast(param); @@ -134,8 +132,6 @@ WSEvents::~WSEvents() { return true; }, this); - unhookTransitionBeginEvent(); - obs_frontend_remove_event_callback(WSEvents::FrontendEventHandler, this); os_cpu_usage_info_destroy(cpuUsageInfo); } @@ -147,13 +143,17 @@ void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private return; } - if (event == OBS_FRONTEND_EVENT_SCENE_CHANGED) { + if (event == OBS_FRONTEND_EVENT_FINISHED_LOADING) { + owner->hookTransitionBeginEvent(); + } + else if (event == OBS_FRONTEND_EVENT_SCENE_CHANGED) { owner->OnSceneChange(); } else if (event == OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED) { owner->OnSceneListChange(); } else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED) { + owner->hookTransitionBeginEvent(); owner->OnSceneCollectionChange(); } else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_LIST_CHANGED) { @@ -222,6 +222,7 @@ void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private owner->OnPreviewSceneChanged(); } else if (event == OBS_FRONTEND_EVENT_EXIT) { + owner->unhookTransitionBeginEvent(); owner->OnExit(); } }