homebridge-ring 11.0.2-beta.0 → 11.0.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [11.0.2-beta.1](https://github.com/dgreif/ring/compare/v11.0.2-beta.0...v11.0.2-beta.1) (2022-05-21)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **api:** prevent duplicate events from `onCallEnded` ([75696d5](https://github.com/dgreif/ring/commit/75696d510969f706248a0f83e98fb1c99fc07213)), closes [#941](https://github.com/dgreif/ring/issues/941)
|
|
11
|
+
* handle pcmu return audio ([ce29fb5](https://github.com/dgreif/ring/commit/ce29fb5638bc488c515518a0fadcaca900ebe750)), closes [#930](https://github.com/dgreif/ring/issues/930)
|
|
12
|
+
|
|
5
13
|
### [11.0.2-beta.0](https://github.com/dgreif/ring/compare/v11.0.1...v11.0.2-beta.0) (2022-05-21)
|
|
6
14
|
|
|
7
15
|
|
|
@@ -20,6 +20,7 @@ export declare class StreamingSession extends Subscribed {
|
|
|
20
20
|
readonly onAudioRtp: Subject<RtpPacket>;
|
|
21
21
|
private readonly audioSplitter;
|
|
22
22
|
private readonly videoSplitter;
|
|
23
|
+
private readonly returnAudioSplitter;
|
|
23
24
|
constructor(camera: RingCamera, connection: RingEdgeConnection | WebrtcConnection);
|
|
24
25
|
private bindToConnection;
|
|
25
26
|
activated: boolean;
|
|
@@ -27,7 +28,12 @@ export declare class StreamingSession extends Subscribed {
|
|
|
27
28
|
cameraSpeakerActivated: boolean;
|
|
28
29
|
activateCameraSpeaker(): Promise<void>;
|
|
29
30
|
reservePort(bufferPorts?: number): Promise<number>;
|
|
31
|
+
get isUsingOpus(): Promise<boolean>;
|
|
30
32
|
startTranscoding(ffmpegOptions: FfmpegOptions): Promise<void>;
|
|
33
|
+
transcodeReturnAudio(ffmpegOptions: {
|
|
34
|
+
input: SpawnInput[];
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
private hasEnded;
|
|
31
37
|
private callEnded;
|
|
32
38
|
stop(): void;
|
|
33
39
|
sendAudioPacket(rtp: RtpPacket): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StreamingSession = void 0;
|
|
4
|
+
const werift_1 = require("werift");
|
|
4
5
|
const camera_utils_1 = require("@homebridge/camera-utils");
|
|
5
6
|
const rxjs_1 = require("rxjs");
|
|
6
7
|
const ffmpeg_1 = require("../ffmpeg");
|
|
@@ -26,8 +27,10 @@ class StreamingSession extends subscribed_1.Subscribed {
|
|
|
26
27
|
this.onAudioRtp = new rxjs_1.Subject();
|
|
27
28
|
this.audioSplitter = new camera_utils_1.RtpSplitter();
|
|
28
29
|
this.videoSplitter = new camera_utils_1.RtpSplitter();
|
|
30
|
+
this.returnAudioSplitter = new camera_utils_1.RtpSplitter();
|
|
29
31
|
this.activated = false;
|
|
30
32
|
this.cameraSpeakerActivated = false;
|
|
33
|
+
this.hasEnded = false;
|
|
31
34
|
this.bindToConnection(connection);
|
|
32
35
|
}
|
|
33
36
|
bindToConnection(connection) {
|
|
@@ -36,14 +39,14 @@ class StreamingSession extends subscribed_1.Subscribed {
|
|
|
36
39
|
}));
|
|
37
40
|
}
|
|
38
41
|
async activate() {
|
|
39
|
-
if (this.activated) {
|
|
42
|
+
if (this.activated || this.hasEnded) {
|
|
40
43
|
return;
|
|
41
44
|
}
|
|
42
45
|
this.activated = true;
|
|
43
46
|
await this.connection.activate();
|
|
44
47
|
}
|
|
45
48
|
async activateCameraSpeaker() {
|
|
46
|
-
if (this.cameraSpeakerActivated) {
|
|
49
|
+
if (this.cameraSpeakerActivated || this.hasEnded) {
|
|
47
50
|
return;
|
|
48
51
|
}
|
|
49
52
|
this.cameraSpeakerActivated = true;
|
|
@@ -53,8 +56,14 @@ class StreamingSession extends subscribed_1.Subscribed {
|
|
|
53
56
|
const ports = await (0, camera_utils_1.reservePorts)({ count: bufferPorts + 1 });
|
|
54
57
|
return ports[0];
|
|
55
58
|
}
|
|
59
|
+
get isUsingOpus() {
|
|
60
|
+
return (0, rxjs_1.firstValueFrom)(this.onUsingOpus);
|
|
61
|
+
}
|
|
56
62
|
async startTranscoding(ffmpegOptions) {
|
|
57
|
-
|
|
63
|
+
if (this.hasEnded) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const videoPort = await this.reservePort(1), audioPort = await this.reservePort(1), transcodeVideoStream = ffmpegOptions.video !== false, ringSdp = await (0, rxjs_1.firstValueFrom)(this.connection.onCallAnswered), usingOpus = await this.isUsingOpus, ffmpegInputArguments = [
|
|
58
67
|
'-hide_banner',
|
|
59
68
|
'-protocol_whitelist',
|
|
60
69
|
'pipe,udp,rtp,file,crypto',
|
|
@@ -100,17 +109,61 @@ class StreamingSession extends subscribed_1.Subscribed {
|
|
|
100
109
|
// Activate the stream now that ffmpeg is ready to receive
|
|
101
110
|
await this.activate();
|
|
102
111
|
}
|
|
112
|
+
async transcodeReturnAudio(ffmpegOptions) {
|
|
113
|
+
if (this.hasEnded) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const audioOutForwarder = new camera_utils_1.RtpSplitter(({ message }) => {
|
|
117
|
+
const rtp = werift_1.RtpPacket.deSerialize(message);
|
|
118
|
+
this.connection.sendAudioPacket(rtp);
|
|
119
|
+
return null;
|
|
120
|
+
}), usingOpus = await this.isUsingOpus, ff = new camera_utils_1.FfmpegProcess({
|
|
121
|
+
ffmpegArgs: [
|
|
122
|
+
'-hide_banner',
|
|
123
|
+
'-protocol_whitelist',
|
|
124
|
+
'pipe,udp,rtp,file,crypto',
|
|
125
|
+
'-re',
|
|
126
|
+
'-i',
|
|
127
|
+
...ffmpegOptions.input,
|
|
128
|
+
'-acodec',
|
|
129
|
+
...(usingOpus
|
|
130
|
+
? ['libopus', '-ac', 2, '-ar', '48k']
|
|
131
|
+
: ['pcm_mulaw', '-ac', 1, '-ar', '8k']),
|
|
132
|
+
'-flags',
|
|
133
|
+
'+global_header',
|
|
134
|
+
'-f',
|
|
135
|
+
'rtp',
|
|
136
|
+
`rtp://127.0.0.1:${await audioOutForwarder.portPromise}`,
|
|
137
|
+
],
|
|
138
|
+
ffmpegPath: (0, ffmpeg_1.getFfmpegPath)(),
|
|
139
|
+
exitCallback: () => this.callEnded(),
|
|
140
|
+
logLabel: `Return Audio (${this.camera.name})`,
|
|
141
|
+
logger: {
|
|
142
|
+
error: util_1.logError,
|
|
143
|
+
info: util_1.logDebug,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
this.onCallEnded.subscribe(() => ff.stop());
|
|
147
|
+
}
|
|
103
148
|
callEnded() {
|
|
149
|
+
if (this.hasEnded) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
this.hasEnded = true;
|
|
104
153
|
this.unsubscribe();
|
|
105
154
|
this.onCallEnded.next();
|
|
106
155
|
this.connection.stop();
|
|
107
156
|
this.audioSplitter.close();
|
|
108
157
|
this.videoSplitter.close();
|
|
158
|
+
this.returnAudioSplitter.close();
|
|
109
159
|
}
|
|
110
160
|
stop() {
|
|
111
161
|
this.callEnded();
|
|
112
162
|
}
|
|
113
163
|
sendAudioPacket(rtp) {
|
|
164
|
+
if (this.hasEnded) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
114
167
|
this.connection.sendAudioPacket(rtp);
|
|
115
168
|
}
|
|
116
169
|
}
|
|
@@ -26,8 +26,8 @@ function getSessionConfig(srtpOptions) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
class StreamingSessionWrapper {
|
|
29
|
-
constructor(
|
|
30
|
-
this.
|
|
29
|
+
constructor(streamingSession, prepareStreamRequest, ringCamera, start) {
|
|
30
|
+
this.streamingSession = streamingSession;
|
|
31
31
|
this.prepareStreamRequest = prepareStreamRequest;
|
|
32
32
|
this.ringCamera = ringCamera;
|
|
33
33
|
this.start = start;
|
|
@@ -63,15 +63,15 @@ class StreamingSessionWrapper {
|
|
|
63
63
|
onReturnPacketReceived.next(null);
|
|
64
64
|
return null;
|
|
65
65
|
});
|
|
66
|
-
|
|
66
|
+
streamingSession.addSubscriptions((0, rxjs_1.merge)((0, rxjs_1.of)(true).pipe((0, operators_1.delay)(15000)), onReturnPacketReceived)
|
|
67
67
|
.pipe((0, operators_1.debounceTime)(5000))
|
|
68
68
|
.subscribe(() => {
|
|
69
69
|
(0, util_1.logInfo)(`Live stream for ${this.ringCamera.name} appears to be inactive. (${getDurationSeconds(start)}s)`);
|
|
70
|
-
|
|
70
|
+
streamingSession.stop();
|
|
71
71
|
}));
|
|
72
72
|
// Periodically send a blank RTCP packet to the HomeKit video port
|
|
73
73
|
// Without this, HomeKit assumes the stream is dead after 30 second and sends a stop request
|
|
74
|
-
|
|
74
|
+
streamingSession.addSubscriptions((0, rxjs_1.interval)(500).subscribe(() => {
|
|
75
75
|
const senderInfo = new werift_1.RtcpSenderInfo({
|
|
76
76
|
ntpTimestamp: BigInt(0),
|
|
77
77
|
packetCount: 0,
|
|
@@ -95,7 +95,7 @@ class StreamingSessionWrapper {
|
|
|
95
95
|
// use to encrypt Ring video to HomeKit
|
|
96
96
|
videoSrtpSession = new werift_1.SrtpSession(getSessionConfig(this.videoSrtp));
|
|
97
97
|
// Set up packet forwarding for video stream
|
|
98
|
-
this.
|
|
98
|
+
this.streamingSession.addSubscriptions(this.streamingSession.onVideoRtp.subscribe(({ header, payload }) => {
|
|
99
99
|
header.ssrc = this.videoSsrc;
|
|
100
100
|
header.payloadType = request.video.pt;
|
|
101
101
|
const encryptedPacket = videoSrtpSession.encrypt(payload, header);
|
|
@@ -112,9 +112,9 @@ class StreamingSessionWrapper {
|
|
|
112
112
|
}));
|
|
113
113
|
const shouldTranscodeAudio = await this.libfdkAacInstalledPromise;
|
|
114
114
|
if (!shouldTranscodeAudio) {
|
|
115
|
-
return this.
|
|
115
|
+
return this.streamingSession.activate();
|
|
116
116
|
}
|
|
117
|
-
const transcodingPromise = this.
|
|
117
|
+
const transcodingPromise = this.streamingSession.startTranscoding({
|
|
118
118
|
input: ['-vn'],
|
|
119
119
|
audio: [
|
|
120
120
|
'-map',
|
|
@@ -167,20 +167,20 @@ class StreamingSessionWrapper {
|
|
|
167
167
|
}, audioSrtpSession = new werift_1.SrtpSession(getSessionConfig(remoteAudioSrtpOptions)), returnAudioTranscodedSplitter = new camera_utils_1.RtpSplitter(({ message }) => {
|
|
168
168
|
if (!cameraSpeakerActive) {
|
|
169
169
|
cameraSpeakerActive = true;
|
|
170
|
-
this.
|
|
170
|
+
this.streamingSession.activateCameraSpeaker().catch(util_1.logError);
|
|
171
171
|
}
|
|
172
172
|
// decrypt the message
|
|
173
173
|
try {
|
|
174
174
|
const rtp = werift_1.RtpPacket.deSerialize(message);
|
|
175
175
|
rtp.payload = audioSrtpSession.decrypt(rtp.payload);
|
|
176
176
|
// send to Ring - werift will handle encryption and other header params
|
|
177
|
-
this.
|
|
177
|
+
this.streamingSession.sendAudioPacket(rtp);
|
|
178
178
|
}
|
|
179
179
|
catch (_) {
|
|
180
180
|
// deSerialize will sometimes fail, but the errors can be ignored
|
|
181
181
|
}
|
|
182
182
|
return null;
|
|
183
|
-
}), returnAudioTranscoder = new camera_utils_1.ReturnAudioTranscoder({
|
|
183
|
+
}), usingOpus = await this.streamingSession.isUsingOpus, returnAudioTranscoder = new camera_utils_1.ReturnAudioTranscoder({
|
|
184
184
|
prepareStreamRequest: this.prepareStreamRequest,
|
|
185
185
|
incomingAudioOptions: {
|
|
186
186
|
ssrc: this.audioSsrc,
|
|
@@ -188,13 +188,11 @@ class StreamingSessionWrapper {
|
|
|
188
188
|
},
|
|
189
189
|
outputArgs: [
|
|
190
190
|
'-acodec',
|
|
191
|
-
|
|
191
|
+
...(usingOpus
|
|
192
|
+
? ['libopus', '-ac', 2, '-ar', '48k']
|
|
193
|
+
: ['pcm_mulaw', '-ac', 1, '-ar', '8k']),
|
|
192
194
|
'-flags',
|
|
193
195
|
'+global_header',
|
|
194
|
-
'-ac',
|
|
195
|
-
2,
|
|
196
|
-
'-ar',
|
|
197
|
-
'48k',
|
|
198
196
|
'-f',
|
|
199
197
|
'rtp',
|
|
200
198
|
`rtp://127.0.0.1:${await returnAudioTranscodedSplitter.portPromise}`,
|
|
@@ -207,7 +205,7 @@ class StreamingSessionWrapper {
|
|
|
207
205
|
logLabel: `Return Audio (${this.ringCamera.name})`,
|
|
208
206
|
returnAudioSplitter: this.audioSplitter,
|
|
209
207
|
});
|
|
210
|
-
this.
|
|
208
|
+
this.streamingSession.onCallEnded.pipe((0, operators_1.take)(1)).subscribe(() => {
|
|
211
209
|
returnAudioTranscoder.stop();
|
|
212
210
|
returnAudioTranscodedSplitter.close();
|
|
213
211
|
});
|
|
@@ -217,7 +215,7 @@ class StreamingSessionWrapper {
|
|
|
217
215
|
stop() {
|
|
218
216
|
this.audioSplitter.close();
|
|
219
217
|
this.videoSplitter.close();
|
|
220
|
-
this.
|
|
218
|
+
this.streamingSession.stop();
|
|
221
219
|
}
|
|
222
220
|
}
|
|
223
221
|
class CameraSource {
|
package/package.json
CHANGED