Chromium Code Reviews| 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 | |
|
minyue
2016/07/28 12:53:29
add findFmtpLine as a helper function
Ivo-OOO until feb 6
2016/07/28 14:00:07
Done.
| |
| 42 var fmtLineNo = findLine(sdpLines, 'a=fmtp:' + codecId); | |
| 43 if (fmtLineNo === null) { | |
| 44 failure('setOpusDtxEnabled', | |
|
minyue
2016/07/28 12:53:29
in this case, we may add "a=fmtp:" + |codecId| lin
Ivo-OOO until feb 6
2016/07/28 14:00:07
Done.
| |
| 45 '\'a=fmtp:' + codecId + '\' line missing from |sdp|.'); | |
| 46 } | |
| 47 | |
| 48 // Modify the line to enable Opus Dtx. | |
| 49 sdpLines[fmtLineNo] += ';usedtx=1' | |
| 50 return mergeSdpLines(sdpLines); | |
| 51 } | |
| 52 | |
| 53 /** | |
| 54 * Check if the opus Dtx flag has been set in |sdp|. | |
| 55 */ | |
| 56 function checkOpusDtxEnabled(sdp) { | |
|
phoglund_chromium
2016/07/28 12:46:38
Ok, then you don't need this anymore right?
Ivo-OOO until feb 6
2016/07/28 14:00:07
Good point, removed this.
| |
| 57 var defaultAudioCodec = getSdpDefaultAudioCodec(sdp); | |
| 58 if (defaultAudioCodec !== 'opus') { | |
| 59 failure('verifyOpusDtxEnabled', | |
| 60 'Default audio codec is not set to opus.'); | |
| 61 } | |
| 62 var sdpLines = splitSdpLines(sdp); | |
| 63 // Find codec ID for Opus, e.g. 111 if 'a=rtpmap:111 opus/48000/2'. | |
| 64 var codecId = findRtpmapId(sdpLines, 'opus'); | |
| 65 if (codecId === null) { | |
| 66 failure('verifyOpusDtxEnabled', 'Unknown ID for |codec| = \'opus\'.'); | |
| 67 } | |
| 68 | |
| 69 // Find 'a=fmtp:111' line, where 111 is the codecId | |
| 70 var fmtLineNo = findLine(sdpLines, 'a=fmtp:' + codecId); | |
| 71 if (fmtLineNo === null) { | |
| 72 failure('verifyOpusDtxEnabled', | |
| 73 '\'a=fmtp:' + codecId + '\' line missing from |sdp|.'); | |
| 74 } | |
| 75 | |
| 76 // Check that 'usedtx=1' appears on the line. | |
| 77 if (sdpLines[fmtLineNo].indexOf('usedtx=1') === -1) { | |
| 78 failure('verifyOpusDtxEnabled', | |
| 79 '\'usedtx=1\' is missing from \'a=fmtp:' + codecId + '\' line.'); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 /** | |
| 22 * Returns a modified version of |sdp| where the |codec| has been promoted to be | 84 * 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 | 85 * 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'. | 86 * the 'm=|type|' line, where |type| is 'audio' or 'video'. |
| 25 * @private | 87 * @private |
| 26 */ | 88 */ |
| 27 function setSdpDefaultCodec(sdp, type, codec) { | 89 function setSdpDefaultCodec(sdp, type, codec) { |
| 28 var sdpLines = splitSdpLines(sdp); | 90 var sdpLines = splitSdpLines(sdp); |
| 29 | 91 |
| 30 // Find codec ID, e.g. 100 for 'VP8' if 'a=rtpmap:100 VP8/9000'. | 92 // Find codec ID, e.g. 100 for 'VP8' if 'a=rtpmap:100 VP8/9000'. |
| 31 var codecId = findRtpmapId(sdpLines, codec); | 93 var codecId = findRtpmapId(sdpLines, codec); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 } | 262 } |
| 201 | 263 |
| 202 /** @private */ | 264 /** @private */ |
| 203 function findLine(lines, startsWith) { | 265 function findLine(lines, startsWith) { |
| 204 for (var i = 0; i < lines.length; i++) { | 266 for (var i = 0; i < lines.length; i++) { |
| 205 if (lines[i].startsWith(startsWith)) | 267 if (lines[i].startsWith(startsWith)) |
| 206 return i; | 268 return i; |
| 207 } | 269 } |
| 208 return null; | 270 return null; |
| 209 } | 271 } |
| OLD | NEW |