Java Code Examples for android.hardware.camera2.CaptureResult#CONTROL_AE_STATE_CONVERGED

The following examples show how to use android.hardware.camera2.CaptureResult#CONTROL_AE_STATE_CONVERGED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AcceptableZslImageFilter.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
private boolean isAEAcceptable(TotalCaptureResultProxy metadata)
{
    Integer aeState = metadata.get(CaptureResult.CONTROL_AE_STATE);
    if (aeState == null)
    {
        return true;
    } else
    {
        switch (aeState)
        {
            case CaptureResult.CONTROL_AE_STATE_INACTIVE:
            case CaptureResult.CONTROL_AE_STATE_LOCKED:
            case CaptureResult.CONTROL_AE_STATE_CONVERGED:
                return true;
            default:
                return false;
        }
    }
}
 
Example 2
Source File: Camera2Helper.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * Auto-Exposure の状態を文字列に変換します。
 *
 * @param asState Auto Exposure の状態
 * @return 文字列
 */
static String debugAEState(Integer asState) {
    if (asState == null) {
        return "NULL";
    }

    switch (asState) {
        default:
            return "UNKNOWN";
        case CaptureResult.CONTROL_AE_STATE_CONVERGED:
            return "CaptureResult.CONTROL_AE_STATE_CONVERGED";
        case CaptureResult.CONTROL_AE_STATE_FLASH_REQUIRED:
            return "CaptureResult.CONTROL_AE_STATE_FLASH_REQUIRED";
        case CaptureResult.CONTROL_AE_STATE_INACTIVE:
            return "CaptureResult.CONTROL_AE_STATE_INACTIVE";
        case CaptureResult.CONTROL_AE_STATE_LOCKED:
            return "CaptureResult.CONTROL_AE_STATE_LOCKED";
        case CaptureResult.CONTROL_AE_STATE_PRECAPTURE:
            return "CaptureResult.CONTROL_AE_STATE_PRECAPTURE";
        case CaptureResult.CONTROL_AE_STATE_SEARCHING:
            return "CaptureResult.CONTROL_AE_STATE_SEARCHING";
    }
}
 
Example 3
Source File: AutoFlashZslImageFilter.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public <T> T get(CaptureResult.Key<T> key)
{
    if (key == TotalCaptureResult.CONTROL_AE_STATE)
    {
        Integer aeState = (Integer) mDelegate.get(key);
        if (Objects.equal(aeState, CaptureResult.CONTROL_AE_STATE_SEARCHING))
        {
            return (T) ((Integer) CaptureResult.CONTROL_AE_STATE_CONVERGED);
        }
    }
    return mDelegate.get(key);
}
 
Example 4
Source File: Camera2StateMachine.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void onCaptureResult(CaptureResult result, boolean isCompleted) {
    Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
    boolean isAeReady = aeState == null
            || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED
            || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED;
    if (isAeReady) {
        nextState(mTakePictureState);
    }
}
 
Example 5
Source File: Camera2Wrapper.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void onCaptureResult(CaptureResult result, boolean isCompleted) {
    Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
    if (DEBUG) {
        Log.d(TAG, "aeState: " + Camera2Helper.debugAEState(aeState) + " isCompleted: " + isCompleted);
    }
    boolean isAeReady = aeState == null
            || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED
            || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED;
    boolean timeout = (System.currentTimeMillis() - mStartTime) > 5000;
    if (isAeReady || timeout) {
        nextState(mTakePictureState);
    }
}
 
Example 6
Source File: LollipopCamera.java    From LiveMultimedia with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void  setupJPEGCaptureListener() {
    mCaptureCallback = new CameraCaptureSession.CaptureCallback() {
       private void process(CaptureResult result) {
                switch (mState) {
                    case STATE_PREVIEW: {
                        // We have nothing to do when the camera preview is working normally.
                        break;
                    }
                    case STATE_WAITING_LOCK: {
                            int afState = result.get(CaptureResult.CONTROL_AF_STATE);
                            if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
                                    CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
                                // CONTROL_AE_STATE can be null on some devices
                                Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
                                if (aeState == null ||
                                        aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
                                    mState = STATE_WAITING_NON_PRECAPTURE;
                                    captureStillPicture();
                                } else {
                                    runPrecaptureSequence();
                                }
                            }
                        break;
                    }
                    case STATE_WAITING_PRECAPTURE: {
                            // CONTROL_AE_STATE can be null on some devices
                            Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
                            if (aeState == null ||
                                    aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
                                    aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
                                mState = STATE_WAITING_NON_PRECAPTURE;
                            }
                        break;
                    }
                    case STATE_WAITING_NON_PRECAPTURE: {
                            // CONTROL_AE_STATE can be null on some devices
                            Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
                            if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
                                mState = STATE_PICTURE_TAKEN;
                                captureStillPicture();
                            }
                        break;
                    }
                }
            }
        };
 }
 
Example 7
Source File: AndroidCamera2AgentImpl.java    From Camera2 with Apache License 2.0 4 votes vote down vote up
@Override
public void monitorControlStates(CaptureResult result) {
    Integer afStateMaybe = result.get(CaptureResult.CONTROL_AF_STATE);
    if (afStateMaybe != null) {
        int afState = afStateMaybe;
        // Since we handle both partial and total results for multiple frames here, we
        // might get the final callbacks for an earlier frame after receiving one or
        // more that correspond to the next one. To prevent our data from oscillating,
        // we never consider AF states that are older than the last one we've seen.
        if (result.getFrameNumber() > mLastAfFrameNumber) {
            boolean afStateChanged = afState != mLastAfState;
            mLastAfState = afState;
            mLastAfFrameNumber = result.getFrameNumber();

            switch (afState) {
                case CaptureResult.CONTROL_AF_STATE_PASSIVE_SCAN:
                case CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED:
                case CaptureResult.CONTROL_AF_STATE_PASSIVE_UNFOCUSED: {
                    if (afStateChanged && mPassiveAfCallback != null) {
                        // A CameraAFMoveCallback is attached. If we just started to
                        // scan, the motor is moving; otherwise, it has settled.
                        mPassiveAfCallback.onAutoFocusMoving(
                                afState == CaptureResult.CONTROL_AF_STATE_PASSIVE_SCAN,
                                mCameraProxy);
                    }
                    break;
                }

                case CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED:
                case CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED: {
                    // This check must be made regardless of whether the focus state has
                    // changed recently to avoid infinite waiting during autoFocus()
                    // when the algorithm has already either converged or failed to.
                    if (mOneshotAfCallback != null) {
                        // A call to autoFocus() was just made to request a focus lock.
                        // Notify the caller that the lens is now indefinitely fixed,
                        // and report whether the image we're stuck with is in focus.
                        mOneshotAfCallback.onAutoFocus(
                                afState == CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED,
                                mCameraProxy);
                        mOneshotAfCallback = null;
                    }
                    break;
                }
            }
        }
    }

    Integer aeStateMaybe = result.get(CaptureResult.CONTROL_AE_STATE);
    if (aeStateMaybe != null) {
        int aeState = aeStateMaybe;
        // Since we handle both partial and total results for multiple frames here, we
        // might get the final callbacks for an earlier frame after receiving one or
        // more that correspond to the next one. To prevent our data from oscillating,
        // we never consider AE states that are older than the last one we've seen.
        if (result.getFrameNumber() > mLastAeFrameNumber) {
            mCurrentAeState = aeStateMaybe;
            mLastAeFrameNumber = result.getFrameNumber();

            switch (aeState) {
                case CaptureResult.CONTROL_AE_STATE_CONVERGED:
                case CaptureResult.CONTROL_AE_STATE_FLASH_REQUIRED:
                case CaptureResult.CONTROL_AE_STATE_LOCKED: {
                    // This check must be made regardless of whether the exposure state
                    // has changed recently to avoid infinite waiting during
                    // takePicture() when the algorithm has already converged.
                    if (mOneshotCaptureCallback != null) {
                        // A call to takePicture() was just made, and autoexposure
                        // converged so it's time to initiate the capture!
                        mCaptureReader.setOnImageAvailableListener(
                                /*listener*/mOneshotCaptureCallback,
                                /*handler*/Camera2Handler.this);
                        try {
                            mSession.capture(
                                    mPersistentSettings.createRequest(mCamera,
                                            CameraDevice.TEMPLATE_STILL_CAPTURE,
                                            mCaptureReader.getSurface()),
                                    /*callback*/mOneshotCaptureCallback,
                                    /*handler*/Camera2Handler.this);
                        } catch (CameraAccessException ex) {
                            Log.e(TAG, "Unable to initiate capture", ex);
                        } finally {
                            mOneshotCaptureCallback = null;
                        }
                    }
                    break;
                }
            }
        }
    }
}
 
Example 8
Source File: Camera2RawFragment.java    From android-Camera2Raw with Apache License 2.0 4 votes vote down vote up
private void process(CaptureResult result) {
    synchronized (mCameraStateLock) {
        switch (mState) {
            case STATE_PREVIEW: {
                // We have nothing to do when the camera preview is running normally.
                break;
            }
            case STATE_WAITING_FOR_3A_CONVERGENCE: {
                boolean readyToCapture = true;
                if (!mNoAFRun) {
                    Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
                    if (afState == null) {
                        break;
                    }

                    // If auto-focus has reached locked state, we are ready to capture
                    readyToCapture =
                            (afState == CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED ||
                                    afState == CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
                }

                // If we are running on an non-legacy device, we should also wait until
                // auto-exposure and auto-white-balance have converged as well before
                // taking a picture.
                if (!isLegacyLocked()) {
                    Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
                    Integer awbState = result.get(CaptureResult.CONTROL_AWB_STATE);
                    if (aeState == null || awbState == null) {
                        break;
                    }

                    readyToCapture = readyToCapture &&
                            aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED &&
                            awbState == CaptureResult.CONTROL_AWB_STATE_CONVERGED;
                }

                // If we haven't finished the pre-capture sequence but have hit our maximum
                // wait timeout, too bad! Begin capture anyway.
                if (!readyToCapture && hitTimeoutLocked()) {
                    Log.w(TAG, "Timed out waiting for pre-capture sequence to complete.");
                    readyToCapture = true;
                }

                if (readyToCapture && mPendingUserCaptures > 0) {
                    // Capture once for each user tap of the "Picture" button.
                    while (mPendingUserCaptures > 0) {
                        captureStillPictureLocked();
                        mPendingUserCaptures--;
                    }
                    // After this, the camera will go back to the normal state of preview.
                    mState = STATE_PREVIEW;
                }
            }
        }
    }
}