From ea70d77fd54fa9bd0401220bfbca585c575f7eff Mon Sep 17 00:00:00 2001 From: Magnus Jedvert Date: Thu, 24 Sep 2015 21:40:57 +0200 Subject: [PATCH] VideoCapturerAndroid: Add test for making calls on stopped camera BUG=webrtc:4978 R=perkj@webrtc.org Review URL: https://codereview.webrtc.org/1350663002 . Cr-Commit-Position: refs/heads/master@{#10062} --- .../org/webrtc/VideoCapturerAndroidTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java index 3702feaf3c..0fe827d1f9 100644 --- a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java +++ b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java @@ -292,6 +292,32 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { assertTrue(capturer.isReleased()); } + @MediumTest + // Test what happens when attempting to call e.g. switchCamera() after camera has been stopped. + public void testCameraCallsAfterStop() throws InterruptedException { + final String deviceName = CameraEnumerationAndroid.getDeviceName(0); + final VideoCapturerAndroid capturer = VideoCapturerAndroid.create(deviceName, null); + final List formats = CameraEnumerationAndroid.getSupportedFormats(0); + final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); + + final FakeCapturerObserver observer = new FakeCapturerObserver(); + capturer.startCapture(format.width, format.height, format.maxFramerate, + getInstrumentation().getContext(), observer); + // Make sure camera is started and then stop it. + assertTrue(observer.WaitForCapturerToStart()); + capturer.stopCapture(); + for (long timeStamp : observer.getCopyAndResetListOftimeStamps()) { + capturer.returnBuffer(timeStamp); + } + // We can't change |capturer| at this point, but we should not crash. + capturer.switchCamera(null); + capturer.onOutputFormatRequest(640, 480, 15); + capturer.changeCaptureFormat(640, 480, 15); + + capturer.dispose(); + assertTrue(capturer.isReleased()); + } + @SmallTest // This test that the VideoSource that the VideoCapturer is connected to can // be stopped and restarted. It tests both the Java and the C++ layer.