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
|
@MediumTest
|
||||||
// This test that CameraEventsHandler.onError is triggered if video buffers are not returned to
|
// This test that CameraEventsHandler.onError is triggered if video buffers are not returned to
|
||||||
// the capturer.
|
// the capturer.
|
||||||
public void testCameraErrorEventOnBufferStarvation() throws InterruptedException {
|
public void testCameraFreezedEventOnBufferStarvation() throws InterruptedException {
|
||||||
VideoCapturerAndroidTestFixtures.CameraEvents cameraEvents =
|
VideoCapturerAndroidTestFixtures.CameraEvents cameraEvents =
|
||||||
VideoCapturerAndroidTestFixtures.createCameraEvents();
|
VideoCapturerAndroidTestFixtures.createCameraEvents();
|
||||||
VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", cameraEvents);
|
VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", cameraEvents);
|
||||||
VideoCapturerAndroidTestFixtures.cameraErrorEventOnBufferStarvation(capturer,
|
VideoCapturerAndroidTestFixtures.cameraFreezedEventOnBufferStarvation(capturer,
|
||||||
cameraEvents, getInstrumentation().getContext());
|
cameraEvents, getInstrumentation().getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,14 +191,18 @@ public class VideoCapturerAndroidTestFixtures {
|
|||||||
VideoCapturerAndroid.CameraEventsHandler {
|
VideoCapturerAndroid.CameraEventsHandler {
|
||||||
public boolean onCameraOpeningCalled;
|
public boolean onCameraOpeningCalled;
|
||||||
public boolean onFirstFrameAvailableCalled;
|
public boolean onFirstFrameAvailableCalled;
|
||||||
public final Object onCameraErrorLock = new Object();
|
public final Object onCameraFreezedLock = new Object();
|
||||||
private String onCameraErrorDescription;
|
private String onCameraFreezedDescription;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCameraError(String errorDescription) {
|
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
|
@Override
|
||||||
public void onCameraClosed() { }
|
public void onCameraClosed() { }
|
||||||
|
|
||||||
public String WaitForCameraError() throws InterruptedException {
|
public String WaitForCameraFreezed() throws InterruptedException {
|
||||||
synchronized (onCameraErrorLock) {
|
synchronized (onCameraFreezedLock) {
|
||||||
onCameraErrorLock.wait();
|
onCameraFreezedLock.wait();
|
||||||
return onCameraErrorDescription;
|
return onCameraFreezedDescription;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -537,7 +541,7 @@ public class VideoCapturerAndroidTestFixtures {
|
|||||||
assertTrue(capturer.isReleased());
|
assertTrue(capturer.isReleased());
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void cameraErrorEventOnBufferStarvation(VideoCapturerAndroid capturer,
|
static public void cameraFreezedEventOnBufferStarvation(VideoCapturerAndroid capturer,
|
||||||
CameraEvents events, Context appContext) throws InterruptedException {
|
CameraEvents events, Context appContext) throws InterruptedException {
|
||||||
final List<CaptureFormat> formats = capturer.getSupportedFormats();
|
final List<CaptureFormat> formats = capturer.getSupportedFormats();
|
||||||
final CameraEnumerationAndroid.CaptureFormat format = formats.get(0);
|
final CameraEnumerationAndroid.CaptureFormat format = formats.get(0);
|
||||||
@ -548,7 +552,8 @@ public class VideoCapturerAndroidTestFixtures {
|
|||||||
// Make sure camera is started.
|
// Make sure camera is started.
|
||||||
assertTrue(observer.WaitForCapturerToStart());
|
assertTrue(observer.WaitForCapturerToStart());
|
||||||
// Since we don't call returnBuffer, we should get a starvation message.
|
// 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();
|
capturer.stopCapture();
|
||||||
for (long timeStamp : observer.getCopyAndResetListOftimeStamps()) {
|
for (long timeStamp : observer.getCopyAndResetListOftimeStamps()) {
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.SurfaceTexture;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
@ -103,7 +102,7 @@ public class VideoCapturerAndroid extends VideoCapturer implements
|
|||||||
// another application when startCaptureOnCameraThread is called.
|
// another application when startCaptureOnCameraThread is called.
|
||||||
private Runnable openCameraOnCodecThreadRunner;
|
private Runnable openCameraOnCodecThreadRunner;
|
||||||
private final static int MAX_OPEN_CAMERA_ATTEMPTS = 3;
|
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;
|
private int openCameraAttempts;
|
||||||
|
|
||||||
// Camera error callback.
|
// Camera error callback.
|
||||||
@ -141,9 +140,9 @@ public class VideoCapturerAndroid extends VideoCapturer implements
|
|||||||
&& eventsHandler != null) {
|
&& eventsHandler != null) {
|
||||||
Logging.e(TAG, "Camera freezed.");
|
Logging.e(TAG, "Camera freezed.");
|
||||||
if (cameraStatistics.pendingFramesCount() == cameraStatistics.maxPendingFrames) {
|
if (cameraStatistics.pendingFramesCount() == cameraStatistics.maxPendingFrames) {
|
||||||
eventsHandler.onCameraError("Camera failure. Client must return video buffers.");
|
eventsHandler.onCameraFreezed("Camera failure. Client must return video buffers.");
|
||||||
} else {
|
} else {
|
||||||
eventsHandler.onCameraError("Camera failure.");
|
eventsHandler.onCameraFreezed("Camera failure.");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -204,10 +203,13 @@ public class VideoCapturerAndroid extends VideoCapturer implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static interface CameraEventsHandler {
|
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.
|
// or any camera exception happens on camera thread.
|
||||||
void onCameraError(String errorDescription);
|
void onCameraError(String errorDescription);
|
||||||
|
|
||||||
|
// Invoked when camera stops receiving frames
|
||||||
|
void onCameraFreezed(String errorDescription);
|
||||||
|
|
||||||
// Callback invoked when camera is opening.
|
// Callback invoked when camera is opening.
|
||||||
void onCameraOpening(int cameraId);
|
void onCameraOpening(int cameraId);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user