diff --git a/src/index.ts b/src/index.ts index 13557bc4..5a7266e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ import type { } from 'homebridge' import type { AutomationReturn } from './autoTypes.js' -import type { CameraConfig, FfmpegPlatformConfig, VideoConfig } from './configTypes.js' +import type { CameraConfig, FfmpegPlatformConfig } from './configTypes.js' import { readFileSync } from 'node:fs' import http from 'node:http' @@ -42,7 +42,6 @@ class FfmpegPlatform implements DynamicPlatformPlugin { private readonly api: API private readonly config: FfmpegPlatformConfig private readonly cameraConfigs: Map = new Map() - private readonly videoConfig?: VideoConfig private readonly cachedAccessories: Array = [] private readonly accessories: Array = [] private readonly motionTimers: Map = new Map() @@ -58,31 +57,30 @@ class FfmpegPlatform implements DynamicPlatformPlugin { let error = false if (!cameraConfig.name) { + this.log.error('One of your cameras has no name configured. This camera will be skipped.') cameraConfig.name = `Camera ${this.cameraConfigs.size + 1}` - this.log.error(`One of your cameras has no name configured, using ${cameraConfig.name}.`) error = false } if (!cameraConfig.videoConfig) { this.log.error('The videoConfig section is missing from the config. This camera will be skipped.', cameraConfig.name) error = true } else { - const videoConfig = cameraConfig.videoConfig - if (!videoConfig.source) { + if (!cameraConfig.videoConfig.source) { this.log.error('There is no source configured for this camera. This camera will be skipped.', cameraConfig.name) error = true } else { - const sourceArgs = videoConfig.source.split(/\s+/) + const sourceArgs = cameraConfig.videoConfig.source.split(/\s+/) if (!sourceArgs.includes('-i')) { this.log.warn('The source for this camera is missing "-i", it is likely misconfigured.', cameraConfig.name) } } - if (videoConfig.stillImageSource) { - const stillArgs = videoConfig.stillImageSource.split(/\s+/) + if (cameraConfig.videoConfig.stillImageSource) { + const stillArgs = cameraConfig.videoConfig.stillImageSource.split(/\s+/) if (!stillArgs.includes('-i')) { this.log.warn('The stillImageSource for this camera is missing "-i", it is likely misconfigured.', cameraConfig.name) } } - if (videoConfig.vcodec === 'copy' && videoConfig.videoFilter) { + if (cameraConfig.videoConfig.vcodec === 'copy' && cameraConfig.videoConfig.videoFilter) { this.log.warn('A videoFilter is defined, but the copy vcodec is being used. This will be ignored.', cameraConfig.name) } } @@ -144,7 +142,7 @@ class FfmpegPlatform implements DynamicPlatformPlugin { accessory.removeService(doorbellSwitch) } - const delegate = new StreamingDelegate(this.log, cameraConfig, this.videoConfig!, this.api, this.api.hap, accessory, this.config.videoProcessor) + const delegate = new StreamingDelegate(this.log, cameraConfig, this.api, this.api.hap, accessory, this.config.videoProcessor) accessory.configureController(delegate.controller) diff --git a/src/recordingDelegate.ts b/src/recordingDelegate.ts index 66c603c6..9b2fe54a 100644 --- a/src/recordingDelegate.ts +++ b/src/recordingDelegate.ts @@ -150,7 +150,6 @@ export class RecordingDelegate implements CameraRecordingDelegate { this.hap = hap this.cameraName = cameraName this.videoProcessor = videoProcessor || ffmpegPathString || 'ffmpeg' - this.videoConfig = videoConfig api.on(APIEvent.SHUTDOWN, () => { if (this.preBufferSession) { diff --git a/src/streamingDelegate.ts b/src/streamingDelegate.ts index 1c5df133..e0c703d1 100644 --- a/src/streamingDelegate.ts +++ b/src/streamingDelegate.ts @@ -94,13 +94,14 @@ export class StreamingDelegate implements CameraStreamingDelegate { ongoingSessions: Map = new Map() timeouts: Map = new Map() - constructor(log: Logger, cameraConfig: CameraConfig, videoConfig: VideoConfig, api: API, hap: HAP, accessory: PlatformAccessory, videoProcessor?: string) { + constructor(log: Logger, cameraConfig: CameraConfig, api: API, hap: HAP, accessory: PlatformAccessory, videoProcessor?: string) { this.log = log this.hap = hap this.api = api this.cameraName = cameraConfig.name! this.unbridge = cameraConfig.unbridge ?? true + this.videoConfig = cameraConfig.videoConfig ?? {} this.videoProcessor = videoProcessor || ffmpegPath as unknown as string || 'ffmpeg' this.recording = cameraConfig.videoConfig?.recording ?? false this.prebuffer = this.recording && (cameraConfig.videoConfig?.prebuffer ?? false) @@ -130,10 +131,10 @@ export class StreamingDelegate implements CameraStreamingDelegate { } recordingCodecs.push(entry) } - this.recordingDelegate = this.recording ? new RecordingDelegate(this.log, this.cameraName, videoConfig, this.api, this.hap, this.videoProcessor) : null + this.recordingDelegate = this.recording ? new RecordingDelegate(this.log, this.cameraName, this.videoConfig, this.api, this.hap, this.videoProcessor) : null const options: CameraControllerOptions = { - cameraStreamCount: videoConfig.maxStreams ?? 2, // HomeKit requires at least 2 streams, but 1 is also just fine + cameraStreamCount: this.videoConfig.maxStreams ?? 2, // HomeKit requires at least 2 streams, but 1 is also just fine delegate: this, streamingOptions: { supportedCryptoSuites: [hap.SRTPCryptoSuites.AES_CM_128_HMAC_SHA1_80], @@ -157,7 +158,7 @@ export class StreamingDelegate implements CameraStreamingDelegate { }, }, audio: { - twoWayAudio: !!videoConfig.returnAudioTarget, + twoWayAudio: !!this.videoConfig.returnAudioTarget, codecs: [ { type: AudioStreamingCodecType.AAC_ELD,