diff --git a/plugins/homekit/package-lock.json b/plugins/homekit/package-lock.json index 9af902f6a..89f6b3056 100644 --- a/plugins/homekit/package-lock.json +++ b/plugins/homekit/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/homekit", - "version": "0.0.219", + "version": "0.0.220", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/homekit", - "version": "0.0.219", + "version": "0.0.220", "dependencies": { "@koush/qrcode-terminal": "^0.12.0", "hap-nodejs": "file:../../external/HAP-NodeJS", diff --git a/plugins/homekit/package.json b/plugins/homekit/package.json index ebbc61520..ef9611c78 100644 --- a/plugins/homekit/package.json +++ b/plugins/homekit/package.json @@ -39,5 +39,5 @@ "@types/node": "^14.17.9", "@types/url-parse": "^1.4.3" }, - "version": "0.0.219" + "version": "0.0.220" } diff --git a/plugins/homekit/src/camera-mixin.ts b/plugins/homekit/src/camera-mixin.ts index 168bd2c7b..e00f42f31 100644 --- a/plugins/homekit/src/camera-mixin.ts +++ b/plugins/homekit/src/camera-mixin.ts @@ -82,34 +82,17 @@ export class CameraMixin extends HomekitMixin { value: 'WARNING', readonly: true, description: 'Transcoding audio and video for HomeKit is not recommended. Configure your camera using the camera web portal or app to output the correct HomeKit compatible codecs (h264/aac/2000kbps).', - }) + }); settings.push({ - title: 'Transcode Streaming', group: 'HomeKit Transcoding', + key: 'needsExtraData', + title: 'Add H264 Extra Data', + description: 'Some cameras do not include H264 extra data in the stream and this causes live streaming to always fail (but recordings may be working). This is a inexpensive video filter and does not perform a transcode. Enable this setting only as necessary.', + value: (this.storage.getItem('needsExtraData') === 'true').toString(), type: 'boolean', - key: 'transcodeStreaming', - value: (this.storage.getItem('transcodeStreaming') === 'true').toString(), - description: 'Use FFMpeg to transcode streaming to a format supported by HomeKit.', }); - settings.push({ - title: 'Transcode Remote Streaming', - group: 'HomeKit Transcoding', - type: 'boolean', - key: 'transcodeStreamingHub', - value: (this.storage.getItem('transcodeStreamingHub') === 'true').toString(), - description: 'Remote Streaming via HomeKit Hub: Use FFMpeg to transcode streaming to a format supported by HomeKit.', - }); - if (this.interfaces.includes(ScryptedInterface.VideoCameraConfiguration)) { - settings.push({ - title: 'Dynamic Bitrate (Remote Streaming)', - group: 'HomeKit Transcoding', - type: 'boolean', - key: 'dynamicBitrate', - value: (this.storage.getItem('dynamicBitrate') === 'true').toString(), - description: 'Remote Streaming via HomeKit Hub: Adjust the bitrate of the native camera stream on demand to accomodate available bandwidth. This setting should be used on secondary streams (sub streams), and not the main stream connected to an NVR, as it will reduce the recording quality.', - }); - } + let showTranscodeArgs = this.storage.getItem('transcodeStreaming') === 'true' || this.storage.getItem('transcodeStreamingHub') === 'true'; @@ -120,12 +103,54 @@ export class CameraMixin extends HomekitMixin { key: 'transcodeRecording', type: 'boolean', value: (this.storage.getItem('transcodeRecording') === 'true').toString(), - description: 'Use FFMpeg to transcode recording to a format supported by HomeKit Secure Video.', + description: 'Use FFMpeg to transcode recordings to a format supported by HomeKit Secure Video.', }); showTranscodeArgs = showTranscodeArgs || this.storage.getItem('transcodeRecording') === 'true'; } + settings.push({ + title: 'Transcode Streaming', + group: 'HomeKit Transcoding', + type: 'boolean', + key: 'transcodeStreaming', + value: (this.storage.getItem('transcodeStreaming') === 'true').toString(), + description: 'Use FFMpeg to transcode streaming to a format supported by HomeKit.', + }); + + if (this.interfaces.includes(ScryptedInterface.VideoCameraConfiguration)) { + let value = this.storage.getItem('hubStreamingMode'); + if (!value) { + if (this.storage.getItem('dynamicBitrate') === 'true') + value = 'Dynamic Bitrate'; + else if (this.storage.getItem('transcodeStreamingHub') === 'true') + value = 'Transcode'; + } + + settings.push({ + title: 'Transcode Remote Streaming', + group: 'HomeKit Transcoding', + key: 'hubStreamingMode', + value: value || 'Disabled', + choices: [ + 'Disabled', + 'Transcode', + 'Dynamic Bitrate', + ], + description: 'Remote Streaming via HomeKit Hub: Transcode will use FFmpeg to stream a format supported by HomeKit. Dynamic Bitrate adjusts the bitrate of the native camera stream on demand to accomodate available bandwidth. Dynamic Bitrate should be used on secondary streams (sub streams), and not the main stream connected to an NVR, as it will reduce the recording quality.', + }); + } + else { + settings.push({ + title: 'Transcode Remote Streaming', + group: 'HomeKit Transcoding', + type: 'boolean', + key: 'transcodeStreamingHub', + value: (this.storage.getItem('transcodeStreamingHub') === 'true').toString(), + description: 'Remote Streaming via HomeKit Hub: Use FFMpeg to transcode streaming to a format supported by HomeKit.', + }); + } + if (showTranscodeArgs) { const decoderArgs = getH264DecoderArgs(); const encoderArgs = getH264EncoderArgs(); @@ -238,6 +263,21 @@ export class CameraMixin extends HomekitMixin { value = substitute ? `\`${substitute}\`` : value; } + if (key === 'hubStreamingMode') { + if (value === 'Dynamic Bitrate') { + this.storage.setItem('dynamicBitrate', 'true'); + this.storage.removeItem('transcodeStreamingHub'); + } + else if (value === 'transcodeStreamingHub') { + this.storage.setItem('transcodeStreamingHub', 'true'); + this.storage.removeItem('dynamicBitrate'); + } + else { + this.storage.removeItem('dynamicBitrate'); + this.storage.removeItem('transcodeStreamingHub'); + } + } + if (key === 'objectDetectionContactSensors') { this.storage.setItem(key, JSON.stringify(value)); } diff --git a/plugins/homekit/src/homekit-mixin.ts b/plugins/homekit/src/homekit-mixin.ts index 9e2708767..f189cafa1 100644 --- a/plugins/homekit/src/homekit-mixin.ts +++ b/plugins/homekit/src/homekit-mixin.ts @@ -7,6 +7,7 @@ const { log } = sdk; export class HomekitMixin extends SettingsMixinDeviceBase { storageSettings = new StorageSettings(this, { resetAccessory: { + group: 'HomeKit Pairing', title: 'Reset Accessory', description: 'Bridged devices will automatically relink as a new device. Accessory devices must be manually removed from the Home app and re-paired.', type: 'button', @@ -19,6 +20,7 @@ export class HomekitMixin extends SettingsMixinDeviceBase { mapPut: () => crypto.randomBytes(8).toString('hex'), }, standalone: { + group: 'HomeKit Pairing', title: 'Standalone Accessory', description: 'Experimental: Advertise this to HomeKit as a standalone accessory rather than through the Scrypted HomeKit bridge. Enabling this option will remove it from the bridge, and the accessory will then need to be re-paired to HomeKit.' + (this.interfaces.includes(ScryptedInterface.VideoCamera) diff --git a/plugins/homekit/src/types/camera/camera-streaming-ffmpeg.ts b/plugins/homekit/src/types/camera/camera-streaming-ffmpeg.ts index c8610651f..0f170aedf 100644 --- a/plugins/homekit/src/types/camera/camera-streaming-ffmpeg.ts +++ b/plugins/homekit/src/types/camera/camera-streaming-ffmpeg.ts @@ -89,14 +89,17 @@ export async function startCameraStreamFfmpeg(device: ScryptedDevice & VideoCame else { args.push( "-vcodec", "copy", - // 3/6/2022 - // Ran into an issue where the RTSP source had SPS/PPS in the SDP, - // and none in the bitstream. Codec copy will not add SPS/PPS before IDR frames - // unless this flag is used. - // 3/7/2022 - // I believe this is causing issues with some users. - // "-bsf:v", "dump_extra", ); + + // 3/6/2022 + // Ran into an issue where the RTSP source had SPS/PPS in the SDP, + // and none in the bitstream. Codec copy will not add SPS/PPS before IDR frames + // unless this flag is used. + // 3/7/2022 + // This flag was enabled by default, but I believe this is causing issues with some users. + // Make it a setting. + if (storage.getItem('needsExtraData') === 'true') + args.push("-bsf:v", "dump_extra"); } args.push(