-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add webui audio && video codec
- Loading branch information
Showing
4 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// @params {string} SDP | ||
// @params {string} audioCodec | ||
// @params {string} videoCodec | ||
// @return {string} SDP | ||
function convertSessionDescription(sdp, audioCodec, videoCodec) { | ||
const sections = sdp.split("m=") | ||
for (let i = 0; i < sections.length; i++) { | ||
const section = sections[i] | ||
if (section.startsWith("audio") && !!audioCodec) { | ||
sections[i] = setCodec(section, audioCodec) | ||
} else if (section.startsWith("video") && !!videoCodec) { | ||
sections[i] = setCodec(section, videoCodec) | ||
} | ||
} | ||
return sections.join("m=") | ||
} | ||
|
||
function setCodec(section, codec) { | ||
const lines = section.split("\r\n") | ||
const lines2 = [] | ||
const payloadFormats = [] | ||
for (const line of lines) { | ||
if (!line.startsWith("a=rtpmap:")) { | ||
lines2.push(line) | ||
} else { | ||
if (line.toLowerCase().includes(codec)) { | ||
payloadFormats.push(line.slice("a=rtpmap:".length).split(" ")[0]) | ||
lines2.push(line) | ||
} | ||
} | ||
} | ||
|
||
const lines3 = [] | ||
|
||
for (const line of lines2) { | ||
if (line.startsWith("a=fmtp:")) { | ||
if (payloadFormats.includes(line.slice("a=fmtp:".length).split(" ")[0])) { | ||
lines3.push(line) | ||
} | ||
} else if (line.startsWith("a=rtcp-fb:")) { | ||
if (payloadFormats.includes(line.slice("a=rtcp-fb:".length).split(" ")[0])) { | ||
lines3.push(line) | ||
} | ||
} else { | ||
lines3.push(line) | ||
} | ||
} | ||
|
||
return lines3.join("\r\n") | ||
} | ||
|
||
export default convertSessionDescription |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters