rebroadcast: fix various bugs related to rtsp mode and soft mute

This commit is contained in:
Koushik Dutta
2022-03-05 09:47:06 -08:00
parent 63b5b7d489
commit ba64a6407e
5 changed files with 19 additions and 11 deletions

View File

@@ -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<string[]> {
}
}
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[]) {

View File

@@ -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",

View File

@@ -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",

View File

@@ -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);

View File

@@ -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) {