From c412d819e02a092feef9ef02cac1cd5bce5fb044 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Tue, 5 Oct 2021 00:00:47 -0700 Subject: [PATCH] homekit: send snapshot hints along --- plugins/homekit/package-lock.json | 4 ++-- plugins/homekit/package.json | 2 +- plugins/homekit/src/common.ts | 5 ++--- plugins/homekit/src/types/camera.ts | 23 ++++++++++++++--------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/plugins/homekit/package-lock.json b/plugins/homekit/package-lock.json index 54ebfa187..2ccdaf9eb 100644 --- a/plugins/homekit/package-lock.json +++ b/plugins/homekit/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/homekit", - "version": "0.0.78", + "version": "0.0.79", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/homekit", - "version": "0.0.78", + "version": "0.0.79", "dependencies": { "hap-nodejs": "file:../HAP-NodeJS", "lodash": "^4.17.21", diff --git a/plugins/homekit/package.json b/plugins/homekit/package.json index 5660a0848..482c23aae 100644 --- a/plugins/homekit/package.json +++ b/plugins/homekit/package.json @@ -40,5 +40,5 @@ "@types/qrcode": "^1.4.1", "@types/url-parse": "^1.4.3" }, - "version": "0.0.78" + "version": "0.0.79" } diff --git a/plugins/homekit/src/common.ts b/plugins/homekit/src/common.ts index 37d71e31b..e53d62857 100644 --- a/plugins/homekit/src/common.ts +++ b/plugins/homekit/src/common.ts @@ -1,7 +1,6 @@ import { EventListenerRegister, ScryptedDevice, ScryptedDeviceType, ScryptedInterface } from '@scrypted/sdk'; -import { Accessory, Service } from './hap'; -import throttle from 'lodash/throttle'; +import { Accessory, Service, SnapshotRequest } from './hap'; export interface DummyDevice { interfaces?: string[]; @@ -9,7 +8,7 @@ export interface DummyDevice { } export interface SnapshotThrottle { - (): Promise; + (request: SnapshotRequest): Promise; } export interface HomeKitSession { diff --git a/plugins/homekit/src/types/camera.ts b/plugins/homekit/src/types/camera.ts index 81b6753a4..82d2e9c2d 100644 --- a/plugins/homekit/src/types/camera.ts +++ b/plugins/homekit/src/types/camera.ts @@ -111,7 +111,7 @@ async function* handleFragmentsRequests(device: ScryptedDevice & VideoCamera & M } log.i(`${device.name} motion recording starting`); - const session = await startFFMPegFragmetedMP4Session(ffmpegInput, audioArgs, videoArgs); + const session = await startFFMPegFragmetedMP4Session(ffmpegInput, audioArgs, videoArgs, console); log.i(`${device.name} motion recording started`); const { socket, cp, generator } = session; @@ -186,12 +186,17 @@ addSupportedType({ } - const takePicture = async () => { + const takePicture = async (request: SnapshotRequest) => { if (pendingPicture) return pendingPicture; if (device.interfaces.includes(ScryptedInterface.Camera)) { - const media = await device.takePicture(); + const media = await device.takePicture({ + picture: { + width: request.width, + height: request.height, + } + }); pendingPicture = mediaManager.convertMediaObjectToBuffer(media, 'image/jpeg'); } else { @@ -235,9 +240,9 @@ addSupportedType({ trailing: true, }); - function snapshotAll() { + function snapshotAll(request: SnapshotRequest) { for (const snapshotThrottle of homekitSession.snapshotThrottles.values()) { - snapshotThrottle(); + snapshotThrottle(request); } } @@ -248,7 +253,7 @@ addSupportedType({ try { // non zero reason is for homekit secure video... or something else. if (request.reason) { - callback(null, await takePicture()); + callback(null, await takePicture(request)); return; } @@ -261,8 +266,8 @@ addSupportedType({ // fetch everything serially. // this call is not a bug, to force lodash to take a picture on the trailing edge, // throttle must be called twice. - snapshotAll(); - snapshotAll(); + snapshotAll(request); + snapshotAll(request); // path to return blank snapshots if (localStorage.getItem('blankSnapshots') === 'true') { @@ -275,7 +280,7 @@ addSupportedType({ return; } - callback(null, await throttledTakePicture()); + callback(null, await throttledTakePicture(request)); } catch (e) { console.error('snapshot error', e);