From ba64a6407e5f2d38eb52166d1601ac0339cd3846 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 5 Mar 2022 09:47:06 -0800 Subject: [PATCH] rebroadcast: fix various bugs related to rtsp mode and soft mute --- common/src/rtsp-server.ts | 8 ++++---- plugins/prebuffer-mixin/package-lock.json | 4 ++-- plugins/prebuffer-mixin/package.json | 2 +- plugins/prebuffer-mixin/src/main.ts | 11 +++++++++-- plugins/prebuffer-mixin/src/rfc4571.ts | 5 +++-- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/common/src/rtsp-server.ts b/common/src/rtsp-server.ts index d3858f9c1..10cf52142 100644 --- a/common/src/rtsp-server.ts +++ b/common/src/rtsp-server.ts @@ -1,7 +1,7 @@ import { readLength, readLine } from './read-stream'; import { Duplex, Readable } from 'stream'; import { randomBytes } from 'crypto'; -import { StreamChunk, StreamParser } from './stream-parser'; +import { StreamChunk, StreamParser, StreamParserOptions } from './stream-parser'; import dgram from 'dgram'; import net from 'net'; import tls from 'tls'; @@ -29,7 +29,7 @@ export async function readMessage(client: Readable): Promise { } } -export function createRtspParser(): RtspStreamParser { +export function createRtspParser(options?: StreamParserOptions): RtspStreamParser { let resolve: any; return { @@ -42,8 +42,8 @@ export function createRtspParser(): RtspStreamParser { outputArguments: [ '-rtsp_transport', 'tcp', - '-vcodec', 'copy', - '-acodec', 'copy', + ...(options?.vcodec || []), + ...(options?.acodec || []), '-f', 'rtsp', ], findSyncFrame(streamChunks: StreamChunk[]) { diff --git a/plugins/prebuffer-mixin/package-lock.json b/plugins/prebuffer-mixin/package-lock.json index 00e7653ba..468bd6fdc 100644 --- a/plugins/prebuffer-mixin/package-lock.json +++ b/plugins/prebuffer-mixin/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.1.175", + "version": "0.1.176", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/prebuffer-mixin", - "version": "0.1.175", + "version": "0.1.176", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/prebuffer-mixin/package.json b/plugins/prebuffer-mixin/package.json index 9b0e84f53..854e074c6 100644 --- a/plugins/prebuffer-mixin/package.json +++ b/plugins/prebuffer-mixin/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.1.175", + "version": "0.1.176", "description": "Rebroadcast and Prebuffer for VideoCameras.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/prebuffer-mixin/src/main.ts b/plugins/prebuffer-mixin/src/main.ts index 49ff9829e..142244403 100644 --- a/plugins/prebuffer-mixin/src/main.ts +++ b/plugins/prebuffer-mixin/src/main.ts @@ -403,7 +403,13 @@ class PrebufferSession { }); } else { - const parser = createRtspParser(); + const parser = createRtspParser({ + vcodec, + // the rtsp parser should always stream copy unless audio is soft muted. + acodec: audioSoftMuted + ? ['-an'] + : ['-acodec', 'copy'], + }); this.sdp = parser.sdp; rbo.parsers.rtsp = parser; } @@ -453,7 +459,8 @@ class PrebufferSession { this.sdp = Promise.resolve(sdp); const { audio, video } = parseTrackIds(sdp); // handle no audio? - await rtspClient.setup(0, audio); + if (!audioSoftMuted) + await rtspClient.setup(0, audio); await rtspClient.setup(2, video); const socket = await rtspClient.play(); session = await startRFC4571Parser(this.console, socket, sdp, ffmpegInput.mediaStreamOptions, true, rbo); diff --git a/plugins/prebuffer-mixin/src/rfc4571.ts b/plugins/prebuffer-mixin/src/rfc4571.ts index af0d6d7cf..8e9516901 100644 --- a/plugins/prebuffer-mixin/src/rfc4571.ts +++ b/plugins/prebuffer-mixin/src/rfc4571.ts @@ -98,8 +98,9 @@ export async function startRFC4571Parser(console: Console, socket: net.Socket, s })() .finally(kill); - let inputAudioCodec = mediaStreamOptions.audio.codec; - let inputVideoCodec = mediaStreamOptions.video.codec; + let inputAudioCodec: string; + let inputVideoCodec: string; + // todo: multiple codecs may be offered, default is the first one in the sdp. const audio = findTrack(sdp, 'audio'); const video = findTrack(sdp, 'video'); if (audio) {