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 12 matching lines...) Expand all Loading... |
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) { |
120 success('createAnswer'); | 152 success('createAnswer'); |
121 setLocalDescription(peerConnection, answer); | 153 setLocalDescription(peerConnection, answer); |
| 154 if (gOpusDtx) { |
| 155 answer.sdp = setOpusDtxEnabled(answer.sdp); |
| 156 } |
122 returnToTest('ok-' + JSON.stringify(answer)); | 157 returnToTest('ok-' + JSON.stringify(answer)); |
123 }, | 158 }, |
124 function(error) { failure('createAnswer', error); }, | 159 function(error) { failure('createAnswer', error); }, |
125 constraints); | 160 constraints); |
126 } | 161 } |
127 | 162 |
128 /** | 163 /** |
129 * Verifies that the specified codec is the default video codec, e.g. the first | 164 * Verifies that the codec previously set using forceVideoCodec() is the |
130 * one in the list on the 'm=video' SDP answer line. If this is not the case, | 165 * default video codec, e.g. the first one in the list on the 'm=video' SDP |
131 * |failure| occurs. | 166 * answer line. If this is not the case, |failure| occurs. If no codec was |
| 167 * previously set using forceVideoCodec(), this function will return |
| 168 * 'ok-no-default-set'. |
132 * | 169 * |
133 * @param {!string} sessionDescJson A JSON-encoded session description. | 170 * @param {!string} sessionDescJson A JSON-encoded session description. |
134 * @param {!string} expectedVideoCodec The case-sensitive codec name, e.g. | |
135 * 'VP8' or 'H264'. | |
136 */ | 171 */ |
137 function verifyDefaultVideoCodec(sessionDescJson, expectedVideoCodec) { | 172 function verifyDefaultVideoCodec(sessionDescJson) { |
138 var sessionDesc = parseJson_(sessionDescJson); | 173 var sessionDesc = parseJson_(sessionDescJson); |
| 174 var defaultVideoCodec = getSdpDefaultVideoCodec(sessionDesc.sdp); |
| 175 if (gDefaultVideoCodec === null) { |
| 176 returnToTest('ok-no-default-set'); |
| 177 return; |
| 178 } |
139 if (!sessionDesc.type) { | 179 if (!sessionDesc.type) { |
140 failure('verifyDefaultVideoCodec', | 180 failure('verifyDefaultVideoCodec', |
141 'Invalid session description: ' + sessionDescJson); | 181 'Invalid session description: ' + sessionDescJson); |
142 } | 182 } |
143 var defaultVideoCodec = getSdpDefaultVideoCodec(sessionDesc.sdp); | 183 var defaultVideoCodec = getSdpDefaultVideoCodec(sessionDesc.sdp); |
144 if (defaultVideoCodec === null) { | 184 if (defaultVideoCodec === null) { |
145 failure('verifyDefaultVideoCodec', | 185 failure('verifyDefaultVideoCodec', |
146 'Could not determine default video codec.'); | 186 'Could not determine default video codec.'); |
147 } | 187 } |
148 if (expectedVideoCodec !== defaultVideoCodec) { | 188 if (gDefaultVideoCodec !== defaultVideoCodec) { |
149 failure('verifyDefaultVideoCodec', | 189 failure('verifyDefaultVideoCodec', |
150 'Expected default video codec ' + expectedVideoCodec + | 190 'Expected default video codec ' + gDefaultVideoCodec + |
151 ', got ' + defaultVideoCodec + '.'); | 191 ', got ' + defaultVideoCodec + '.'); |
152 } | 192 } |
153 returnToTest('ok-verified'); | 193 returnToTest('ok-verified'); |
154 } | 194 } |
155 | 195 |
156 /** | 196 /** |
157 * Asks this page to accept an answer generated by the peer in response to a | 197 * Asks this page to accept an answer generated by the peer in response to a |
158 * previous offer by this page | 198 * previous offer by this page |
159 * | 199 * |
160 * Returns a string ok-accepted-answer on success. | 200 * Returns a string ok-accepted-answer on success. |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 function parseJson_(json) { | 389 function parseJson_(json) { |
350 // Escape since the \r\n in the SDP tend to get unescaped. | 390 // Escape since the \r\n in the SDP tend to get unescaped. |
351 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); | 391 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); |
352 try { | 392 try { |
353 return JSON.parse(jsonWithEscapedLineBreaks); | 393 return JSON.parse(jsonWithEscapedLineBreaks); |
354 } catch (exception) { | 394 } catch (exception) { |
355 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + | 395 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + |
356 exception); | 396 exception); |
357 } | 397 } |
358 } | 398 } |
OLD | NEW |