From ee69ed505b6ba4a9dbb47cc927aaf220d661fa06 Mon Sep 17 00:00:00 2001 From: glaznev Date: Mon, 30 Nov 2015 15:26:34 -0800 Subject: [PATCH] Add separate event for camera freeze. Review URL: https://codereview.webrtc.org/1479523003 Cr-Commit-Position: refs/heads/master@{#10846} --- .../org/webrtc/VideoCapturerAndroidTest.java | 4 +-- .../VideoCapturerAndroidTestFixtures.java | 27 +++++++++++-------- .../org/webrtc/VideoCapturerAndroid.java | 12 +++++---- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java index d21e42fed1..f89d222428 100644 --- a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java +++ b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java @@ -292,11 +292,11 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { @MediumTest // This test that CameraEventsHandler.onError is triggered if video buffers are not returned to // the capturer. - public void testCameraErrorEventOnBufferStarvation() throws InterruptedException { + public void testCameraFreezedEventOnBufferStarvation() throws InterruptedException { VideoCapturerAndroidTestFixtures.CameraEvents cameraEvents = VideoCapturerAndroidTestFixtures.createCameraEvents(); VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", cameraEvents); - VideoCapturerAndroidTestFixtures.cameraErrorEventOnBufferStarvation(capturer, + VideoCapturerAndroidTestFixtures.cameraFreezedEventOnBufferStarvation(capturer, cameraEvents, getInstrumentation().getContext()); } diff --git a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java index 2bd49beba2..f90fd4fcc0 100644 --- a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java +++ b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java @@ -191,14 +191,18 @@ public class VideoCapturerAndroidTestFixtures { VideoCapturerAndroid.CameraEventsHandler { public boolean onCameraOpeningCalled; public boolean onFirstFrameAvailableCalled; - public final Object onCameraErrorLock = new Object(); - private String onCameraErrorDescription; + public final Object onCameraFreezedLock = new Object(); + private String onCameraFreezedDescription; @Override public void onCameraError(String errorDescription) { - synchronized (onCameraErrorLock) { - onCameraErrorDescription = errorDescription; - onCameraErrorLock.notifyAll(); + } + + @Override + public void onCameraFreezed(String errorDescription) { + synchronized (onCameraFreezedLock) { + onCameraFreezedDescription = errorDescription; + onCameraFreezedLock.notifyAll(); } } @@ -215,10 +219,10 @@ public class VideoCapturerAndroidTestFixtures { @Override public void onCameraClosed() { } - public String WaitForCameraError() throws InterruptedException { - synchronized (onCameraErrorLock) { - onCameraErrorLock.wait(); - return onCameraErrorDescription; + public String WaitForCameraFreezed() throws InterruptedException { + synchronized (onCameraFreezedLock) { + onCameraFreezedLock.wait(); + return onCameraFreezedDescription; } } } @@ -537,7 +541,7 @@ public class VideoCapturerAndroidTestFixtures { assertTrue(capturer.isReleased()); } - static public void cameraErrorEventOnBufferStarvation(VideoCapturerAndroid capturer, + static public void cameraFreezedEventOnBufferStarvation(VideoCapturerAndroid capturer, CameraEvents events, Context appContext) throws InterruptedException { final List formats = capturer.getSupportedFormats(); final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); @@ -548,7 +552,8 @@ public class VideoCapturerAndroidTestFixtures { // Make sure camera is started. assertTrue(observer.WaitForCapturerToStart()); // Since we don't call returnBuffer, we should get a starvation message. - assertEquals("Camera failure. Client must return video buffers.", events.WaitForCameraError()); + assertEquals("Camera failure. Client must return video buffers.", + events.WaitForCameraFreezed()); capturer.stopCapture(); for (long timeStamp : observer.getCopyAndResetListOftimeStamps()) { diff --git a/talk/app/webrtc/java/android/org/webrtc/VideoCapturerAndroid.java b/talk/app/webrtc/java/android/org/webrtc/VideoCapturerAndroid.java index 952bd08395..66b4048b9d 100644 --- a/talk/app/webrtc/java/android/org/webrtc/VideoCapturerAndroid.java +++ b/talk/app/webrtc/java/android/org/webrtc/VideoCapturerAndroid.java @@ -28,7 +28,6 @@ package org.webrtc; import android.content.Context; -import android.graphics.SurfaceTexture; import android.os.Handler; import android.os.HandlerThread; import android.os.SystemClock; @@ -103,7 +102,7 @@ public class VideoCapturerAndroid extends VideoCapturer implements // another application when startCaptureOnCameraThread is called. private Runnable openCameraOnCodecThreadRunner; private final static int MAX_OPEN_CAMERA_ATTEMPTS = 3; - private final static int OPEN_CAMERA_DELAY_MS = 300; + private final static int OPEN_CAMERA_DELAY_MS = 500; private int openCameraAttempts; // Camera error callback. @@ -141,9 +140,9 @@ public class VideoCapturerAndroid extends VideoCapturer implements && eventsHandler != null) { Logging.e(TAG, "Camera freezed."); if (cameraStatistics.pendingFramesCount() == cameraStatistics.maxPendingFrames) { - eventsHandler.onCameraError("Camera failure. Client must return video buffers."); + eventsHandler.onCameraFreezed("Camera failure. Client must return video buffers."); } else { - eventsHandler.onCameraError("Camera failure."); + eventsHandler.onCameraFreezed("Camera failure."); } return; } @@ -204,10 +203,13 @@ public class VideoCapturerAndroid extends VideoCapturer implements } public static interface CameraEventsHandler { - // Camera error handler - invoked when camera stops receiving frames + // Camera error handler - invoked when camera can not be opened // or any camera exception happens on camera thread. void onCameraError(String errorDescription); + // Invoked when camera stops receiving frames + void onCameraFreezed(String errorDescription); + // Callback invoked when camera is opening. void onCameraOpening(int cameraId);