Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Bridged Cameras #1552

Draft
wants to merge 1 commit into
base: beta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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
28 changes: 4 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 @@
platformAccessories: PlatformAccessory[] = [],
externalAccessories: PlatformAccessory[] = [],
activeAccessoryIds: string[] = []
let hasBridgedCameras = false

logInfo('Found the following locations:')

Expand Down Expand Up @@ -286,8 +285,7 @@
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,8 @@
return
}

if (isExternalCamera && this.homebridgeAccessories[uuid]) {
// TODO: I think we can remove this, uuid is different with the camera differentiator

Check failure on line 303 in packages/homebridge-ring/ring-platform.ts

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected 'todo' comment: 'TODO: I think we can remove this, uuid...'

Check failure on line 303 in packages/homebridge-ring/ring-platform.ts

View workflow job for this annotation

GitHub Actions / build (22)

Unexpected 'todo' comment: 'TODO: I think we can remove this, uuid...'

Check failure on line 303 in packages/homebridge-ring/ring-platform.ts

View workflow job for this annotation

GitHub Actions / build (20)

Unexpected 'todo' comment: 'TODO: I think we can remove this, uuid...'

Check failure on line 303 in packages/homebridge-ring/ring-platform.ts

View workflow job for this annotation

GitHub Actions / build (20)

Unexpected 'todo' comment: 'TODO: I think we can remove this, uuid...'

Check failure on line 303 in packages/homebridge-ring/ring-platform.ts

View workflow job for this annotation

GitHub Actions / build (22)

Unexpected 'todo' comment: 'TODO: I think we can remove this, uuid...'

Check failure on line 303 in packages/homebridge-ring/ring-platform.ts

View workflow job for this annotation

GitHub Actions / build (20)

Unexpected 'todo' comment: 'TODO: I think we can remove this, uuid...'

Check failure on line 303 in packages/homebridge-ring/ring-platform.ts

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected 'todo' comment: 'TODO: I think we can remove this, uuid...'

Check failure on line 303 in packages/homebridge-ring/ring-platform.ts

View workflow job for this annotation

GitHub Actions / build (22)

Unexpected 'todo' comment: 'TODO: I think we can remove this, 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 +321,7 @@
: hap.Categories.SECURITY_SYSTEM,
)

if (isExternalCamera) {
if (isCamera) {
logInfo(
`Configured camera ${uuid} ${deviceType} ${displayName}`,
)
Expand All @@ -334,17 +333,6 @@
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 +346,6 @@

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

hasBridgedCameras ||= isCamera && !isExternalCamera
},
)
}),
Expand Down Expand Up @@ -406,11 +392,5 @@
})
},
)

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.',
)
}
}
}
Loading