Example usage for android.hardware.camera2 CaptureRequest CONTROL_AE_PRECAPTURE_TRIGGER

List of usage examples for android.hardware.camera2 CaptureRequest CONTROL_AE_PRECAPTURE_TRIGGER

Introduction

In this page you can find the example usage for android.hardware.camera2 CaptureRequest CONTROL_AE_PRECAPTURE_TRIGGER.

Prototype

Key CONTROL_AE_PRECAPTURE_TRIGGER

To view the source code for android.hardware.camera2 CaptureRequest CONTROL_AE_PRECAPTURE_TRIGGER.

Click Source Link

Document

Whether the camera device will trigger a precapture metering sequence when it processes this request.

This entry is normally set to IDLE, or is not included at all in the request settings.

Usage

From source file:com.example.camera2apidemo.Camera2Fragment.java

private void runPrecaptureSequence() {
    try {/*from  w w w . j  av a2 s .  c  om*/
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);

        CameraCaptureSession.CaptureCallback mPrecaptureCallback = new CameraCaptureSession.CaptureCallback() {
            @Override
            public void onCaptureProgressed(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull CaptureResult partialResult) {
                Integer aeState = partialResult.get(CaptureResult.CONTROL_AE_STATE);
                if (aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE
                        || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
                    mState = STATE_WAITING_NON_PRECAPTURE;
                }
            }

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                if (mState == STATE_WAITING_NON_PRECAPTURE) {
                    Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
                    if (aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
                        mState = STATE_PICTURE_TAKEN;
                        captureStillPicture();
                    }
                }

            }
        };
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mPrecaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.example.android.learnmore.Camera2BasicFragment.java

private void runPrecaptureSequence() {
    try {//  www.  j a v a  2  s. c o m
        // This is how to tell the camera to trigger.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the precapture sequence to be set.
        mState = STATE_WAITING_PRECAPTURE;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:info.staticfree.mqtt_camera.fragment.CameraFragment.java

/**
 * Run the precapture sequence for capturing a still image. This method should be called when
 * we get a response in {@link #captureCallback} from {@link #lockFocus()}.
 *//*from  www  .ja v a 2  s  .  com*/
private void runPrecaptureSequence() {
    try {
        // This is how to tell the camera to trigger.
        previewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        // Tell #captureCallback to wait for the precapture sequence to be set.
        state = STATE_WAITING_PRECAPTURE;
        captureSession.capture(previewRequestBuilder.build(), captureCallback, backgroundHandler);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Error running pre-capture sequence", e);
    }
}

From source file:org.odk.collect.android.fragments.Camera2Fragment.java

/**
 * Run the precapture sequence for capturing a still image. This method should be called when
 * we get a response in {@link #captureCallback} from {@link #lockFocus()}.
 *///from   www  .  j av  a  2 s  .co  m
private void runPrecaptureSequence() {
    try {
        // This is how to tell the camera to trigger.
        previewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        // Tell #captureCallback to wait for the precapture sequence to be set.
        state = STATE_WAITING_PRECAPTURE;
        captureSession.capture(previewRequestBuilder.build(), captureCallback, backgroundHandler);
    } catch (CameraAccessException e) {
        Timber.e(e);
    }
}

From source file:camera2basic.Camera2BasicFragment.java

/**
 * Run the precapture sequence for capturing a still image. This method should be called when
 * we get a response in {@link #mCaptureCallback} from {@link #lockFocus()}.
 *///from  w w w .jav a 2 s  .c  om
private void runPrecaptureSequence() {
    try {
        // This is how to tell the camera to trigger.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the precapture sequence to be set.
        mState = STATE_WAITING_PRECAPTURE;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.visualnavigate.CameraFragment.java

/**
 * Run the precapture sequence for capturing a still image. This method should be called when
 * we get a response in {@link #mCaptureCallback} from {@link #lockFocus()}.
 *//*from   www  .  j a  v  a 2s .  c om*/
private void runPrecaptureSequence() {
    try {
        // This is how to tell the camera to trigger.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);

        // Tell #mCaptureCallback to wait for the precapture sequence to be set.
        mState = STATE_WAITING_PRECAPTURE;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);

    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.example.administrator.testscreenrecording.control.StreamingCamera2Fragment.java

/**
 * Run the precapture sequence for capturing a still image. This method should be called when
 * we get a response in {@link #mCaptureCallback} from {@link #lockFocus()}.
 *//*from  w w w  .  ja  v  a2  s  . com*/
private void runPrecaptureSequence() {
    try {
        // This is how to tell the camera to trigger.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the precapture sequence to be set.
        mState = STATE_WAITING_PRECAPTURE;

        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.vest.album.fragment.CameraBasicFragment.java

/**
 * Run the precapture sequence for capturing a still image. This method should be called when
 * we get a response in {@link #mCaptureCallback} from {@link #lockFocus()}.
 *//*from  www  . j  a v  a2s  .c  o m*/
private void runPrecaptureSequence() {
    try {
        // This is how to tell the camera to trigger.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the precapture sequence to be set.
        mState = STATE_WAITING_PRECAPTURE;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        callback.onPhotoError("?");
        e.printStackTrace();
    }
}

From source file:com.obviousengine.android.focus.ZslFocusCamera.java

private boolean sendAutoExposureTriggerRequest(Flash flashMode) {
    Timber.v("sendAutoExposureTriggerRequest()");
    try {/*from  w  w w .ja  va 2  s.  c  o  m*/
        CaptureRequest.Builder builder;
        if (ZSL_ENABLED) {
            builder = device.createCaptureRequest(CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG);
        } else {
            builder = device.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        }

        builder.addTarget(previewSurface);

        if (ZSL_ENABLED) {
            builder.addTarget(captureImageReader.getSurface());
        }

        builder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);

        builder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);

        addRegionsToCaptureRequestBuilder(builder);
        addFlashToCaptureRequestBuilder(builder, flashMode);

        captureSession.capture(builder.build(), captureManager, cameraHandler);

        return true;
    } catch (CameraAccessException e) {
        Timber.w(e, "Could not execute auto exposure trigger request.");
        return false;
    }
}

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

/**
 * Initiate a still image capture./* w  ww.ja v  a 2s.  c om*/
 * <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;
    }
}