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

Side by Side Diff: webrtc/api/androidtests/src/org/webrtc/CameraVideoCapturerTestFixtures.java

Issue 2168623002: Refactor stopCapture to be asynchronous in VideoCapturerAndroid. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@androidvideotracksource
Patch Set: Synchronized. Created 4 years, 5 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 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 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 package org.webrtc; 10 package org.webrtc;
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 private void createCapturerAndRender(String name) throws InterruptedException { 395 private void createCapturerAndRender(String name) throws InterruptedException {
396 if (name == null) { 396 if (name == null) {
397 Logging.w(TAG, "Skipping video capturer test because device name is null." ); 397 Logging.w(TAG, "Skipping video capturer test because device name is null." );
398 return; 398 return;
399 } 399 }
400 400
401 final CapturerInstance capturerInstance = createCapturer(name, false /* init ialize */); 401 final CapturerInstance capturerInstance = createCapturer(name, false /* init ialize */);
402 final VideoTrackWithRenderer videoTrackWithRenderer = 402 final VideoTrackWithRenderer videoTrackWithRenderer =
403 createVideoTrackWithRenderer(capturerInstance.capturer); 403 createVideoTrackWithRenderer(capturerInstance.capturer);
404 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender () > 0); 404 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender () > 0);
405 disposeCapturer(capturerInstance);
405 disposeVideoTrackWithRenderer(videoTrackWithRenderer); 406 disposeVideoTrackWithRenderer(videoTrackWithRenderer);
406 disposeCapturer(capturerInstance);
407 } 407 }
408 408
409 // Test methods 409 // Test methods
410 public void createCapturerAndDispose() { 410 public void createCapturerAndDispose() {
411 disposeCapturer(createCapturer(true /* initialize */)); 411 disposeCapturer(createCapturer(true /* initialize */));
412 } 412 }
413 413
414 public void createNonExistingCamera() { 414 public void createNonExistingCamera() {
415 try { 415 try {
416 disposeCapturer(createCapturer("non-existing camera", false /* initialize */)); 416 disposeCapturer(createCapturer("non-existing camera", false /* initialize */));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 barrier.countDown(); 459 barrier.countDown();
460 } 460 }
461 }); 461 });
462 // Wait until the camera has been switched. 462 // Wait until the camera has been switched.
463 barrier.await(); 463 barrier.await();
464 464
465 // Check result. 465 // Check result.
466 assertTrue(cameraSwitchSuccessful[0]); 466 assertTrue(cameraSwitchSuccessful[0]);
467 // Ensure that frames are received. 467 // Ensure that frames are received.
468 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender () > 0); 468 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender () > 0);
469 disposeCapturer(capturerInstance);
469 disposeVideoTrackWithRenderer(videoTrackWithRenderer); 470 disposeVideoTrackWithRenderer(videoTrackWithRenderer);
470 disposeCapturer(capturerInstance);
471 } 471 }
472 472
473 public void cameraEventsInvoked() throws InterruptedException { 473 public void cameraEventsInvoked() throws InterruptedException {
474 final CapturerInstance capturerInstance = createCapturer(true /* initialize */); 474 final CapturerInstance capturerInstance = createCapturer(true /* initialize */);
475 startCapture(capturerInstance); 475 startCapture(capturerInstance);
476 // Make sure camera is started and first frame is received and then stop it. 476 // Make sure camera is started and first frame is received and then stop it.
477 assertTrue(capturerInstance.observer.waitForCapturerToStart()); 477 assertTrue(capturerInstance.observer.waitForCapturerToStart());
478 capturerInstance.observer.waitForNextCapturedFrame(); 478 capturerInstance.observer.waitForNextCapturedFrame();
479 capturerInstance.capturer.stopCapture(); 479 capturerInstance.capturer.stopCapture();
480 disposeCapturer(capturerInstance); 480 disposeCapturer(capturerInstance);
(...skipping 26 matching lines...) Expand all
507 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender () > 0); 507 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender () > 0);
508 assertEquals(MediaSource.State.LIVE, videoTrackWithRenderer.source.state()); 508 assertEquals(MediaSource.State.LIVE, videoTrackWithRenderer.source.state());
509 509
510 videoTrackWithRenderer.source.stop(); 510 videoTrackWithRenderer.source.stop();
511 assertEquals(MediaSource.State.ENDED, videoTrackWithRenderer.source.state()) ; 511 assertEquals(MediaSource.State.ENDED, videoTrackWithRenderer.source.state()) ;
512 512
513 videoTrackWithRenderer.source.restart(); 513 videoTrackWithRenderer.source.restart();
514 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender () > 0); 514 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender () > 0);
515 assertEquals(MediaSource.State.LIVE, videoTrackWithRenderer.source.state()); 515 assertEquals(MediaSource.State.LIVE, videoTrackWithRenderer.source.state());
516 516
517 disposeCapturer(capturerInstance);
517 disposeVideoTrackWithRenderer(videoTrackWithRenderer); 518 disposeVideoTrackWithRenderer(videoTrackWithRenderer);
518 disposeCapturer(capturerInstance);
519 } 519 }
520 520
521 public void startStopWithDifferentResolutions() throws InterruptedException { 521 public void startStopWithDifferentResolutions() throws InterruptedException {
522 final CapturerInstance capturerInstance = createCapturer(true /* initialize */); 522 final CapturerInstance capturerInstance = createCapturer(true /* initialize */);
523 523
524 for(int i = 0; i < 3 ; ++i) { 524 for(int i = 0; i < 3 ; ++i) {
525 startCapture(capturerInstance, i); 525 startCapture(capturerInstance, i);
526 assertTrue(capturerInstance.observer.waitForCapturerToStart()); 526 assertTrue(capturerInstance.observer.waitForCapturerToStart());
527 capturerInstance.observer.waitForNextCapturedFrame(); 527 capturerInstance.observer.waitForNextCapturedFrame();
528 528
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 throws InterruptedException { 578 throws InterruptedException {
579 final CapturerInstance capturerInstance = createCapturer(false /* initialize */); 579 final CapturerInstance capturerInstance = createCapturer(false /* initialize */);
580 final VideoTrackWithRenderer videoTrackWithRenderer = 580 final VideoTrackWithRenderer videoTrackWithRenderer =
581 createVideoTrackWithFakeAsyncRenderer(capturerInstance.capturer); 581 createVideoTrackWithFakeAsyncRenderer(capturerInstance.capturer);
582 // Wait for at least one frame that has not been returned. 582 // Wait for at least one frame that has not been returned.
583 assertFalse(videoTrackWithRenderer.fakeAsyncRenderer.waitForPendingFrames(). isEmpty()); 583 assertFalse(videoTrackWithRenderer.fakeAsyncRenderer.waitForPendingFrames(). isEmpty());
584 584
585 capturerInstance.capturer.stopCapture(); 585 capturerInstance.capturer.stopCapture();
586 586
587 // Dispose everything. 587 // Dispose everything.
588 disposeCapturer(capturerInstance);
588 disposeVideoTrackWithRenderer(videoTrackWithRenderer); 589 disposeVideoTrackWithRenderer(videoTrackWithRenderer);
589 disposeCapturer(capturerInstance);
590 590
591 // Return the frame(s), on a different thread out of spite. 591 // Return the frame(s), on a different thread out of spite.
592 final List<I420Frame> pendingFrames = 592 final List<I420Frame> pendingFrames =
593 videoTrackWithRenderer.fakeAsyncRenderer.waitForPendingFrames(); 593 videoTrackWithRenderer.fakeAsyncRenderer.waitForPendingFrames();
594 final Thread returnThread = new Thread(new Runnable() { 594 final Thread returnThread = new Thread(new Runnable() {
595 @Override 595 @Override
596 public void run() { 596 public void run() {
597 for (I420Frame frame : pendingFrames) { 597 for (I420Frame frame : pendingFrames) {
598 VideoRenderer.renderFrameDone(frame); 598 VideoRenderer.renderFrameDone(frame);
599 } 599 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 int numberOfInspectedFrames = 0; 636 int numberOfInspectedFrames = 0;
637 637
638 do { 638 do {
639 videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender(); 639 videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender();
640 ++numberOfInspectedFrames; 640 ++numberOfInspectedFrames;
641 641
642 gotExpectedResolution = (videoTrackWithRenderer.rendererCallbacks.frameWid th() == scaledWidth 642 gotExpectedResolution = (videoTrackWithRenderer.rendererCallbacks.frameWid th() == scaledWidth
643 && videoTrackWithRenderer.rendererCallbacks.frameHeight() == scaledHe ight); 643 && videoTrackWithRenderer.rendererCallbacks.frameHeight() == scaledHe ight);
644 } while (!gotExpectedResolution && numberOfInspectedFrames < 30); 644 } while (!gotExpectedResolution && numberOfInspectedFrames < 30);
645 645
646 disposeCapturer(capturerInstance);
646 disposeVideoTrackWithRenderer(videoTrackWithRenderer); 647 disposeVideoTrackWithRenderer(videoTrackWithRenderer);
647 disposeCapturer(capturerInstance);
648 648
649 assertTrue(gotExpectedResolution); 649 assertTrue(gotExpectedResolution);
650 } 650 }
651 651
652 public void startWhileCameraIsAlreadyOpen() throws InterruptedException { 652 public void startWhileCameraIsAlreadyOpen() throws InterruptedException {
653 final String cameraName = testObjectFactory.getNameOfBackFacingDevice(); 653 final String cameraName = testObjectFactory.getNameOfBackFacingDevice();
654 // At this point camera is not actually opened. 654 // At this point camera is not actually opened.
655 final CapturerInstance capturerInstance = createCapturer(cameraName, true /* initialize */); 655 final CapturerInstance capturerInstance = createCapturer(cameraName, true /* initialize */);
656 656
657 final Object competingCamera = testObjectFactory.rawOpenCamera(cameraName); 657 final Object competingCamera = testObjectFactory.rawOpenCamera(cameraName);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 final Object competingCamera = testObjectFactory.rawOpenCamera(cameraName); 702 final Object competingCamera = testObjectFactory.rawOpenCamera(cameraName);
703 703
704 startCapture(capturerInstance); 704 startCapture(capturerInstance);
705 705
706 capturerInstance.capturer.stopCapture(); 706 capturerInstance.capturer.stopCapture();
707 disposeCapturer(capturerInstance); 707 disposeCapturer(capturerInstance);
708 708
709 testObjectFactory.rawCloseCamera(competingCamera); 709 testObjectFactory.rawCloseCamera(competingCamera);
710 } 710 }
711 } 711 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698