Skip to content

Commit

Permalink
Remove bridged cameras (#1552)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreif authored Jan 12, 2025
1 parent a93e3db commit 93a9f6b
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 144 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-waves-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'homebridge-ring': major
---

Removed bridged cameras. If you already had `unbridgeCameras: true` in your config, this change will not affect you. For those who were still using bridged cameras, you will need to manually add each camera to HomeKit after upgrading. This change allows us to stop requiring special builds of ffmpeg and should make video streaming more reliable. Unbridge cameras are also avoid blocking the whole bridge while waiting for requests (e.g. Snapshot), which leads to a better overall experience. After updating, you can delete the `unbridgeCameras` option from your config.
45 changes: 22 additions & 23 deletions packages/homebridge-ring/README.md

Large diffs are not rendered by default.

117 changes: 32 additions & 85 deletions packages/homebridge-ring/camera-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,6 @@ class StreamingSessionWrapper {
videoSplitter = new RtpSplitter()
repacketizeAudioSplitter = new RtpSplitter()

libfdkAacInstalledPromise = doesFfmpegSupportCodec(
'libfdk_aac',
getFfmpegPath(),
)
.then((supported) => {
if (!supported) {
logError(
'Streaming video only - found ffmpeg, but libfdk_aac is not installed. See https://github.com/dgreif/ring/wiki/FFmpeg for details.',
)
}
return supported
})
.catch(() => {
logError(
'Streaming video only - ffmpeg was not found. See https://github.com/dgreif/ring/wiki/FFmpeg for details.',
)
return false
})

constructor(
public streamingSession: StreamingSession,
public prepareStreamRequest: PrepareStreamRequest,
Expand Down Expand Up @@ -262,38 +243,19 @@ class StreamingSessionWrapper {
}),
)

const shouldTranscodeAudio = await this.libfdkAacInstalledPromise
if (!shouldTranscodeAudio) {
return this.streamingSession.requestKeyFrame()
}

const transcodingPromise = this.streamingSession.startTranscoding({
input: ['-vn'],
audio: [
'-map',
'0:a',

...(request.audio.codec === AudioStreamingCodecType.OPUS
? [
// OPUS specific - it works, but audio is very choppy
'-acodec',
'libopus',
'-frame_duration',
request.audio.packet_time,
'-application',
'lowdelay',
]
: [
// AAC-eld specific
'-acodec',
'libfdk_aac',
'-profile:a',
'aac_eld',
'-eld_sbr:a',
'1',
'-eld_v2',
'1',
]),
// OPUS specific - it works, but audio is very choppy
'-acodec',
'libopus',
'-frame_duration',
request.audio.packet_time,
'-application',
'lowdelay',

// Shared options
'-flags',
Expand Down Expand Up @@ -337,7 +299,6 @@ class StreamingSessionWrapper {

return null
}),
isRingUsingOpus = await this.streamingSession.isUsingOpus,
returnAudioTranscoder = new ReturnAudioTranscoder({
prepareStreamRequest: this.prepareStreamRequest,
startStreamRequest: request,
Expand All @@ -347,19 +308,15 @@ class StreamingSessionWrapper {
},
outputArgs: [
'-acodec',
...(isRingUsingOpus
? [
'libopus',
'-ac',
'1',
'-ar',
'24k',
'-b:a',
'24k',
'-application',
'lowdelay',
]
: ['pcm_mulaw', '-ac', 1, '-ar', '8k']),
'libopus',
'-ac',
'1',
'-ar',
'24k',
'-b:a',
'24k',
'-application',
'lowdelay',
'-flags',
'+global_header',
'-f',
Expand Down Expand Up @@ -398,10 +355,7 @@ export class CameraSource implements CameraStreamingDelegate {
private sessions: { [sessionKey: string]: StreamingSessionWrapper } = {}
private cachedSnapshot?: Buffer

constructor(
private ringCamera: RingCamera,
private useOpus = false,
) {
constructor(private ringCamera: RingCamera) {
this.controller = new hap.CameraController({
cameraStreamCount: 10,
delegate: this,
Expand All @@ -425,28 +379,21 @@ export class CameraSource implements CameraStreamingDelegate {
},
},
audio: {
codecs: this.useOpus
? [
{
type: AudioStreamingCodecType.OPUS,
// required by watch
samplerate: AudioStreamingSamplerate.KHZ_8,
},
{
type: AudioStreamingCodecType.OPUS,
samplerate: AudioStreamingSamplerate.KHZ_16,
},
{
type: AudioStreamingCodecType.OPUS,
samplerate: AudioStreamingSamplerate.KHZ_24,
},
]
: [
{
type: AudioStreamingCodecType.AAC_ELD,
samplerate: AudioStreamingSamplerate.KHZ_16,
},
],
codecs: [
{
type: AudioStreamingCodecType.OPUS,
// required by watch
samplerate: AudioStreamingSamplerate.KHZ_8,
},
{
type: AudioStreamingCodecType.OPUS,
samplerate: AudioStreamingSamplerate.KHZ_16,
},
{
type: AudioStreamingCodecType.OPUS,
samplerate: AudioStreamingSamplerate.KHZ_24,
},
],
},
},
})
Expand Down
5 changes: 1 addition & 4 deletions packages/homebridge-ring/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ export class Camera extends BaseDataAccessory<RingCamera> {
) {
super()

this.cameraSource = new CameraSource(
this.device,
this.config.unbridgeCameras,
)
this.cameraSource = new CameraSource(this.device)

if (!hap.CameraController) {
const error =
Expand Down
6 changes: 0 additions & 6 deletions packages/homebridge-ring/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
"description": "Click \"Generate New Refresh Token\" above to change accounts or if your refresh token has expired",
"placeholder": "Refresh Token"
},
"unbridgeCameras": {
"title": "Unbridge Cameras",
"type": "boolean",
"description": "If enabled, all Ring Cameras we be treated as external accessories, which generally leads to better performance. This means they each need to be individually added to HomeKit. This option will be enabled by default in the next major release. WARNING: If your cameras are already bridged, they will be deleted from HomeKit when you enable this option, and you will need to reconfigure any associated automations or HomeKit settings"
},
"alarmOnEntryDelay": {
"title": "Alarm on Entry Delay",
"type": "boolean",
Expand Down Expand Up @@ -157,7 +152,6 @@
"title": "Optional Configuration",
"expandable": true,
"items": [
"unbridgeCameras",
"alarmOnEntryDelay",
"hideLightGroups",
"hideDoorbellSwitch",
Expand Down
1 change: 0 additions & 1 deletion packages/homebridge-ring/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export interface RingPlatformConfig extends RingApiOptions {
nightModeBypassFor: AlarmMode
onlyDeviceTypes?: string[]
showPanicButtons?: boolean
unbridgeCameras?: boolean
disableLogs?: boolean
}

Expand Down
27 changes: 3 additions & 24 deletions packages/homebridge-ring/ring-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ export class RingPlatform implements DynamicPlatformPlugin {
platformAccessories: PlatformAccessory[] = [],
externalAccessories: PlatformAccessory[] = [],
activeAccessoryIds: string[] = []
let hasBridgedCameras = false

logInfo('Found the following locations:')

Expand Down Expand Up @@ -286,8 +285,7 @@ export class RingPlatform implements DynamicPlatformPlugin {
hapDevices.forEach(
({ deviceType, device, isCamera, id, name, AccessoryClass }) => {
const uuid = hap.uuid.generate(debugPrefix + id),
displayName = debugPrefix + name,
isExternalCamera = isCamera && this.config.unbridgeCameras
displayName = debugPrefix + name

if (
!AccessoryClass ||
Expand All @@ -302,7 +300,7 @@ export class RingPlatform implements DynamicPlatformPlugin {
return
}

if (isExternalCamera && this.homebridgeAccessories[uuid]) {
if (isCamera && this.homebridgeAccessories[uuid]) {
// Camera was previously bridged. Remove it from the platform so that it can be added as an external accessory
this.log.warn(
`Camera ${displayName} was previously bridged. You will need to manually pair it as a new accessory.`,
Expand All @@ -322,7 +320,7 @@ export class RingPlatform implements DynamicPlatformPlugin {
: hap.Categories.SECURITY_SYSTEM,
)

if (isExternalCamera) {
if (isCamera) {
logInfo(
`Configured camera ${uuid} ${deviceType} ${displayName}`,
)
Expand All @@ -334,17 +332,6 @@ export class RingPlatform implements DynamicPlatformPlugin {
platformAccessories.push(accessory)
}

if (
isCamera &&
!isExternalCamera &&
typeof hap.Accessory.cleanupAccessoryData === 'function'
) {
// This is a one-time cleanup that will remove persist files for old external accessories from unbridged cameras
hap.Accessory.cleanupAccessoryData(
generateMacAddress(accessory.UUID),
)
}

return accessory
},
homebridgeAccessory =
Expand All @@ -358,8 +345,6 @@ export class RingPlatform implements DynamicPlatformPlugin {

this.homebridgeAccessories[uuid] = homebridgeAccessory
activeAccessoryIds.push(uuid)

hasBridgedCameras ||= isCamera && !isExternalCamera
},
)
}),
Expand Down Expand Up @@ -406,11 +391,5 @@ export class RingPlatform implements DynamicPlatformPlugin {
})
},
)

if (hasBridgedCameras) {
logError(
'Bridged camera support will be removed in the next major release of homebridge-ring. Please enable the unbridgeCameras option in your configuration and add the individual cameras to HomeKit to prepare for this change.',
)
}
}
}
3 changes: 2 additions & 1 deletion packages/ring-client-api/ring-camera.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SocketTicketResponse, RingCameraKind } from './ring-types.ts'
import type { SocketTicketResponse } from './ring-types.ts'
import { RingCameraKind } from './ring-types.ts'
import {
type CameraData,
type CameraDeviceSettingsData,
Expand Down

0 comments on commit 93a9f6b

Please sign in to comment.