Skip to content

Commit

Permalink
Add OCR filter callbacks for media events and enable state management (
Browse files Browse the repository at this point in the history
…#30)

* Add OCR filter callbacks for media events and enable state management

* Remove unused media event callback functions from OCR filter
  • Loading branch information
royshil authored Nov 25, 2024
1 parent 0c1314d commit bd16a1f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 18 additions & 0 deletions src/ocr-filter-callbacks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#include "filter-data.h"
#include "plugin-support.h"

#include <obs.h>

void enable_callback(void *data_, calldata_t *cd)
{
filter_data *gf_ = static_cast<struct filter_data *>(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;
}
}
5 changes: 5 additions & 0 deletions src/ocr-filter-callbacks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <callback/calldata.h>

void enable_callback(void *data_, calldata_t *cd);
15 changes: 15 additions & 0 deletions src/ocr-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<filter_data *>(data);
obs_log(LOG_INFO, "ocr_filter_activate");
tf->isDisabled = false;
}

void ocr_filter_deactivate(void *data)
{
struct filter_data *tf = reinterpret_cast<filter_data *>(data);
obs_log(LOG_INFO, "ocr_filter_deactivate");
tf->isDisabled = true;
}

Expand Down Expand Up @@ -119,13 +122,25 @@ 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;
}

void ocr_filter_destroy(void *data)
{
struct filter_data *tf = reinterpret_cast<filter_data *>(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);
Expand Down

0 comments on commit bd16a1f

Please sign in to comment.