| OLD | NEW |
| 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 | 10 |
| 11 package org.webrtc; | 11 package org.webrtc; |
| 12 | 12 |
| 13 import static org.junit.Assert.assertEquals; | 13 import static org.junit.Assert.assertEquals; |
| 14 import static org.junit.Assert.assertFalse; | 14 import static org.junit.Assert.assertFalse; |
| 15 import static org.junit.Assert.assertTrue; | 15 import static org.junit.Assert.assertTrue; |
| 16 import static org.junit.Assert.fail; | 16 import static org.junit.Assert.fail; |
| 17 | 17 |
| 18 import android.annotation.TargetApi; | |
| 19 import android.content.Context; | 18 import android.content.Context; |
| 20 import android.media.CamcorderProfile; | |
| 21 import android.media.MediaRecorder; | |
| 22 import android.os.Environment; | |
| 23 import java.io.File; | |
| 24 import java.io.IOException; | |
| 25 import java.util.ArrayList; | 19 import java.util.ArrayList; |
| 26 import java.util.List; | 20 import java.util.List; |
| 27 import java.util.concurrent.CountDownLatch; | 21 import java.util.concurrent.CountDownLatch; |
| 28 import org.chromium.base.test.BaseJUnit4ClassRunner; | 22 import org.chromium.base.test.BaseJUnit4ClassRunner; |
| 29 import org.junit.runner.RunWith; | 23 import org.junit.runner.RunWith; |
| 30 import org.webrtc.CameraEnumerationAndroid.CaptureFormat; | 24 import org.webrtc.CameraEnumerationAndroid.CaptureFormat; |
| 31 import org.webrtc.VideoRenderer.I420Frame; | 25 import org.webrtc.VideoRenderer.I420Frame; |
| 32 | 26 |
| 33 class CameraVideoCapturerTestFixtures { | 27 class CameraVideoCapturerTestFixtures { |
| 34 static final String TAG = "CameraVideoCapturerTestFixtures"; | 28 static final String TAG = "CameraVideoCapturerTestFixtures"; |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 // Wait until the camera has been switched. | 494 // Wait until the camera has been switched. |
| 501 barrier.await(); | 495 barrier.await(); |
| 502 | 496 |
| 503 // Check result. | 497 // Check result. |
| 504 assertTrue(cameraSwitchSuccessful[0]); | 498 assertTrue(cameraSwitchSuccessful[0]); |
| 505 // Ensure that frames are received. | 499 // Ensure that frames are received. |
| 506 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender
() > 0); | 500 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender
() > 0); |
| 507 disposeCapturer(capturerInstance); | 501 disposeCapturer(capturerInstance); |
| 508 disposeVideoTrackWithRenderer(videoTrackWithRenderer); | 502 disposeVideoTrackWithRenderer(videoTrackWithRenderer); |
| 509 } | 503 } |
| 510 | |
| 511 @TargetApi(21) | |
| 512 public void updateMediaRecorder(boolean useSurfaceCapture) | |
| 513 throws InterruptedException, IOException { | |
| 514 final CapturerInstance capturerInstance = createCapturer(false /* initialize
*/); | |
| 515 final VideoTrackWithRenderer videoTrackWithRenderer = | |
| 516 createVideoTrackWithRenderer(capturerInstance.capturer); | |
| 517 // Wait for the camera to start so we can add and remove MediaRecorder. | |
| 518 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender
() > 0); | |
| 519 | |
| 520 final String videoOutPath = Environment.getExternalStorageDirectory().getPat
h() | |
| 521 + "/chromium_tests_root/testmediarecorder.mp4"; | |
| 522 File outputFile = new File(videoOutPath); | |
| 523 | |
| 524 // Create MediaRecorder object | |
| 525 MediaRecorder mediaRecorder = new MediaRecorder(); | |
| 526 mediaRecorder.setVideoSource( | |
| 527 useSurfaceCapture ? MediaRecorder.VideoSource.SURFACE : MediaRecorder.Vi
deoSource.CAMERA); | |
| 528 CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480
P); | |
| 529 profile.videoCodec = MediaRecorder.VideoEncoder.H264; | |
| 530 profile.videoBitRate = 2500000; | |
| 531 profile.videoFrameWidth = 640; | |
| 532 profile.videoFrameHeight = 480; | |
| 533 mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); | |
| 534 mediaRecorder.setVideoFrameRate(profile.videoFrameRate); | |
| 535 mediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight
); | |
| 536 mediaRecorder.setVideoEncodingBitRate(profile.videoBitRate); | |
| 537 mediaRecorder.setVideoEncoder(profile.videoCodec); | |
| 538 mediaRecorder.setOutputFile(outputFile.getPath()); | |
| 539 mediaRecorder.prepare(); | |
| 540 | |
| 541 // Add MediaRecorder to camera pipeline. | |
| 542 final boolean[] addMediaRecorderSuccessful = new boolean[1]; | |
| 543 final CountDownLatch addBarrier = new CountDownLatch(1); | |
| 544 CameraVideoCapturer.MediaRecorderHandler addMediaRecorderHandler = | |
| 545 new CameraVideoCapturer.MediaRecorderHandler() { | |
| 546 @Override | |
| 547 public void onMediaRecorderSuccess() { | |
| 548 addMediaRecorderSuccessful[0] = true; | |
| 549 addBarrier.countDown(); | |
| 550 } | |
| 551 @Override | |
| 552 public void onMediaRecorderError(String errorDescription) { | |
| 553 addMediaRecorderSuccessful[0] = false; | |
| 554 addBarrier.countDown(); | |
| 555 } | |
| 556 }; | |
| 557 capturerInstance.capturer.addMediaRecorderToCamera(mediaRecorder, addMediaRe
corderHandler); | |
| 558 // Wait until MediaRecoder has been added. | |
| 559 addBarrier.await(); | |
| 560 // Check result. | |
| 561 assertTrue(addMediaRecorderSuccessful[0]); | |
| 562 | |
| 563 // Start MediaRecorder and wait for a few frames to capture. | |
| 564 mediaRecorder.start(); | |
| 565 for (int i = 0; i < 5; i++) { | |
| 566 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRend
er() > 0); | |
| 567 } | |
| 568 mediaRecorder.stop(); | |
| 569 | |
| 570 // Remove MediaRecorder from camera pipeline. | |
| 571 final boolean[] removeMediaRecorderSuccessful = new boolean[1]; | |
| 572 final CountDownLatch removeBarrier = new CountDownLatch(1); | |
| 573 CameraVideoCapturer.MediaRecorderHandler removeMediaRecorderHandler = | |
| 574 new CameraVideoCapturer.MediaRecorderHandler() { | |
| 575 @Override | |
| 576 public void onMediaRecorderSuccess() { | |
| 577 removeMediaRecorderSuccessful[0] = true; | |
| 578 removeBarrier.countDown(); | |
| 579 } | |
| 580 @Override | |
| 581 public void onMediaRecorderError(String errorDescription) { | |
| 582 removeMediaRecorderSuccessful[0] = false; | |
| 583 removeBarrier.countDown(); | |
| 584 } | |
| 585 }; | |
| 586 capturerInstance.capturer.removeMediaRecorderFromCamera(removeMediaRecorderH
andler); | |
| 587 // Wait until MediaRecoder has been removed. | |
| 588 removeBarrier.await(); | |
| 589 // Check result. | |
| 590 assertTrue(removeMediaRecorderSuccessful[0]); | |
| 591 // Ensure that frames are received after removing MediaRecorder. | |
| 592 assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender
() > 0); | |
| 593 // Check that recorded file contains some data. | |
| 594 assertTrue(outputFile.length() > 0); | |
| 595 | |
| 596 disposeCapturer(capturerInstance); | |
| 597 disposeVideoTrackWithRenderer(videoTrackWithRenderer); | |
| 598 } | |
| 599 | 504 |
| 600 public void cameraEventsInvoked() throws InterruptedException { | 505 public void cameraEventsInvoked() throws InterruptedException { |
| 601 final CapturerInstance capturerInstance = createCapturer(true /* initialize
*/); | 506 final CapturerInstance capturerInstance = createCapturer(true /* initialize
*/); |
| 602 startCapture(capturerInstance); | 507 startCapture(capturerInstance); |
| 603 // Make sure camera is started and first frame is received and then stop it. | 508 // Make sure camera is started and first frame is received and then stop it. |
| 604 assertTrue(capturerInstance.observer.waitForCapturerToStart()); | 509 assertTrue(capturerInstance.observer.waitForCapturerToStart()); |
| 605 capturerInstance.observer.waitForNextCapturedFrame(); | 510 capturerInstance.observer.waitForNextCapturedFrame(); |
| 606 disposeCapturer(capturerInstance); | 511 disposeCapturer(capturerInstance); |
| 607 | 512 |
| 608 assertTrue(capturerInstance.cameraEvents.onCameraOpeningCalled); | 513 assertTrue(capturerInstance.cameraEvents.onCameraOpeningCalled); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 final CapturerInstance capturerInstance = createCapturer(cameraName, true /*
initialize */); | 727 final CapturerInstance capturerInstance = createCapturer(cameraName, true /*
initialize */); |
| 823 | 728 |
| 824 final Object competingCamera = testObjectFactory.rawOpenCamera(cameraName); | 729 final Object competingCamera = testObjectFactory.rawOpenCamera(cameraName); |
| 825 | 730 |
| 826 startCapture(capturerInstance); | 731 startCapture(capturerInstance); |
| 827 disposeCapturer(capturerInstance); | 732 disposeCapturer(capturerInstance); |
| 828 | 733 |
| 829 testObjectFactory.rawCloseCamera(competingCamera); | 734 testObjectFactory.rawCloseCamera(competingCamera); |
| 830 } | 735 } |
| 831 } | 736 } |
| OLD | NEW |