cameras: dont run configuration in parallel due to race conditions in camera side

This commit is contained in:
Koushik Dutta
2024-08-11 22:20:59 -07:00
parent 9c195594ea
commit b06a3ac55f
7 changed files with 23 additions and 29 deletions

View File

@@ -104,8 +104,18 @@ export async function autoconfigureCodecs(
// get the fps of 20 or highest available
let fps = Math.min(20, Math.max(...l.video.fpsRange));
const waiting: Promise<MediaStreamConfiguration>[] = [];
const confLow = configureCodecs({
let errors = '';
const logConfigureCodecs = async (config: MediaStreamConfiguration) => {
try {
await configureCodecs(config);
}
catch (e) {
errors += e;
}
}
await logConfigureCodecs({
id: l.id,
video: {
width: resolution[0],
@@ -120,7 +130,6 @@ export async function autoconfigureCodecs(
},
audio: audioOptions,
});
waiting.push(confLow);
if (used.length === 3) {
// find remote and low
@@ -131,7 +140,7 @@ export async function autoconfigureCodecs(
const lResolution = findResolutionTarget(l, 640, 360);
fps = Math.min(20, Math.max(...r.video.fpsRange));
const confRemote = configureCodecs({
await logConfigureCodecs({
id: r.id,
video: {
width: rResolution[0],
@@ -146,10 +155,9 @@ export async function autoconfigureCodecs(
},
audio: audioOptions,
});
waiting.push(confRemote);
fps = Math.min(20, Math.max(...l.video.fpsRange));
const confLow = configureCodecs({
await logConfigureCodecs({
id: l.id,
video: {
width: lResolution[0],
@@ -164,8 +172,6 @@ export async function autoconfigureCodecs(
},
audio: audioOptions,
});
waiting.push(confLow);
}
else if (used.length == 2) {
let target: [number, number];
@@ -191,23 +197,11 @@ export async function autoconfigureCodecs(
},
audio: audioOptions,
});
waiting.push(confRemote);
}
else if (used.length === 1) {
// no nop
}
const waited = await Promise.allSettled(waiting);
let errors = '';
for (const w of waited) {
if (w.status === 'rejected') {
console.error(w.reason?.message);
errors += w.reason?.message + '\n';
}
}
if (errors)
throw new Error(errors);
}

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/amcrest",
"version": "0.0.156",
"version": "0.0.158",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@scrypted/amcrest",
"version": "0.0.156",
"version": "0.0.158",
"license": "Apache",
"dependencies": {
"@scrypted/common": "file:../../common",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/amcrest",
"version": "0.0.156",
"version": "0.0.158",
"description": "Amcrest Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/hikvision",
"version": "0.0.154",
"version": "0.0.155",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/hikvision",
"version": "0.0.154",
"version": "0.0.155",
"license": "Apache",
"dependencies": {
"@scrypted/common": "file:../../common",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/hikvision",
"version": "0.0.154",
"version": "0.0.155",
"description": "Hikvision Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/onvif",
"version": "0.1.18",
"version": "0.1.19",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@scrypted/onvif",
"version": "0.1.18",
"version": "0.1.19",
"license": "Apache",
"dependencies": {
"@scrypted/common": "file:../../common",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/onvif",
"version": "0.1.18",
"version": "0.1.19",
"description": "ONVIF Camera Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",