Split SDP (string) for m line to change video codecs

General Tech Bugs & Fixes 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I want to have a method at the end that can set VP9 or H.264 as preferred video codec in a SDP.

So I am looking for the m line in my SDP:

m=video 9 UDP/TLS/RTP/SAVPF 96 98 100 102 127 97 99 101 125

Console log of my SDP:

Screenshot of console log

In this case I would get and use VP8 (96) as video codec instead of VP9 (98). So I want to check if 98/VP9 is possible/available and want to set it at the beginning/first position to actually use it.

What I got so far:

if(sdpOrigin == 'local') {
    let lines = sdp.split('\n').map(l => l.trim());
    lines.forEach(function(line) {
        if (line.indexOf('m=video') === 0) {
            let parts = line.substr(28); // Should be avoided!
            let vp9_order = parts.indexOf("98");
            let array = parts.split(/\s+/);
            console.log("array", array); // 96 98 100 102 127 97 99 101 125
            if (vp9_order > 0) {
                array.splice(vp9_order, 1);
                array.unshift("98");
            }
            console.log("array-new", array); // 98 96 100 102 127 97 99 101 125

            // How do I update my SDP now with the new codec order?

        }
    })
}

This approach is bad in my opinion, because I get my desired m line but I do a fix substring at the position '28', so it will break if something before changes.

At the end I should have the following "m line" in my SDP:

m=video 9 UDP/TLS/RTP/SAVPF 98 96 100 102 127 97 99 101 125

Can somebody help me with that?

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.