From 7cebd6f02087d02e2762a44c52dcb04e552d882f Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 9 May 2022 09:47:31 -0700 Subject: [PATCH] common: sdp parsing should handle default audio type --- common/src/rtsp-server.ts | 5 ++--- common/src/sdp-utils.ts | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/common/src/rtsp-server.ts b/common/src/rtsp-server.ts index cd3281b21..e73879ef7 100644 --- a/common/src/rtsp-server.ts +++ b/common/src/rtsp-server.ts @@ -9,7 +9,6 @@ import tls from 'tls'; import { BASIC, DIGEST } from 'http-auth-utils/dist/index'; import crypto from 'crypto'; import { timeoutPromise } from './promise-utils'; -import { sleep } from './sleep'; export const RTSP_FRAME_MAGIC = 36; @@ -617,7 +616,7 @@ export class RtspServer { control: msection.control, protocol: 'udp', destination: parseInt(rtp), - codec: msection.codec || (msection.type === 'audio' ? 'pcm' : undefined), + codec: msection.codec, } } else if (transport.includes('TCP')) { @@ -629,7 +628,7 @@ export class RtspServer { control: msection.control, protocol: 'tcp', destination: low, - codec: msection.codec || (msection.type === 'audio' ? 'pcm' : undefined), + codec: msection.codec, } } } diff --git a/common/src/sdp-utils.ts b/common/src/sdp-utils.ts index 0e7f683d9..c8e3d885f 100644 --- a/common/src/sdp-utils.ts +++ b/common/src/sdp-utils.ts @@ -163,6 +163,7 @@ const artpmap = 'a=rtpmap:'; export function parseMSection(msection: string[]) { const control = msection.find(line => line.startsWith(acontrol))?.substring(acontrol.length); const rtpmap = msection.find(line => line.startsWith(artpmap))?.toLowerCase(); + const mline = parseMLine(msection[0]); let codec: string; if (rtpmap?.includes('mpeg4')) { @@ -171,6 +172,12 @@ export function parseMSection(msection: string[]) { else if (rtpmap?.includes('opus')) { codec = 'opus'; } + else if (rtpmap?.includes('pcma')) { + codec = 'pcm_alaw'; + } + else if (rtpmap?.includes('pcmu')) { + codec = 'pcm_ulaw'; + } else if (rtpmap?.includes('pcm')) { codec = 'pcm'; } @@ -180,8 +187,13 @@ export function parseMSection(msection: string[]) { else if (rtpmap?.includes('h265')) { codec = 'h265'; } + else if (!rtpmap && mline.type === 'audio') { + // ffmpeg seems to omit the rtpmap type for pcm alaw when creating sdp? + // is this the default? + codec = 'pcm_alaw'; + } - let direction: string; + let direction: string; for (const checkDirection of ['sendonly', 'sendrecv', 'recvonly', 'inactive']) { const found = msection.find(line => line === 'a=' + checkDirection); if (found) { @@ -191,7 +203,7 @@ export function parseMSection(msection: string[]) { } return { - ...parseMLine(msection[0]), + ...mline, fmtp: parseFmtp(msection), lines: msection, contents: msection.join('\r\n'),