Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #530 from tylergibson/fix-multi-sdp-h264
Browse files Browse the repository at this point in the history
Find all matching SDP codecs for defaults
  • Loading branch information
KaptenJansson authored Feb 26, 2018
2 parents c6af0c2 + 5ef563d commit cfb35d9
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions src/web_app/js/sdputils.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,23 @@ function maybePreferCodec(sdp, type, dir, codec) {
}

// If the codec is available, set it as the default in m line.
var payload = getCodecPayloadType(sdpLines, codec);
if (payload) {
sdpLines[mLineIndex] = setDefaultCodec(sdpLines[mLineIndex], payload);
var payload = null;
// Iterate through rtpmap enumerations to find all matching codec entries
for (var i = sdpLines.length-1; i >= 0 ; --i) {
// Finds first match in rtpmap
var index = findLineInRange(sdpLines, i, 0, 'a=rtpmap', codec, 'desc');
if (index !== null) {
// Skip all of the entries between i and index match
i = index;
payload = getCodecPayloadTypeFromLine(sdpLines[index]);
if (payload) {
// Move codec to top
sdpLines[mLineIndex] = setDefaultCodec(sdpLines[mLineIndex], payload);
}
} else {
// No match means we can break the loop
break;
}
}

sdp = sdpLines.join('\r\n');
Expand Down Expand Up @@ -450,13 +464,40 @@ function findLine(sdpLines, prefix, substr) {

// Find the line in sdpLines[startLine...endLine - 1] that starts with |prefix|
// and, if specified, contains |substr| (case-insensitive search).
function findLineInRange(sdpLines, startLine, endLine, prefix, substr) {
var realEndLine = endLine !== -1 ? endLine : sdpLines.length;
for (var i = startLine; i < realEndLine; ++i) {
if (sdpLines[i].indexOf(prefix) === 0) {
if (!substr ||
sdpLines[i].toLowerCase().indexOf(substr.toLowerCase()) !== -1) {
return i;
function findLineInRange(
sdpLines,
startLine,
endLine,
prefix,
substr,
direction
) {
if (direction === undefined) {
direction = 'asc';
}

direction = direction || 'asc';

if (direction === 'asc') {
// Search beginning to end
var realEndLine = endLine !== -1 ? endLine : sdpLines.length;
for (var i = startLine; i < realEndLine; ++i) {
if (sdpLines[i].indexOf(prefix) === 0) {
if (!substr ||
sdpLines[i].toLowerCase().indexOf(substr.toLowerCase()) !== -1) {
return i;
}
}
}
} else {
// Search end to beginning
var realStartLine = startLine !== -1 ? startLine : sdpLines.length-1;
for (var j = realStartLine; j >= 0; --j) {
if (sdpLines[j].indexOf(prefix) === 0) {
if (!substr ||
sdpLines[j].toLowerCase().indexOf(substr.toLowerCase()) !== -1) {
return j;
}
}
}
}
Expand Down

0 comments on commit cfb35d9

Please sign in to comment.