@Override void setAutoFocus(boolean autoFocus) { if (mAutoFocus == autoFocus) { return; } mAutoFocus = autoFocus; if (mPreviewRequestBuilder != null) { updateAutoFocus(); if (mCaptureSession != null) { try { mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, null); } catch (CameraAccessException e) { mAutoFocus = !mAutoFocus; // Revert } } } }
@Override void stop() { if (mCaptureSession != null) { mCaptureSession.close(); mCaptureSession = null; } if (mCamera != null) { mCamera.close(); mCamera = null; } if (mImageReader != null) { mImageReader.close(); mImageReader = null; } }
private void unlockFocus() { try { previewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); captureSession.capture(previewRequestBuilder.build(), captureCallback, backgroundHandler); previewState = STATE_PREVIEW; captureSession.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler); } catch (Exception e) { Log.e(TAG, "Error during focus unlocking"); } }
private void closePreviewSession() { if (captureSession != null) { captureSession.close(); try { captureSession.abortCaptures(); } catch (Exception ignore) { } finally { captureSession = null; } } }
mCaptureSession.stopRepeating(); mCaptureSession.abortCaptures(); mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null); } catch (CameraAccessException e) { e.printStackTrace();
/** * Locks the focus as the first step for a still image capture. */ private void lockFocus() { mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START); try { mCaptureCallback.setState(PictureCaptureCallback.STATE_LOCKING); mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, null); } catch (CameraAccessException e) { Log.e(TAG, "Failed to lock focus.", e); } }
private void captureStillPicture() { try { if (null == cameraDevice) { return; } final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); captureBuilder.addTarget(imageReader.getSurface()); captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getPhotoOrientation(configurationProvider.getSensorPosition())); CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() { @Override public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) { Log.d(TAG, "onCaptureCompleted: "); } }; captureSession.stopRepeating(); captureSession.capture(captureBuilder.build(), CaptureCallback, null); } catch (CameraAccessException e) { Log.e(TAG, "Error during capturing picture"); } }
private void prepareFaceDetectionCallback() { try { cameraCaptureSession.stopRepeating(); if (builderPreview != null) { cameraCaptureSession.setRepeatingRequest(builderPreview.build(), faceDetectionEnabled ? cb : null, null); } cameraCaptureSession.setRepeatingRequest(builderInputSurface.build(), faceDetectionEnabled ? cb : null, null); } catch (CameraAccessException e) { Log.e(TAG, "Error", e); } }
/** * close camera when not in use/pausing/leaving */ public void closeCamera() { try { mCameraOpenCloseLock.acquire(); if (null != mCameraDevice) { mPreviewSession.stopRepeating(); mCameraDevice.close(); mCameraDevice = null; mCameraIsOpen = false; } } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera closing."); } catch (CameraAccessException acex) { Log.e(TAG, "Failed to stop repeaing preview request", acex); } finally { mCameraOpenCloseLock.release(); } }
private void runPreCaptureSequence() { try { previewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START); previewState = STATE_WAITING_PRE_CAPTURE; captureSession.capture(previewRequestBuilder.build(), captureCallback, backgroundHandler); } catch (CameraAccessException e) { } }
360) % 360); mCaptureSession.stopRepeating(); mCaptureSession.capture(captureRequestBuilder.build(), new CameraCaptureSession.CaptureCallback() { @Override
private void closePreviewSession() { if (mCaptureSession != null) { mCaptureSession.close(); try { mCaptureSession.abortCaptures(); } catch (Exception ignore) { } finally { mCaptureSession = null; } } }
@Override void setFlash(int flash) { if (mFlash == flash) { return; } int saved = mFlash; mFlash = flash; if (mPreviewRequestBuilder != null) { updateFlash(); if (mCaptureSession != null) { try { mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, null); } catch (CameraAccessException e) { mFlash = saved; // Revert } } } }
@Override void stop() { if (mCaptureSession != null) { mCaptureSession.close(); mCaptureSession = null; } if (mCamera != null) { mCamera.close(); mCamera = null; } if (mImageReader != null) { mImageReader.close(); mImageReader = null; } }
/** * Unlock the focus. This method should be called when still image capture sequence is * finished. */ private void unlockFocus() { try { // Reset the auto-focus trigger mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); setAutoFlash(mPreviewRequestBuilder); mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler); // After this, the camera will go back to the normal state of preview. mState = STATE_PREVIEW; mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } }
private void lockFocus() { try { previewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START); previewState = STATE_WAITING_LOCK; captureSession.capture(previewRequestBuilder.build(), captureCallback, backgroundHandler); } catch (Exception ignore) { } }
360) % 360); mCaptureSession.stopRepeating(); mCaptureSession.capture(captureRequestBuilder.build(), new CameraCaptureSession.CaptureCallback() { @Override
@Override void setAutoFocus(boolean autoFocus) { if (mAutoFocus == autoFocus) { return; } mAutoFocus = autoFocus; if (mPreviewRequestBuilder != null) { updateAutoFocus(); if (mCaptureSession != null) { try { mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, null); } catch (CameraAccessException e) { mAutoFocus = !mAutoFocus; // Revert } } } }
/** * Closes the current {@link CameraDevice}. */ private void closeCamera() { try { mCameraOpenCloseLock.acquire(); if (null != mCaptureSession) { mCaptureSession.close(); mCaptureSession = null; } if (null != mCameraDevice) { mCameraDevice.close(); mCameraDevice = null; } if (null != mImageReader) { mImageReader.close(); mImageReader = null; } } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera closing.", e); } finally { mCameraOpenCloseLock.release(); } }
/** * Unlocks the auto-focus and restart camera preview. This is supposed to be called after * capturing a still picture. */ void unlockFocus() { mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_CANCEL); try { mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, null); updateAutoFocus(); updateFlash(); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_IDLE); mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, null); mCaptureCallback.setState(PictureCaptureCallback.STATE_PREVIEW); } catch (CameraAccessException e) { Log.e(TAG, "Failed to restart camera preview.", e); } }