| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright 2014 The Chromium Authors. All rights reserved. | 2 * Copyright 2014 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 * The one and only peer connection in this page. | 8 * The one and only peer connection in this page. |
| 9 * @private | 9 * @private |
| 10 */ | 10 */ |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 /** | 70 /** |
| 71 * Asks this page to create a local offer. | 71 * Asks this page to create a local offer. |
| 72 * | 72 * |
| 73 * Returns a string on the format ok-(JSON encoded session description). | 73 * Returns a string on the format ok-(JSON encoded session description). |
| 74 * | 74 * |
| 75 * @param {!Object} constraints Any createOffer constraints. | 75 * @param {!Object} constraints Any createOffer constraints. |
| 76 * @param {string} videoCodec If not null, promotes the specified codec to be | 76 * @param {string} videoCodec If not null, promotes the specified codec to be |
| 77 * the default video codec, e.g. the first one in the list on the 'm=video' | 77 * the default video codec, e.g. the first one in the list on the 'm=video' |
| 78 * SDP offer line. |videoCodec| is the case-sensitive codec name, e.g. | 78 * SDP offer line. |videoCodec| is the case-sensitive codec name, e.g. |
| 79 * 'VP8' or 'H264'. | 79 * 'VP8' or 'H264'. |
| 80 * @param {boolean} enableOpusDtx If true, enable Opus Dtx, e.g. append |
| 81 * 'usedtx=1' to the appropriate 'a=fmtp' line. |
| 80 */ | 82 */ |
| 81 function createLocalOffer(constraints, videoCodec = null) { | 83 function createLocalOffer(constraints, |
| 84 videoCodec = null, |
| 85 enableOpusDtx = false) { |
| 82 peerConnection_().createOffer( | 86 peerConnection_().createOffer( |
| 83 function(localOffer) { | 87 function(localOffer) { |
| 84 success('createOffer'); | 88 success('createOffer'); |
| 85 | 89 |
| 86 setLocalDescription(peerConnection, localOffer); | 90 setLocalDescription(peerConnection, localOffer); |
| 87 if (videoCodec !== null) | 91 if (videoCodec !== null) |
| 88 localOffer.sdp = setSdpDefaultVideoCodec(localOffer.sdp, videoCodec); | 92 localOffer.sdp = setSdpDefaultVideoCodec(localOffer.sdp, videoCodec); |
| 93 if (enableOpusDtx) |
| 94 localOffer.sdp = setOpusDtxEnabled(localOffer.sdp); |
| 89 | 95 |
| 90 returnToTest('ok-' + JSON.stringify(localOffer)); | 96 returnToTest('ok-' + JSON.stringify(localOffer)); |
| 91 }, | 97 }, |
| 92 function(error) { failure('createOffer', error); }, | 98 function(error) { failure('createOffer', error); }, |
| 93 constraints); | 99 constraints); |
| 94 } | 100 } |
| 95 | 101 |
| 96 /** | 102 /** |
| 97 * Asks this page to accept an offer and generate an answer. | 103 * Asks this page to accept an offer and generate an answer. |
| 98 * | 104 * |
| 99 * Returns a string on the format ok-(JSON encoded session description). | 105 * Returns a string on the format ok-(JSON encoded session description). |
| 100 * | 106 * |
| 101 * @param {!string} sessionDescJson A JSON-encoded session description of type | 107 * @param {!string} sessionDescJson A JSON-encoded session description of type |
| 102 * 'offer'. | 108 * 'offer'. |
| 103 * @param {!Object} constraints Any createAnswer constraints. | 109 * @param {!Object} constraints Any createAnswer constraints. |
| 110 * @param {boolean} enableOpusDtx If true, enable Opus Dtx, e.g. append |
| 111 * 'usedtx=1' to the appropriate 'a=fmtp' line. |
| 104 */ | 112 */ |
| 105 function receiveOfferFromPeer(sessionDescJson, constraints) { | 113 function receiveOfferFromPeer(sessionDescJson, |
| 114 constraints, |
| 115 enableOpusDtx = false) { |
| 106 offer = parseJson_(sessionDescJson); | 116 offer = parseJson_(sessionDescJson); |
| 107 if (!offer.type) | 117 if (!offer.type) |
| 108 failTest('Got invalid session description from peer: ' + sessionDescJson); | 118 failTest('Got invalid session description from peer: ' + sessionDescJson); |
| 109 if (offer.type != 'offer') | 119 if (offer.type != 'offer') |
| 110 failTest('Expected to receive offer from peer, got ' + offer.type); | 120 failTest('Expected to receive offer from peer, got ' + offer.type); |
| 111 | 121 |
| 112 var sessionDescription = new RTCSessionDescription(offer); | 122 var sessionDescription = new RTCSessionDescription(offer); |
| 113 peerConnection_().setRemoteDescription( | 123 peerConnection_().setRemoteDescription( |
| 114 sessionDescription, | 124 sessionDescription, |
| 115 function() { success('setRemoteDescription'); }, | 125 function() { success('setRemoteDescription'); }, |
| 116 function(error) { failure('setRemoteDescription', error); }); | 126 function(error) { failure('setRemoteDescription', error); }); |
| 117 | 127 |
| 118 peerConnection_().createAnswer( | 128 peerConnection_().createAnswer( |
| 119 function(answer) { | 129 function(answer) { |
| 120 success('createAnswer'); | 130 success('createAnswer'); |
| 121 setLocalDescription(peerConnection, answer); | 131 setLocalDescription(peerConnection, answer); |
| 132 if (enableOpusDtx) |
| 133 answer.sdp = setOpusDtxEnabled(answer.sdp); |
| 122 returnToTest('ok-' + JSON.stringify(answer)); | 134 returnToTest('ok-' + JSON.stringify(answer)); |
| 123 }, | 135 }, |
| 124 function(error) { failure('createAnswer', error); }, | 136 function(error) { failure('createAnswer', error); }, |
| 125 constraints); | 137 constraints); |
| 126 } | 138 } |
| 127 | 139 |
| 128 /** | 140 /** |
| 129 * Verifies that the specified codec is the default video codec, e.g. the first | 141 * Verifies that the specified codec is the default video codec, e.g. the first |
| 130 * one in the list on the 'm=video' SDP answer line. If this is not the case, | 142 * one in the list on the 'm=video' SDP answer line. If this is not the case, |
| 131 * |failure| occurs. | 143 * |failure| occurs. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 147 } | 159 } |
| 148 if (expectedVideoCodec !== defaultVideoCodec) { | 160 if (expectedVideoCodec !== defaultVideoCodec) { |
| 149 failure('verifyDefaultVideoCodec', | 161 failure('verifyDefaultVideoCodec', |
| 150 'Expected default video codec ' + expectedVideoCodec + | 162 'Expected default video codec ' + expectedVideoCodec + |
| 151 ', got ' + defaultVideoCodec + '.'); | 163 ', got ' + defaultVideoCodec + '.'); |
| 152 } | 164 } |
| 153 returnToTest('ok-verified'); | 165 returnToTest('ok-verified'); |
| 154 } | 166 } |
| 155 | 167 |
| 156 /** | 168 /** |
| 169 * Verifies that Opus Dtx is enabled, e.g. 'usedtx=1' can be found in the |
| 170 * appropriate 'a=fmtp' line. If this is not the case, |failure| occurs. |
| 171 * |
| 172 * @param {!string} sessionDescJson A JSON-encoded session description. |
| 173 */ |
| 174 function verifyOpusDtxEnabled(sessionDescJson) { |
| 175 var sessionDesc = parseJson_(sessionDescJson); |
| 176 if (!sessionDesc.type) { |
| 177 failure('verifyOpusDtxEnabled', |
| 178 'Invalid session description: ' + sessionDescJson); |
| 179 } |
| 180 checkOpusDtxEnabled(sessionDesc.sdp); |
| 181 returnToTest('ok-verified'); |
| 182 } |
| 183 |
| 184 /** |
| 157 * Asks this page to accept an answer generated by the peer in response to a | 185 * Asks this page to accept an answer generated by the peer in response to a |
| 158 * previous offer by this page | 186 * previous offer by this page |
| 159 * | 187 * |
| 160 * Returns a string ok-accepted-answer on success. | 188 * Returns a string ok-accepted-answer on success. |
| 161 * | 189 * |
| 162 * @param {!string} sessionDescJson A JSON-encoded session description of type | 190 * @param {!string} sessionDescJson A JSON-encoded session description of type |
| 163 * 'answer'. | 191 * 'answer'. |
| 164 */ | 192 */ |
| 165 function receiveAnswerFromPeer(sessionDescJson) { | 193 function receiveAnswerFromPeer(sessionDescJson) { |
| 166 answer = parseJson_(sessionDescJson); | 194 answer = parseJson_(sessionDescJson); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 function parseJson_(json) { | 377 function parseJson_(json) { |
| 350 // Escape since the \r\n in the SDP tend to get unescaped. | 378 // Escape since the \r\n in the SDP tend to get unescaped. |
| 351 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); | 379 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); |
| 352 try { | 380 try { |
| 353 return JSON.parse(jsonWithEscapedLineBreaks); | 381 return JSON.parse(jsonWithEscapedLineBreaks); |
| 354 } catch (exception) { | 382 } catch (exception) { |
| 355 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + | 383 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + |
| 356 exception); | 384 exception); |
| 357 } | 385 } |
| 358 } | 386 } |
| OLD | NEW |