Skip to content

Commit

Permalink
see if this works
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Oct 25, 2024
1 parent abc55e5 commit 8e27dbf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"watch": "npm run build && npm link && nodemon",
"build": "npm run clean && tsc",
"prepublishOnly": "npm run lint && npm run build",
"postpublish": "npm run clean && npm ci",
"clean": "shx rm -rf ./dist",
"test": "npm run lint",
"docs": "typedoc",
Expand Down
18 changes: 10 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
} from 'homebridge'

import type { AutomationReturn } from './autoTypes.js'
import type { CameraConfig, FfmpegPlatformConfig } from './configTypes.js'
import type { CameraConfig, FfmpegPlatformConfig, VideoConfig } from './configTypes.js'

import { readFileSync } from 'node:fs'
import http from 'node:http'
Expand Down Expand Up @@ -42,6 +42,7 @@ class FfmpegPlatform implements DynamicPlatformPlugin {
private readonly api: API
private readonly config: FfmpegPlatformConfig
private readonly cameraConfigs: Map<string, CameraConfig> = new Map()
private readonly videoConfig?: VideoConfig
private readonly cachedAccessories: Array<PlatformAccessory> = []
private readonly accessories: Array<PlatformAccessory> = []
private readonly motionTimers: Map<string, NodeJS.Timeout> = new Map()
Expand All @@ -57,30 +58,31 @@ 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 {
if (!cameraConfig.videoConfig.source) {
const videoConfig = cameraConfig.videoConfig
if (!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 = cameraConfig.videoConfig.source.split(/\s+/)
const sourceArgs = 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 (cameraConfig.videoConfig.stillImageSource) {
const stillArgs = cameraConfig.videoConfig.stillImageSource.split(/\s+/)
if (videoConfig.stillImageSource) {
const stillArgs = 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 (cameraConfig.videoConfig.vcodec === 'copy' && cameraConfig.videoConfig.videoFilter) {
if (videoConfig.vcodec === 'copy' && videoConfig.videoFilter) {
this.log.warn('A videoFilter is defined, but the copy vcodec is being used. This will be ignored.', cameraConfig.name)
}
}
Expand Down Expand Up @@ -142,7 +144,7 @@ class FfmpegPlatform implements DynamicPlatformPlugin {
accessory.removeService(doorbellSwitch)
}

const delegate = new StreamingDelegate(this.log, cameraConfig, this.api, this.api.hap, accessory, this.config.videoProcessor)
const delegate = new StreamingDelegate(this.log, cameraConfig, this.videoConfig!, this.api, this.api.hap, accessory, this.config.videoProcessor)

accessory.configureController(delegate.controller)

Expand Down
1 change: 1 addition & 0 deletions src/recordingDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ 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) {
Expand Down
6 changes: 3 additions & 3 deletions src/streamingDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ export class StreamingDelegate implements CameraStreamingDelegate {
ongoingSessions: Map<string, ActiveSession> = new Map()
timeouts: Map<string, NodeJS.Timeout> = new Map()

constructor(log: Logger, cameraConfig: CameraConfig, api: API, hap: HAP, accessory: PlatformAccessory, videoProcessor?: string) {
constructor(log: Logger, cameraConfig: CameraConfig, videoConfig: VideoConfig, 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.videoConfig = videoConfig
this.videoProcessor = videoProcessor || ffmpegPath as unknown as string || 'ffmpeg'
this.recording = cameraConfig.videoConfig?.recording ?? false
this.prebuffer = this.recording && (cameraConfig.videoConfig?.prebuffer ?? false)
Expand Down Expand Up @@ -131,7 +131,7 @@ export class StreamingDelegate implements CameraStreamingDelegate {
}
recordingCodecs.push(entry)
}
this.recordingDelegate = this.recording ? new RecordingDelegate(this.log, this.cameraName, this.videoConfig, this.api, this.hap, this.videoProcessor) : null
this.recordingDelegate = this.recording ? new RecordingDelegate(this.log, this.cameraName, videoConfig, this.api, this.hap, this.videoProcessor) : null

const options: CameraControllerOptions = {
cameraStreamCount: this.videoConfig.maxStreams || 2, // HomeKit requires at least 2 streams, but 1 is also just fine
Expand Down

0 comments on commit 8e27dbf

Please sign in to comment.