/** * 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(); } }
/** * 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); if(mFlashSupported) { mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, mFlashMode); } 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 switchHdrMode() { switch (mHdrMode) { case 0: mHdrMode = 1; mIvHdr.setImageResource(R.mipmap.hdr_on); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_HDR); break; case 1: mHdrMode = 0; mIvHdr.setImageResource(R.mipmap.hdr_off); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_DISABLED); break; } try { mCaptureSession.setRepeatingRequest( mPreviewRequestBuilder.build(), mPreCaptureCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); return; } }
/** * Called after a RAW/JPEG capture has completed; resets the AF trigger state for the * pre-capture sequence. * <p/> * Call this only with {@link #mCameraStateLock} held. */ private void finishedCaptureLocked() { try { // Reset the auto-focus trigger in case AF didn't run quickly enough. if (!mNoAFRun) { mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); mCaptureSession.capture(mPreviewRequestBuilder.build(), mPreCaptureCallback, mBackgroundHandler); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_IDLE); } } catch (CameraAccessException e) { e.printStackTrace(); } }
private void start() { checkIsOnCameraThread(); Logging.d(TAG, "start"); try { cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId); } catch (final CameraAccessException e) { reportError("getCameraCharacteristics(): " + e.getMessage()); return; } cameraOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); isCameraFrontFacing = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING) == CameraMetadata.LENS_FACING_FRONT; findCaptureFormat(); openCamera(); }
/** * 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); mPreviewSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler); updateAutoFocus(); updateFlash(mPreviewRequestBuilder); // After this, the camera will go back to the normal state of preview. mState = STATE_PREVIEW; mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_IDLE); mPreviewSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } }
private void doPreviewConfiguration() { if (mCamera == null) { return; } try { // mPreviewBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); // mPreviewBuilder.addTarget(surfaceView.getHolder().getSurface()); // mPreviewBuilder.addTarget(mImageReader.getSurface()); mPreviewBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); // mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO); // mPreviewBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF); // mPreviewBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); mPreviewBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, mFps[mFps.length -1 ]); mCaptureSession.setRepeatingRequest(mPreviewBuilder.build(), mPreCaptureCallback, mHandler); } catch (CameraAccessException e) { e.printStackTrace(); } }
@Override public void onOpened(@NonNull CameraDevice camera) { mCameraDevice = camera; //get builder try { mBuilder = camera.createCaptureRequest(CameraDevice.TEMPLATE_MANUAL); //flash on, default is on mBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AF_MODE_AUTO); mBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH); List<Surface> list = new ArrayList<>(); SurfaceTexture mSurfaceTexture = new SurfaceTexture(1); Size size = getSmallestSize(mCameraDevice.getId()); mSurfaceTexture.setDefaultBufferSize(size.getWidth(), size.getHeight()); Surface mSurface = new Surface(mSurfaceTexture); list.add(mSurface); mBuilder.addTarget(mSurface); camera.createCaptureSession(list, new MyCameraCaptureSessionStateCallback(), null); mSurfaceTexture.release(); } catch (CameraAccessException e) { e.printStackTrace(); } }
/** * Lock the focus as the first step for a still image capture. */ private void lockFocus() { try { // This is how to tell the camera to lock focus. mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START); // Tell #mCaptureCallback to wait for the lock. mState = STATE_WAITING_LOCK; mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler); } catch(CameraAccessException e) { LogExt.e(getClass(), e); } }
/** * 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) { LogExt.e(getClass(), e); LogExt.e(getClass(), e); } }
private void unlockFocus() { try { // AFのロックを解除する(トリガーをキャンセルする) mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH); // AFトリガーのキャンセルを実行する mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mInterface.getBackgroundHandler()); // プレビューを継続するためsetRepeatingRequestメソッドを実行する mState = STATE_PREVIEW; mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mInterface.getBackgroundHandler()); } catch (CameraAccessException e) { e.printStackTrace(); } }
/** * Generate a human-readable string of the given capture request and write * it to the given file. */ public static void toFile(String title, CameraMetadata<?> metadata, File file) { try { // Will append if the file already exists. FileWriter writer = new FileWriter(file, true); if (metadata instanceof CaptureRequest) { dumpMetadata(title, (CaptureRequest) metadata, writer); } else if (metadata instanceof CaptureResult) { dumpMetadata(title, (CaptureResult) metadata, writer); } else { writer.close(); throw new IllegalArgumentException("Cannot generate debug data from type " + metadata.getClass().getName()); } writer.close(); } catch (IOException ex) { Log.e(TAG, "Could not write capture data to file.", ex); } }
/** * Request preview capture stream with AF_MODE_CONTINUOUS_PICTURE. * * @return true if request was build and sent successfully. * @param tag */ private boolean repeatingPreview(Object tag) { try { CaptureRequest.Builder builder = mDevice. createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); builder.addTarget(mPreviewSurface); builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); addBaselineCaptureKeysToRequest(builder); mCaptureSession.setRepeatingRequest(builder.build(), mAutoFocusStateListener, mCameraHandler); Log.v(TAG, String.format("Sent repeating Preview request, zoom = %.2f", mZoomValue)); return true; } catch (CameraAccessException ex) { Log.e(TAG, "Could not access camera setting up preview.", ex); return false; } }
/** * Request preview capture stream with auto focus trigger cycle. */ private void sendAutoFocusTriggerCaptureRequest(Object tag) { try { // Step 1: Request single frame CONTROL_AF_TRIGGER_START. CaptureRequest.Builder builder; builder = mDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); builder.addTarget(mPreviewSurface); builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); mControlAFMode = CameraMetadata.CONTROL_AF_MODE_AUTO; addBaselineCaptureKeysToRequest(builder); builder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START); builder.setTag(tag); mCaptureSession.capture(builder.build(), mAutoFocusStateListener, mCameraHandler); // Step 2: Call repeatingPreview to update mControlAFMode. repeatingPreview(tag); resumeContinuousAFAfterDelay(FOCUS_HOLD_MILLIS); } catch (CameraAccessException ex) { Log.e(TAG, "Could not execute preview request.", ex); } }
static int getCaptureApiType(int id) { final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(id); if (cameraCharacteristics == null) { return VideoCaptureApi.UNKNOWN; } final int supportedHWLevel = cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); switch (supportedHWLevel) { case CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY: return VideoCaptureApi.ANDROID_API2_LEGACY; case CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_FULL: return VideoCaptureApi.ANDROID_API2_FULL; case CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED: return VideoCaptureApi.ANDROID_API2_LIMITED; default: return VideoCaptureApi.ANDROID_API2_LEGACY; } }
private void lockFocus() { try { if (mAfAvailable) { // This is how to tell the camera to lock focus. mPreviewBuilder.set( CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START); // Tell #mCaptureCallback to wait for the lock. mState = STATE_WAITING_LOCK; } else { runPrecaptureSequence(); return; } setFlashMode(mPreviewBuilder); mPreviewSession.capture(mPreviewBuilder.build(), mCaptureCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } }
private void setFlashMode(CaptureRequest.Builder requestBuilder) { mPreviewBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); int aeMode; int flashMode; switch (mInterface.getFlashMode()) { case FLASH_MODE_AUTO: aeMode = CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH; flashMode = CameraMetadata.FLASH_MODE_SINGLE; break; case FLASH_MODE_ALWAYS_ON: aeMode = CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH; flashMode = CameraMetadata.FLASH_MODE_TORCH; break; case FLASH_MODE_OFF: default: aeMode = CaptureRequest.CONTROL_AE_MODE_ON; flashMode = CameraMetadata.FLASH_MODE_OFF; break; } requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, aeMode); requestBuilder.set(CaptureRequest.FLASH_MODE, flashMode); }
/** * Unlock the focus. This method should be called when still image capture sequence is finished. */ private void unlockFocus() { try { // Reset the autofucos trigger mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH); 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(); } }
/** * Lock the focus as the first step for a still image capture. */ private void lockFocus() { Log.d(TAG, "lockFocus: "); try { // This is how to tell the camera to lock focus. mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START); // Tell #mCaptureCallback to wait for the lock. mState = STATE_WAITING_LOCK; mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler); } catch (CameraAccessException e) { Log.e(TAG, "CameraAccessException: " + e); e.printStackTrace(); } }
/** * Unlock the focus. This method should be called when still image capture sequence is finished. */ private void unlockFocus() { Log.d(TAG, "unlockFocus: "); try { if (mEnabledAutoFocus) { // Reset the autofucos trigger mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH); } 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(); } }
/************************************************************************************************ * Unlock the focus. This method should be called when still image capture sequence is finished. ************************************************************************************************/ @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void unlockFocus() { try { // Reset the autofucos trigger mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH); 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(); } }
/** * Reconfigure the camera with new flash and focus settings. */ private void reconfigureCamera() { if (mCameraDevice != null && mCaptureSession != null) { try { mCaptureSession.stopRepeating(); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler); doPreviewConfiguration(); } catch (CameraAccessException | IllegalStateException e) { mCameraCallback.onCameraError("Failed to reconfigure the camera", "rec1", e); } } }
/** * Lock the focus as the first step for a still image capture. */ private void lockFocus() { try { Log.d(TAG, "lockFocus: "); // This is how to tell the camera to lock focus. mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START); // Tell #mCaptureCallback to wait for the lock. // mState = STATE_WAITING_LOCK; mCaptureSession.capture(mPreviewRequestBuilder.build(), 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) { } }
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"); } }