| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.media; | 5 package org.chromium.media; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.graphics.ImageFormat; | 9 import android.graphics.ImageFormat; |
| 10 import android.graphics.Rect; | 10 import android.graphics.Rect; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 private static final double kNanoSecondsToFps = 1.0E-9; | 236 private static final double kNanoSecondsToFps = 1.0E-9; |
| 237 private static final String TAG = "VideoCapture"; | 237 private static final String TAG = "VideoCapture"; |
| 238 | 238 |
| 239 private static enum CameraState { OPENING, CONFIGURING, STARTED, STOPPED } | 239 private static enum CameraState { OPENING, CONFIGURING, STARTED, STOPPED } |
| 240 | 240 |
| 241 private final Object mCameraStateLock = new Object(); | 241 private final Object mCameraStateLock = new Object(); |
| 242 | 242 |
| 243 private CameraDevice mCameraDevice; | 243 private CameraDevice mCameraDevice; |
| 244 private CameraCaptureSession mPreviewSession; | 244 private CameraCaptureSession mPreviewSession; |
| 245 private CaptureRequest mPreviewRequest; | 245 private CaptureRequest mPreviewRequest; |
| 246 private Handler mMainHandler = null; |
| 246 | 247 |
| 247 private CameraState mCameraState = CameraState.STOPPED; | 248 private CameraState mCameraState = CameraState.STOPPED; |
| 248 private final float mMaxZoom; | 249 private final float mMaxZoom; |
| 249 private Rect mCropRect = new Rect(); | 250 private Rect mCropRect = new Rect(); |
| 250 private int mPhotoWidth = 0; | 251 private int mPhotoWidth = 0; |
| 251 private int mPhotoHeight = 0; | 252 private int mPhotoHeight = 0; |
| 252 private int mFocusMode = AndroidMeteringMode.CONTINUOUS; | 253 private int mFocusMode = AndroidMeteringMode.CONTINUOUS; |
| 253 private int mExposureMode = AndroidMeteringMode.CONTINUOUS; | 254 private int mExposureMode = AndroidMeteringMode.CONTINUOUS; |
| 254 private MeteringRectangle mAreaOfInterest; | 255 private MeteringRectangle mAreaOfInterest; |
| 255 private int mExposureCompensation = 0; | 256 private int mExposureCompensation = 0; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 && cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTE
D_HARDWARE_LEVEL) | 450 && cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTE
D_HARDWARE_LEVEL) |
| 450 == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY; | 451 == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY; |
| 451 } | 452 } |
| 452 | 453 |
| 453 static int getNumberOfCameras(Context appContext) { | 454 static int getNumberOfCameras(Context appContext) { |
| 454 final CameraManager manager = | 455 final CameraManager manager = |
| 455 (CameraManager) appContext.getSystemService(Context.CAMERA_SERVI
CE); | 456 (CameraManager) appContext.getSystemService(Context.CAMERA_SERVI
CE); |
| 456 try { | 457 try { |
| 457 return manager.getCameraIdList().length; | 458 return manager.getCameraIdList().length; |
| 458 } catch (CameraAccessException | SecurityException ex) { | 459 } catch (CameraAccessException | SecurityException ex) { |
| 459 // SecurityException is an undocumented exception, but has been seen
in | 460 // SecurityException is undocumented but seen in the wild: https://c
rbug/605424. |
| 460 // http://crbug/605424. | |
| 461 Log.e(TAG, "getNumberOfCameras: getCameraIdList(): ", ex); | 461 Log.e(TAG, "getNumberOfCameras: getCameraIdList(): ", ex); |
| 462 return 0; | 462 return 0; |
| 463 } | 463 } |
| 464 } | 464 } |
| 465 | 465 |
| 466 static int getCaptureApiType(int id, Context appContext) { | 466 static int getCaptureApiType(int id, Context appContext) { |
| 467 final CameraCharacteristics cameraCharacteristics = | 467 final CameraCharacteristics cameraCharacteristics = |
| 468 getCameraCharacteristics(appContext, id); | 468 getCameraCharacteristics(appContext, id); |
| 469 if (cameraCharacteristics == null) { | 469 if (cameraCharacteristics == null) { |
| 470 return VideoCaptureApi.UNKNOWN; | 470 return VideoCaptureApi.UNKNOWN; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 == CameraCharacteristics.LENS_FACING_BACK; | 578 == CameraCharacteristics.LENS_FACING_BACK; |
| 579 return true; | 579 return true; |
| 580 } | 580 } |
| 581 | 581 |
| 582 @Override | 582 @Override |
| 583 public boolean startCapture() { | 583 public boolean startCapture() { |
| 584 Log.d(TAG, "startCapture"); | 584 Log.d(TAG, "startCapture"); |
| 585 changeCameraStateAndNotify(CameraState.OPENING); | 585 changeCameraStateAndNotify(CameraState.OPENING); |
| 586 final CameraManager manager = | 586 final CameraManager manager = |
| 587 (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE
); | 587 (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE
); |
| 588 final Handler mainHandler = new Handler(mContext.getMainLooper()); | 588 |
| 589 if (!mUseBackgroundThreadForTesting) { |
| 590 mMainHandler = new Handler(mContext.getMainLooper()); |
| 591 } else { |
| 592 // Usually we deliver frames on |mContext|s thread, but unit tests |
| 593 // occupy its Looper; deliver frames on a background thread instead. |
| 594 HandlerThread thread = new HandlerThread("CameraPicture"); |
| 595 thread.start(); |
| 596 mMainHandler = new Handler(thread.getLooper()); |
| 597 } |
| 598 |
| 589 final CrStateListener stateListener = new CrStateListener(); | 599 final CrStateListener stateListener = new CrStateListener(); |
| 590 try { | 600 try { |
| 591 manager.openCamera(Integer.toString(mId), stateListener, mainHandler
); | 601 manager.openCamera(Integer.toString(mId), stateListener, mMainHandle
r); |
| 592 } catch (CameraAccessException | IllegalArgumentException | SecurityExce
ption ex) { | 602 } catch (CameraAccessException | IllegalArgumentException | SecurityExce
ption ex) { |
| 593 Log.e(TAG, "allocate: manager.openCamera: ", ex); | 603 Log.e(TAG, "allocate: manager.openCamera: ", ex); |
| 594 return false; | 604 return false; |
| 595 } | 605 } |
| 596 | 606 |
| 597 return true; | 607 return true; |
| 598 } | 608 } |
| 599 | 609 |
| 600 @Override | 610 @Override |
| 601 public boolean stopCapture() { | 611 public boolean stopCapture() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 616 } | 626 } |
| 617 | 627 |
| 618 try { | 628 try { |
| 619 mPreviewSession.abortCaptures(); | 629 mPreviewSession.abortCaptures(); |
| 620 } catch (CameraAccessException | IllegalStateException ex) { | 630 } catch (CameraAccessException | IllegalStateException ex) { |
| 621 Log.e(TAG, "abortCaptures: ", ex); | 631 Log.e(TAG, "abortCaptures: ", ex); |
| 622 return false; | 632 return false; |
| 623 } | 633 } |
| 624 if (mCameraDevice == null) return false; | 634 if (mCameraDevice == null) return false; |
| 625 mCameraDevice.close(); | 635 mCameraDevice.close(); |
| 636 |
| 637 if (mUseBackgroundThreadForTesting) mMainHandler.getLooper().quit(); |
| 638 |
| 626 changeCameraStateAndNotify(CameraState.STOPPED); | 639 changeCameraStateAndNotify(CameraState.STOPPED); |
| 627 mCropRect = new Rect(); | 640 mCropRect = new Rect(); |
| 628 return true; | 641 return true; |
| 629 } | 642 } |
| 630 | 643 |
| 631 public PhotoCapabilities getPhotoCapabilities() { | 644 public PhotoCapabilities getPhotoCapabilities() { |
| 632 final CameraCharacteristics cameraCharacteristics = getCameraCharacteris
tics(mContext, mId); | 645 final CameraCharacteristics cameraCharacteristics = getCameraCharacteris
tics(mContext, mId); |
| 633 PhotoCapabilities.Builder builder = new PhotoCapabilities.Builder(); | 646 PhotoCapabilities.Builder builder = new PhotoCapabilities.Builder(); |
| 634 | 647 |
| 635 int minIso = 0; | 648 int minIso = 0; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 return false; | 903 return false; |
| 891 } | 904 } |
| 892 return true; | 905 return true; |
| 893 } | 906 } |
| 894 | 907 |
| 895 @Override | 908 @Override |
| 896 public void deallocate() { | 909 public void deallocate() { |
| 897 Log.d(TAG, "deallocate"); | 910 Log.d(TAG, "deallocate"); |
| 898 } | 911 } |
| 899 } | 912 } |
| OLD | NEW |