Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: webrtc/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java

Issue 2377003002: Format all Java in WebRTC. (Closed)
Patch Set: Rebase. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 19 matching lines...) Expand all
30 import org.webrtc.StatsReport; 30 import org.webrtc.StatsReport;
31 import org.webrtc.VideoRenderer; 31 import org.webrtc.VideoRenderer;
32 32
33 import java.util.LinkedList; 33 import java.util.LinkedList;
34 import java.util.List; 34 import java.util.List;
35 import java.util.concurrent.CountDownLatch; 35 import java.util.concurrent.CountDownLatch;
36 import java.util.concurrent.ExecutorService; 36 import java.util.concurrent.ExecutorService;
37 import java.util.concurrent.Executors; 37 import java.util.concurrent.Executors;
38 import java.util.concurrent.TimeUnit; 38 import java.util.concurrent.TimeUnit;
39 39
40 public class PeerConnectionClientTest extends InstrumentationTestCase 40 public class PeerConnectionClientTest
41 implements PeerConnectionEvents { 41 extends InstrumentationTestCase implements PeerConnectionEvents {
42 private static final String TAG = "RTCClientTest"; 42 private static final String TAG = "RTCClientTest";
43 private static final int ICE_CONNECTION_WAIT_TIMEOUT = 10000; 43 private static final int ICE_CONNECTION_WAIT_TIMEOUT = 10000;
44 private static final int WAIT_TIMEOUT = 7000; 44 private static final int WAIT_TIMEOUT = 7000;
45 private static final int CAMERA_SWITCH_ATTEMPTS = 3; 45 private static final int CAMERA_SWITCH_ATTEMPTS = 3;
46 private static final int VIDEO_RESTART_ATTEMPTS = 3; 46 private static final int VIDEO_RESTART_ATTEMPTS = 3;
47 private static final int CAPTURE_FORMAT_CHANGE_ATTEMPTS = 3; 47 private static final int CAPTURE_FORMAT_CHANGE_ATTEMPTS = 3;
48 private static final int VIDEO_RESTART_TIMEOUT = 500; 48 private static final int VIDEO_RESTART_TIMEOUT = 500;
49 private static final int EXPECTED_VIDEO_FRAMES = 10; 49 private static final int EXPECTED_VIDEO_FRAMES = 10;
50 private static final String VIDEO_CODEC_VP8 = "VP8"; 50 private static final String VIDEO_CODEC_VP8 = "VP8";
51 private static final String VIDEO_CODEC_VP9 = "VP9"; 51 private static final String VIDEO_CODEC_VP9 = "VP9";
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // Resets render to wait for new amount of video frames. 96 // Resets render to wait for new amount of video frames.
97 public synchronized void reset(int expectedFrames) { 97 public synchronized void reset(int expectedFrames) {
98 renderFrameCalled = false; 98 renderFrameCalled = false;
99 doneRendering = new CountDownLatch(expectedFrames); 99 doneRendering = new CountDownLatch(expectedFrames);
100 } 100 }
101 101
102 @Override 102 @Override
103 public synchronized void renderFrame(VideoRenderer.I420Frame frame) { 103 public synchronized void renderFrame(VideoRenderer.I420Frame frame) {
104 if (!renderFrameCalled) { 104 if (!renderFrameCalled) {
105 if (rendererName != null) { 105 if (rendererName != null) {
106 Log.d(TAG, rendererName + " render frame: " 106 Log.d(TAG, rendererName + " render frame: " + frame.rotatedWidth() + " x "
107 + frame.rotatedWidth() + " x " + frame.rotatedHeight()); 107 + frame.rotatedHeight());
108 } else { 108 } else {
109 Log.d(TAG, "Render frame: " + frame.rotatedWidth() + " x " + frame.rot atedHeight()); 109 Log.d(TAG, "Render frame: " + frame.rotatedWidth() + " x " + frame.rot atedHeight());
110 } 110 }
111 } 111 }
112 renderFrameCalled = true; 112 renderFrameCalled = true;
113 VideoRenderer.renderFrameDone(frame); 113 VideoRenderer.renderFrameDone(frame);
114 doneRendering.countDown(); 114 doneRendering.countDown();
115 } 115 }
116 116
117
118 // This method shouldn't hold any locks or touch member variables since it 117 // This method shouldn't hold any locks or touch member variables since it
119 // blocks. 118 // blocks.
120 public boolean waitForFramesRendered(int timeoutMs) 119 public boolean waitForFramesRendered(int timeoutMs) throws InterruptedExcept ion {
121 throws InterruptedException {
122 doneRendering.await(timeoutMs, TimeUnit.MILLISECONDS); 120 doneRendering.await(timeoutMs, TimeUnit.MILLISECONDS);
123 return (doneRendering.getCount() <= 0); 121 return (doneRendering.getCount() <= 0);
124 } 122 }
125 } 123 }
126 124
127 // Peer connection events implementation. 125 // Peer connection events implementation.
128 @Override 126 @Override
129 public void onLocalDescription(SessionDescription sdp) { 127 public void onLocalDescription(SessionDescription sdp) {
130 Log.d(TAG, "LocalSDP type: " + sdp.type); 128 Log.d(TAG, "LocalSDP type: " + sdp.type);
131 synchronized (localSdpEvent) { 129 synchronized (localSdpEvent) {
132 localSdp = sdp; 130 localSdp = sdp;
133 localSdpEvent.notifyAll(); 131 localSdpEvent.notifyAll();
134 } 132 }
135 } 133 }
136 134
137 @Override 135 @Override
138 public void onIceCandidate(final IceCandidate candidate) { 136 public void onIceCandidate(final IceCandidate candidate) {
139 synchronized(iceCandidateEvent) { 137 synchronized (iceCandidateEvent) {
140 Log.d(TAG, "IceCandidate #" + iceCandidates.size() + " : " + candidate.toS tring()); 138 Log.d(TAG, "IceCandidate #" + iceCandidates.size() + " : " + candidate.toS tring());
141 if (loopback) { 139 if (loopback) {
142 // Loopback local ICE candidate in a separate thread to avoid adding 140 // Loopback local ICE candidate in a separate thread to avoid adding
143 // remote ICE candidate in a local ICE candidate callback. 141 // remote ICE candidate in a local ICE candidate callback.
144 signalingExecutor.execute(new Runnable() { 142 signalingExecutor.execute(new Runnable() {
145 @Override 143 @Override
146 public void run() { 144 public void run() {
147 pcClient.addRemoteIceCandidate(candidate); 145 pcClient.addRemoteIceCandidate(candidate);
148 } 146 }
149 }); 147 });
150 } 148 }
151 iceCandidates.add(candidate); 149 iceCandidates.add(candidate);
152 iceCandidateEvent.notifyAll(); 150 iceCandidateEvent.notifyAll();
153 } 151 }
154 } 152 }
155 153
156 @Override 154 @Override
157 public void onIceCandidatesRemoved(final IceCandidate[] candidates) { 155 public void onIceCandidatesRemoved(final IceCandidate[] candidates) {
158 // TODO(honghaiz): Add this for tests. 156 // TODO(honghaiz): Add this for tests.
159 } 157 }
160 158
161 @Override 159 @Override
162 public void onIceConnected() { 160 public void onIceConnected() {
163 Log.d(TAG, "ICE Connected"); 161 Log.d(TAG, "ICE Connected");
164 synchronized(iceConnectedEvent) { 162 synchronized (iceConnectedEvent) {
165 isIceConnected = true; 163 isIceConnected = true;
166 iceConnectedEvent.notifyAll(); 164 iceConnectedEvent.notifyAll();
167 } 165 }
168 } 166 }
169 167
170 @Override 168 @Override
171 public void onIceDisconnected() { 169 public void onIceDisconnected() {
172 Log.d(TAG, "ICE Disconnected"); 170 Log.d(TAG, "ICE Disconnected");
173 synchronized(iceConnectedEvent) { 171 synchronized (iceConnectedEvent) {
174 isIceConnected = false; 172 isIceConnected = false;
175 iceConnectedEvent.notifyAll(); 173 iceConnectedEvent.notifyAll();
176 } 174 }
177 } 175 }
178 176
179 @Override 177 @Override
180 public void onPeerConnectionClosed() { 178 public void onPeerConnectionClosed() {
181 Log.d(TAG, "PeerConnection closed"); 179 Log.d(TAG, "PeerConnection closed");
182 synchronized(closeEvent) { 180 synchronized (closeEvent) {
183 isClosed = true; 181 isClosed = true;
184 closeEvent.notifyAll(); 182 closeEvent.notifyAll();
185 } 183 }
186 } 184 }
187 185
188 @Override 186 @Override
189 public void onPeerConnectionError(String description) { 187 public void onPeerConnectionError(String description) {
190 fail("PC Error: " + description); 188 fail("PC Error: " + description);
191 } 189 }
192 190
193 @Override 191 @Override
194 public void onPeerConnectionStatsReady(StatsReport[] reports) { 192 public void onPeerConnectionStatsReady(StatsReport[] reports) {}
195 }
196 193
197 // Helper wait functions. 194 // Helper wait functions.
198 private boolean waitForLocalSDP(int timeoutMs) 195 private boolean waitForLocalSDP(int timeoutMs) throws InterruptedException {
199 throws InterruptedException { 196 synchronized (localSdpEvent) {
200 synchronized(localSdpEvent) {
201 if (localSdp == null) { 197 if (localSdp == null) {
202 localSdpEvent.wait(timeoutMs); 198 localSdpEvent.wait(timeoutMs);
203 } 199 }
204 return (localSdp != null); 200 return (localSdp != null);
205 } 201 }
206 } 202 }
207 203
208 private boolean waitForIceCandidates(int timeoutMs) 204 private boolean waitForIceCandidates(int timeoutMs) throws InterruptedExceptio n {
209 throws InterruptedException { 205 synchronized (iceCandidateEvent) {
210 synchronized(iceCandidateEvent) {
211 if (iceCandidates.size() == 0) { 206 if (iceCandidates.size() == 0) {
212 iceCandidateEvent.wait(timeoutMs); 207 iceCandidateEvent.wait(timeoutMs);
213 } 208 }
214 return (iceCandidates.size() > 0); 209 return (iceCandidates.size() > 0);
215 } 210 }
216 } 211 }
217 212
218 private boolean waitForIceConnected(int timeoutMs) 213 private boolean waitForIceConnected(int timeoutMs) throws InterruptedException {
219 throws InterruptedException { 214 synchronized (iceConnectedEvent) {
220 synchronized(iceConnectedEvent) {
221 if (!isIceConnected) { 215 if (!isIceConnected) {
222 iceConnectedEvent.wait(timeoutMs); 216 iceConnectedEvent.wait(timeoutMs);
223 } 217 }
224 if (!isIceConnected) { 218 if (!isIceConnected) {
225 Log.e(TAG, "ICE connection failure"); 219 Log.e(TAG, "ICE connection failure");
226 } 220 }
227 221
228 return isIceConnected; 222 return isIceConnected;
229 } 223 }
230 } 224 }
231 225
232 private boolean waitForPeerConnectionClosed(int timeoutMs) 226 private boolean waitForPeerConnectionClosed(int timeoutMs) throws InterruptedE xception {
233 throws InterruptedException { 227 synchronized (closeEvent) {
234 synchronized(closeEvent) {
235 if (!isClosed) { 228 if (!isClosed) {
236 closeEvent.wait(timeoutMs); 229 closeEvent.wait(timeoutMs);
237 } 230 }
238 return isClosed; 231 return isClosed;
239 } 232 }
240 } 233 }
241 234
242 PeerConnectionClient createPeerConnectionClient( 235 PeerConnectionClient createPeerConnectionClient(MockRenderer localRenderer,
243 MockRenderer localRenderer, MockRenderer remoteRenderer, 236 MockRenderer remoteRenderer, PeerConnectionParameters peerConnectionParame ters,
244 PeerConnectionParameters peerConnectionParameters, EglBase.Context eglCont ext) { 237 EglBase.Context eglContext) {
245 List<PeerConnection.IceServer> iceServers = 238 List<PeerConnection.IceServer> iceServers = new LinkedList<PeerConnection.Ic eServer>();
246 new LinkedList<PeerConnection.IceServer>(); 239 SignalingParameters signalingParameters =
247 SignalingParameters signalingParameters = new SignalingParameters( 240 new SignalingParameters(iceServers, true, // iceServers, initiator.
248 iceServers, true, // iceServers, initiator. 241 null, null, null, // clientId, wssUrl, wssPostUrl.
249 null, null, null, // clientId, wssUrl, wssPostUrl. 242 null, null); // offerSdp, iceCandidates.
250 null, null); // offerSdp, iceCandidates.
251 243
252 PeerConnectionClient client = PeerConnectionClient.getInstance(); 244 PeerConnectionClient client = PeerConnectionClient.getInstance();
253 PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(); 245 PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
254 options.networkIgnoreMask = 0; 246 options.networkIgnoreMask = 0;
255 options.disableNetworkMonitor = true; 247 options.disableNetworkMonitor = true;
256 client.setPeerConnectionFactoryOptions(options); 248 client.setPeerConnectionFactoryOptions(options);
257 client.createPeerConnectionFactory( 249 client.createPeerConnectionFactory(
258 getInstrumentation().getTargetContext(), peerConnectionParameters, this) ; 250 getInstrumentation().getTargetContext(), peerConnectionParameters, this) ;
259 client.createPeerConnection(eglContext, localRenderer, remoteRenderer, signa lingParameters); 251 client.createPeerConnection(eglContext, localRenderer, remoteRenderer, signa lingParameters);
260 client.createOffer(); 252 client.createOffer();
261 return client; 253 return client;
262 } 254 }
263 255
264 private PeerConnectionParameters createParametersForAudioCall() { 256 private PeerConnectionParameters createParametersForAudioCall() {
265 PeerConnectionParameters peerConnectionParameters = 257 PeerConnectionParameters peerConnectionParameters =
266 new PeerConnectionParameters( 258 new PeerConnectionParameters(false, /* videoCallEnabled */
267 false, /* videoCallEnabled */
268 true, /* loopback */ 259 true, /* loopback */
269 false, /* tracing */ 260 false, /* tracing */
270 // Video codec parameters. 261 // Video codec parameters.
271 true, /* useCamera2 */ 262 true, /* useCamera2 */
272 0, /* videoWidth */ 263 0, /* videoWidth */
273 0, /* videoHeight */ 264 0, /* videoHeight */
274 0, /* videoFps */ 265 0, /* videoFps */
275 0, /* videoStartBitrate */ 266 0, /* videoStartBitrate */
276 "", /* videoCodec */ 267 "", /* videoCodec */
277 true, /* videoCodecHwAcceleration */ 268 true, /* videoCodecHwAcceleration */
278 false, /* captureToToTexture */ 269 false, /* captureToToTexture */
279 // Audio codec parameters. 270 // Audio codec parameters.
280 0, /* audioStartBitrate */ 271 0, /* audioStartBitrate */
281 "OPUS", /* audioCodec */ 272 "OPUS", /* audioCodec */
282 false, /* noAudioProcessing */ 273 false, /* noAudioProcessing */
283 false, /* aecDump */ 274 false, /* aecDump */
284 false /* useOpenSLES */, 275 false /* useOpenSLES */, false /* disableBuiltInAEC */, false /* dis ableBuiltInAGC */,
285 false /* disableBuiltInAEC */, 276 false /* disableBuiltInNS */, false /* enableLevelControl */);
286 false /* disableBuiltInAGC */,
287 false /* disableBuiltInNS */,
288 false /* enableLevelControl */);
289 return peerConnectionParameters; 277 return peerConnectionParameters;
290 } 278 }
291 279
292 private PeerConnectionParameters createParametersForVideoCall( 280 private PeerConnectionParameters createParametersForVideoCall(
293 String videoCodec, boolean captureToTexture) { 281 String videoCodec, boolean captureToTexture) {
294 final boolean useCamera2 = captureToTexture 282 final boolean useCamera2 =
295 && Camera2Enumerator.isSupported(getInstrumentation().getTargetContext() ); 283 captureToTexture && Camera2Enumerator.isSupported(getInstrumentation().g etTargetContext());
296 284
297 PeerConnectionParameters peerConnectionParameters = 285 PeerConnectionParameters peerConnectionParameters =
298 new PeerConnectionParameters( 286 new PeerConnectionParameters(true, /* videoCallEnabled */
299 true, /* videoCallEnabled */
300 true, /* loopback */ 287 true, /* loopback */
301 false, /* tracing */ 288 false, /* tracing */
302 // Video codec parameters. 289 // Video codec parameters.
303 useCamera2, /* useCamera2 */ 290 useCamera2, /* useCamera2 */
304 0, /* videoWidth */ 291 0, /* videoWidth */
305 0, /* videoHeight */ 292 0, /* videoHeight */
306 0, /* videoFps */ 293 0, /* videoFps */
307 0, /* videoStartBitrate */ 294 0, /* videoStartBitrate */
308 videoCodec, /* videoCodec */ 295 videoCodec, /* videoCodec */
309 true, /* videoCodecHwAcceleration */ 296 true, /* videoCodecHwAcceleration */
310 captureToTexture, /* captureToToTexture */ 297 captureToTexture, /* captureToToTexture */
311 // Audio codec parameters. 298 // Audio codec parameters.
312 0, /* audioStartBitrate */ 299 0, /* audioStartBitrate */
313 "OPUS", /* audioCodec */ 300 "OPUS", /* audioCodec */
314 false, /* noAudioProcessing */ 301 false, /* noAudioProcessing */
315 false, /* aecDump */ 302 false, /* aecDump */
316 false /* useOpenSLES */, 303 false /* useOpenSLES */, false /* disableBuiltInAEC */, false /* dis ableBuiltInAGC */,
317 false /* disableBuiltInAEC */, 304 false /* disableBuiltInNS */, false /* enableLevelControl */);
318 false /* disableBuiltInAGC */,
319 false /* disableBuiltInNS */,
320 false /* enableLevelControl */);
321 return peerConnectionParameters; 305 return peerConnectionParameters;
322 } 306 }
323 307
324 @Override 308 @Override
325 public void setUp() { 309 public void setUp() {
326 signalingExecutor = Executors.newSingleThreadExecutor(); 310 signalingExecutor = Executors.newSingleThreadExecutor();
327 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 311 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
328 eglBase = EglBase.create(); 312 eglBase = EglBase.create();
329 } 313 }
330 } 314 }
331 315
332 @Override 316 @Override
333 public void tearDown() { 317 public void tearDown() {
334 signalingExecutor.shutdown(); 318 signalingExecutor.shutdown();
335 if (eglBase != null) { 319 if (eglBase != null) {
336 eglBase.release(); 320 eglBase.release();
337 } 321 }
338 } 322 }
339 323
340 @SmallTest 324 @SmallTest
341 public void testSetLocalOfferMakesVideoFlowLocally() 325 public void testSetLocalOfferMakesVideoFlowLocally() throws InterruptedExcepti on {
342 throws InterruptedException {
343 Log.d(TAG, "testSetLocalOfferMakesVideoFlowLocally"); 326 Log.d(TAG, "testSetLocalOfferMakesVideoFlowLocally");
344 MockRenderer localRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, LOCAL_R ENDERER_NAME); 327 MockRenderer localRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, LOCAL_R ENDERER_NAME);
345 pcClient = createPeerConnectionClient( 328 pcClient = createPeerConnectionClient(localRenderer, new MockRenderer(0, nul l),
346 localRenderer, new MockRenderer(0, null),
347 createParametersForVideoCall(VIDEO_CODEC_VP8, false), null); 329 createParametersForVideoCall(VIDEO_CODEC_VP8, false), null);
348 330
349 // Wait for local SDP and ice candidates set events. 331 // Wait for local SDP and ice candidates set events.
350 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT)); 332 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT));
351 assertTrue("ICE candidates were not generated.", 333 assertTrue("ICE candidates were not generated.", waitForIceCandidates(WAIT_T IMEOUT));
352 waitForIceCandidates(WAIT_TIMEOUT));
353 334
354 // Check that local video frames were rendered. 335 // Check that local video frames were rendered.
355 assertTrue("Local video frames were not rendered.", 336 assertTrue(
356 localRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 337 "Local video frames were not rendered.", localRenderer.waitForFramesRend ered(WAIT_TIMEOUT));
357 338
358 pcClient.close(); 339 pcClient.close();
359 assertTrue("PeerConnection close event was not received.", 340 assertTrue(
360 waitForPeerConnectionClosed(WAIT_TIMEOUT)); 341 "PeerConnection close event was not received.", waitForPeerConnectionClo sed(WAIT_TIMEOUT));
361 Log.d(TAG, "testSetLocalOfferMakesVideoFlowLocally Done."); 342 Log.d(TAG, "testSetLocalOfferMakesVideoFlowLocally Done.");
362 } 343 }
363 344
364 private void doLoopbackTest(PeerConnectionParameters parameters, boolean decod eToTexure) 345 private void doLoopbackTest(PeerConnectionParameters parameters, boolean decod eToTexure)
365 throws InterruptedException { 346 throws InterruptedException {
366 loopback = true; 347 loopback = true;
367 MockRenderer localRenderer = null; 348 MockRenderer localRenderer = null;
368 MockRenderer remoteRenderer = null; 349 MockRenderer remoteRenderer = null;
369 if (parameters.videoCallEnabled) { 350 if (parameters.videoCallEnabled) {
370 Log.d(TAG, "testLoopback for video " + parameters.videoCodec); 351 Log.d(TAG, "testLoopback for video " + parameters.videoCodec);
371 localRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, LOCAL_RENDERER_NAM E); 352 localRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, LOCAL_RENDERER_NAM E);
372 remoteRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, REMOTE_RENDERER_N AME); 353 remoteRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, REMOTE_RENDERER_N AME);
373 } else { 354 } else {
374 Log.d(TAG, "testLoopback for audio."); 355 Log.d(TAG, "testLoopback for audio.");
375 } 356 }
376 pcClient = createPeerConnectionClient(localRenderer, remoteRenderer, paramet ers, 357 pcClient = createPeerConnectionClient(localRenderer, remoteRenderer, paramet ers,
377 decodeToTexure ? eglBase.getEglBaseContext() : null); 358 decodeToTexure ? eglBase.getEglBaseContext() : null);
378 359
379 // Wait for local SDP, rename it to answer and set as remote SDP. 360 // Wait for local SDP, rename it to answer and set as remote SDP.
380 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT)); 361 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT));
381 SessionDescription remoteSdp = new SessionDescription( 362 SessionDescription remoteSdp = new SessionDescription(
382 SessionDescription.Type.fromCanonicalForm("answer"), 363 SessionDescription.Type.fromCanonicalForm("answer"), localSdp.descriptio n);
383 localSdp.description);
384 pcClient.setRemoteDescription(remoteSdp); 364 pcClient.setRemoteDescription(remoteSdp);
385 365
386 // Wait for ICE connection. 366 // Wait for ICE connection.
387 assertTrue("ICE connection failure.", waitForIceConnected(ICE_CONNECTION_WAI T_TIMEOUT)); 367 assertTrue("ICE connection failure.", waitForIceConnected(ICE_CONNECTION_WAI T_TIMEOUT));
388 368
389 if (parameters.videoCallEnabled) { 369 if (parameters.videoCallEnabled) {
390 // Check that local and remote video frames were rendered. 370 // Check that local and remote video frames were rendered.
391 assertTrue("Local video frames were not rendered.", 371 assertTrue("Local video frames were not rendered.",
392 localRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 372 localRenderer.waitForFramesRendered(WAIT_TIMEOUT));
393 assertTrue("Remote video frames were not rendered.", 373 assertTrue("Remote video frames were not rendered.",
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // Wait for local SDP, rename it to answer and set as remote SDP. 465 // Wait for local SDP, rename it to answer and set as remote SDP.
486 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT)); 466 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT));
487 467
488 // Release the EGL context used for creating the PeerConnectionClient. 468 // Release the EGL context used for creating the PeerConnectionClient.
489 // Since createPeerConnectionClient is asynchronous, we must wait for the lo cal 469 // Since createPeerConnectionClient is asynchronous, we must wait for the lo cal
490 // SessionDescription. 470 // SessionDescription.
491 eglBase.release(); 471 eglBase.release();
492 eglBase = null; 472 eglBase = null;
493 473
494 SessionDescription remoteSdp = new SessionDescription( 474 SessionDescription remoteSdp = new SessionDescription(
495 SessionDescription.Type.fromCanonicalForm("answer"), 475 SessionDescription.Type.fromCanonicalForm("answer"), localSdp.descriptio n);
496 localSdp.description);
497 pcClient.setRemoteDescription(remoteSdp); 476 pcClient.setRemoteDescription(remoteSdp);
498 477
499 // Wait for ICE connection. 478 // Wait for ICE connection.
500 assertTrue("ICE connection failure.", waitForIceConnected(ICE_CONNECTION_WAI T_TIMEOUT)); 479 assertTrue("ICE connection failure.", waitForIceConnected(ICE_CONNECTION_WAI T_TIMEOUT));
501 // Check that local and remote video frames were rendered. 480 // Check that local and remote video frames were rendered.
502 assertTrue("Local video frames were not rendered.", 481 assertTrue(
503 localRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 482 "Local video frames were not rendered.", localRenderer.waitForFramesRend ered(WAIT_TIMEOUT));
504 assertTrue("Remote video frames were not rendered.", 483 assertTrue("Remote video frames were not rendered.",
505 remoteRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 484 remoteRenderer.waitForFramesRendered(WAIT_TIMEOUT));
506 485
507 pcClient.close(); 486 pcClient.close();
508 assertTrue(waitForPeerConnectionClosed(WAIT_TIMEOUT)); 487 assertTrue(waitForPeerConnectionClosed(WAIT_TIMEOUT));
509 Log.d(TAG, "testLoopback done."); 488 Log.d(TAG, "testLoopback done.");
510 } 489 }
511 490
512 @SmallTest 491 @SmallTest
513 public void testLoopbackH264CaptureToTexture() throws InterruptedException { 492 public void testLoopbackH264CaptureToTexture() throws InterruptedException {
514 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 493 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
515 Log.i(TAG, "Encode to textures is not supported. Requires KITKAT"); 494 Log.i(TAG, "Encode to textures is not supported. Requires KITKAT");
516 return; 495 return;
517 } 496 }
518 // TODO(perkj): If we can always capture to textures, there is no need to ch eck if the 497 // TODO(perkj): If we can always capture to textures, there is no need to ch eck if the
519 // hardware encoder supports to encode from a texture. 498 // hardware encoder supports to encode from a texture.
520 if (!MediaCodecVideoEncoder.isH264HwSupportedUsingTextures()) { 499 if (!MediaCodecVideoEncoder.isH264HwSupportedUsingTextures()) {
521 Log.i(TAG, "H264 encode to textures is not supported."); 500 Log.i(TAG, "H264 encode to textures is not supported.");
522 return; 501 return;
523 } 502 }
524 doLoopbackTest(createParametersForVideoCall(VIDEO_CODEC_H264, true), true); 503 doLoopbackTest(createParametersForVideoCall(VIDEO_CODEC_H264, true), true);
525 } 504 }
526 505
527
528 // Checks if default front camera can be switched to back camera and then 506 // Checks if default front camera can be switched to back camera and then
529 // again to front camera. 507 // again to front camera.
530 @SmallTest 508 @SmallTest
531 public void testCameraSwitch() throws InterruptedException { 509 public void testCameraSwitch() throws InterruptedException {
532 Log.d(TAG, "testCameraSwitch"); 510 Log.d(TAG, "testCameraSwitch");
533 loopback = true; 511 loopback = true;
534 512
535 MockRenderer localRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, LOCAL_R ENDERER_NAME); 513 MockRenderer localRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, LOCAL_R ENDERER_NAME);
536 MockRenderer remoteRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, REMOTE _RENDERER_NAME); 514 MockRenderer remoteRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, REMOTE _RENDERER_NAME);
537 515
538 pcClient = createPeerConnectionClient( 516 pcClient = createPeerConnectionClient(
539 localRenderer, remoteRenderer, createParametersForVideoCall(VIDEO_CODEC_ VP8, false), null); 517 localRenderer, remoteRenderer, createParametersForVideoCall(VIDEO_CODEC_ VP8, false), null);
540 518
541 // Wait for local SDP, rename it to answer and set as remote SDP. 519 // Wait for local SDP, rename it to answer and set as remote SDP.
542 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT)); 520 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT));
543 SessionDescription remoteSdp = new SessionDescription( 521 SessionDescription remoteSdp = new SessionDescription(
544 SessionDescription.Type.fromCanonicalForm("answer"), 522 SessionDescription.Type.fromCanonicalForm("answer"), localSdp.descriptio n);
545 localSdp.description);
546 pcClient.setRemoteDescription(remoteSdp); 523 pcClient.setRemoteDescription(remoteSdp);
547 524
548 // Wait for ICE connection. 525 // Wait for ICE connection.
549 assertTrue("ICE connection failure.", waitForIceConnected(ICE_CONNECTION_WAI T_TIMEOUT)); 526 assertTrue("ICE connection failure.", waitForIceConnected(ICE_CONNECTION_WAI T_TIMEOUT));
550 527
551 // Check that local and remote video frames were rendered. 528 // Check that local and remote video frames were rendered.
552 assertTrue("Local video frames were not rendered before camera switch.", 529 assertTrue("Local video frames were not rendered before camera switch.",
553 localRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 530 localRenderer.waitForFramesRendered(WAIT_TIMEOUT));
554 assertTrue("Remote video frames were not rendered before camera switch.", 531 assertTrue("Remote video frames were not rendered before camera switch.",
555 remoteRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 532 remoteRenderer.waitForFramesRendered(WAIT_TIMEOUT));
(...skipping 25 matching lines...) Expand all
581 558
582 MockRenderer localRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, LOCAL_R ENDERER_NAME); 559 MockRenderer localRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, LOCAL_R ENDERER_NAME);
583 MockRenderer remoteRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, REMOTE _RENDERER_NAME); 560 MockRenderer remoteRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, REMOTE _RENDERER_NAME);
584 561
585 pcClient = createPeerConnectionClient( 562 pcClient = createPeerConnectionClient(
586 localRenderer, remoteRenderer, createParametersForVideoCall(VIDEO_CODEC_ VP8, false), null); 563 localRenderer, remoteRenderer, createParametersForVideoCall(VIDEO_CODEC_ VP8, false), null);
587 564
588 // Wait for local SDP, rename it to answer and set as remote SDP. 565 // Wait for local SDP, rename it to answer and set as remote SDP.
589 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT)); 566 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT));
590 SessionDescription remoteSdp = new SessionDescription( 567 SessionDescription remoteSdp = new SessionDescription(
591 SessionDescription.Type.fromCanonicalForm("answer"), 568 SessionDescription.Type.fromCanonicalForm("answer"), localSdp.descriptio n);
592 localSdp.description);
593 pcClient.setRemoteDescription(remoteSdp); 569 pcClient.setRemoteDescription(remoteSdp);
594 570
595 // Wait for ICE connection. 571 // Wait for ICE connection.
596 assertTrue("ICE connection failure.", waitForIceConnected(ICE_CONNECTION_WAI T_TIMEOUT)); 572 assertTrue("ICE connection failure.", waitForIceConnected(ICE_CONNECTION_WAI T_TIMEOUT));
597 573
598 // Check that local and remote video frames were rendered. 574 // Check that local and remote video frames were rendered.
599 assertTrue("Local video frames were not rendered before video restart.", 575 assertTrue("Local video frames were not rendered before video restart.",
600 localRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 576 localRenderer.waitForFramesRendered(WAIT_TIMEOUT));
601 assertTrue("Remote video frames were not rendered before video restart.", 577 assertTrue("Remote video frames were not rendered before video restart.",
602 remoteRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 578 remoteRenderer.waitForFramesRendered(WAIT_TIMEOUT));
(...skipping 26 matching lines...) Expand all
629 605
630 MockRenderer localRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, LOCAL_R ENDERER_NAME); 606 MockRenderer localRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, LOCAL_R ENDERER_NAME);
631 MockRenderer remoteRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, REMOTE _RENDERER_NAME); 607 MockRenderer remoteRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, REMOTE _RENDERER_NAME);
632 608
633 pcClient = createPeerConnectionClient( 609 pcClient = createPeerConnectionClient(
634 localRenderer, remoteRenderer, createParametersForVideoCall(VIDEO_CODEC_ VP8, false), null); 610 localRenderer, remoteRenderer, createParametersForVideoCall(VIDEO_CODEC_ VP8, false), null);
635 611
636 // Wait for local SDP, rename it to answer and set as remote SDP. 612 // Wait for local SDP, rename it to answer and set as remote SDP.
637 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT)); 613 assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT));
638 SessionDescription remoteSdp = new SessionDescription( 614 SessionDescription remoteSdp = new SessionDescription(
639 SessionDescription.Type.fromCanonicalForm("answer"), 615 SessionDescription.Type.fromCanonicalForm("answer"), localSdp.descriptio n);
640 localSdp.description);
641 pcClient.setRemoteDescription(remoteSdp); 616 pcClient.setRemoteDescription(remoteSdp);
642 617
643 // Wait for ICE connection. 618 // Wait for ICE connection.
644 assertTrue("ICE connection failure.", waitForIceConnected(ICE_CONNECTION_WAI T_TIMEOUT)); 619 assertTrue("ICE connection failure.", waitForIceConnected(ICE_CONNECTION_WAI T_TIMEOUT));
645 620
646 // Check that local and remote video frames were rendered. 621 // Check that local and remote video frames were rendered.
647 assertTrue("Local video frames were not rendered before camera resolution ch ange.", 622 assertTrue("Local video frames were not rendered before camera resolution ch ange.",
648 localRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 623 localRenderer.waitForFramesRendered(WAIT_TIMEOUT));
649 assertTrue("Remote video frames were not rendered before camera resolution c hange.", 624 assertTrue("Remote video frames were not rendered before camera resolution c hange.",
650 remoteRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 625 remoteRenderer.waitForFramesRendered(WAIT_TIMEOUT));
(...skipping 13 matching lines...) Expand all
664 assertTrue("Local video frames were not rendered after capture format chan ge.", 639 assertTrue("Local video frames were not rendered after capture format chan ge.",
665 localRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 640 localRenderer.waitForFramesRendered(WAIT_TIMEOUT));
666 assertTrue("Remote video frames were not rendered after capture format cha nge.", 641 assertTrue("Remote video frames were not rendered after capture format cha nge.",
667 remoteRenderer.waitForFramesRendered(WAIT_TIMEOUT)); 642 remoteRenderer.waitForFramesRendered(WAIT_TIMEOUT));
668 } 643 }
669 644
670 pcClient.close(); 645 pcClient.close();
671 assertTrue(waitForPeerConnectionClosed(WAIT_TIMEOUT)); 646 assertTrue(waitForPeerConnectionClosed(WAIT_TIMEOUT));
672 Log.d(TAG, "testCaptureFormatChange done."); 647 Log.d(TAG, "testCaptureFormatChange done.");
673 } 648 }
674
675 } 649 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698