From 90c9efc8a61fd920a3fd3fd00e2edce0602bd58b Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 11 May 2023 10:20:28 -0700 Subject: [PATCH] rebroadcast: use highwatermark for nvr perf improvement --- plugins/prebuffer-mixin/package-lock.json | 4 ++-- plugins/prebuffer-mixin/package.json | 2 +- plugins/prebuffer-mixin/src/file-rtsp-server.ts | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/prebuffer-mixin/package-lock.json b/plugins/prebuffer-mixin/package-lock.json index 81702bbbd..55b9d0901 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.9.86", + "version": "0.9.87", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/prebuffer-mixin", - "version": "0.9.86", + "version": "0.9.87", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/prebuffer-mixin/package.json b/plugins/prebuffer-mixin/package.json index f8ab47119..cb678491b 100644 --- a/plugins/prebuffer-mixin/package.json +++ b/plugins/prebuffer-mixin/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.9.86", + "version": "0.9.87", "description": "Video Stream Rebroadcast, Prebuffer, and Management Plugin for Scrypted.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/prebuffer-mixin/src/file-rtsp-server.ts b/plugins/prebuffer-mixin/src/file-rtsp-server.ts index 006730839..883ee0422 100644 --- a/plugins/prebuffer-mixin/src/file-rtsp-server.ts +++ b/plugins/prebuffer-mixin/src/file-rtsp-server.ts @@ -4,6 +4,8 @@ import fs from 'fs'; import { format } from "path"; import { Duplex } from "stream"; +const highWaterMark = 1024 * 1024; + // non standard extension that dumps the rtp payload to a file. export class FileRtspServer extends RtspServer { writeStream: fs.WriteStream; @@ -56,6 +58,7 @@ export class FileRtspServer extends RtspServer { await fs.promises.rename(truncate, file); truncateWriteStream = fs.createWriteStream(undefined, { fd, + highWaterMark, }) // this.writeConsole?.log('truncating', truncate); } @@ -72,7 +75,9 @@ export class FileRtspServer extends RtspServer { this.cleanup(); this.segmentBytesWritten = 0; - this.writeStream = truncateWriteStream || fs.createWriteStream(file); + this.writeStream = truncateWriteStream || fs.createWriteStream(file, { + highWaterMark, + }); this.writeStream.on('error', e => { this.writeConsole?.error('RTSP WRITE error', e); });