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