rebroadcast: set online/offline state without prebuffer requirement

This commit is contained in:
Koushik Dutta
2024-10-29 12:21:40 -07:00
parent 44644448f5
commit ec2e4d64fd
6 changed files with 31 additions and 26 deletions

View File

@@ -1,3 +1,3 @@
{
"scrypted.debugHost": "127.0.0.1",
"scrypted.debugHost": "scrypted-nvr",
}

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/prebuffer-mixin",
"version": "0.10.36",
"version": "0.10.37",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/prebuffer-mixin",
"version": "0.10.36",
"version": "0.10.37",
"license": "Apache-2.0",
"dependencies": {
"@scrypted/common": "file:../../common",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/prebuffer-mixin",
"version": "0.10.36",
"version": "0.10.37",
"description": "Video Stream Rebroadcast, Prebuffer, and Management Plugin for Scrypted.",
"author": "Scrypted",
"license": "Apache-2.0",

View File

@@ -196,13 +196,33 @@ class PrebufferSession {
return;
this.console.log(this.streamName, 'prebuffer session started');
this.parserSessionPromise = this.startPrebufferSession();
this.parserSessionPromise.then(pso => pso.killed.finally(() => {
this.console.error(this.streamName, 'prebuffer session ended');
this.parserSessionPromise = undefined;
}))
let active = false;
this.parserSessionPromise.then(pso => {
pso.once('rtsp', () => {
active = true;
if (!this.mixin.online)
this.mixin.online = true;
});
pso.killed.finally(() => {
this.console.error(this.streamName, 'prebuffer session ended');
this.parserSessionPromise = undefined;
});
})
.catch(e => {
this.console.error(this.streamName, 'prebuffer session ended with error', e);
this.parserSessionPromise = undefined;
if (!active) {
// find sessions that arent this one, and check their prebuffers to see if any data has been received.
// if there's no data, then consider this camera offline.
const others = [...this.mixin.sessions.values()].filter(s => s !== this);
if (others.length) {
const hasData = others.some(s => s.rtspPrebuffer.length);
if (!hasData && this.mixin.online)
this.mixin.online = false;
}
}
});
}
@@ -1415,11 +1435,6 @@ class PrebufferMixin extends SettingsMixinDeviceBase<VideoCamera> implements Vid
}
}
if (!enabledIds.length)
this.online = true;
let active = 0;
// figure out the default stream and streams that may have been removed due to
// a config change.
const toRemove = new Set(this.sessions.keys());
@@ -1462,23 +1477,13 @@ class PrebufferMixin extends SettingsMixinDeviceBase<VideoCamera> implements Vid
}
session.ensurePrebufferSession();
let wasActive = false;
try {
this.console.log(name, 'prebuffer session starting');
const ps = await session.parserSessionPromise;
active++;
wasActive = true;
this.online = !!active;
await ps.killed;
}
catch (e) {
}
finally {
if (wasActive)
active--;
wasActive = false;
this.online = !!active;
}
this.console.log(this.name, 'restarting prebuffer session in 5 seconds');
await new Promise(resolve => setTimeout(resolve, 5000));
}

View File

@@ -1,4 +1,4 @@
{
"scrypted.debugHost": "127.0.0.1",
"scrypted.debugHost": "scrypted-nvr",
}

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/server",
"version": "0.121.4",
"version": "0.121.5",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@scrypted/server",
"version": "0.121.4",
"version": "0.121.5",
"hasInstallScript": true,
"license": "ISC",
"dependencies": {