Skip to content
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
10 changes: 4 additions & 6 deletions obs-studio-client/source/callback-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

bool globalCallback::isWorkerRunning = false;
bool globalCallback::worker_stop = true;
uint32_t globalCallback::sleepIntervalMS = 50;
std::chrono::milliseconds globalCallback::sleepInterval(50);
std::thread *globalCallback::worker_thread = nullptr;
Napi::ThreadSafeFunction globalCallback::js_source_callback;
Napi::ThreadSafeFunction globalCallback::js_transition_callback;
Expand Down Expand Up @@ -244,8 +244,6 @@ void globalCallback::worker()
delete data;
};

size_t totalSleepMS = 0;

while (!worker_stop && !m_all_workers_stop) {
auto tp_start = std::chrono::high_resolution_clock::now();

Expand Down Expand Up @@ -382,9 +380,9 @@ void globalCallback::worker()
do_sleep:
auto tp_end = std::chrono::high_resolution_clock::now();
auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(tp_end - tp_start);
totalSleepMS = std::max(0, static_cast<int>(sleepIntervalMS - dur.count()));
if (totalSleepMS > 0)
std::this_thread::sleep_for(std::chrono::milliseconds(totalSleepMS));
const auto sleepDuration = sleepInterval - dur;
if (sleepDuration > std::chrono::milliseconds(0))
std::this_thread::sleep_for(sleepDuration);
}
return;
}
Expand Down
5 changes: 3 additions & 2 deletions obs-studio-client/source/callback-manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

******************************************************************************/

#include <chrono>
#include <mutex>
#include <napi.h>
#include <string>
Expand Down Expand Up @@ -60,7 +61,7 @@ struct SourceMessageInfoData {
namespace globalCallback {
extern bool isWorkerRunning;
extern bool worker_stop;
extern uint32_t sleepIntervalMS;
extern std::chrono::milliseconds sleepInterval;
extern std::thread *worker_thread;
extern Napi::ThreadSafeFunction js_source_callback;
extern Napi::ThreadSafeFunction js_transition_callback;
Expand Down Expand Up @@ -91,4 +92,4 @@ Napi::Value RemoveVolmeterCallback(const Napi::CallbackInfo &info);

Napi::Value RegisterSourceMessageCallback(const Napi::CallbackInfo &info);
Napi::Value RemoveSourceMessageCallback(const Napi::CallbackInfo &info);
}
}
9 changes: 4 additions & 5 deletions obs-studio-client/source/nodeobs_autoconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

bool autoConfig::isWorkerRunning = false;
bool autoConfig::worker_stop = true;
uint32_t autoConfig::sleepIntervalMS = 33;
std::chrono::milliseconds autoConfig::sleepInterval(33);
Napi::ThreadSafeFunction autoConfig::js_thread;
std::thread *autoConfig::worker_thread = nullptr;
std::vector<std::thread *> autoConfig::ac_queue_task_workers;
Expand All @@ -36,8 +36,6 @@ sem_t *ac_sem;

void autoConfig::worker()
{
size_t totalSleepMS = 0;

while (!worker_stop) {
auto tp_start = std::chrono::high_resolution_clock::now();

Expand Down Expand Up @@ -66,8 +64,9 @@ void autoConfig::worker()
do_sleep:
auto tp_end = std::chrono::high_resolution_clock::now();
auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(tp_end - tp_start);
totalSleepMS = sleepIntervalMS - dur.count();
std::this_thread::sleep_for(std::chrono::milliseconds(totalSleepMS));
const auto sleepDuration = sleepInterval - dur;
if (sleepDuration > std::chrono::milliseconds(0))
std::this_thread::sleep_for(sleepDuration);
}
return;
}
Expand Down
3 changes: 2 additions & 1 deletion obs-studio-client/source/nodeobs_autoconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

******************************************************************************/
#pragma once
#include <chrono>
#include <napi.h>
#include "utility-v8.hpp"
#ifdef WIN32
Expand All @@ -40,7 +41,7 @@ extern sem_t *ac_sem;
namespace autoConfig {
extern bool isWorkerRunning;
extern bool worker_stop;
extern uint32_t sleepIntervalMS;
extern std::chrono::milliseconds sleepInterval;
extern Napi::ThreadSafeFunction js_thread;
extern std::thread *worker_thread;
extern std::vector<std::thread *> ac_queue_task_workers;
Expand Down
8 changes: 4 additions & 4 deletions obs-studio-client/source/nodeobs_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ enum VcamInstalledStatus : uint8_t { NotInstalled = 0, LegacyInstalled = 1, Inst

bool service::isWorkerRunning = false;
bool service::worker_stop = true;
uint32_t service::sleepIntervalMS = 33;
std::chrono::milliseconds service::sleepInterval(33);
std::thread *service::worker_thread = nullptr;
Napi::ThreadSafeFunction service::js_thread;
Napi::FunctionReference service::cb;
Expand Down Expand Up @@ -304,7 +304,6 @@ void service::worker()
}
data->sent = true;
};
size_t totalSleepMS = 0;
std::vector<ServiceSignalInfo *> signalsList;
while (!worker_stop) {
auto tp_start = std::chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -348,8 +347,9 @@ void service::worker()

auto tp_end = std::chrono::high_resolution_clock::now();
auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(tp_end - tp_start);
totalSleepMS = sleepIntervalMS - dur.count();
std::this_thread::sleep_for(std::chrono::milliseconds(totalSleepMS));
const auto sleepDuration = sleepInterval - dur;
if (sleepDuration > std::chrono::milliseconds(0))
std::this_thread::sleep_for(sleepDuration);
}

for (auto &signalData : signalsList) {
Expand Down
5 changes: 3 additions & 2 deletions obs-studio-client/source/nodeobs_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

******************************************************************************/

#include <chrono>
#include <mutex>
#include <napi.h>
#include <thread>
Expand All @@ -40,7 +41,7 @@ namespace service {

extern bool isWorkerRunning;
extern bool worker_stop;
extern uint32_t sleepIntervalMS;
extern std::chrono::milliseconds sleepInterval;
extern std::thread *worker_thread;
extern Napi::ThreadSafeFunction js_thread;
extern Napi::FunctionReference cb;
Expand Down Expand Up @@ -79,4 +80,4 @@ Napi::Value OBS_service_updateVirtualCam(const Napi::CallbackInfo &info);
Napi::Value OBS_service_installVirtualCamPlugin(const Napi::CallbackInfo &info);
Napi::Value OBS_service_uninstallVirtualCamPlugin(const Napi::CallbackInfo &info);
Napi::Value OBS_service_isVirtualCamPluginInstalled(const Napi::CallbackInfo &info);
}
}
13 changes: 7 additions & 6 deletions obs-studio-client/source/worker-signals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
******************************************************************************/

#pragma once
#include <chrono>
#include <napi.h>
#include "osn-error.hpp"
#include "utility.hpp"
Expand All @@ -36,15 +37,15 @@ class WorkerSignals {
{
isWorkerRunning = false;
workerStop = true;
sleepIntervalMS = 33;
sleepInterval = std::chrono::milliseconds(33);
workerThread = nullptr;
};
~WorkerSignals(){};

protected:
bool isWorkerRunning;
bool workerStop;
uint32_t sleepIntervalMS;
std::chrono::milliseconds sleepInterval;
std::thread *workerThread;
Napi::ThreadSafeFunction jsThread;
Napi::FunctionReference cb;
Expand Down Expand Up @@ -79,7 +80,6 @@ class WorkerSignals {
}
data->sent = true;
};
size_t totalSleepMS = 0;
std::vector<SignalOutput *> signalsList;
while (!workerStop) {
auto tp_start = std::chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -122,8 +122,9 @@ class WorkerSignals {

auto tp_end = std::chrono::high_resolution_clock::now();
auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(tp_end - tp_start);
totalSleepMS = sleepIntervalMS - dur.count();
std::this_thread::sleep_for(std::chrono::milliseconds(totalSleepMS));
const auto sleepDuration = sleepInterval - dur;
if (sleepDuration > std::chrono::milliseconds(0))
std::this_thread::sleep_for(sleepDuration);
}

return;
Expand All @@ -140,4 +141,4 @@ class WorkerSignals {
workerThread->join();
}
}
};
};
Loading