Example usage for android.hardware.camera2 CameraMetadata CONTROL_AE_PRECAPTURE_TRIGGER_START

List of usage examples for android.hardware.camera2 CameraMetadata CONTROL_AE_PRECAPTURE_TRIGGER_START

Introduction

In this page you can find the example usage for android.hardware.camera2 CameraMetadata CONTROL_AE_PRECAPTURE_TRIGGER_START.

Prototype

int CONTROL_AE_PRECAPTURE_TRIGGER_START

To view the source code for android.hardware.camera2 CameraMetadata CONTROL_AE_PRECAPTURE_TRIGGER_START.

Click Source Link

Document

The precapture metering sequence will be started by the camera device.

The exact effect of the precapture trigger depends on the current AE mode and state.

Usage

From source file:com.example.aschere.cdhprototype2.Camera2RawFragment.java

/**
 * Initiate a still image capture.//from   w w  w .j av  a  2s .c  o m
 * <p/>
 * This function sends a capture request that initiates a pre-capture sequence in our state
 * machine that waits for auto-focus to finish, ending in a "locked" state where the lens is no
 * longer moving, waits for auto-exposure to choose a good exposure value, and waits for
 * auto-white-balance to converge.
 */
public String takePicture() {
    synchronized (mCameraStateLock) {
        mPendingUserCaptures++;

        Log.i("fragmentTakePicture", "Take Picture called!");
        // If we already triggered a pre-capture sequence, or are in a state where we cannot
        // do this, return immediately.
        /*if (mState != STATE_PREVIEW) {
           Log.w(TAG, "return immediately");
        return null;
        }*/
        setUpCameraOutputs();
        openCamera();
        startBackgroundThread();

        try {
            Log.i(TAG, "inside try");

            if (mPreviewRequestBuilder == null) {
                Log.i(TAG, "Have to create preview request builder");
                if (mCameraDevice == null) {
                    Log.w(TAG, "Camera device not opened?");
                    setUpCameraOutputs();
                    openCamera();
                }
                createCameraPreviewSessionLocked();
            }
            // Update state machine to wait for auto-focus, auto-exposure, and
            // auto-white-balance (aka. "3A") to converge.
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_START);
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                    CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);
            mState = STATE_WAITING_FOR_3A_CONVERGENCE;

            // Start a timer for the pre-capture sequence.
            startTimerLocked();

            // Replace the existing repeating request with one with updated 3A triggers.
            mCaptureSession.capture(mPreviewRequestBuilder.build(), mPreCaptureCallback, mBackgroundHandler);
            //closeCamera();
            int count = 0;
            while (!imageReturnable) {
                count++;
            }
            Log.i(TAG, "Image acquired!" + count);
            imageReturnable = false;
            return imageToReturn;
        } catch (CameraAccessException e) {
            e.printStackTrace();
        } finally {
            closeCamera();
        }
        return null;
    }
}

From source file:com.ape.camera2raw.Camera2RawFragment.java

/**
 * Initiate a still image capture.//ww  w . ja va 2  s. co  m
 * <p/>
 * This function sends a capture request that initiates a pre-capture sequence in our state
 * machine that waits for auto-focus to finish, ending in a "locked" state where the lens is no
 * longer moving, waits for auto-exposure to choose a good exposure value, and waits for
 * auto-white-balance to converge.
 */
private void takePicture() {
    synchronized (mCameraStateLock) {
        mPendingUserCaptures++;

        // If we already triggered a pre-capture sequence, or are in a state where we cannot
        // do this, return immediately.
        if (mState != STATE_PREVIEW) {
            return;
        }

        try {
            // Trigger an auto-focus run if camera is capable. If the camera is already focused,
            // this should do nothing.
            if (!mNoAFRun) {
                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                        CameraMetadata.CONTROL_AF_TRIGGER_START);
            }

            // If this is not a legacy device, we can also trigger an auto-exposure metering
            // run.
            if (!isLegacyLocked()) {
                // Tell the camera to lock focus.
                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                        CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);
            }

            // Update state machine to wait for auto-focus, auto-exposure, and
            // auto-white-balance (aka. "3A") to converge.
            mState = STATE_WAITING_FOR_3A_CONVERGENCE;

            // Start a timer for the pre-capture sequence.
            startTimerLocked();

            // Replace the existing repeating request with one with updated 3A triggers.
            mCaptureSession.capture(mPreviewRequestBuilder.build(), mPreCaptureCallback, mBackgroundHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
}