| 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 /** | |
| 56 * Returns a modified version of |sdp| where the |codec| has been promoted to be | 22 * Returns a modified version of |sdp| where the |codec| has been promoted to be |
| 57 * the default codec, i.e. the codec whose ID is first in the list of codecs on | 23 * the default codec, i.e. the codec whose ID is first in the list of codecs on |
| 58 * the 'm=|type|' line, where |type| is 'audio' or 'video'. | 24 * the 'm=|type|' line, where |type| is 'audio' or 'video'. |
| 59 * @private | 25 * @private |
| 60 */ | 26 */ |
| 61 function setSdpDefaultCodec(sdp, type, codec) { | 27 function setSdpDefaultCodec(sdp, type, codec) { |
| 62 var sdpLines = splitSdpLines(sdp); | 28 var sdpLines = splitSdpLines(sdp); |
| 63 | 29 |
| 64 // Find codec ID, e.g. 100 for 'VP8' if 'a=rtpmap:100 VP8/9000'. | 30 // Find codec ID, e.g. 100 for 'VP8' if 'a=rtpmap:100 VP8/9000'. |
| 65 var codecId = findRtpmapId(sdpLines, codec); | 31 var codecId = findRtpmapId(sdpLines, codec); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 if (!sdpLines[i].match(pattern)) | 143 if (!sdpLines[i].match(pattern)) |
| 178 failure('findRtpmapLine', 'Unexpected "a=rtpmap:" pattern.'); | 144 failure('findRtpmapLine', 'Unexpected "a=rtpmap:" pattern.'); |
| 179 // Return line index. | 145 // Return line index. |
| 180 return i; | 146 return i; |
| 181 } | 147 } |
| 182 } | 148 } |
| 183 return null; | 149 return null; |
| 184 } | 150 } |
| 185 | 151 |
| 186 /** | 152 /** |
| 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 /** | |
| 197 * Returns a modified version of |mLine| that has |codecId| first in the list of | 153 * Returns a modified version of |mLine| that has |codecId| first in the list of |
| 198 * codec IDs. For example, setMLineDefaultCodec( | 154 * codec IDs. For example, setMLineDefaultCodec( |
| 199 * 'm=video 9 UDP/TLS/RTP/SAVPF 100 101 107 116 117 96', 107) | 155 * 'm=video 9 UDP/TLS/RTP/SAVPF 100 101 107 116 117 96', 107) |
| 200 * Returns: | 156 * Returns: |
| 201 * 'm=video 9 UDP/TLS/RTP/SAVPF 107 100 101 116 117 96' | 157 * 'm=video 9 UDP/TLS/RTP/SAVPF 107 100 101 116 117 96' |
| 202 * @private | 158 * @private |
| 203 */ | 159 */ |
| 204 function setMLineDefaultCodec(mLine, codecId) { | 160 function setMLineDefaultCodec(mLine, codecId) { |
| 205 var elements = mLine.split(' '); | 161 var elements = mLine.split(' '); |
| 206 | 162 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 200 } |
| 245 | 201 |
| 246 /** @private */ | 202 /** @private */ |
| 247 function findLine(lines, startsWith) { | 203 function findLine(lines, startsWith) { |
| 248 for (var i = 0; i < lines.length; i++) { | 204 for (var i = 0; i < lines.length; i++) { |
| 249 if (lines[i].startsWith(startsWith)) | 205 if (lines[i].startsWith(startsWith)) |
| 250 return i; | 206 return i; |
| 251 } | 207 } |
| 252 return null; | 208 return null; |
| 253 } | 209 } |
| OLD | NEW |