From e526f3c40dfac0b6c70eb3a67cc5c685c036df54 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 1 Nov 2021 11:48:55 -0700 Subject: [PATCH] homekit: transcode cleanup --- common/src/ffmpeg-hardware-acceleration.ts | 2 -- plugins/homekit/package-lock.json | 4 ++-- plugins/homekit/package.json | 2 +- plugins/homekit/src/camera-mixin.ts | 12 ++++++++++-- plugins/homekit/src/common.ts | 4 +++- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/common/src/ffmpeg-hardware-acceleration.ts b/common/src/ffmpeg-hardware-acceleration.ts index bb1e47552..ec73a0dd8 100644 --- a/common/src/ffmpeg-hardware-acceleration.ts +++ b/common/src/ffmpeg-hardware-acceleration.ts @@ -118,8 +118,6 @@ export function getH264EncoderArgs() { encoderArgs[name] = [ '-c:v', encoder, - '-b:v', - '${request.video.max_bit_rate * 10}k', ] } return encoderArgs; diff --git a/plugins/homekit/package-lock.json b/plugins/homekit/package-lock.json index 7c9c944d4..df67239ac 100644 --- a/plugins/homekit/package-lock.json +++ b/plugins/homekit/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/homekit", - "version": "0.0.115", + "version": "0.0.117", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/homekit", - "version": "0.0.115", + "version": "0.0.117", "dependencies": { "hap-nodejs": "file:../../external/HAP-NodeJS", "lodash": "^4.17.21", diff --git a/plugins/homekit/package.json b/plugins/homekit/package.json index 7ceaf4aa7..e39cb6f19 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.115" + "version": "0.0.117" } diff --git a/plugins/homekit/src/camera-mixin.ts b/plugins/homekit/src/camera-mixin.ts index 9837fb80c..697a536b5 100644 --- a/plugins/homekit/src/camera-mixin.ts +++ b/plugins/homekit/src/camera-mixin.ts @@ -4,6 +4,11 @@ import { getH264DecoderArgs, getH264EncoderArgs } from "../../../common/src/ffmp const { log, systemManager, deviceManager } = sdk; +const extraEncoderArgs = [ + '-b:v', + '${request.video.max_bit_rate * 2}k', +]; + export class CameraMixin extends SettingsMixinDeviceBase implements Settings { constructor(mixinDevice: any, mixinDeviceInterfaces: ScryptedInterface[], mixinDeviceState: { [key: string]: any }, providerNativeId: string) { super(mixinDevice, mixinDeviceState, { @@ -84,8 +89,8 @@ export class CameraMixin extends SettingsMixinDeviceBase implements Setting } if (showTranscodeArgs) { - const encoderArgs = getH264EncoderArgs(); const decoderArgs = getH264DecoderArgs(); + const encoderArgs = getH264EncoderArgs(); settings.push({ title: 'Video Decoder Arguments', @@ -167,7 +172,10 @@ export class CameraMixin extends SettingsMixinDeviceBase implements Setting if (key === 'h264EncoderArguments') { const encoderArgs = getH264EncoderArgs(); - const substitute = encoderArgs[value.toString()]?.join(' '); + const args = encoderArgs[value.toString()]; + if (args) + args.push(...extraEncoderArgs); + const substitute = args?.join(' '); value = substitute ? `\`${substitute}\`` : value; } diff --git a/plugins/homekit/src/common.ts b/plugins/homekit/src/common.ts index ac2ef4d9b..250610ad0 100644 --- a/plugins/homekit/src/common.ts +++ b/plugins/homekit/src/common.ts @@ -36,7 +36,9 @@ export function bindCharacteristic(device: ScryptedDevice, event: ScryptedInterf service.getCharacteristic(characteristic).on(CharacteristicEventTypes.GET, callback => { try { if (device.interfaces.includes(ScryptedInterface.Refresh)) { - (device as ScryptedDevice & Refresh).refresh(event, true); + // it's not possible to determine if this is user initiated. + // homekit seems to aggressively call get... + (device as ScryptedDevice & Refresh).refresh(event, false); } callback(null, map()); }