diff --git a/src/obs_interface.cpp b/src/obs_interface.cpp index d343128..bbb2298 100644 --- a/src/obs_interface.cpp +++ b/src/obs_interface.cpp @@ -612,6 +612,8 @@ void ObsInterface::connect_signal_handlers(obs_output_t *output) { signal_handler_connect(sh, "starting", output_signal_handler, starting_ctx); signal_handler_connect(sh, "stopping", output_signal_handler, stopping_ctx); signal_handler_connect(sh, "stop", output_signal_handler, stop_ctx); + signal_handler_connect(sh, "activate", output_signal_handler, activate_ctx); + signal_handler_connect(sh, "deactivate", output_signal_handler, deactivate_ctx); } void ObsInterface::disconnect_signal_handlers(obs_output_t *output) { @@ -620,6 +622,8 @@ void ObsInterface::disconnect_signal_handlers(obs_output_t *output) { signal_handler_disconnect(sh, "start", output_signal_handler, start_ctx); signal_handler_disconnect(sh, "stopping", output_signal_handler, stopping_ctx); signal_handler_disconnect(sh, "stop", output_signal_handler, stop_ctx); + signal_handler_disconnect(sh, "activate", output_signal_handler, activate_ctx); + signal_handler_disconnect(sh, "deactivate ", output_signal_handler, deactivate_ctx); } bool draw_source_outline(obs_scene_t *scene, obs_sceneitem_t *item, void *p) { @@ -935,6 +939,8 @@ ObsInterface::ObsInterface( start_ctx = new SignalContext{ this, "start" }; stopping_ctx = new SignalContext{ this, "stopping" }; stop_ctx = new SignalContext{ this, "stop" }; + activate_ctx = new SignalContext{this, "activate"}; + deactivate_ctx = new SignalContext{this, "deactivate"}; // Create the resources we rely on. create_scene(); @@ -965,6 +971,8 @@ ObsInterface::~ObsInterface() { delete start_ctx; delete stopping_ctx; delete stop_ctx; + delete activate_ctx; + delete deactivate_ctx; for (auto& kv : sources) { std::string name = kv.first; diff --git a/src/obs_interface.h b/src/obs_interface.h index e3ff07b..5dc2e64 100644 --- a/src/obs_interface.h +++ b/src/obs_interface.h @@ -119,6 +119,8 @@ class ObsInterface { SignalContext* start_ctx; SignalContext* stopping_ctx; SignalContext* stop_ctx; + SignalContext* activate_ctx; + SignalContext* deactivate_ctx; static void output_signal_handler(void *data, calldata_t *cd); void list_encoders(obs_encoder_type type = OBS_ENCODER_VIDEO); diff --git a/test/buffered.js b/test/buffered.js index 1151bc3..62271af 100644 --- a/test/buffered.js +++ b/test/buffered.js @@ -1,11 +1,29 @@ const noobs = require('../index.js'); const path = require('path'); +process.on('uncaughtException', (err) => { + console.log('Uncaught exception:', err); +}); + +const someGlobalState = { + shouldRebuffer: false, +}; + +o = console.log; +console.log = (...args) => { + o(`[${new Date().toISOString()}] ` + args[0], args[1]); +}; + async function test() { console.log('Starting obs...'); const cb = (msg) => { console.log('Callback received:', msg); + if (someGlobalState.shouldRebuffer && msg.id === 'deactivate') { + console.log('Starting buffer.'); + noobs.StartBuffer(); + someGlobalState.shouldRebuffer = false; + } }; const distPath = path.resolve(__dirname, '../dist'); @@ -35,17 +53,19 @@ async function test() { console.log('Source properties:', properties); console.log('Source properties:', properties[0].items); - await new Promise((resolve) => setTimeout(resolve, 1000)); + await new Promise((resolve) => setTimeout(resolve, 5000)); const recordingNames = new Set(); - for (let i = 0; i < 2; i++) { + for (let i = 0; i < 1; i++) { console.log('Test Recording Loop:', i + 1); // Start the buffer. + console.log('Starting buffer.'); noobs.StartBuffer(); await new Promise((resolve) => setTimeout(resolve, 5000)); // Start the recording, with 1s offset into the past. + console.log('Starting recording.'); noobs.StartRecording(1); await new Promise((resolve) => setTimeout(resolve, 5000)); @@ -59,10 +79,17 @@ async function test() { noobs.RemoveSourceFromScene('Test Source'); await new Promise((resolve) => setTimeout(resolve, 1000)); + someGlobalState.shouldRebuffer = true; // Stop the recording. + console.log('Stopping recording.'); noobs.StopRecording(); await new Promise((resolve) => setTimeout(resolve, 5000)); + console.log('Starting recording.'); + noobs.StartRecording(0); + await new Promise((resolve) => setTimeout(resolve, 5000)); + noobs.StopRecording(); + // Get the path to the last recording. const last = noobs.GetLastRecording(); recordingNames.add(last);