Skip to content

Commit

Permalink
unbridged by default
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Oct 25, 2024
1 parent a89cde4 commit 704d488
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 63 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Other users have been sharing configurations that work for them on our GitHub si
- `model`: Set the model for display in the Home app. (Default: `Camera FFmpeg`)
- `serialNumber`: Set the serial number for display in the Home app. (Default: `SerialNumber`)
- `firmwareRevision`: Set the firmware revision for display in the Home app. (Default: current plugin version)
- `unbridge`: Bridged cameras can cause slowdowns of the entire Homebridge instance. If unbridged, the camera will need to be added to HomeKit manually. (Default: `false`)
- `unbridge`: Bridged cameras can cause slowdowns of the entire Homebridge instance. If unbridged, the camera will need to be added to HomeKit manually. (Default: `true`)

#### Config Example with Manufacturer and Model Set

Expand Down Expand Up @@ -94,7 +94,7 @@ Other users have been sharing configurations that work for them on our GitHub si
- `maxFPS`: The maximum frame rate used for video streamed to HomeKit. If set to 0, the framerate of the source is used. If not set, will use any frame rate HomeKit requests.
- `maxBitrate`: The maximum bitrate used for video streamed to HomeKit, in kbit/s. If not set, will use any bitrate HomeKit requests.
- `forceMax`: If set, the settings requested by HomeKit will be overridden with any 'maximum' values defined in this config. (Default: `false`)
- `vcodec`: Set the codec used for encoding video sent to HomeKit, must be H.264-based. You can change to a hardware accelerated video codec with this option, if one is available. (Default: `libx264`)
- `vcodec`: Set the codec used for encoding video sent to HomeKit, must be H.264-based. You can change to a hardware accelerated video codec with this option, if one is available. (Default: `libx264`)
- `audio`: Enables audio streaming from camera. (Default: `false`)
- `packetSize`: If audio or video is choppy try a smaller value, should be set to a multiple of 188. (Default: `1316`)
- `mapvideo`: Selects the stream used for video. (Default: FFmpeg [automatically selects](https://ffmpeg.org/ffmpeg.html#Automatic-stream-selection) a video stream)
Expand Down
3 changes: 2 additions & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@
"description": "Rings the doorbell when motion is activated. This allows for motion alerts to appear on Apple TVs."
},
"unbridge": {
"title": "Unbridge Camera (Recommended)",
"title": "Unbridge Camera",
"type": "boolean",
"default": true,
"description": "Bridged cameras can cause slowdowns of the entire Homebridge instance. If unbridged, the camera will need to be added to HomeKit manually."
},
"videoConfig": {
Expand Down
14 changes: 5 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 34 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"displayName": "Homebridge Camera FFmpeg",
"name": "homebridge-camera-ffmpeg",
"displayName": "Homebridge Camera FFmpeg",
"type": "module",
"version": "3.1.4",
"description": "Homebridge Plugin Providing FFmpeg-based Camera Support",
"main": "dist/index.js",
"license": "ISC",
"type": "module",
"funding": [
{
"type": "kofi",
Expand All @@ -24,6 +23,32 @@
"url": "https://liberapay.com/Sunoo"
}
],
"repository": {
"type": "git",
"url": "git://github.com/homebridge-plugins/homebridge-camera-ffmpeg.git"
},
"bugs": {
"url": "http://github.com/homebridge-plugins/homebridge-camera-ffmpeg/issues"
},
"keywords": [
"homebridge-plugin",
"camera",
"ffmpeg",
"homebridge"
],
"main": "dist/index.js",
"files": [
"CHANGELOG.md",
"LICENSE",
"README.md",
"config.schema.json",
"dist/**/*",
"package.json"
],
"engines": {
"homebridge": "^1.8.4 || ^2.0.0 || ^2.0.0-beta.22 || ^2.0.0-alpha.37",
"node": "^20 || ^22"
},
"scripts": {
"check": "npm install && npm outdated",
"update": "ncu -u && npm update && npm install",
Expand All @@ -38,41 +63,21 @@
"docs": "typedoc",
"lint-docs": "typedoc --emit none --treatWarningsAsErrors"
},
"keywords": [
"homebridge-plugin",
"camera",
"ffmpeg",
"homebridge"
],
"repository": {
"type": "git",
"url": "git://github.com/homebridge-plugins/homebridge-camera-ffmpeg.git"
},
"bugs": {
"url": "http://github.com/homebridge-plugins/homebridge-camera-ffmpeg/issues"
},
"engines": {
"homebridge": "^1.8.4 || ^2.0.0 || ^2.0.0-beta.22 || ^2.0.0-alpha.37",
"node": "^20 || ^22"
"dependencies": {
"ffmpeg-for-homebridge": "^2.1.7",
"mqtt": "5.10.1",
"pick-port": "^1.0.1"
},
"files": [
"CHANGELOG.md",
"config.schema.json",
"dist/**/*",
"LICENSE",
"package.json",
"README.md"
],
"devDependencies": {
"@antfu/eslint-config": "^3.8.0",
"@types/aes-js": "^3.1.4",
"@types/debug": "^4.1.12",
"@types/fs-extra": "^11.0.4",
"@types/mdast": "^4.0.4",
"@types/node": "^22.7.9",
"@types/ws": "^8.5.12",
"@types/semver": "^7.5.8",
"@types/source-map-support": "^0.5.10",
"@types/ws": "^8.5.12",
"@vitest/coverage-v8": "^2.1.3",
"eslint": "^9.13.0",
"eslint-plugin-format": "^0.1.2",
Expand All @@ -85,10 +90,5 @@
"typedoc": "^0.26.10",
"typescript": "^5.6.3",
"vitest": "^2.1.3"
},
"dependencies": {
"ffmpeg-for-homebridge": "^2.1.7",
"mqtt": "5.10.1",
"pick-port": "^2.1.0"
}
}
}
35 changes: 19 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class FfmpegPlatform implements DynamicPlatformPlugin {

if (!cameraConfig.name) {
this.log.error('One of your cameras has no name configured. This camera will be skipped.')
error = true
cameraConfig.name = `Camera ${this.cameraConfigs.size + 1}`
error = false
}
if (!cameraConfig.videoConfig) {
this.log.error('The videoConfig section is missing from the config. This camera will be skipped.', cameraConfig.name)
Expand All @@ -85,7 +86,7 @@ class FfmpegPlatform implements DynamicPlatformPlugin {
}

if (!error) {
const uuid = this.api.hap.uuid.generate(cameraConfig.name!)
const uuid = this.api.hap.uuid.generate(cameraConfig.name ?? `Camera ${this.cameraConfigs.size + 1}`)
if (this.cameraConfigs.has(uuid)) {
// Camera names must be unique
this.log.warn('Multiple cameras are configured with this name. Duplicate cameras will be skipped.', cameraConfig.name)
Expand Down Expand Up @@ -359,23 +360,17 @@ class FfmpegPlatform implements DynamicPlatformPlugin {

didFinishLaunching(): void {
for (const [uuid, cameraConfig] of this.cameraConfigs) {
if (cameraConfig.unbridge) {
const accessory = new this.api.platformAccessory(cameraConfig.name!, uuid)
this.log.info('Configuring unbridged accessory...', accessory.displayName)
const unbridge = cameraConfig.unbridge ?? true
const name = cameraConfig.name || `Camera ${this.cameraConfigs.size + 1}`
const cachedAccessory = this.cachedAccessories.find((curAcc: PlatformAccessory) => curAcc.UUID === uuid)
if (!cachedAccessory) {
const accessory = new this.api.platformAccessory(name, uuid)
this.log.info('Configuring bridged accessory...', accessory.displayName)
this.setupAccessory(accessory, cameraConfig)
this.api.publishExternalAccessories(PLUGIN_NAME, [accessory])
this.externalOrPlatform(unbridge, accessory)
this.accessories.push(accessory)
} else {
const cachedAccessory = this.cachedAccessories.find((curAcc: PlatformAccessory) => curAcc.UUID === uuid)
if (!cachedAccessory) {
const accessory = new this.api.platformAccessory(cameraConfig.name!, uuid)
this.log.info('Configuring bridged accessory...', accessory.displayName)
this.setupAccessory(accessory, cameraConfig)
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory])
this.accessories.push(accessory)
} else {
this.accessories.push(cachedAccessory)
}
this.accessories.push(cachedAccessory)
}
}

Expand Down Expand Up @@ -441,6 +436,14 @@ class FfmpegPlatform implements DynamicPlatformPlugin {
}
})
}

public async externalOrPlatform(unbridge: boolean, accessory: PlatformAccessory) {
if (unbridge) {
this.api.publishExternalAccessories(PLUGIN_NAME, [accessory])
} else {
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory])
}
}
}

function getVersion() {
Expand Down
2 changes: 1 addition & 1 deletion src/streamingDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class StreamingDelegate implements CameraStreamingDelegate {
this.api = api

this.cameraName = cameraConfig.name!
this.unbridge = cameraConfig.unbridge ?? false
this.unbridge = cameraConfig.unbridge ?? true
this.videoConfig = cameraConfig.videoConfig!
this.videoProcessor = videoProcessor || ffmpegPath as unknown as string || 'ffmpeg'
this.recording = cameraConfig.videoConfig?.recording ?? false
Expand Down

0 comments on commit 704d488

Please sign in to comment.