From dbfcb0948ee6b20bfe2e85e6bc032096b8034d27 Mon Sep 17 00:00:00 2001 From: Alexander Hussein-Kershaw Date: Tue, 27 May 2025 12:47:59 +0100 Subject: [PATCH 1/2] add force stop recording --- obs-studio-client/source/nodeobs_service.cpp | 14 +++++++-- obs-studio-client/source/nodeobs_service.hpp | 1 + obs-studio-server/source/nodeobs_service.cpp | 32 +++++++++++++++----- obs-studio-server/source/nodeobs_service.h | 2 ++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/obs-studio-client/source/nodeobs_service.cpp b/obs-studio-client/source/nodeobs_service.cpp index 208ff5a53..f66ff065a 100644 --- a/obs-studio-client/source/nodeobs_service.cpp +++ b/obs-studio-client/source/nodeobs_service.cpp @@ -186,6 +186,16 @@ Napi::Value service::OBS_service_stopRecording(const Napi::CallbackInfo &info) return info.Env().Undefined(); } +Napi::Value service::OBS_service_stopRecordingForce(const Napi::CallbackInfo &info) +{ + auto conn = GetConnection(info); + if (!conn) + return info.Env().Undefined(); + + conn->call("NodeOBS_Service", "OBS_service_stopRecordingForce", {}); + return info.Env().Undefined(); +} + Napi::Value service::OBS_service_stopReplayBuffer(const Napi::CallbackInfo &info) { bool forceStop = info[0].ToBoolean().Value(); @@ -510,6 +520,7 @@ void service::Init(Napi::Env env, Napi::Object exports) exports.Set(Napi::String::New(env, "OBS_service_startRecording"), Napi::Function::New(env, service::OBS_service_startRecording)); exports.Set(Napi::String::New(env, "OBS_service_startReplayBuffer"), Napi::Function::New(env, service::OBS_service_startReplayBuffer)); exports.Set(Napi::String::New(env, "OBS_service_stopRecording"), Napi::Function::New(env, service::OBS_service_stopRecording)); + exports.Set(Napi::String::New(env, "OBS_service_stopRecordingForce"), Napi::Function::New(env, service::OBS_service_stopRecordingForce)); exports.Set(Napi::String::New(env, "OBS_service_stopStreaming"), Napi::Function::New(env, service::OBS_service_stopStreaming)); exports.Set(Napi::String::New(env, "OBS_service_stopReplayBuffer"), Napi::Function::New(env, service::OBS_service_stopReplayBuffer)); exports.Set(Napi::String::New(env, "OBS_service_connectOutputSignals"), Napi::Function::New(env, service::OBS_service_connectOutputSignals)); @@ -523,6 +534,5 @@ void service::Init(Napi::Env env, Napi::Object exports) exports.Set(Napi::String::New(env, "OBS_service_updateVirtualCam"), Napi::Function::New(env, service::OBS_service_updateVirtualCam)); exports.Set(Napi::String::New(env, "OBS_service_installVirtualCamPlugin"), Napi::Function::New(env, service::OBS_service_installVirtualCamPlugin)); exports.Set(Napi::String::New(env, "OBS_service_uninstallVirtualCamPlugin"), Napi::Function::New(env, service::OBS_service_uninstallVirtualCamPlugin)); - exports.Set(Napi::String::New(env, "OBS_service_isVirtualCamPluginInstalled"), - Napi::Function::New(env, service::OBS_service_isVirtualCamPluginInstalled)); + exports.Set(Napi::String::New(env, "OBS_service_isVirtualCamPluginInstalled"), Napi::Function::New(env, service::OBS_service_isVirtualCamPluginInstalled)); } diff --git a/obs-studio-client/source/nodeobs_service.hpp b/obs-studio-client/source/nodeobs_service.hpp index ffdf29751..16c9b4877 100644 --- a/obs-studio-client/source/nodeobs_service.hpp +++ b/obs-studio-client/source/nodeobs_service.hpp @@ -56,6 +56,7 @@ Napi::Value OBS_service_startRecording(const Napi::CallbackInfo &info); Napi::Value OBS_service_startReplayBuffer(const Napi::CallbackInfo &info); Napi::Value OBS_service_stopStreaming(const Napi::CallbackInfo &info); Napi::Value OBS_service_stopRecording(const Napi::CallbackInfo &info); +Napi::Value OBS_service_stopRecordingForce(const Napi::CallbackInfo &info); Napi::Value OBS_service_stopReplayBuffer(const Napi::CallbackInfo &info); Napi::Value OBS_service_connectOutputSignals(const Napi::CallbackInfo &info); diff --git a/obs-studio-server/source/nodeobs_service.cpp b/obs-studio-server/source/nodeobs_service.cpp index 1a09e8617..5a2dfe05a 100644 --- a/obs-studio-server/source/nodeobs_service.cpp +++ b/obs-studio-server/source/nodeobs_service.cpp @@ -137,23 +137,20 @@ void OBS_service::Register(ipc::server &srv) cls->register_function(std::make_shared("OBS_service_startStreaming", std::vector{}, OBS_service_startStreaming)); cls->register_function(std::make_shared("OBS_service_startRecording", std::vector{}, OBS_service_startRecording)); cls->register_function(std::make_shared("OBS_service_startReplayBuffer", std::vector{}, OBS_service_startReplayBuffer)); - cls->register_function( - std::make_shared("OBS_service_stopStreaming", std::vector{ipc::type::Int32}, OBS_service_stopStreaming)); + cls->register_function(std::make_shared("OBS_service_stopStreaming", std::vector{ipc::type::Int32}, OBS_service_stopStreaming)); cls->register_function(std::make_shared("OBS_service_stopRecording", std::vector{}, OBS_service_stopRecording)); - cls->register_function( - std::make_shared("OBS_service_stopReplayBuffer", std::vector{ipc::type::Int32}, OBS_service_stopReplayBuffer)); + cls->register_function(std::make_shared("OBS_service_stopRecordingForce", std::vector{}, OBS_service_stopRecordingForce)); + cls->register_function(std::make_shared("OBS_service_stopReplayBuffer", std::vector{ipc::type::Int32}, OBS_service_stopReplayBuffer)); cls->register_function(std::make_shared("OBS_service_connectOutputSignals", std::vector{}, OBS_service_connectOutputSignals)); cls->register_function(std::make_shared("Query", std::vector{}, Query)); - cls->register_function( - std::make_shared("OBS_service_processReplayBufferHotkey", std::vector{}, OBS_service_processReplayBufferHotkey)); + cls->register_function(std::make_shared("OBS_service_processReplayBufferHotkey", std::vector{}, OBS_service_processReplayBufferHotkey)); cls->register_function(std::make_shared("OBS_service_splitFile", std::vector{}, OBS_service_splitFile)); cls->register_function(std::make_shared("OBS_service_getLastReplay", std::vector{}, OBS_service_getLastReplay)); cls->register_function(std::make_shared("OBS_service_getLastRecording", std::vector{}, OBS_service_getLastRecording)); cls->register_function(std::make_shared("OBS_service_startVirtualCam", std::vector{}, OBS_service_startVirtualCam)); cls->register_function(std::make_shared("OBS_service_stopVirtualCam", std::vector{}, OBS_service_stopVirtualCam)); - cls->register_function(std::make_shared("OBS_service_updateVirtualCam", std::vector{ipc::type::Int32, ipc::type::String}, - OBS_service_updateVirtualCam)); + cls->register_function(std::make_shared("OBS_service_updateVirtualCam", std::vector{ipc::type::Int32, ipc::type::String}, OBS_service_updateVirtualCam)); srv.register_collection(cls); } @@ -278,6 +275,18 @@ void OBS_service::OBS_service_stopRecording(void *data, const int64_t id, const AUTO_DEBUG; } +void OBS_service::OBS_service_stopRecordingForce(void *data, const int64_t id, const std::vector &args, std::vector &rval) +{ + stopRecordingForce(); + rval.push_back(ipc::value((uint64_t)ErrorCode::Ok)); + +#if !defined(_WIN32) + util::CrashManager::UpdateBriefCrashInfoAppState(); +#endif + + AUTO_DEBUG; +} + void OBS_service::OBS_service_stopReplayBuffer(void *data, const int64_t id, const std::vector &args, std::vector &rval) { stopReplayBuffer((bool)args[0].value_union.i32); @@ -1762,6 +1771,13 @@ void OBS_service::stopRecording(void) isRecording = false; } +void OBS_service::stopRecordingForce(void) +{ + blog(LOG_WARNING, "stopRecordingForce with %s", obs_output_active(recordingOutput) ? "recordingOutput active" : "recordingOutput not active"); + obs_output_force_stop(recordingOutput); + isRecording = false; +} + void OBS_service::updateReplayBufferOutput(bool isSimpleMode, bool useStreamEncoder) { blog(LOG_INFO, "updateReplayBufferOutput - isSimpleMode: %d, useStreamEncoder: %d", (int)isSimpleMode, (int)useStreamEncoder); diff --git a/obs-studio-server/source/nodeobs_service.h b/obs-studio-server/source/nodeobs_service.h index 0c9d873a6..29ae849bf 100644 --- a/obs-studio-server/source/nodeobs_service.h +++ b/obs-studio-server/source/nodeobs_service.h @@ -137,6 +137,7 @@ class OBS_service { static void OBS_service_startReplayBuffer(void *data, const int64_t id, const std::vector &args, std::vector &rval); static void OBS_service_stopStreaming(void *data, const int64_t id, const std::vector &args, std::vector &rval); static void OBS_service_stopRecording(void *data, const int64_t id, const std::vector &args, std::vector &rval); + static void OBS_service_stopRecordingForce(void *data, const int64_t id, const std::vector &args, std::vector &rval); static void OBS_service_stopReplayBuffer(void *data, const int64_t id, const std::vector &args, std::vector &rval); static void OBS_service_connectOutputSignals(void *data, const int64_t id, const std::vector &args, std::vector &rval); static void OBS_service_processReplayBufferHotkey(void *data, const int64_t id, const std::vector &args, std::vector &rval); @@ -158,6 +159,7 @@ class OBS_service { static bool startReplayBuffer(void); static void stopReplayBuffer(bool forceStop); static void stopRecording(void); + static void stopRecordingForce(void); static void releaseStreamingOutput(StreamServiceId serviceId); From 4fc3a1bcd724b715aa9d773b2f17c6257f1d3c19 Mon Sep 17 00:00:00 2001 From: aza547 Date: Wed, 28 May 2025 19:34:36 +0100 Subject: [PATCH 2/2] bugfix force stop --- obs-studio-server/source/nodeobs_service.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/obs-studio-server/source/nodeobs_service.cpp b/obs-studio-server/source/nodeobs_service.cpp index 5a2dfe05a..8aacae847 100644 --- a/obs-studio-server/source/nodeobs_service.cpp +++ b/obs-studio-server/source/nodeobs_service.cpp @@ -1773,8 +1773,11 @@ void OBS_service::stopRecording(void) void OBS_service::stopRecordingForce(void) { - blog(LOG_WARNING, "stopRecordingForce with %s", obs_output_active(recordingOutput) ? "recordingOutput active" : "recordingOutput not active"); - obs_output_force_stop(recordingOutput); + blog(LOG_WARNING, "stopRecordingForce called"); + + if (recordingOutput && obs_output_active(recordingOutput)) + obs_output_force_stop(recordingOutput); + isRecording = false; }