From 915d776a414e4dcd927de99965b72b2edced9b59 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Fri, 8 Oct 2021 20:25:33 -0700 Subject: [PATCH] rebroadcast: various memory fixes and process observations. --- plugins/prebuffer-mixin/package-lock.json | 4 ++-- plugins/prebuffer-mixin/package.json | 2 +- plugins/prebuffer-mixin/src/main.ts | 10 ++++++++++ plugins/unifi-protect/package-lock.json | 4 ++-- plugins/unifi-protect/package.json | 2 +- plugins/unifi-protect/src/main.ts | 12 +++++++++--- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/plugins/prebuffer-mixin/package-lock.json b/plugins/prebuffer-mixin/package-lock.json index 85c17c8ea..69667a5c3 100644 --- a/plugins/prebuffer-mixin/package-lock.json +++ b/plugins/prebuffer-mixin/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.1.51", + "version": "0.1.52", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/prebuffer-mixin", - "version": "0.1.51", + "version": "0.1.52", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/prebuffer-mixin/package.json b/plugins/prebuffer-mixin/package.json index 92e996ff0..7fd9427bb 100644 --- a/plugins/prebuffer-mixin/package.json +++ b/plugins/prebuffer-mixin/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.1.51", + "version": "0.1.52", "description": "Rebroadcast and Prebuffer for VideoCameras.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/prebuffer-mixin/src/main.ts b/plugins/prebuffer-mixin/src/main.ts index 4141d90a2..1ebb245b3 100644 --- a/plugins/prebuffer-mixin/src/main.ts +++ b/plugins/prebuffer-mixin/src/main.ts @@ -209,6 +209,16 @@ class PrebufferMixin extends SettingsMixinDeviceBase implements Vid }); } + let watchdog: NodeJS.Timeout; + session.events.on('mp4-data', () => { + clearTimeout(watchdog); + setTimeout(() => { + this.console.error('watchdog for mp4 parser timed out... killing ffmpeg session'); + session.kill(); + }, 30000); + }) + session.events.once('killed', () => clearTimeout(watchdog)); + return session; } diff --git a/plugins/unifi-protect/package-lock.json b/plugins/unifi-protect/package-lock.json index 4dbf0422e..b82c6112e 100644 --- a/plugins/unifi-protect/package-lock.json +++ b/plugins/unifi-protect/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/unifi-protect", - "version": "0.0.38", + "version": "0.0.39", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/unifi-protect", - "version": "0.0.38", + "version": "0.0.39", "license": "Apache", "dependencies": { "@types/ws": "^7.4.7", diff --git a/plugins/unifi-protect/package.json b/plugins/unifi-protect/package.json index e67eef81a..16a2be274 100644 --- a/plugins/unifi-protect/package.json +++ b/plugins/unifi-protect/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/unifi-protect", - "version": "0.0.38", + "version": "0.0.39", "description": "Unifi Protect Plugin for Scrypted", "author": "Scrypted", "license": "Apache", diff --git a/plugins/unifi-protect/src/main.ts b/plugins/unifi-protect/src/main.ts index 3b98959c2..4da830acd 100644 --- a/plugins/unifi-protect/src/main.ts +++ b/plugins/unifi-protect/src/main.ts @@ -31,6 +31,10 @@ class UnifiCamera extends ScryptedDeviceBase implements Camera, VideoCamera, Mot } } + async getObjectTypes(): Promise { + return this.findCamera().featureFlags.smartDetectTypes; + } + async getDetectionInput(detectionId: any): Promise { const data = this.detections.get(detectionId); if (!data) @@ -95,7 +99,6 @@ class UnifiCamera extends ScryptedDeviceBase implements Camera, VideoCamera, Mot const rtspChannels = camera.channels.filter(channel => channel.isRtspEnabled && this.isChannelEnabled(channel)); const rtspChannel = camera.channels.find(channel => channel.id === options?.id) || rtspChannels[0]; - this.console.log('serving rtsp channel', rtspChannel); const { rtspAlias } = rtspChannel; const u = `rtsp://${this.protect.getSetting('ip')}:7447/${rtspAlias}` @@ -288,6 +291,8 @@ class UnifiProtect extends ScryptedDeviceBase implements Settings, DeviceProvide } const detectionId = Math.random().toString(); + const camera = rtsp.findCamera(); + const snapshotChannel = camera.channels[0]; const detection: ObjectDetection = { detectionId, @@ -295,13 +300,14 @@ class UnifiProtect extends ScryptedDeviceBase implements Settings, DeviceProvide detections: payload.smartDetectTypes.map(type => ({ className: type, score: payload.score, - })) + })), + inputDimensions: [snapshotChannel.width, snapshotChannel.height], }; - rtsp.onDeviceEvent(ScryptedInterface.ObjectDetector, detection); const snapshot = rtsp.getSnapshot(); rtsp.detections.set(detectionId, snapshot); setTimeout(() => rtsp.detections.delete(detectionId), 30000); + rtsp.onDeviceEvent(ScryptedInterface.ObjectDetector, detection); rtsp.lastSeen = payload.start; break;