Add separate event for camera freeze.

Review URL: https://codereview.webrtc.org/1479523003

Cr-Commit-Position: refs/heads/master@{#10846}
diff --git a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java
index d21e42f..f89d222 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 @@
   @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 2bd49be..f90fd4f 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 @@
       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 @@
     @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 @@
     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 @@
     // 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 952bd08..66b4048 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 @@
   // 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 @@
             && 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 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);