| Index: media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
|
| diff --git a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
|
| index a1d2867fc759eb526b5db337726adbf35f02d733..08ef0b8b4d3737cde6a2e0a5ba2c547a62f693b9 100644
|
| --- a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
|
| +++ b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
|
| @@ -242,6 +242,7 @@ public class VideoCaptureCamera2 extends VideoCapture {
|
| private CameraDevice mCameraDevice;
|
| private CameraCaptureSession mPreviewSession;
|
| private CaptureRequest mPreviewRequest;
|
| + private Handler mMainHandler = null;
|
|
|
| private CameraState mCameraState = CameraState.STOPPED;
|
| private final float mMaxZoom;
|
| @@ -455,8 +456,7 @@ public class VideoCaptureCamera2 extends VideoCapture {
|
| try {
|
| return manager.getCameraIdList().length;
|
| } catch (CameraAccessException | SecurityException ex) {
|
| - // SecurityException is an undocumented exception, but has been seen in
|
| - // http://crbug/605424.
|
| + // SecurityException is undocumented but seen in the wild: https://crbug/605424.
|
| Log.e(TAG, "getNumberOfCameras: getCameraIdList(): ", ex);
|
| return 0;
|
| }
|
| @@ -584,10 +584,20 @@ public class VideoCaptureCamera2 extends VideoCapture {
|
| changeCameraStateAndNotify(CameraState.OPENING);
|
| final CameraManager manager =
|
| (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
|
| - final Handler mainHandler = new Handler(mContext.getMainLooper());
|
| +
|
| + if (!mUseBackgroundThreadForTesting) {
|
| + mMainHandler = new Handler(mContext.getMainLooper());
|
| + } else {
|
| + // Usually we deliver frames on |mContext|s thread, but unit tests
|
| + // occupy its Looper; deliver frames on a background thread instead.
|
| + HandlerThread thread = new HandlerThread("CameraPicture");
|
| + thread.start();
|
| + mMainHandler = new Handler(thread.getLooper());
|
| + }
|
| +
|
| final CrStateListener stateListener = new CrStateListener();
|
| try {
|
| - manager.openCamera(Integer.toString(mId), stateListener, mainHandler);
|
| + manager.openCamera(Integer.toString(mId), stateListener, mMainHandler);
|
| } catch (CameraAccessException | IllegalArgumentException | SecurityException ex) {
|
| Log.e(TAG, "allocate: manager.openCamera: ", ex);
|
| return false;
|
| @@ -622,6 +632,9 @@ public class VideoCaptureCamera2 extends VideoCapture {
|
| }
|
| if (mCameraDevice == null) return false;
|
| mCameraDevice.close();
|
| +
|
| + if (mUseBackgroundThreadForTesting) mMainHandler.getLooper().quit();
|
| +
|
| changeCameraStateAndNotify(CameraState.STOPPED);
|
| mCropRect = new Rect();
|
| return true;
|
|
|