Example usage for android.hardware.camera2 CaptureRequest getTag

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

Introduction

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

Prototype

@Nullable
public Object getTag() 

Source Link

Document

Retrieve the tag for this request, if any.

Usage

From source file:com.dastanapps.camera2.view.Cam2AutoFitTextureView.java

@Nullable
private Boolean touchTofocus2(MotionEvent event) {
    MotionEvent motionEvent = event;//from w w w .  j  a va  2  s .c  o  m
    final int actionMasked = motionEvent.getActionMasked();
    if (actionMasked != MotionEvent.ACTION_DOWN) {
        return false;
    }
    if (mManualFocusEngaged) {
        Log.d(TAG, "Manual focus already engaged");
        return true;
    }

    final Rect sensorArraySize = mCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);

    //TODO: here I just flip x,y, but this needs to correspond with the sensor orientation (via SENSOR_ORIENTATION)
    final int y = (int) ((motionEvent.getX() / (float) getWidth()) * (float) sensorArraySize.height());
    final int x = (int) ((motionEvent.getY() / (float) getHeight()) * (float) sensorArraySize.width());
    final int halfTouchWidth = 150; //(int)motionEvent.getTouchMajor(); //TODO: this doesn't represent actual touch size in pixel. Values range in [3, 10]...
    final int halfTouchHeight = 150; //(int)motionEvent.getTouchMinor();
    MeteringRectangle focusAreaTouch = new MeteringRectangle(Math.max(x - halfTouchWidth, 0),
            Math.max(y - halfTouchHeight, 0), halfTouchWidth * 2, halfTouchHeight * 2,
            MeteringRectangle.METERING_WEIGHT_MAX - 1);

    CameraCaptureSession.CaptureCallback captureCallbackHandler = new CameraCaptureSession.CaptureCallback() {
        @Override
        public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
                TotalCaptureResult result) {
            super.onCaptureCompleted(session, request, result);
            mManualFocusEngaged = false;

            if (request.getTag() == "FOCUS_TAG") {
                //the focus trigger is complete -
                //resume repeating (preview surface will get frames), clear AF trigger
                mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, null);
                try {
                    mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), null, null);
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request,
                CaptureFailure failure) {
            super.onCaptureFailed(session, request, failure);
            Log.e(TAG, "Manual AF failure: " + failure);
            mManualFocusEngaged = false;
        }
    };

    //first stop the existing repeating request
    try {
        mPreviewSession.stopRepeating();
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }

    //cancel any existing AF trigger (repeated touches, etc.)
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
    try {
        mPreviewSession.capture(mPreviewBuilder.build(), captureCallbackHandler, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }

    //Now add a new AF trigger with focus region
    if (isMeteringAreaAFSupported()) {
        mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[] { focusAreaTouch });
    }
    mPreviewBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
    mPreviewBuilder.setTag("FOCUS_TAG"); //we'll capture this later for resuming the preview

    //            //then we ask for a single request (not repeating!)
    //            mPreviewSession.capture(mPreviewBuilder.build(), captureCallbackHandler, mBackgroundHandler);
    return null;
}

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

/**
 * Send a capture request to the camera device that initiates a capture targeting the JPEG and
 * RAW outputs.//from  ww w . java  2  s  .c  o  m
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 */
private void captureStillPictureLocked() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

        captureBuilder.addTarget(mJpegImageReader.get().getSurface());
        captureBuilder.addTarget(mRawImageReader.get().getSurface());

        // Use the same AE and AF modes as the preview.
        setup3AControlsLocked(captureBuilder);

        // Set orientation.
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, sensorToDeviceRotation(mCharacteristics, rotation));

        // Set request tag to easily track results in callbacks.
        captureBuilder.setTag(mRequestCounter.getAndIncrement());

        CaptureRequest request = captureBuilder.build();

        // Create an ImageSaverBuilder in which to collect results, and add it to the queue
        // of active requests.
        ImageSaverBuilder jpegBuilder = new ImageSaverBuilder(activity).setCharacteristics(mCharacteristics);
        ImageSaverBuilder rawBuilder = new ImageSaverBuilder(activity).setCharacteristics(mCharacteristics);

        mJpegResultQueue.put((int) request.getTag(), jpegBuilder);
        mRawResultQueue.put((int) request.getTag(), rawBuilder);

        mCaptureSession.capture(request, mCaptureCallback, mBackgroundHandler);

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

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

/**
 * Send a capture request to the camera device that initiates a capture targeting the JPEG and
 * RAW outputs.//from w  w w .  j av  a 2  s.  c om
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 */
private void captureStillPictureLocked() {
    try {
        if (null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

        captureBuilder.addTarget(mJpegImageReader.get().getSurface());
        captureBuilder.addTarget(mRawImageReader.get().getSurface());

        // Use the same AE and AF modes as the preview.
        setup3AControlsLocked(captureBuilder);

        // Set orientation.
        int rotation = Surface.ROTATION_0;
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, sensorToDeviceRotation(mCharacteristics, rotation));

        // Set request tag to easily track results in callbacks.
        captureBuilder.setTag(mRequestCounter.getAndIncrement());

        CaptureRequest request = captureBuilder.build();

        // Create an ImageSaverBuilder in which to collect results, and add it to the queue
        // of active requests.
        ImageSaver.ImageSaverBuilder jpegBuilder = new ImageSaver.ImageSaverBuilder(appContext)
                .setCharacteristics(mCharacteristics);
        ImageSaver.ImageSaverBuilder rawBuilder = new ImageSaver.ImageSaverBuilder(appContext)
                .setCharacteristics(mCharacteristics);

        mJpegResultQueue.put((int) request.getTag(), jpegBuilder);
        mRawResultQueue.put((int) request.getTag(), rawBuilder);

        mCaptureSession.capture(request, mCaptureCallback, mBackgroundHandler);

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

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

/**
 * Send a capture request to the camera device that initiates a capture targeting the JPEG and
 * RAW outputs.//w w  w . j a v a2  s .  c  om
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 */
private void captureStillPictureLocked() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

        captureBuilder.addTarget(mJpegImageReader.get().getSurface());
        captureBuilder.addTarget(mRawImageReader.get().getSurface());

        // Use the same AE and AF modes as the preview.
        setup3AControlsLocked(captureBuilder);

        // Set orientation.
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, sensorToDeviceRotation(mCharacteristics, rotation));

        // Set request tag to easily track results in callbacks.
        captureBuilder.setTag(mRequestCounter.getAndIncrement());

        CaptureRequest request = captureBuilder.build();

        // Create an ImageSaverBuilder in which to collect results, and add it to the queue
        // of active requests.
        ImageSaver.ImageSaverBuilder jpegBuilder = new ImageSaver.ImageSaverBuilder(activity)
                .setCharacteristics(mCharacteristics);
        ImageSaver.ImageSaverBuilder rawBuilder = new ImageSaver.ImageSaverBuilder(activity)
                .setCharacteristics(mCharacteristics);

        mJpegResultQueue.put((int) request.getTag(), jpegBuilder);
        mRawResultQueue.put((int) request.getTag(), rawBuilder);

        mCaptureSession.capture(request, mCaptureCallback, mBackgroundHandler);

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

From source file:us.bojie.rawgyroscope.camera.Camera2RawFragment.java

/**
 * Send a capture request to the camera device that initiates a capture targeting the JPEG and
 * RAW outputs./* w ww.  j a  v  a 2  s  . c o m*/
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 */
private void captureStillPictureLocked() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

        captureBuilder.addTarget(mJpegImageReader.get().getSurface());
        captureBuilder.addTarget(mRawImageReader.get().getSurface());

        // Use the same AE and AF modes as the preview.
        setup3AControlsLocked(captureBuilder);

        // Set orientation.
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, sensorToDeviceRotation(mCharacteristics, rotation));

        // Set request tag to easily track results in callbacks.
        captureBuilder.setTag(mRequestCounter.getAndIncrement());

        CaptureRequest request = captureBuilder.build();

        // Create an ImageSaverBuilder in which to collect results, and add it to the queue
        // of active requests.
        ImageSaver.ImageSaverBuilder jpegBuilder = new ImageSaver.ImageSaverBuilder(activity, mListener)
                .setCharacteristics(mCharacteristics);
        ImageSaver.ImageSaverBuilder rawBuilder = new ImageSaver.ImageSaverBuilder(activity, mListener)
                .setCharacteristics(mCharacteristics);

        mJpegResultQueue.put((int) request.getTag(), jpegBuilder);
        mRawResultQueue.put((int) request.getTag(), rawBuilder);

        mCaptureSession.capture(request, mCaptureCallback, mBackgroundHandler);

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