| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright 2016 The Chromium Authors. All rights reserved. | 2 * Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * See |setSdpDefaultCodec|. | 8 * See |setSdpDefaultCodec|. |
| 9 */ | 9 */ |
| 10 function setSdpDefaultAudioCodec(sdp, codec) { | 10 function setSdpDefaultAudioCodec(sdp, codec) { |
| 11 return setSdpDefaultCodec(sdp, 'audio', codec); | 11 return setSdpDefaultCodec(sdp, 'audio', codec); |
| 12 } | 12 } |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * See |setSdpDefaultCodec|. | 15 * See |setSdpDefaultCodec|. |
| 16 */ | 16 */ |
| 17 function setSdpDefaultVideoCodec(sdp, codec) { | 17 function setSdpDefaultVideoCodec(sdp, codec) { |
| 18 return setSdpDefaultCodec(sdp, 'video', codec); | 18 return setSdpDefaultCodec(sdp, 'video', codec); |
| 19 } | 19 } |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Returns a modified version of |sdp| where the opus DTX flag has been |
| 23 * enabled. |
| 24 */ |
| 25 function setOpusDtxEnabled(sdp) { |
| 26 var sdpLines = splitSdpLines(sdp); |
| 27 |
| 28 // Get default audio codec |
| 29 var defaultCodec = getSdpDefaultAudioCodec(sdp); |
| 30 if (defaultCodec !== 'opus') { |
| 31 failure('setOpusDtxEnabled', |
| 32 'Default audio codec is not set to \'opus\'.'); |
| 33 } |
| 34 |
| 35 // Find codec ID for Opus, e.g. 111 if 'a=rtpmap:111 opus/48000/2'. |
| 36 var codecId = findRtpmapId(sdpLines, 'opus'); |
| 37 if (codecId === null) { |
| 38 failure('setOpusDtxEnabled', 'Unknown ID for |codec| = \'opus\'.'); |
| 39 } |
| 40 |
| 41 // Find 'a=fmtp:111' line, where 111 is the codecId |
| 42 var fmtLineNo = findFmtpLine(sdpLines, codecId); |
| 43 if (fmtLineNo === null) { |
| 44 // Add the line to the SDP. |
| 45 newLine = 'a=fmtp:' + codecId + ' usedtx=1' |
| 46 rtpMapLine = findRtpmapLine(sdpLines, codecId); |
| 47 sdpLines.splice(rtpMapLine + 1, 0, newLine); |
| 48 } else { |
| 49 // Modify the line to enable Opus Dtx. |
| 50 sdpLines[fmtLineNo] += ';usedtx=1' |
| 51 } |
| 52 return mergeSdpLines(sdpLines); |
| 53 } |
| 54 |
| 55 /** |
| 22 * Returns a modified version of |sdp| where the |codec| has been promoted to be | 56 * Returns a modified version of |sdp| where the |codec| has been promoted to be |
| 23 * the default codec, i.e. the codec whose ID is first in the list of codecs on | 57 * the default codec, i.e. the codec whose ID is first in the list of codecs on |
| 24 * the 'm=|type|' line, where |type| is 'audio' or 'video'. | 58 * the 'm=|type|' line, where |type| is 'audio' or 'video'. |
| 25 * @private | 59 * @private |
| 26 */ | 60 */ |
| 27 function setSdpDefaultCodec(sdp, type, codec) { | 61 function setSdpDefaultCodec(sdp, type, codec) { |
| 28 var sdpLines = splitSdpLines(sdp); | 62 var sdpLines = splitSdpLines(sdp); |
| 29 | 63 |
| 30 // Find codec ID, e.g. 100 for 'VP8' if 'a=rtpmap:100 VP8/9000'. | 64 // Find codec ID, e.g. 100 for 'VP8' if 'a=rtpmap:100 VP8/9000'. |
| 31 var codecId = findRtpmapId(sdpLines, codec); | 65 var codecId = findRtpmapId(sdpLines, codec); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 if (!sdpLines[i].match(pattern)) | 177 if (!sdpLines[i].match(pattern)) |
| 144 failure('findRtpmapLine', 'Unexpected "a=rtpmap:" pattern.'); | 178 failure('findRtpmapLine', 'Unexpected "a=rtpmap:" pattern.'); |
| 145 // Return line index. | 179 // Return line index. |
| 146 return i; | 180 return i; |
| 147 } | 181 } |
| 148 } | 182 } |
| 149 return null; | 183 return null; |
| 150 } | 184 } |
| 151 | 185 |
| 152 /** | 186 /** |
| 187 * Finds the fmtp line in |sdpLines| for the given |codecId|, and returns its |
| 188 * line number. The line starts with 'a=fmtp:<codecId>'. |
| 189 * @private |
| 190 */ |
| 191 function findFmtpLine(sdpLines, codecId) { |
| 192 return findLine(sdpLines, 'a=fmtp:' + codecId); |
| 193 |
| 194 } |
| 195 |
| 196 /** |
| 153 * Returns a modified version of |mLine| that has |codecId| first in the list of | 197 * Returns a modified version of |mLine| that has |codecId| first in the list of |
| 154 * codec IDs. For example, setMLineDefaultCodec( | 198 * codec IDs. For example, setMLineDefaultCodec( |
| 155 * 'm=video 9 UDP/TLS/RTP/SAVPF 100 101 107 116 117 96', 107) | 199 * 'm=video 9 UDP/TLS/RTP/SAVPF 100 101 107 116 117 96', 107) |
| 156 * Returns: | 200 * Returns: |
| 157 * 'm=video 9 UDP/TLS/RTP/SAVPF 107 100 101 116 117 96' | 201 * 'm=video 9 UDP/TLS/RTP/SAVPF 107 100 101 116 117 96' |
| 158 * @private | 202 * @private |
| 159 */ | 203 */ |
| 160 function setMLineDefaultCodec(mLine, codecId) { | 204 function setMLineDefaultCodec(mLine, codecId) { |
| 161 var elements = mLine.split(' '); | 205 var elements = mLine.split(' '); |
| 162 | 206 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 244 } |
| 201 | 245 |
| 202 /** @private */ | 246 /** @private */ |
| 203 function findLine(lines, startsWith) { | 247 function findLine(lines, startsWith) { |
| 204 for (var i = 0; i < lines.length; i++) { | 248 for (var i = 0; i < lines.length; i++) { |
| 205 if (lines[i].startsWith(startsWith)) | 249 if (lines[i].startsWith(startsWith)) |
| 206 return i; | 250 return i; |
| 207 } | 251 } |
| 208 return null; | 252 return null; |
| 209 } | 253 } |
| OLD | NEW |