From 61ee81dc3b3fe8d64dd5e903452cbf3d8e7e7fb2 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Sun, 24 Nov 2024 21:48:05 -0500 Subject: [PATCH] Add OCR filter callbacks for media events and enable state management --- CMakeLists.txt | 1 + src/ocr-filter-callbacks.cpp | 58 ++++++++++++++++++++++++++++++++++++ src/ocr-filter-callbacks.h | 10 +++++++ src/ocr-filter.cpp | 15 ++++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/ocr-filter-callbacks.cpp create mode 100644 src/ocr-filter-callbacks.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f8291b..eee9cdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,7 @@ target_sources( src/obs-utils.cpp src/tesseract-ocr-utils.cpp src/ocr-filter.cpp + src/ocr-filter-callbacks.cpp src/ocr-filter-info.c src/text-render-helper.cpp) diff --git a/src/ocr-filter-callbacks.cpp b/src/ocr-filter-callbacks.cpp new file mode 100644 index 0000000..8207a4d --- /dev/null +++ b/src/ocr-filter-callbacks.cpp @@ -0,0 +1,58 @@ + +#include "filter-data.h" +#include "plugin-support.h" + +#include + +void media_play_callback(void *data_, calldata_t *cd) +{ + UNUSED_PARAMETER(cd); + filter_data *gf_ = static_cast(data_); + obs_log(LOG_INFO, "media_play"); + gf_->isDisabled = false; +} + +void media_started_callback(void *data_, calldata_t *cd) +{ + UNUSED_PARAMETER(cd); + filter_data *gf_ = static_cast(data_); + obs_log(LOG_INFO, "media_started"); + gf_->isDisabled = false; +} + +void media_pause_callback(void *data_, calldata_t *cd) +{ + UNUSED_PARAMETER(cd); + filter_data *gf_ = static_cast(data_); + obs_log(LOG_INFO, "media_pause"); + gf_->isDisabled = true; +} + +void media_restart_callback(void *data_, calldata_t *cd) +{ + UNUSED_PARAMETER(cd); + filter_data *gf_ = static_cast(data_); + obs_log(LOG_INFO, "media_restart"); + gf_->isDisabled = false; +} + +void media_stopped_callback(void *data_, calldata_t *cd) +{ + UNUSED_PARAMETER(cd); + filter_data *gf_ = static_cast(data_); + obs_log(LOG_INFO, "media_stopped"); + gf_->isDisabled = true; +} + +void enable_callback(void *data_, calldata_t *cd) +{ + filter_data *gf_ = static_cast(data_); + bool enable = calldata_bool(cd, "enabled"); + if (enable) { + obs_log(LOG_INFO, "enable_callback: enable"); + gf_->isDisabled = false; + } else { + obs_log(LOG_INFO, "enable_callback: disable"); + gf_->isDisabled = true; + } +} diff --git a/src/ocr-filter-callbacks.h b/src/ocr-filter-callbacks.h new file mode 100644 index 0000000..77f3ae4 --- /dev/null +++ b/src/ocr-filter-callbacks.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +void media_play_callback(void *data_, calldata_t *cd); +void media_started_callback(void *data_, calldata_t *cd); +void media_pause_callback(void *data_, calldata_t *cd); +void media_restart_callback(void *data_, calldata_t *cd); +void media_stopped_callback(void *data_, calldata_t *cd); +void enable_callback(void *data_, calldata_t *cd); diff --git a/src/ocr-filter.cpp b/src/ocr-filter.cpp index 9292136..5c5cfc7 100644 --- a/src/ocr-filter.cpp +++ b/src/ocr-filter.cpp @@ -17,6 +17,7 @@ #include "consts.h" #include "tesseract-ocr-utils.h" #include "ocr-filter.h" +#include "ocr-filter-callbacks.h" const char *ocr_filter_getname(void *unused) { @@ -79,12 +80,14 @@ void ocr_filter_update(void *data, obs_data_t *settings) void ocr_filter_activate(void *data) { struct filter_data *tf = reinterpret_cast(data); + obs_log(LOG_INFO, "ocr_filter_activate"); tf->isDisabled = false; } void ocr_filter_deactivate(void *data) { struct filter_data *tf = reinterpret_cast(data); + obs_log(LOG_INFO, "ocr_filter_deactivate"); tf->isDisabled = true; } @@ -119,6 +122,15 @@ void *ocr_filter_create(obs_data_t *settings, obs_source_t *source) ocr_filter_update(tf, settings); + signal_handler_t *sh_filter = obs_source_get_signal_handler(tf->source); + if (sh_filter == nullptr) { + obs_log(LOG_ERROR, "Failed to get signal handler"); + tf->isDisabled = true; + return nullptr; + } + + signal_handler_connect(sh_filter, "enable", enable_callback, tf); + return tf; } @@ -126,6 +138,9 @@ void ocr_filter_destroy(void *data) { struct filter_data *tf = reinterpret_cast(data); + signal_handler_t *sh_filter = obs_source_get_signal_handler(tf->source); + signal_handler_disconnect(sh_filter, "enable", enable_callback, tf); + if (tf) { obs_enter_graphics(); gs_texrender_destroy(tf->texrender);