Skip to content

Commit

Permalink
logging level
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Sep 8, 2023
1 parent 5dd8901 commit 45c1db7
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions src/transcription-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ const char *transcription_filter_name(void *unused)

void transcription_filter_destroy(void *data)
{
obs_log(LOG_INFO, "transcription_filter_destroy");

struct transcription_filter_data *gf =
static_cast<struct transcription_filter_data *>(data);

obs_log(gf->log_level, "transcription_filter_destroy");
{
std::lock_guard<std::mutex> lock(*gf->whisper_ctx_mutex);
if (gf->whisper_context != nullptr) {
Expand Down Expand Up @@ -206,21 +205,15 @@ void set_text_callback(struct transcription_filter_data *gf, const std::string &

void transcription_filter_update(void *data, obs_data_t *s)
{
obs_log(LOG_INFO, "transcription_filter_update");

if (!data) {
obs_log(LOG_ERROR, "transcription_filter_update: data is null");
return;
}

struct transcription_filter_data *gf =
static_cast<struct transcription_filter_data *>(data);

obs_log(gf->log_level, "transcription_filter_update");
gf->log_level = (int)obs_data_get_int(s, "log_level");
gf->vad_enabled = obs_data_get_bool(s, "vad_enabled");
gf->log_words = obs_data_get_bool(s, "log_words");

obs_log(LOG_INFO, "transcription_filter: update text source");
obs_log(gf->log_level, "transcription_filter: update text source");
// update the text source
const char *new_text_source_name = obs_data_get_string(s, "subtitle_sources");
obs_weak_source_t *old_weak_text_source = NULL;
Expand Down Expand Up @@ -260,11 +253,11 @@ void transcription_filter_update(void *data, obs_data_t *s)
}

if (old_weak_text_source) {
obs_log(LOG_INFO, "releasing old text source");
obs_log(gf->log_level, "releasing old text source");
obs_weak_source_release(old_weak_text_source);
}

obs_log(LOG_INFO, "transcription_filter: update whisper model");
obs_log(gf->log_level, "transcription_filter: update whisper model");
// update the whisper model path
std::string new_model_path = obs_data_get_string(s, "whisper_model_path");

Expand Down Expand Up @@ -315,7 +308,7 @@ void transcription_filter_update(void *data, obs_data_t *s)
return;
}

obs_log(LOG_INFO, "transcription_filter: update whisper params");
obs_log(gf->log_level, "transcription_filter: update whisper params");
std::lock_guard<std::mutex> lock(*gf->whisper_ctx_mutex);

gf->whisper_params = whisper_full_default_params(
Expand Down Expand Up @@ -350,7 +343,7 @@ void transcription_filter_update(void *data, obs_data_t *s)
void *transcription_filter_create(obs_data_t *settings, obs_source_t *filter)
{
struct transcription_filter_data *gf = static_cast<struct transcription_filter_data *>(
bzalloc(sizeof(struct transcription_filter_data)));
bmalloc(sizeof(struct transcription_filter_data)));

// Get the number of channels for the input source
gf->channels = audio_output_get_channels(obs_get_audio());
Expand Down Expand Up @@ -380,10 +373,10 @@ void *transcription_filter_create(obs_data_t *settings, obs_source_t *filter)

gf->overlap_ms = OVERLAP_SIZE_MSEC;
gf->overlap_frames = (size_t)((float)gf->sample_rate / (1000.0f / (float)gf->overlap_ms));
obs_log(LOG_INFO, "transcription_filter: channels %d, frames %d, sample_rate %d",
obs_log(gf->log_level, "transcription_filter: channels %d, frames %d, sample_rate %d",
(int)gf->channels, (int)gf->frames, gf->sample_rate);

obs_log(LOG_INFO, "transcription_filter: setup audio resampler");
obs_log(gf->log_level, "transcription_filter: setup audio resampler");
struct resample_info src, dst;
src.samples_per_sec = gf->sample_rate;
src.format = AUDIO_FORMAT_FLOAT_PLANAR;
Expand All @@ -395,42 +388,42 @@ void *transcription_filter_create(obs_data_t *settings, obs_source_t *filter)

gf->resampler = audio_resampler_create(&dst, &src);

obs_log(LOG_INFO, "transcription_filter: setup mutexes and condition variables");
obs_log(gf->log_level, "transcription_filter: setup mutexes and condition variables");
gf->whisper_buf_mutex = new std::mutex();
gf->whisper_ctx_mutex = new std::mutex();
gf->wshiper_thread_cv = new std::condition_variable();
gf->text_source_mutex = new std::mutex();
gf->text_source = nullptr;
gf->text_source_name = bstrdup(obs_data_get_string(settings, "subtitle_sources"));

obs_log(LOG_INFO, "transcription_filter: run update");
obs_log(gf->log_level, "transcription_filter: run update");
// get the settings updated on the filter data struct
transcription_filter_update(gf, settings);

obs_log(LOG_INFO, "transcription_filter: start whisper thread");
obs_log(gf->log_level, "transcription_filter: start whisper thread");
// start the thread
std::thread new_whisper_thread(whisper_loop, gf);
gf->whisper_thread.swap(new_whisper_thread);

gf->active = true;

obs_log(LOG_INFO, "transcription_filter: filter created.");
obs_log(gf->log_level, "transcription_filter: filter created.");
return gf;
}

void transcription_filter_activate(void *data)
{
struct transcription_filter_data *gf =
static_cast<struct transcription_filter_data *>(data);
obs_log(LOG_INFO, "transcription_filter filter activated");
obs_log(gf->log_level, "transcription_filter filter activated");
gf->active = true;
}

void transcription_filter_deactivate(void *data)
{
struct transcription_filter_data *gf =
static_cast<struct transcription_filter_data *>(data);
obs_log(LOG_INFO, "transcription_filter filter deactivated");
obs_log(gf->log_level, "transcription_filter filter deactivated");
gf->active = false;
}

Expand Down

0 comments on commit 45c1db7

Please sign in to comment.