Chromium Code Reviews| 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 */ |
| 11 var gPeerConnection = null; | 11 var gPeerConnection = null; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * This stores ICE candidates generated on this side. | 14 * This stores ICE candidates generated on this side. |
| 15 * @private | 15 * @private |
| 16 */ | 16 */ |
| 17 var gIceCandidates = []; | 17 var gIceCandidates = []; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Keeps track of whether we have seen crypto information in the SDP. | 20 * Keeps track of whether we have seen crypto information in the SDP. |
| 21 * @private | 21 * @private |
| 22 */ | 22 */ |
| 23 var gHasSeenCryptoInSdp = 'no-crypto-seen'; | 23 var gHasSeenCryptoInSdp = 'no-crypto-seen'; |
| 24 | 24 |
| 25 /** | |
| 26 * The default video codec that should be used. | |
| 27 * @private | |
| 28 */ | |
| 29 var gDefaultVideoCodec = null; | |
| 30 | |
| 31 /** | |
| 32 * Flag to indicate if Opus Dtx should be enabled. | |
| 33 * @private | |
| 34 */ | |
| 35 var gOpusDtx = false; | |
| 36 | |
| 25 // Public interface to tests. These are expected to be called with | 37 // Public interface to tests. These are expected to be called with |
| 26 // ExecuteJavascript invocations from the browser tests and will return answers | 38 // ExecuteJavascript invocations from the browser tests and will return answers |
| 27 // through the DOM automation controller. | 39 // through the DOM automation controller. |
| 28 | 40 |
| 29 /** | 41 /** |
| 30 * Creates a peer connection. Must be called before most other public functions | 42 * Creates a peer connection. Must be called before most other public functions |
| 31 * in this file. Alternatively, see |preparePeerConnectionWithCertificate|. | 43 * in this file. Alternatively, see |preparePeerConnectionWithCertificate|. |
| 32 * @param {Object} keygenAlgorithm Unless null, this is an |AlgorithmIdentifier| | 44 * @param {Object} keygenAlgorithm Unless null, this is an |AlgorithmIdentifier| |
| 33 * to be used as parameter to |RTCPeerConnection.generateCertificate|. The | 45 * to be used as parameter to |RTCPeerConnection.generateCertificate|. The |
| 34 * resulting certificate will be used by the peer connection. If null, a default | 46 * resulting certificate will be used by the peer connection. If null, a default |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 61 */ | 73 */ |
| 62 function preparePeerConnectionWithCertificate(certificate) { | 74 function preparePeerConnectionWithCertificate(certificate) { |
| 63 if (gPeerConnection !== null) | 75 if (gPeerConnection !== null) |
| 64 throw failTest('Creating peer connection, but we already have one.'); | 76 throw failTest('Creating peer connection, but we already have one.'); |
| 65 gPeerConnection = createPeerConnection_( | 77 gPeerConnection = createPeerConnection_( |
| 66 {iceServers:[], certificates:[certificate]}); | 78 {iceServers:[], certificates:[certificate]}); |
| 67 returnToTest('ok-peerconnection-created'); | 79 returnToTest('ok-peerconnection-created'); |
| 68 } | 80 } |
| 69 | 81 |
| 70 /** | 82 /** |
| 83 * Sets the flag to force Opus Dtx to be used when creating an offer. | |
| 84 */ | |
| 85 function forceOpusDtx() { | |
| 86 gOpusDtx = true; | |
| 87 returnToTest('ok-forced'); | |
| 88 } | |
| 89 | |
| 90 /** | |
| 91 * Sets the default video codec be used when creating an offer. | |
| 92 * @param {string} videoCodec promotes the specified codec to be the default | |
| 93 * video codec, e.g. the first one in the list on the 'm=video' SDP offer | |
| 94 * line. |videoCodec| is the case-sensitive codec name, e.g. 'VP8' or | |
| 95 * 'H264'. | |
| 96 */ | |
| 97 function forceVideoCodec(videoCodec) { | |
| 98 gDefaultVideoCodec = videoCodec; | |
| 99 returnToTest('ok-forced'); | |
| 100 } | |
| 101 | |
| 102 /** | |
| 71 * Asks this page to create a local offer. | 103 * Asks this page to create a local offer. |
| 72 * | 104 * |
| 73 * Returns a string on the format ok-(JSON encoded session description). | 105 * Returns a string on the format ok-(JSON encoded session description). |
| 74 * | 106 * |
| 75 * @param {!Object} constraints Any createOffer constraints. | 107 * @param {!Object} constraints Any createOffer constraints. |
| 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' | |
| 78 * SDP offer line. |videoCodec| is the case-sensitive codec name, e.g. | |
| 79 * 'VP8' or 'H264'. | |
| 80 */ | 108 */ |
| 81 function createLocalOffer(constraints, videoCodec = null) { | 109 function createLocalOffer(constraints) { |
| 82 peerConnection_().createOffer( | 110 peerConnection_().createOffer( |
| 83 function(localOffer) { | 111 function(localOffer) { |
| 84 success('createOffer'); | 112 success('createOffer'); |
| 85 | 113 |
| 86 setLocalDescription(peerConnection, localOffer); | 114 setLocalDescription(peerConnection, localOffer); |
| 87 if (videoCodec !== null) | 115 if (gDefaultVideoCodec !== null) { |
| 88 localOffer.sdp = setSdpDefaultVideoCodec(localOffer.sdp, videoCodec); | 116 localOffer.sdp = setSdpDefaultVideoCodec(localOffer.sdp, |
| 89 | 117 gDefaultVideoCodec); |
| 118 } | |
| 119 if (gOpusDtx) { | |
| 120 localOffer.sdp = setOpusDtxEnabled(localOffer.sdp); | |
| 121 } | |
| 90 returnToTest('ok-' + JSON.stringify(localOffer)); | 122 returnToTest('ok-' + JSON.stringify(localOffer)); |
| 91 }, | 123 }, |
| 92 function(error) { failure('createOffer', error); }, | 124 function(error) { failure('createOffer', error); }, |
| 93 constraints); | 125 constraints); |
| 94 } | 126 } |
| 95 | 127 |
| 96 /** | 128 /** |
| 97 * Asks this page to accept an offer and generate an answer. | 129 * Asks this page to accept an offer and generate an answer. |
| 98 * | 130 * |
| 99 * Returns a string on the format ok-(JSON encoded session description). | 131 * Returns a string on the format ok-(JSON encoded session description). |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 110 failTest('Expected to receive offer from peer, got ' + offer.type); | 142 failTest('Expected to receive offer from peer, got ' + offer.type); |
| 111 | 143 |
| 112 var sessionDescription = new RTCSessionDescription(offer); | 144 var sessionDescription = new RTCSessionDescription(offer); |
| 113 peerConnection_().setRemoteDescription( | 145 peerConnection_().setRemoteDescription( |
| 114 sessionDescription, | 146 sessionDescription, |
| 115 function() { success('setRemoteDescription'); }, | 147 function() { success('setRemoteDescription'); }, |
| 116 function(error) { failure('setRemoteDescription', error); }); | 148 function(error) { failure('setRemoteDescription', error); }); |
| 117 | 149 |
| 118 peerConnection_().createAnswer( | 150 peerConnection_().createAnswer( |
| 119 function(answer) { | 151 function(answer) { |
| 152 if (gDefaultVideoCodec !== null) { | |
| 153 verifyDefaultVideoCodec(answer.sdp, gDefaultVideoCodec); | |
|
phoglund_chromium
2016/07/28 06:39:01
I still want to keep the verification as a separat
Ivo-OOO until feb 6
2016/07/28 12:29:31
Ok, done.
I realized that dtx verification is a b
| |
| 154 } | |
| 120 success('createAnswer'); | 155 success('createAnswer'); |
| 121 setLocalDescription(peerConnection, answer); | 156 setLocalDescription(peerConnection, answer); |
| 157 if (gOpusDtx) { | |
| 158 answer.sdp = setOpusDtxEnabled(answer.sdp); | |
| 159 } | |
| 122 returnToTest('ok-' + JSON.stringify(answer)); | 160 returnToTest('ok-' + JSON.stringify(answer)); |
| 123 }, | 161 }, |
| 124 function(error) { failure('createAnswer', error); }, | 162 function(error) { failure('createAnswer', error); }, |
| 125 constraints); | 163 constraints); |
| 126 } | 164 } |
| 127 | 165 |
| 128 /** | 166 /** |
| 129 * Verifies that the specified codec is the default video codec, e.g. the first | 167 * 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, | 168 * one in the list on the 'm=video' SDP answer line. If this is not the case, |
| 131 * |failure| occurs. | 169 * |failure| occurs. |
| 132 * | 170 * |
| 133 * @param {!string} sessionDescJson A JSON-encoded session description. | 171 * @param {!string} sessionDescJson A JSON-encoded session description. |
| 134 * @param {!string} expectedVideoCodec The case-sensitive codec name, e.g. | 172 * @param {!string} expectedVideoCodec The case-sensitive codec name, e.g. |
| 135 * 'VP8' or 'H264'. | 173 * 'VP8' or 'H264'. |
| 136 */ | 174 */ |
| 137 function verifyDefaultVideoCodec(sessionDescJson, expectedVideoCodec) { | 175 function verifyDefaultVideoCodec(sdp, expectedVideoCodec) { |
| 138 var sessionDesc = parseJson_(sessionDescJson); | 176 var defaultVideoCodec = getSdpDefaultVideoCodec(sdp); |
| 139 if (!sessionDesc.type) { | |
| 140 failure('verifyDefaultVideoCodec', | |
| 141 'Invalid session description: ' + sessionDescJson); | |
| 142 } | |
| 143 var defaultVideoCodec = getSdpDefaultVideoCodec(sessionDesc.sdp); | |
| 144 if (defaultVideoCodec === null) { | 177 if (defaultVideoCodec === null) { |
| 145 failure('verifyDefaultVideoCodec', | 178 failure('verifyDefaultVideoCodec', |
| 146 'Could not determine default video codec.'); | 179 'Could not determine default video codec.'); |
| 147 } | 180 } |
| 148 if (expectedVideoCodec !== defaultVideoCodec) { | 181 if (expectedVideoCodec !== defaultVideoCodec) { |
| 149 failure('verifyDefaultVideoCodec', | 182 failure('verifyDefaultVideoCodec', |
| 150 'Expected default video codec ' + expectedVideoCodec + | 183 'Expected default video codec ' + expectedVideoCodec + |
| 151 ', got ' + defaultVideoCodec + '.'); | 184 ', got ' + defaultVideoCodec + '.'); |
| 152 } | 185 } |
| 153 returnToTest('ok-verified'); | |
| 154 } | 186 } |
| 155 | 187 |
| 156 /** | 188 /** |
| 157 * Asks this page to accept an answer generated by the peer in response to a | 189 * Asks this page to accept an answer generated by the peer in response to a |
| 158 * previous offer by this page | 190 * previous offer by this page |
| 159 * | 191 * |
| 160 * Returns a string ok-accepted-answer on success. | 192 * Returns a string ok-accepted-answer on success. |
| 161 * | 193 * |
| 162 * @param {!string} sessionDescJson A JSON-encoded session description of type | 194 * @param {!string} sessionDescJson A JSON-encoded session description of type |
| 163 * 'answer'. | 195 * 'answer'. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 function parseJson_(json) { | 381 function parseJson_(json) { |
| 350 // Escape since the \r\n in the SDP tend to get unescaped. | 382 // Escape since the \r\n in the SDP tend to get unescaped. |
| 351 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); | 383 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); |
| 352 try { | 384 try { |
| 353 return JSON.parse(jsonWithEscapedLineBreaks); | 385 return JSON.parse(jsonWithEscapedLineBreaks); |
| 354 } catch (exception) { | 386 } catch (exception) { |
| 355 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + | 387 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + |
| 356 exception); | 388 exception); |
| 357 } | 389 } |
| 358 } | 390 } |
| OLD | NEW |