homekit: repbublish with some reverts to the low bandwidth forcing due to ios 15.5 rc bug still being present

This commit is contained in:
Koushik Dutta
2022-05-16 14:35:06 -07:00
parent a65ec1096e
commit fee283ca92
4 changed files with 25 additions and 14 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/homekit",
"version": "0.0.280",
"version": "0.0.281",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/homekit",
"version": "0.0.280",
"version": "0.0.281",
"dependencies": {
"@koush/qrcode-terminal": "^0.12.0",
"@koush/werift-src": "file:../../external/werift",

View File

@@ -45,5 +45,5 @@
"@types/node": "^14.17.9",
"@types/url-parse": "^1.4.3"
},
"version": "0.0.280"
"version": "0.0.281"
}

View File

@@ -27,9 +27,13 @@ export interface CameraStreamingSession {
// macos 12.3 beta 1
// bug seems resolved:
// ios 15.5 gm
// macos 12.4
// bug is still present:
// ios 15.5 RC
export async function waitForFirstVideoRtcp(console: Console, session: CameraStreamingSession) {
if (!session.videoReturnRtcpReady)
return;
console.log('Waiting for video RTCP packet before sending video.');
await session.videoReturnRtcpReady;
console.log('Received first video RTCP packet.');

View File

@@ -4,8 +4,10 @@ import { RtpPacket } from '@koush/werift-src/packages/rtp/src/rtp/rtp';
import { ProtectionProfileAes128CmHmacSha1_80 } from '@koush/werift-src/packages/rtp/src/srtp/const';
import { SrtcpSession } from '@koush/werift-src/packages/rtp/src/srtp/srtcp';
import { bindUdp, closeQuiet } from '@scrypted/common/src/listen-cluster';
import { timeoutPromise } from '@scrypted/common/src/promise-utils';
import sdk, { Camera, FFmpegInput, Intercom, MediaStreamOptions, RequestMediaStreamOptions, ScryptedDevice, ScryptedInterface, ScryptedMimeTypes, VideoCamera, VideoCameraConfiguration } from '@scrypted/sdk';
import dgram, { SocketType } from 'dgram';
import { once } from 'events';
import os from 'os';
import { AudioStreamingCodecType, CameraController, CameraStreamingDelegate, PrepareStreamCallback, PrepareStreamRequest, PrepareStreamResponse, StartStreamRequest, StreamingRequest, StreamRequestCallback, StreamRequestTypes } from '../../hap';
import type { HomeKitPlugin } from "../../main";
@@ -66,6 +68,16 @@ export function createCameraStreamingDelegate(device: ScryptedDevice & VideoCame
closeQuiet(audioReturn);
});
const isHomeHub = homekitPlugin.storageSettings.values.lastKnownHomeHub?.includes(request.targetAddress);
if (isHomeHub)
console.log('Streaming request is coming from the active HomeHub. Will wait for initial RTCP packet.');
const videoReturnRtcpReady = !isHomeHub
? undefined
: timeoutPromise(1000, once(videoReturn, 'message')).catch(() => {
console.warn('Video RTCP Packet timed out. There may be a network (routing/firewall) issue preventing the Apple device sending UDP packets back to Scrypted.');
});
const session: CameraStreamingSession = {
aconfig: {
keys: {
@@ -94,15 +106,9 @@ export function createCameraStreamingDelegate(device: ScryptedDevice & VideoCame
audiossrc,
videoReturn,
audioReturn,
videoReturnRtcpReady: Promise.resolve(undefined),
// waitForFirstVideoRtcp no longer seems necessary as of the GM release
// of ios 15.5 and macos 12.4
// videoReturnRtcpReady: timeoutPromise(1000, once(videoReturn, 'message')).catch(() => {
// console.warn('Video RTCP Packet timed out. There may be a network (routing/firewall) issue preventing the Apple device sending UDP packets back to Scrypted.');
// }),
videoReturnRtcpReady,
};
sessions.set(request.sessionID, session);
const response: PrepareStreamResponse = {
@@ -184,9 +190,10 @@ export function createCameraStreamingDelegate(device: ScryptedDevice & VideoCame
session.startRequest = request as StartStreamRequest;
const forceLowBandwidth = homekitPlugin.storageSettings.values.lastKnownHomeHub?.includes(session.prepareRequest.targetAddress);
if (forceLowBandwidth)
console.log('Streaming request is coming from the active HomeHub. Low bandwidth stream will be selected in case this is a remote wifi connection.');
// const forceLowBandwidth = homekitPlugin.storageSettings.values.lastKnownHomeHub?.includes(session.prepareRequest.targetAddress);
// if (forceLowBandwidth)
// console.log('Streaming request is coming from the active HomeHub. Low bandwidth stream will be selected in case this is a remote wifi connection.');
const forceLowBandwidth = false;
const {
destination,