Search in sources :

Example 96 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project android_packages_apps_Dialer by LineageOS.

the class InCallCameraManager method maybeInitializeCameraList.

/**
 * Get the list of cameras available for use.
 *
 * @param context The context.
 */
private void maybeInitializeCameraList(Context context) {
    if (mIsInitialized || context == null) {
        return;
    }
    Log.v(this, "initializeCameraList");
    CameraManager cameraManager = null;
    try {
        cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    } catch (Exception e) {
        Log.e(this, "Could not get camera service.");
        return;
    }
    if (cameraManager == null) {
        return;
    }
    String[] cameraIds = {};
    try {
        cameraIds = cameraManager.getCameraIdList();
    } catch (CameraAccessException e) {
        Log.d(this, "Could not access camera: " + e);
        // Camera disabled by device policy.
        return;
    }
    for (int i = 0; i < cameraIds.length; i++) {
        CameraCharacteristics c = null;
        try {
            c = cameraManager.getCameraCharacteristics(cameraIds[i]);
        } catch (IllegalArgumentException e) {
        // Device Id is unknown.
        } catch (CameraAccessException e) {
        // Camera disabled by device policy.
        }
        if (c != null) {
            int facingCharacteristic = c.get(CameraCharacteristics.LENS_FACING);
            if (facingCharacteristic == CameraCharacteristics.LENS_FACING_FRONT) {
                mFrontFacingCameraId = cameraIds[i];
            } else if (facingCharacteristic == CameraCharacteristics.LENS_FACING_BACK) {
                mRearFacingCameraId = cameraIds[i];
            }
        }
    }
    mIsInitialized = true;
    Log.v(this, "initializeCameraList : done");
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) CameraManager(android.hardware.camera2.CameraManager) CameraAccessException(android.hardware.camera2.CameraAccessException)

Example 97 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project android_packages_apps_Snap by LineageOS.

the class ClearSightImageProcessor method init.

public void init(StreamConfigurationMap map, int width, int height, Context context, OnMediaSavedListener mediaListener) {
    Log.d(TAG, "init() start");
    mIsClosing = false;
    mImageProcessThread = new HandlerThread("CameraImageProcess");
    mImageProcessThread.start();
    mClearsightRegisterThread = new HandlerThread("ClearsightRegister");
    mClearsightRegisterThread.start();
    mClearsightProcessThread = new HandlerThread("ClearsightProcess");
    mClearsightProcessThread.start();
    mImageEncodeThread = new HandlerThread("CameraImageEncode");
    mImageEncodeThread.start();
    mDepthProcessThread = new HandlerThread("DepthProcess");
    mDepthProcessThread.start();
    mImageProcessHandler = new ImageProcessHandler(mImageProcessThread.getLooper());
    mClearsightRegisterHandler = new ClearsightRegisterHandler(mClearsightRegisterThread.getLooper());
    mClearsightProcessHandler = new ClearsightProcessHandler(mClearsightProcessThread.getLooper());
    mImageEncodeHandler = new ImageEncodeHandler(mImageEncodeThread.getLooper());
    mDepthProcessHandler = new DepthProcessHandler(mImageEncodeThread.getLooper());
    mFinalPictureSize = new Size(width, height);
    mFinalPictureRatio = (float) width / (float) height;
    mFinalMonoSize = getFinalMonoSize();
    Size maxSize = findMaxOutputSize(map);
    int maxWidth = maxSize.getWidth();
    int maxHeight = maxSize.getHeight();
    mImageReader[CAM_TYPE_BAYER] = createImageReader(CAM_TYPE_BAYER, maxWidth, maxHeight);
    mImageReader[CAM_TYPE_MONO] = createImageReader(CAM_TYPE_MONO, maxWidth, maxHeight);
    mEncodeImageReader[CAM_TYPE_BAYER] = createEncodeImageReader(CAM_TYPE_BAYER, maxWidth, maxHeight);
    mEncodeImageReader[CAM_TYPE_MONO] = createEncodeImageReader(CAM_TYPE_MONO, maxWidth, maxHeight);
    mMediaSavedListener = mediaListener;
    CameraManager cm = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    try {
        CameraCharacteristics cc = cm.getCameraCharacteristics("0");
        byte[] blob = cc.get(OTP_CALIB_BLOB);
        CamSystemCalibrationData calibrationData = CamSystemCalibrationData.createFromBytes(blob);
        ClearSightNativeEngine.getInstance().init(mNumFrameCount * 2, maxWidth, maxHeight, calibrationData);
        mDepthProcessHandler.obtainMessage(MSG_CALIBRATION_DATA, 0, 0, calibrationData).sendToTarget();
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
    Log.d(TAG, "init() done");
}
Also used : CamSystemCalibrationData(org.codeaurora.snapcam.filter.ClearSightNativeEngine.CamSystemCalibrationData) Size(android.util.Size) CameraManager(android.hardware.camera2.CameraManager) CameraAccessException(android.hardware.camera2.CameraAccessException) HandlerThread(android.os.HandlerThread) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics)

Example 98 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project android_packages_apps_Dialer by MoKee.

the class InCallCameraManager method maybeInitializeCameraList.

/**
 * Get the list of cameras available for use.
 *
 * @param context The context.
 */
private void maybeInitializeCameraList(Context context) {
    if (mIsInitialized || context == null) {
        return;
    }
    Log.v(this, "initializeCameraList");
    CameraManager cameraManager = null;
    try {
        cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    } catch (Exception e) {
        Log.e(this, "Could not get camera service.");
        return;
    }
    if (cameraManager == null) {
        return;
    }
    String[] cameraIds = {};
    try {
        cameraIds = cameraManager.getCameraIdList();
    } catch (CameraAccessException e) {
        Log.d(this, "Could not access camera: " + e);
        // Camera disabled by device policy.
        return;
    }
    for (int i = 0; i < cameraIds.length; i++) {
        CameraCharacteristics c = null;
        try {
            c = cameraManager.getCameraCharacteristics(cameraIds[i]);
        } catch (IllegalArgumentException e) {
        // Device Id is unknown.
        } catch (CameraAccessException e) {
        // Camera disabled by device policy.
        }
        if (c != null) {
            int facingCharacteristic = c.get(CameraCharacteristics.LENS_FACING);
            if (facingCharacteristic == CameraCharacteristics.LENS_FACING_FRONT) {
                mFrontFacingCameraId = cameraIds[i];
            } else if (facingCharacteristic == CameraCharacteristics.LENS_FACING_BACK) {
                mRearFacingCameraId = cameraIds[i];
            }
        }
    }
    mIsInitialized = true;
    Log.v(this, "initializeCameraList : done");
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) CameraManager(android.hardware.camera2.CameraManager) String(java.lang.String) CameraAccessException(android.hardware.camera2.CameraAccessException)

Example 99 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project android_packages_apps_Dialer by MoKee.

the class InCallZoomController method isCameraZoomSupported.

/**
 * Queries the camera characteristics to figure out if zoom is supported or not
 */
private boolean isCameraZoomSupported() {
    try {
        final InCallCameraManager inCallCameraManager = mInCallPresenter.getInCallCameraManager();
        final float CAMERA_ZOOM_NOT_SUPPORTED = 1.0f;
        CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(inCallCameraManager.getActiveCameraId());
        return (characteristics != null) && (characteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM) > CAMERA_ZOOM_NOT_SUPPORTED);
    } catch (Exception e) {
        Log.e(this, "isCameraZoomSupported: Failed to retrieve Max Zoom, " + e);
        return false;
    }
}
Also used : CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) CameraAccessException(android.hardware.camera2.CameraAccessException)

Example 100 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project OpenCamera by ageback.

the class CameraControllerManager2 method isFrontFacing.

@Override
public boolean isFrontFacing(int cameraId) {
    CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    try {
        String cameraIdS = manager.getCameraIdList()[cameraId];
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraIdS);
        return characteristics.get(CameraCharacteristics.LENS_FACING) == CameraMetadata.LENS_FACING_FRONT;
    } catch (Throwable e) {
        // back to old camera API.
        if (MyDebug.LOG)
            Log.e(TAG, "exception trying to get camera characteristics");
        e.printStackTrace();
    }
    return false;
}
Also used : CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) CameraManager(android.hardware.camera2.CameraManager)

Aggregations

CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)104 CameraAccessException (android.hardware.camera2.CameraAccessException)42 CameraManager (android.hardware.camera2.CameraManager)37 Size (android.util.Size)37 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)29 Camera (android.hardware.Camera)25 Rect (android.graphics.Rect)20 CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)20 CaptureRequest (android.hardware.camera2.CaptureRequest)18 Parameters (android.hardware.Camera.Parameters)15 ArrayList (java.util.ArrayList)13 ZoomData (android.hardware.camera2.legacy.ParameterUtils.ZoomData)10 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)10 ServiceSpecificException (android.os.ServiceSpecificException)10 Range (android.util.Range)10 Point (android.graphics.Point)8 NonNull (android.annotation.NonNull)6 Activity (android.app.Activity)5 CameraInfo (android.hardware.Camera.CameraInfo)5 CameraInfo (android.hardware.CameraInfo)5