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
8 changes: 8 additions & 0 deletions src/obs_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/obs_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 29 additions & 2 deletions test/buffered.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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));

Expand All @@ -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);
Expand Down