Add separate event for camera freeze.
Review URL: https://codereview.webrtc.org/1479523003 Cr-Commit-Position: refs/heads/master@{#10846}
This commit is contained in:
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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<CaptureFormat> 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()) {
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user