Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OCR filter callbacks for media events and enable state management #30

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading