Search in sources :

Example 1 with CameraProxy

use of com.android.camera.CameraManager.CameraProxy in project android_packages_apps_Snap by LineageOS.

the class DrawAutoHDR method startPreview.

/**
 * This can run on a background thread, so don't do UI updates here. Post any
 *             view updates to MainHandler or do it on onPreviewStarted() .
 */
private void startPreview() {
    if (mPaused || mCameraDevice == null || mParameters == null) {
        return;
    }
    synchronized (mCameraDevice) {
        SurfaceHolder sh = null;
        Log.v(TAG, "startPreview: SurfaceHolder (MDP path)");
        if (mUI != null) {
            sh = mUI.getSurfaceHolder();
        }
        // Let UI set its expected aspect ratio
        mCameraDevice.setPreviewDisplay(sh);
    }
    if (!mCameraPreviewParamsReady) {
        Log.w(TAG, "startPreview: parameters for preview are not ready.");
        return;
    }
    mErrorCallback.setActivity(mActivity);
    mCameraDevice.setErrorCallback(mErrorCallback);
    // Reset camera state after taking a picture
    if (mCameraState != PREVIEW_STOPPED && mCameraState != INIT) {
        setCameraState(IDLE);
    }
    // Preview needs to be stopped when changing resolution
    if (mRestartPreview && mCameraState != PREVIEW_STOPPED && mCameraState != INIT) {
        stopPreview();
        mRestartPreview = false;
    }
    if (mFocusManager == null)
        initializeFocusManager();
    if (!mSnapshotOnIdle) {
        // Unlock AE and AWB.
        mFocusManager.setAeAwbLock(false);
    }
    setCameraParameters(UPDATE_PARAM_ALL);
    mCameraDevice.setOneShotPreviewCallback(mHandler, new CameraManager.CameraPreviewDataCallback() {

        @Override
        public void onPreviewFrame(byte[] data, CameraProxy camera) {
            mUI.hidePreviewCover();
        }
    });
    mCameraDevice.startPreview();
    mHandler.sendEmptyMessage(ON_PREVIEW_STARTED);
    setDisplayOrientation();
    if (!mSnapshotOnIdle && !mInstantCaptureSnapShot) {
        // resume it because it may have been paused by autoFocus call.
        if (CameraUtil.FOCUS_MODE_CONTINUOUS_PICTURE.equals(mFocusManager.getFocusMode(false)) && mCameraState != INIT || CameraUtil.FOCUS_MODE_MW_CONTINUOUS_PICTURE.equals(mFocusManager.getFocusMode(false))) {
            mCameraDevice.cancelAutoFocus();
        }
    } else {
        Log.v(TAG, "Trigger snapshot from start preview.");
        mHandler.sendEmptyMessageDelayed(INSTANT_CAPTURE, 1500);
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) CameraProxy(com.android.camera.CameraManager.CameraProxy)

Example 2 with CameraProxy

use of com.android.camera.CameraManager.CameraProxy in project android_packages_apps_Snap by LineageOS.

the class VideoModule method startPreview.

private void startPreview() {
    Log.v(TAG, "startPreview");
    mStartPrevPending = true;
    SurfaceHolder sh = null;
    Log.v(TAG, "startPreview: SurfaceHolder (MDP path)");
    sh = mUI.getSurfaceHolder();
    if (!mPreferenceRead || mPaused == true || mCameraDevice == null) {
        mStartPrevPending = false;
        return;
    }
    mErrorCallback.setActivity(mActivity);
    mCameraDevice.setErrorCallback(mErrorCallback);
    if (mPreviewing == true) {
        stopPreview();
    }
    setDisplayOrientation();
    mCameraDevice.setDisplayOrientation(mCameraDisplayOrientation);
    setCameraParameters(true);
    try {
        mCameraDevice.setPreviewDisplay(sh);
        mCameraDevice.setOneShotPreviewCallback(mHandler, new CameraManager.CameraPreviewDataCallback() {

            @Override
            public void onPreviewFrame(byte[] data, CameraProxy camera) {
                mUI.hidePreviewCover();
            }
        });
        mCameraDevice.startPreview();
        mPreviewing = true;
        onPreviewStarted();
    } catch (Throwable ex) {
        closeCamera();
        throw new RuntimeException("startPreview failed", ex);
    }
    mStartPrevPending = false;
    mFocusManager.onPreviewStarted();
}
Also used : SurfaceHolder(android.view.SurfaceHolder) CameraProxy(com.android.camera.CameraManager.CameraProxy)

Aggregations

SurfaceHolder (android.view.SurfaceHolder)2 CameraProxy (com.android.camera.CameraManager.CameraProxy)2