Skip to content
Open
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
25 changes: 21 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
ReleaseName: release
Architecture: x86_64
- BuildReleases: Release-arm64
image: macos-14
image: macos-15
BuildConfig: RelWithDebInfo
ReleaseName: release
Architecture: arm64
Expand Down Expand Up @@ -99,6 +99,7 @@ jobs:
needs: build-macos
runs-on: ${{ matrix.image }}
strategy:
fail-fast: false # Don't cancel the other architecture's tests if one fails, so we can get test results for both.
matrix:
BuildReleases: [Release-x86_64, Release-arm64]
include:
Expand All @@ -108,7 +109,7 @@ jobs:
ReleaseName: release
Architecture: x86_64
- BuildReleases: Release-arm64
image: macos-14
image: macos-15
BuildConfig: RelWithDebInfo
ReleaseName: release
Architecture: arm64
Expand Down Expand Up @@ -151,6 +152,15 @@ jobs:
OSN_ACCESS_KEY_ID: ${{secrets.AWS_RELEASE_ACCESS_KEY_ID}}
OSN_SECRET_ACCESS_KEY: ${{secrets.AWS_RELEASE_SECRET_ACCESS_KEY}}
RELEASE_NAME: ${{matrix.ReleaseName}}
CI: true
SUPPRESS_STREAMLABS_OBS_LOGS: true # Prevents logs from being printed in the test output, but still generates log files that can be uploaded as artifacts.
- name: Upload OBS logs
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: obs-logs-mac-${{ matrix.Architecture }}
path: tests/osn-tests/osnData/slobs-client/node-obs/logs/
if-no-files-found: ignore
# Run even after test failures so the PR still gets the flaky summary.
- name: Publish flaky test check
if: ${{ always() }}
Expand Down Expand Up @@ -181,7 +191,7 @@ jobs:
ReleaseName: release
Architecture: x86_64
- BuildReleases: Release-arm64
image: macos-14
image: macos-15
BuildConfig: RelWithDebInfo
ReleaseName: release
Architecture: arm64
Expand Down Expand Up @@ -234,7 +244,7 @@ jobs:
ReleaseName: release
Architecture: x86_64
- BuildReleases: Release-arm64
image: macos-14
image: macos-15
BuildConfig: RelWithDebInfo
ReleaseName: release
Architecture: arm64
Expand Down Expand Up @@ -360,6 +370,13 @@ jobs:
OSN_ACCESS_KEY_ID: ${{secrets.AWS_RELEASE_ACCESS_KEY_ID}}
OSN_SECRET_ACCESS_KEY: ${{secrets.AWS_RELEASE_SECRET_ACCESS_KEY}}
RELEASE_NAME: release
- name: Upload OBS logs
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: obs-logs-windows
path: tests/osn-tests/osnData/slobs-client/node-obs/logs/
if-no-files-found: ignore
# Run even after test failures so the PR still gets the flaky summary.
- name: Publish flaky test check
if: ${{ always() }}
Expand Down
27 changes: 24 additions & 3 deletions obs-studio-client/source/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ std::wstring utfWorkingDir = L"";
#include <wchar.h>
#include <windows.h>
#else
#include <algorithm>
#include <errno.h>
#include <signal.h>
#include <libproc.h>
#include <iostream>
#include <spawn.h>
#include <fcntl.h>
#include <strings.h>
#include <unistd.h>
#include <sys/wait.h>
Comment thread
sandboxcoder marked this conversation as resolved.
extern char **environ;
#endif

Expand Down Expand Up @@ -301,16 +307,31 @@ std::shared_ptr<ipc::client> Controller::host(const std::string &uri)
int st = proc_pidinfo(pids[i], PROC_PIDTBSDINFO, 0, &proc, PROC_PIDTBSDINFO_SIZE);
if (st == PROC_PIDTBSDINFO_SIZE) {
if (strcmp("obs64", proc.pbi_name) == 0) {
if (pids[i] != 0)
kill(pids[i], SIGKILL);
if (pids[i] != 0 && kill(pids[i], SIGKILL) != 0) {
std::cout << "Warning: could not kill orphaned/former obs64 process" << std::endl;
}
}
Comment thread
sandboxcoder marked this conversation as resolved.
}
}

pid_t pid;
std::vector<const char *> argv = {"obs64", uri.c_str(), version.c_str(), serverBinaryPath.c_str(), nullptr};

int ret = posix_spawnp(&pid, serverBinaryPath.c_str(), NULL, NULL, const_cast<char *const *>(argv.data()), environ);
const char *suppressLogsEnv = std::getenv("SUPPRESS_STREAMLABS_OBS_LOGS");
int ret = 0;
if (suppressLogsEnv == nullptr || strcasecmp(suppressLogsEnv, "false") == 0) {
// For development, it can be helpful for process to share stdout/stderr.
ret = posix_spawnp(&pid, serverBinaryPath.c_str(), NULL, NULL, const_cast<char *const *>(argv.data()), environ);
Comment thread
sandboxcoder marked this conversation as resolved.
} else {
// Do not send the logs to stdout/stderr.
posix_spawn_file_actions_t file_actions;
posix_spawn_file_actions_init(&file_actions);
posix_spawn_file_actions_addopen(&file_actions, STDOUT_FILENO, "/dev/null", O_WRONLY, 0);
posix_spawn_file_actions_addopen(&file_actions, STDERR_FILENO, "/dev/null", O_WRONLY, 0);
ret = posix_spawnp(&pid, serverBinaryPath.c_str(), &file_actions, NULL, const_cast<char *const *>(argv.data()), environ);
posix_spawn_file_actions_destroy(&file_actions);
}

if (ret != 0) {
std::cerr << "Could not spawn the server at " << serverBinaryPath.c_str() << " with error code: " << ret << std::endl;
return nullptr;
Expand Down
6 changes: 5 additions & 1 deletion obs-studio-client/source/nodeobs_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
******************************************************************************/

#include "controller.hpp"
#include <filesystem>
#include "osn-error.hpp"
#include "nodeobs_api.hpp"
#include <sstream>
Expand All @@ -36,12 +37,15 @@ Napi::Value api::OBS_API_initAPI(const Napi::CallbackInfo &info)
std::string language;
std::string version;
std::string crashserverurl;
std::string logFilename;

ASSERT_GET_VALUE(info, info[0], language);
ASSERT_GET_VALUE(info, info[1], path);
ASSERT_GET_VALUE(info, info[2], version);
if (info.Length() > 3)
ASSERT_GET_VALUE(info, info[3], crashserverurl);
if (info.Length() > 4)
ASSERT_GET_VALUE(info, info[4], logFilename);

auto conn = GetConnection(info);
if (!conn)
Expand All @@ -50,7 +54,7 @@ Napi::Value api::OBS_API_initAPI(const Napi::CallbackInfo &info)
conn->set_freeze_callback(ipc_freeze_callback, path);

std::vector<ipc::value> response = conn->call_synchronous_helper(
"API", "OBS_API_initAPI", {ipc::value(path), ipc::value(language), ipc::value(version), ipc::value(crashserverurl)});
"API", "OBS_API_initAPI", {ipc::value(path), ipc::value(language), ipc::value(version), ipc::value(crashserverurl), ipc::value(logFilename)});

Comment thread
sandboxcoder marked this conversation as resolved.
// The API init method will return a response error + graphical error
// If there is a problem with the IPC the number of responses here will be zero so we must validate the
Expand Down
3 changes: 2 additions & 1 deletion obs-studio-client/source/nodeobs_autoconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ 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();
auto durCount = dur.count();
totalSleepMS = durCount < sleepIntervalMS ? sleepIntervalMS - durCount : 0;
std::this_thread::sleep_for(std::chrono::milliseconds(totalSleepMS));
}
return;
Expand Down
3 changes: 2 additions & 1 deletion obs-studio-client/source/nodeobs_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ 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();
auto durCount = dur.count();
totalSleepMS = durCount < sleepIntervalMS ? sleepIntervalMS - durCount : 0;
std::this_thread::sleep_for(std::chrono::milliseconds(totalSleepMS));
}

Expand Down
27 changes: 22 additions & 5 deletions obs-studio-client/source/worker-signals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
******************************************************************************/

#pragma once
#include <atomic>
#include <iostream>
#include <napi.h>
#include "osn-error.hpp"
#include "utility.hpp"
Expand All @@ -42,18 +44,21 @@ class WorkerSignals {
~WorkerSignals(){};

protected:
bool isWorkerRunning;
bool workerStop;
std::atomic<bool> isWorkerRunning;
std::atomic<bool> workerStop;
Comment thread
sandboxcoder marked this conversation as resolved.
std::atomic<bool> isOrphaned;
uint32_t sleepIntervalMS;
std::thread *workerThread;
Napi::ThreadSafeFunction jsThread;
Napi::FunctionReference cb;

void startWorker(napi_env env, Napi::Function asyncCallback, const std::string &name, const uint64_t &refID)
{
if (!workerStop || isWorkerRunning)
// If worker has been orphaned; allow it to be rejoined
if (!isOrphaned && (!workerStop || isWorkerRunning))
return;

isOrphaned = false;
isWorkerRunning = true;
workerStop = false;
jsThread = Napi::ThreadSafeFunction::New(env, asyncCallback, name.c_str(), 0, 1, [](Napi::Env) {});
Expand Down Expand Up @@ -88,6 +93,17 @@ class WorkerSignals {
auto conn = Controller::GetInstance().GetConnection();
if (conn) {
std::vector<ipc::value> response = conn->call_synchronous_helper(name, "Query", {ipc::value(refID)});
if (!response.empty()) {
ErrorCode firstError = (ErrorCode)response[0].value_union.ui64;
if (firstError == ErrorCode::InvalidReference) {
// This typically happens if the worker thread is orphaned.
std::string errorMessage = response.size() > 1 ? response[1].value_str : "";
std::cout << "Worker thread exiting due to Invalid reference error encountered: " << errorMessage << std::endl;
isWorkerRunning = false;
isOrphaned = true;
break;
Comment thread
sandboxcoder marked this conversation as resolved.
}
Comment thread
sandboxcoder marked this conversation as resolved.
Comment thread
sandboxcoder marked this conversation as resolved.
Comment thread
sandboxcoder marked this conversation as resolved.
}
if ((response.size() == 5) && signalsList.size() < maximum_signals_in_queue) {
ErrorCode error = (ErrorCode)response[0].value_union.ui64;
if (error == ErrorCode::Ok) {
Expand Down Expand Up @@ -122,7 +138,8 @@ 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();
auto durCount = dur.count();
totalSleepMS = durCount < sleepIntervalMS ? sleepIntervalMS - durCount : 0;
std::this_thread::sleep_for(std::chrono::milliseconds(totalSleepMS));
}

Expand All @@ -140,4 +157,4 @@ class WorkerSignals {
workerThread->join();
}
}
};
};
23 changes: 22 additions & 1 deletion obs-studio-server/source/nodeobs_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,17 @@ void addModulePaths()
#endif
}

std::filesystem::path sanitize_path(const std::filesystem::path &input)
{
std::filesystem::path normalized = input.lexically_normal();

if (normalized.is_absolute() || normalized.string().find("..") != std::string::npos) {
Comment thread
sandboxcoder marked this conversation as resolved.
return {};
}

return normalized;
Comment thread
sandboxcoder marked this conversation as resolved.
Comment thread
sandboxcoder marked this conversation as resolved.
}

static void listEncoders(obs_encoder_type type)
{
constexpr uint32_t hide_flags = OBS_ENCODER_CAP_DEPRECATED | OBS_ENCODER_CAP_INTERNAL;
Expand Down Expand Up @@ -874,10 +885,20 @@ void OBS_API::OBS_API_initAPI(void *data, const int64_t id, const std::vector<ip
std::string appdata = args[0].value_str;
std::string locale = args[1].value_str;
currentVersion = args[2].value_str;
std::string logFilename;
// Skip index 3 which is reserved for crash-handler server
if (args.size() > 4) {
std::string logname = sanitize_path(args[4].value_str).string();
if (logname.size() > 0) {
std::ostringstream ss;
ss << logname << '-' << GenerateTimeDateFilename("txt");
logFilename = ss.str();
}
Comment thread
sandboxcoder marked this conversation as resolved.
}
utility::osn_current_version(currentVersion);

/* Logging */
std::string filename = GenerateTimeDateFilename("txt");
std::string filename = logFilename.size() > 0 ? logFilename : GenerateTimeDateFilename("txt");
std::string log_path = appdata;
log_path.append("/node-obs/logs/");

Expand Down
30 changes: 17 additions & 13 deletions obs-studio-server/source/osn-replay-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,23 @@ void osn::IReplayBuffer::Query(void *data, const int64_t id, const std::vector<i

void osn::IReplayBuffer::Save(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval)
{
obs_enum_hotkeys(
[](void *data, obs_hotkey_id id, obs_hotkey_t *key) {
if (obs_hotkey_get_registerer_type(key) == OBS_HOTKEY_REGISTERER_OUTPUT) {
std::string key_name = obs_hotkey_get_name(key);
if (key_name.compare("ReplayBuffer.Save") == 0) {
obs_hotkey_enable_callback_rerouting(true);
obs_hotkey_trigger_routed_callback(id, true);
}
}
return true;
},
nullptr);
ReplayBuffer *replayBuffer = static_cast<ReplayBuffer *>(osn::IFileOutput::Manager::GetInstance().find(args.at(0).value_union.ui64));
if (!replayBuffer) {
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "ReplayBuffer reference is not valid.");
}

obs_output_t *output = replayBuffer->GetOutput();
if (!output) {
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "Invalid replay buffer output.");
}

calldata_t cd = {0};
proc_handler_t *ph = obs_output_get_proc_handler(output);
bool hasInvoked = proc_handler_call(ph, "save", &cd);
calldata_free(&cd);

if (!hasInvoked)
PRETTY_ERROR_RETURN(ErrorCode::NotFound, "Could not find ReplayBuffer::Save");
rval.push_back(ipc::value((uint64_t)ErrorCode::Ok));
AUTO_DEBUG;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"local:build": "cmake --build build --target install --config Debug",
"local:clean": "rm -rf build/*",
"test": "electron-mocha -t 80000 --js-flags=\"--expose-gc\" --color -r ts-node/register tests/osn-tests/src/**/*.ts --reporter tests/osn-tests/util/list-reporter.js",
"test:ci": "yarn run test --retries 2"
"test:ci": "yarn run test --retries 3"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.0.0",
Expand Down
4 changes: 0 additions & 4 deletions tests/osn-tests/src/test_nodeobs_autoconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { deleteConfigFiles } from '../util/general';
const testName = 'nodeobs_autoconfig';

describe(testName, function() {
this.timeout(30000)
let obs: OBSHandler;
let hasTestFailed: boolean = false;

Expand Down Expand Up @@ -50,9 +49,6 @@ describe(testName, function() {
});

it('Run autoconfig', async function() {
if (obs.isDarwin()) {
this.skip();
}
const start = performance.now();
let progressInfo: IConfigProgress;
let settingValue: any;
Expand Down
Loading
Loading