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:
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?