diff --git a/src/nest/streamer.ts b/src/nest/streamer.ts index 3a621b2..b94184e 100644 --- a/src/nest/streamer.ts +++ b/src/nest/streamer.ts @@ -21,6 +21,8 @@ export class NexusStreamer { private ffmpegAudio: FfmpegProcess | undefined; private ffmpegReturnAudio: FfmpegProcess | undefined; private authorized = false; + private videoStarted = false; + private returnAudioStarted = false; private readonly log: Logging; private readonly config: NestConfig; private sessionID: number = Math.floor(Math.random() * 100); @@ -32,7 +34,6 @@ export class NexusStreamer { private videoChannelID = -1; private audioChannelID = -1; private returnAudioTimeout: NodeJS.Timeout | undefined; - private started = false; constructor( cameraInfo: CameraInfo, @@ -57,7 +58,7 @@ export class NexusStreamer { * Close the socket and stop playback */ stopPlayback(): void { - this.started = false; + this.videoStarted = false; if (this.socket) { this.sendStopPlayback(); this.socket.close(); @@ -92,20 +93,24 @@ export class NexusStreamer { } this.returnAudioTimeout = setTimeout(() => { self.sendAudioPayload(Buffer.from([])); - }, 1000); + }, 500); }); + this.returnAudioStarted = true; } } /** * Setup socket communication and send hello packet + * @param {string} host The websocket server address */ private setupConnection(host: string): void { const self = this; let pingInterval: NodeJS.Timeout; this.stopPlayback(); - this.createReturnAudioServer(); + if (!this.returnAudioStarted) { + this.createReturnAudioServer(); + } this.socket = new WebSocket(`wss://${host}/nexustalk`); this.socket.on('open', () => { self.log.info('[NexusStreamer] Connected'); @@ -247,7 +252,7 @@ export class NexusStreamer { * Request that playback start with specific params */ startPlayback(): void { - this.started = true; + this.videoStarted = true; // Attempt to use camera's stream profile or use default let primaryProfile = StreamProfile.VIDEO_H264_2MBIT_L40; const otherProfiles: Array = []; @@ -373,7 +378,7 @@ export class NexusStreamer { // H264 NAL Units require 0001 added to beginning const startCode = Buffer.from([0x00, 0x00, 0x00, 0x01]); const stdin = this.ffmpegVideo.getStdin(); - if (this.started) { + if (this.videoStarted) { stdin?.write(Buffer.concat([startCode, Buffer.from(packet.payload)]), () => { // Do nothing }); @@ -381,7 +386,7 @@ export class NexusStreamer { } if (packet.channel_id === this.audioChannelID) { const stdin = this.ffmpegAudio?.getStdin(); - if (this.started) { + if (this.videoStarted) { stdin?.write(Buffer.from(packet.payload), () => { // Do nothing }); diff --git a/src/streaming-delegate.ts b/src/streaming-delegate.ts index 8e2e807..6633fde 100644 --- a/src/streaming-delegate.ts +++ b/src/streaming-delegate.ts @@ -324,12 +324,8 @@ export class StreamingDelegate implements CameraStreamingDelegate { '0:0', '-c:a', 'libspeex', - '-af', - 'atempo=2.0,asetrate=16000/0.95', '-frames_per_packet', - '2', - '-cbr_quality', - '10', + '4', '-ac', '1', '-ar',