Search in sources :

Example 76 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project platform_frameworks_base by android.

the class CameraDeviceImpl method setRemoteDevice.

/**
     * Set remote device, which triggers initial onOpened/onUnconfigured callbacks
     *
     * <p>This function may post onDisconnected and throw CAMERA_DISCONNECTED if remoteDevice dies
     * during setup.</p>
     *
     */
public void setRemoteDevice(ICameraDeviceUser remoteDevice) throws CameraAccessException {
    synchronized (mInterfaceLock) {
        // If setRemoteFailure already called, do nothing
        if (mInError)
            return;
        mRemoteDevice = new ICameraDeviceUserWrapper(remoteDevice);
        IBinder remoteDeviceBinder = remoteDevice.asBinder();
        // asBinder returns NULL.
        if (remoteDeviceBinder != null) {
            try {
                remoteDeviceBinder.linkToDeath(this, /*flag*/
                0);
            } catch (RemoteException e) {
                CameraDeviceImpl.this.mDeviceHandler.post(mCallOnDisconnected);
                throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "The camera device has encountered a serious error");
            }
        }
        mDeviceHandler.post(mCallOnOpened);
        mDeviceHandler.post(mCallOnUnconfigured);
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) IBinder(android.os.IBinder) RemoteException(android.os.RemoteException)

Example 77 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by DirtyUnicorns.

the class FlashlightController method getCameraId.

private String getCameraId() throws CameraAccessException {
    String[] ids = mCameraManager.getCameraIdList();
    for (String id : ids) {
        CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id);
        Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
        Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING);
        if (flashAvailable != null && flashAvailable && lensFacing != null && lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
            return id;
        }
    }
    return null;
}
Also used : CameraCharacteristics(android.hardware.camera2.CameraCharacteristics)

Example 78 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by DirtyUnicorns.

the class Camera2Source method onOpen.

@Override
protected void onOpen() {
    mLooperThread = new CameraTestThread();
    Handler mHandler;
    try {
        mHandler = mLooperThread.start();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    try {
        String backCameraId = "0";
        BlockingCameraManager blkManager = new BlockingCameraManager(mCameraManager);
        mCamera = blkManager.openCamera(backCameraId, /*listener*/
        null, mHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } catch (BlockingOpenException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    Element ele = Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV);
    rgbConverter = ScriptIntrinsicYuvToRGB.create(mRS, ele);
    Type.Builder yuvBuilder = new Type.Builder(mRS, ele);
    yuvBuilder.setYuvFormat(ImageFormat.YUV_420_888);
    yuvBuilder.setX(mWidth);
    yuvBuilder.setY(mHeight);
    mAllocationIn = Allocation.createTyped(mRS, yuvBuilder.create(), Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_INPUT);
    mSurface = mAllocationIn.getSurface();
    mAllocationIn.setOnBufferAvailableListener(this);
    rgbConverter.setInput(mAllocationIn);
    mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
    mAllocationOut = Allocation.createFromBitmap(mRS, mBitmap);
    Log.v(TAG, "mcamera: " + mCamera);
    List<Surface> surfaces = new ArrayList<Surface>();
    surfaces.add(mSurface);
    CaptureRequest.Builder mCaptureRequest = null;
    try {
        BlockingSessionCallback blkSession = new BlockingSessionCallback();
        mCamera.createCaptureSession(surfaces, blkSession, mHandler);
        mCaptureRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mCaptureRequest.addTarget(mSurface);
        mCameraSession = blkSession.waitAndGetSession(SESSION_TIMEOUT_MS);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    try {
        mCameraSession.setRepeatingRequest(mCaptureRequest.build(), new MyCaptureCallback(), mHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    mProperties = null;
    try {
        mProperties = mCameraManager.getCameraCharacteristics(mCamera.getId());
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) Element(android.renderscript.Element) ArrayList(java.util.ArrayList) Handler(android.os.Handler) BlockingCameraManager(com.android.ex.camera2.blocking.BlockingCameraManager) BlockingOpenException(com.android.ex.camera2.blocking.BlockingCameraManager.BlockingOpenException) CameraAccessException(android.hardware.camera2.CameraAccessException) Surface(android.view.Surface) CameraAccessException(android.hardware.camera2.CameraAccessException) Type(android.renderscript.Type) FrameType(androidx.media.filterfw.FrameType) BlockingOpenException(com.android.ex.camera2.blocking.BlockingCameraManager.BlockingOpenException) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 79 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project AndroidDevelop by 7449.

the class Camera2 method chooseCameraIdByFacing.

/**
     * <p>Chooses a camera ID by the specified camera facing ({@link #mFacing}).</p>
     * <p>This rewrites {@link #mCameraId}, {@link #mCameraCharacteristics}, and optionally
     * {@link #mFacing}.</p>
     */
private void chooseCameraIdByFacing() {
    try {
        int internalFacing = INTERNAL_FACINGS.get(mFacing);
        final String[] ids = mCameraManager.getCameraIdList();
        for (String id : ids) {
            CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(id);
            Integer internal = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (internal == null) {
                throw new NullPointerException("Unexpected state: LENS_FACING null");
            }
            if (internal == internalFacing) {
                mCameraId = id;
                mCameraCharacteristics = characteristics;
                return;
            }
        }
        // Not found
        mCameraId = ids[0];
        mCameraCharacteristics = mCameraManager.getCameraCharacteristics(mCameraId);
        Integer internal = mCameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
        if (internal == null) {
            throw new NullPointerException("Unexpected state: LENS_FACING null");
        }
        for (int i = 0, count = INTERNAL_FACINGS.size(); i < count; i++) {
            if (INTERNAL_FACINGS.valueAt(i) == internal) {
                mFacing = INTERNAL_FACINGS.keyAt(i);
                return;
            }
        }
        // The operation can reach here when the only camera device is an external one.
        // We treat it as facing back.
        mFacing = Constants.FACING_BACK;
    } catch (CameraAccessException e) {
        throw new RuntimeException("Failed to get a list of camera devices", e);
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics)

Example 80 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by DirtyUnicorns.

the class CameraManager method getCameraCharacteristics.

/**
     * <p>Query the capabilities of a camera device. These capabilities are
     * immutable for a given camera.</p>
     *
     * @param cameraId The id of the camera device to query
     * @return The properties of the given camera
     *
     * @throws IllegalArgumentException if the cameraId does not match any
     *         known camera device.
     * @throws CameraAccessException if the camera device has been disconnected.
     *
     * @see #getCameraIdList
     * @see android.app.admin.DevicePolicyManager#setCameraDisabled
     */
@NonNull
public CameraCharacteristics getCameraCharacteristics(@NonNull String cameraId) throws CameraAccessException {
    CameraCharacteristics characteristics = null;
    synchronized (mLock) {
        if (!getOrCreateDeviceIdListLocked().contains(cameraId)) {
            throw new IllegalArgumentException(String.format("Camera id %s does not match any" + " currently connected camera device", cameraId));
        }
        int id = Integer.parseInt(cameraId);
        /*
             * Get the camera characteristics from the camera service directly if it supports it,
             * otherwise get them from the legacy shim instead.
             */
        ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
        if (cameraService == null) {
            throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "Camera service is currently unavailable");
        }
        try {
            if (!supportsCamera2ApiLocked(cameraId)) {
                // Legacy backwards compatibility path; build static info from the camera
                // parameters
                String parameters = cameraService.getLegacyParameters(id);
                CameraInfo info = cameraService.getCameraInfo(id);
                characteristics = LegacyMetadataMapper.createCharacteristics(parameters, info);
            } else {
                // Normal path: Get the camera characteristics directly from the camera service
                CameraMetadataNative info = cameraService.getCameraCharacteristics(id);
                characteristics = new CameraCharacteristics(info);
            }
        } catch (ServiceSpecificException e) {
            throwAsPublicException(e);
        } catch (RemoteException e) {
            // Camera service died - act as if the camera was disconnected
            throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "Camera service is currently unavailable", e);
        }
    }
    return characteristics;
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) RemoteException(android.os.RemoteException) ICameraService(android.hardware.ICameraService) CameraInfo(android.hardware.CameraInfo) NonNull(android.annotation.NonNull)

Aggregations

ArrayList (java.util.ArrayList)50 Surface (android.view.Surface)42 OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)40 CameraAccessException (android.hardware.camera2.CameraAccessException)35 CaptureRequest (android.hardware.camera2.CaptureRequest)35 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)25 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)21 RemoteException (android.os.RemoteException)15 BlockingSessionCallback (com.android.ex.camera2.blocking.BlockingSessionCallback)14 CameraCaptureSession (android.hardware.camera2.CameraCaptureSession)12 Size (android.util.Size)11 ICameraService (android.hardware.ICameraService)10 CaptureCallback (android.hardware.camera2.CameraCaptureSession.CaptureCallback)10 CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)10 ServiceSpecificException (android.os.ServiceSpecificException)10 CameraManager (android.hardware.camera2.CameraManager)6 NonNull (android.annotation.NonNull)5 CameraInfo (android.hardware.CameraInfo)5 InputConfiguration (android.hardware.camera2.params.InputConfiguration)5 SubmitInfo (android.hardware.camera2.utils.SubmitInfo)5