From 58b27805ba687e6e7201d1fa3ab9ae8f8673b43f Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 21 Apr 2025 09:02:25 -0700 Subject: [PATCH] common: fix sdp default rtpmap props --- common/src/sdp-utils.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/common/src/sdp-utils.ts b/common/src/sdp-utils.ts index e383f302f..f5f8d301b 100644 --- a/common/src/sdp-utils.ts +++ b/common/src/sdp-utils.ts @@ -175,6 +175,8 @@ export type RTPMap = ReturnType; export function parseRtpMap(mline: ReturnType, rtpmap: string) { const mlineType = mline.type; const match = rtpmap?.match(/a=rtpmap:([\d]+) (.*?)\/([\d]+)(\/([\d]+))?/); + let channels = parseInt(match?.[5]) || undefined; + let payloadType = parseInt(match?.[1]); rtpmap = rtpmap?.toLowerCase(); @@ -222,14 +224,20 @@ export function parseRtpMap(mline: ReturnType, rtpmap: string if (mline.payloadTypes?.includes(0)) { codec = 'pcm_mulaw'; ffmpegEncoder = 'pcm_mulaw'; + payloadType = 0; + channels = 1; } else if (mline.payloadTypes?.includes(8)) { codec = 'pcm_alaw'; ffmpegEncoder = 'pcm_alaw'; + payloadType = 8; + channels = 1; } else if (mline.payloadTypes?.includes(14)) { codec = 'mp3'; ffmpegEncoder = 'mp3'; + payloadType = 14; + channels = 2; } else { // ffmpeg seems to omit the rtpmap type for pcm alaw when creating sdp? @@ -239,6 +247,8 @@ export function parseRtpMap(mline: ReturnType, rtpmap: string // https://en.wikipedia.org/wiki/RTP_payload_formats codec = 'pcm_alaw'; ffmpegEncoder = 'pcm_alaw'; + payloadType = 8; + channels = 1; } } @@ -258,8 +268,8 @@ export function parseRtpMap(mline: ReturnType, rtpmap: string ffmpegEncoder, rawCodec: match?.[2], clock, - channels: parseInt(match?.[5]) || undefined, - payloadType: parseInt(match?.[1]), + channels, + payloadType, } }