Skip to content

Commit

Permalink
New settings API for autoconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
avoitenko-logitech committed Aug 31, 2023
1 parent 6ad035d commit eaca4fe
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 236 deletions.
72 changes: 53 additions & 19 deletions obs-studio-client/source/nodeobs_autoconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
#include "nodeobs_autoconfig.hpp"
#include "shared.hpp"

#include <unordered_set>

bool autoConfig::isWorkerRunning = false;
bool autoConfig::worker_stop = true;
uint32_t autoConfig::sleepIntervalMS = 33;
Napi::ThreadSafeFunction autoConfig::js_thread;
std::thread *autoConfig::worker_thread = nullptr;
std::vector<std::thread *> autoConfig::ac_queue_task_workers;
std::string bind_ip = "default";

#ifdef WIN32
const char *ac_sem_name = nullptr; // Not used on Windows
Expand Down Expand Up @@ -106,6 +109,7 @@ Napi::Value autoConfig::InitializeAutoConfig(const Napi::CallbackInfo &info)
Napi::Object serverInfo = info[1].ToObject();
std::string continent = serverInfo.Get("continent").ToString().Utf8Value();
std::string service = serverInfo.Get("service_name").ToString().Utf8Value();
bind_ip = serverInfo.Get("bind_ip").ToString().Utf8Value();

auto conn = GetConnection(info);
if (!conn)
Expand All @@ -130,7 +134,7 @@ Napi::Value autoConfig::StartBandwidthTest(const Napi::CallbackInfo &info)
if (!conn)
return info.Env().Undefined();

std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "StartBandwidthTest", {});
std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "StartBandwidthTest", {ipc::value(bind_ip)});
if (!ValidateResponse(info, response))
return info.Env().Undefined();

Expand Down Expand Up @@ -225,43 +229,74 @@ Napi::Value autoConfig::StartCheckSettings(const Napi::CallbackInfo &info)
return info.Env().Undefined();
}

Napi::Value autoConfig::StartSetDefaultSettings(const Napi::CallbackInfo &info)
Napi::Value autoConfig::UseAutoConfigDefaultSettings(const Napi::CallbackInfo &info)
{
auto conn = GetConnection(info);
if (!conn)
return info.Env().Undefined();

std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "StartSetDefaultSettings", {});
std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "UseAutoConfigDefaultSettings", {});
if (!ValidateResponse(info, response))
return info.Env().Undefined();

return info.Env().Undefined();
}

Napi::Value autoConfig::StartSaveStreamSettings(const Napi::CallbackInfo &info)
{
auto conn = GetConnection(info);
if (!conn)
return info.Env().Undefined();
namespace {

std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "StartSaveStreamSettings", {});
if (!ValidateResponse(info, response))
return info.Env().Undefined();

return info.Env().Undefined();
Napi::Value napiValueFromIpcValue(const Napi::Env &env, const ipc::value &v)
{
switch (v.type) {
case ipc::type::Null:
return env.Null();
case ipc::type::Float:
return Napi::Number::New(env, v.value_union.fp32);
case ipc::type::Double:
return Napi::Number::New(env, v.value_union.fp64);
case ipc::type::Int32:
return Napi::Number::New(env, v.value_union.i32);
case ipc::type::Int64:
return Napi::Number::New(env, v.value_union.i64);
case ipc::type::UInt32:
return Napi::Number::New(env, v.value_union.ui32);
case ipc::type::UInt64:
return Napi::Number::New(env, v.value_union.ui64);
case ipc::type::String:
return Napi::String::New(env, v.value_str);
case ipc::type::Binary: {
auto res = Napi::ArrayBuffer::New(env, v.value_bin.size());
for (std::size_t i = 0; i < v.value_bin.size(); ++i) {
res.Set(i, v.value_bin[i]);
}
return res;
}
}
}

Napi::Value autoConfig::StartSaveSettings(const Napi::CallbackInfo &info)
} // namespace

Napi::Value autoConfig::GetNewSettings(const Napi::CallbackInfo &info)
{
auto conn = GetConnection(info);
if (!conn)
return info.Env().Undefined();

std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "StartSaveSettings", {});
std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "GetNewSettings", {});
if (!ValidateResponse(info, response))
return info.Env().Undefined();

return info.Env().Undefined();
std::size_t counter = 0;
auto result = Napi::Array::New(info.Env());
for (std::size_t i = 1; i < response.size(); i += 3, counter++) {
auto settingsTuple = Napi::Array::New(info.Env());
settingsTuple.Set(uint32_t(0), Napi::String::New(info.Env(), response[i].value_str));
settingsTuple.Set(uint32_t(1), Napi::String::New(info.Env(), response[i + 1].value_str));
settingsTuple.Set(uint32_t(2), napiValueFromIpcValue(info.Env(), response[i + 2]));

result.Set(counter, settingsTuple);
}

return result;
}

Napi::Value autoConfig::TerminateAutoConfig(const Napi::CallbackInfo &info)
Expand All @@ -288,8 +323,7 @@ void autoConfig::Init(Napi::Env env, Napi::Object exports)
exports.Set(Napi::String::New(env, "StartStreamEncoderTest"), Napi::Function::New(env, autoConfig::StartStreamEncoderTest));
exports.Set(Napi::String::New(env, "StartRecordingEncoderTest"), Napi::Function::New(env, autoConfig::StartRecordingEncoderTest));
exports.Set(Napi::String::New(env, "StartCheckSettings"), Napi::Function::New(env, autoConfig::StartCheckSettings));
exports.Set(Napi::String::New(env, "StartSetDefaultSettings"), Napi::Function::New(env, autoConfig::StartSetDefaultSettings));
exports.Set(Napi::String::New(env, "StartSaveStreamSettings"), Napi::Function::New(env, autoConfig::StartSaveStreamSettings));
exports.Set(Napi::String::New(env, "StartSaveSettings"), Napi::Function::New(env, autoConfig::StartSaveSettings));
exports.Set(Napi::String::New(env, "UseAutoConfigDefaultSettings"), Napi::Function::New(env, autoConfig::UseAutoConfigDefaultSettings));
exports.Set(Napi::String::New(env, "GetNewSettings"), Napi::Function::New(env, autoConfig::GetNewSettings));
exports.Set(Napi::String::New(env, "TerminateAutoConfig"), Napi::Function::New(env, autoConfig::TerminateAutoConfig));
}
5 changes: 2 additions & 3 deletions obs-studio-client/source/nodeobs_autoconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ Napi::Value StartBandwidthTest(const Napi::CallbackInfo &info);
Napi::Value StartStreamEncoderTest(const Napi::CallbackInfo &info);
Napi::Value StartRecordingEncoderTest(const Napi::CallbackInfo &info);
Napi::Value StartCheckSettings(const Napi::CallbackInfo &info);
Napi::Value StartSetDefaultSettings(const Napi::CallbackInfo &info);
Napi::Value StartSaveStreamSettings(const Napi::CallbackInfo &info);
Napi::Value StartSaveSettings(const Napi::CallbackInfo &info);
Napi::Value UseAutoConfigDefaultSettings(const Napi::CallbackInfo &info);
Napi::Value GetNewSettings(const Napi::CallbackInfo &info);
Napi::Value TerminateAutoConfig(const Napi::CallbackInfo &info);
}
Loading

0 comments on commit eaca4fe

Please sign in to comment.