From 7066bd6e893057a59a08dffaaa3bc66f944e6641 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Wed, 19 Jan 2022 23:10:35 -0800 Subject: [PATCH] google-device-access: nre fix --- .../google-device-access/.vscode/settings.json | 2 +- plugins/google-device-access/package-lock.json | 4 ++-- plugins/google-device-access/package.json | 2 +- plugins/google-device-access/src/main.ts | 4 ++-- plugins/homekit/package-lock.json | 4 ++-- plugins/homekit/package.json | 2 +- plugins/homekit/src/types/camera.ts | 5 ++++- .../src/types/camera/camera-recording.ts | 11 +++-------- .../homekit/src/types/camera/camera-utils.ts | 17 +++++++++++++++++ 9 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 plugins/homekit/src/types/camera/camera-utils.ts diff --git a/plugins/google-device-access/.vscode/settings.json b/plugins/google-device-access/.vscode/settings.json index 77ccdbd6d..c2da58593 100644 --- a/plugins/google-device-access/.vscode/settings.json +++ b/plugins/google-device-access/.vscode/settings.json @@ -1,4 +1,4 @@ { - "scrypted.debugHost": "127.0.0.1", + "scrypted.debugHost": "192.168.2.119", } \ No newline at end of file diff --git a/plugins/google-device-access/package-lock.json b/plugins/google-device-access/package-lock.json index cd0c4fa07..86af9944f 100644 --- a/plugins/google-device-access/package-lock.json +++ b/plugins/google-device-access/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/google-device-access", - "version": "0.0.45", + "version": "0.0.52", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/google-device-access", - "version": "0.0.45", + "version": "0.0.52", "dependencies": { "@googleapis/smartdevicemanagement": "^0.2.0", "axios": "^0.21.1", diff --git a/plugins/google-device-access/package.json b/plugins/google-device-access/package.json index 86129ec20..48d62e728 100644 --- a/plugins/google-device-access/package.json +++ b/plugins/google-device-access/package.json @@ -43,5 +43,5 @@ "@types/node": "^14.17.11", "@types/url-parse": "^1.4.3" }, - "version": "0.0.45" + "version": "0.0.52" } diff --git a/plugins/google-device-access/src/main.ts b/plugins/google-device-access/src/main.ts index 9b9e2a924..87ae21c35 100644 --- a/plugins/google-device-access/src/main.ts +++ b/plugins/google-device-access/src/main.ts @@ -59,7 +59,7 @@ class NestCamera extends ScryptedDeviceBase implements VideoCamera, MotionSensor this.console.log(result.data); const expirationDate = new Date(expiresAt); const refreshAt = expirationDate.getTime(); - + return mediaManager.createFFmpegMediaObject({ url: u, mediaStreamOptions: { @@ -347,7 +347,7 @@ class GoogleSmartDeviceAccess extends ScryptedDeviceBase implements OauthClient, const traits = payload.resourceUpdate?.traits; const events = payload.resourceUpdate?.events; - const nativeId = payload.resourceUpdate.name.split('/').pop(); + const nativeId = payload.resourceUpdate?.name.split('/').pop(); const device = this.devices.get(nativeId); if (device) { if (traits) { diff --git a/plugins/homekit/package-lock.json b/plugins/homekit/package-lock.json index 9ca6b749f..c323a485a 100644 --- a/plugins/homekit/package-lock.json +++ b/plugins/homekit/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/homekit", - "version": "0.0.160", + "version": "0.0.161", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/homekit", - "version": "0.0.160", + "version": "0.0.161", "dependencies": { "hap-nodejs": "file:../../external/HAP-NodeJS", "lodash": "^4.17.21", diff --git a/plugins/homekit/package.json b/plugins/homekit/package.json index 1172e6bbd..5c8590a79 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.160" + "version": "0.0.161" } diff --git a/plugins/homekit/src/types/camera.ts b/plugins/homekit/src/types/camera.ts index 07456e557..547db586b 100644 --- a/plugins/homekit/src/types/camera.ts +++ b/plugins/homekit/src/types/camera.ts @@ -23,6 +23,7 @@ import { CharacteristicEventTypes, DataStreamConnection, Service, WithUUID } fro import { RecordingManagement } from 'hap-nodejs/src/lib/camera'; import { defaultObjectDetectionContactSensorTimeout } from '../camera-mixin'; import os from 'os'; +import { levelToFfmpeg, profileToFfmpeg } from './camera/camera-utils'; const { log, mediaManager, deviceManager, systemManager } = sdk; @@ -225,7 +226,7 @@ addSupportedType({ const videomtu = request.video.mtu; - // seems fine? no idea what to use here. this is the mtu for sending audio to homekit. + // 400 seems fine? no idea what to use here. this is the mtu for sending audio to homekit. // from my observation of talkback packets, the max packet size is ~370, so // I'm just guessing that HomeKit wants something similar for the audio it receives. // going higher causes choppiness. going lower may cause other issues. @@ -282,6 +283,8 @@ addSupportedType({ '-pix_fmt', 'yuv420p', '-color_range', 'mpeg', "-bf", "0", + "-profile:v", profileToFfmpeg(request.video.profile), + '-level:v', levelToFfmpeg(request.video.level), "-b:v", request.video.max_bit_rate.toString() + "k", "-bufsize", (2 * request.video.max_bit_rate).toString() + "k", "-maxrate", request.video.max_bit_rate.toString() + "k", diff --git a/plugins/homekit/src/types/camera/camera-recording.ts b/plugins/homekit/src/types/camera/camera-recording.ts index a45c76a3d..083ac4500 100644 --- a/plugins/homekit/src/types/camera/camera-recording.ts +++ b/plugins/homekit/src/types/camera/camera-recording.ts @@ -9,6 +9,7 @@ import { AudioRecordingCodecType, AudioRecordingSamplerateValues, CameraRecordin import { FFMpegFragmentedMP4Session, startFFMPegFragmetedMP4Session } from '@scrypted/common/src/ffmpeg-mp4-parser-session'; import { evalRequest } from './camera-transcode'; import { parseFragmentedMP4 } from '@scrypted/common/src/stream-parser'; +import { levelToFfmpeg, profileToFfmpeg } from './camera-utils'; const { log, mediaManager, deviceManager } = sdk; @@ -109,19 +110,13 @@ export async function* handleFragmentsRequests(device: ScryptedDevice & VideoCam ]; } - const profile = configuration.videoCodec.profile === H264Profile.HIGH ? 'high' - : configuration.videoCodec.profile === H264Profile.MAIN ? 'main' : 'baseline'; - - const level = configuration.videoCodec.level === H264Level.LEVEL4_0 ? '4.0' - : configuration.videoCodec.level === H264Level.LEVEL3_2 ? '3.2' : '3.1'; - let videoArgs: string[]; if (transcodeRecording) { const h264EncoderArguments = storage.getItem('h264EncoderArguments') || ''; videoArgs = h264EncoderArguments ? evalRequest(h264EncoderArguments, request) : [ - '-profile:v', profile, - '-level:v', level, + "-profile:v", profileToFfmpeg(request.video.profile), + '-level:v', levelToFfmpeg(request.video.level), '-b:v', `${configuration.videoCodec.bitrate}k`, '-force_key_frames', `expr:gte(t,n_forced*${iframeIntervalSeconds})`, '-r', configuration.videoCodec.resolution[2].toString(), diff --git a/plugins/homekit/src/types/camera/camera-utils.ts b/plugins/homekit/src/types/camera/camera-utils.ts new file mode 100644 index 000000000..24100a4a3 --- /dev/null +++ b/plugins/homekit/src/types/camera/camera-utils.ts @@ -0,0 +1,17 @@ +import { H264Profile, H264Level } from "../../hap"; + +export function profileToFfmpeg(profile: H264Profile): string { + if (profile === H264Profile.HIGH) + return "high"; + if (profile === H264Profile.MAIN) + return "main"; + return "baseline"; +} + +export function levelToFfmpeg(level: H264Level): string { + if (level === H264Level.LEVEL4_0) + return '4.0'; + if (level === H264Level.LEVEL3_2) + return '3.2'; + return '3.1'; +}