From debaedfd8ca91a5afd5bd689d8d0d67df7487ee0 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Wed, 3 May 2023 12:39:50 -0700 Subject: [PATCH] rebroadcast: publish --- plugins/prebuffer-mixin/package-lock.json | 4 ++-- plugins/prebuffer-mixin/package.json | 2 +- plugins/prebuffer-mixin/src/normalize-codec.ts | 12 ++++++++++++ plugins/prebuffer-mixin/src/rfc4571.ts | 5 +++-- plugins/prebuffer-mixin/src/rtsp-session.ts | 6 +++--- 5 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 plugins/prebuffer-mixin/src/normalize-codec.ts diff --git a/plugins/prebuffer-mixin/package-lock.json b/plugins/prebuffer-mixin/package-lock.json index 272fec26b..ca0d9bce0 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.82", + "version": "0.9.83", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/prebuffer-mixin", - "version": "0.9.82", + "version": "0.9.83", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/prebuffer-mixin/package.json b/plugins/prebuffer-mixin/package.json index b69af5043..95a8b3e8f 100644 --- a/plugins/prebuffer-mixin/package.json +++ b/plugins/prebuffer-mixin/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.9.82", + "version": "0.9.83", "description": "Video Stream Rebroadcast, Prebuffer, and Management Plugin for Scrypted.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/prebuffer-mixin/src/normalize-codec.ts b/plugins/prebuffer-mixin/src/normalize-codec.ts new file mode 100644 index 000000000..ab8adb27d --- /dev/null +++ b/plugins/prebuffer-mixin/src/normalize-codec.ts @@ -0,0 +1,12 @@ +export function normalizeCodec(codec: string) { + codec = codec?.toLowerCase()?.replaceAll('.', ''); + // todo: more codecs from sdps + switch (codec) { + case 'pcm_ulaw': + return 'pcm_mulaw'; + case 'h265': + return 'hevc'; + } + + return codec; +} diff --git a/plugins/prebuffer-mixin/src/rfc4571.ts b/plugins/prebuffer-mixin/src/rfc4571.ts index 216c99788..6ed73b00e 100644 --- a/plugins/prebuffer-mixin/src/rfc4571.ts +++ b/plugins/prebuffer-mixin/src/rfc4571.ts @@ -10,6 +10,7 @@ import { parse as spsParse } from "h264-sps-parser"; import net from 'net'; import { EventEmitter, Readable } from "stream"; import { getSpsResolution } from "./sps-resolution"; +import { normalizeCodec } from "./normalize-codec"; export function negotiateMediaStream(sdp: string, mediaStreamOptions: MediaStreamOptions, inputVideoCodec: string, inputAudioCodec: string, requestMediaStream: MediaStreamOptions) { const parsedSdp = parseSdp(sdp); @@ -76,8 +77,8 @@ export function startRFC4571Parser(console: Console, socket: Readable, sdp: stri const audioPt = audioSection?.payloadTypes?.[0]; const videoPt = videoSection?.payloadTypes?.[0]; - const inputAudioCodec = audioSection?.codec; - const inputVideoCodec = videoSection.codec; + const inputAudioCodec = normalizeCodec(audioSection?.codec); + const inputVideoCodec = normalizeCodec(videoSection.codec); let sessionKilled: any; const killed = new Promise(resolve => { diff --git a/plugins/prebuffer-mixin/src/rtsp-session.ts b/plugins/prebuffer-mixin/src/rtsp-session.ts index 5c8c9c6ba..7847e4593 100644 --- a/plugins/prebuffer-mixin/src/rtsp-session.ts +++ b/plugins/prebuffer-mixin/src/rtsp-session.ts @@ -9,6 +9,7 @@ import { parse as spsParse } from "h264-sps-parser"; import { EventEmitter } from "stream"; import { negotiateMediaStream } from "./rfc4571"; import { getSpsResolution } from "./sps-resolution"; +import { normalizeCodec } from "./normalize-codec"; export type RtspChannelCodecMapping = { [key: number]: string }; @@ -209,9 +210,8 @@ export async function startRtspSession(console: Console, url: string, mediaStrea if (!videoSection) throw new Error('SDP does not contain a video section!'); - const inputAudioCodec = audioSection?.codec; - const inputVideoCodec = videoSection.codec; - + const inputAudioCodec = normalizeCodec(audioSection?.codec); + const inputVideoCodec = normalizeCodec(videoSection.codec); let inputVideoResolution: { width: number;