Search in sources :

Example 1 with CameraConstrainedHighSpeedCaptureSession

use of android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession in project android_frameworks_base by ResurrectionRemix.

the class Camera2RecordingTest method startSlowMotionRecording.

private void startSlowMotionRecording(boolean useMediaRecorder, int videoFrameRate, int captureRate, Range<Integer> fpsRange, CameraCaptureSession.CaptureCallback listener, boolean useHighSpeedSession) throws Exception {
    List<Surface> outputSurfaces = new ArrayList<Surface>(2);
    assertTrue("Both preview and recording surfaces should be valid", mPreviewSurface.isValid() && mRecordingSurface.isValid());
    outputSurfaces.add(mPreviewSurface);
    outputSurfaces.add(mRecordingSurface);
    // Video snapshot surface
    if (mReaderSurface != null) {
        outputSurfaces.add(mReaderSurface);
    }
    mSessionListener = new BlockingSessionCallback();
    mSession = configureCameraSession(mCamera, outputSurfaces, useHighSpeedSession, mSessionListener, mHandler);
    // Create slow motion request list
    List<CaptureRequest> slowMoRequests = null;
    if (useHighSpeedSession) {
        CaptureRequest.Builder requestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        requestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
        requestBuilder.addTarget(mPreviewSurface);
        requestBuilder.addTarget(mRecordingSurface);
        slowMoRequests = ((CameraConstrainedHighSpeedCaptureSession) mSession).createHighSpeedRequestList(requestBuilder.build());
    } else {
        CaptureRequest.Builder recordingRequestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        recordingRequestBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_USE_SCENE_MODE);
        recordingRequestBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO);
        CaptureRequest.Builder recordingOnlyBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        recordingOnlyBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_USE_SCENE_MODE);
        recordingOnlyBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO);
        int slowMotionFactor = captureRate / videoFrameRate;
        // Make sure camera output frame rate is set to correct value.
        recordingRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
        recordingRequestBuilder.addTarget(mRecordingSurface);
        recordingRequestBuilder.addTarget(mPreviewSurface);
        recordingOnlyBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
        recordingOnlyBuilder.addTarget(mRecordingSurface);
        slowMoRequests = new ArrayList<CaptureRequest>();
        // Preview + recording.
        slowMoRequests.add(recordingRequestBuilder.build());
        for (int i = 0; i < slowMotionFactor - 1; i++) {
            // Recording only.
            slowMoRequests.add(recordingOnlyBuilder.build());
        }
    }
    mSession.setRepeatingBurst(slowMoRequests, listener, mHandler);
    if (useMediaRecorder) {
        mMediaRecorder.start();
    } else {
    // TODO: need implement MediaCodec path.
    }
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) ArrayList(java.util.ArrayList) CaptureRequest(android.hardware.camera2.CaptureRequest) Surface(android.view.Surface)

Example 2 with CameraConstrainedHighSpeedCaptureSession

use of android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession in project android_frameworks_base by AOSPA.

the class Camera2RecordingTest method startSlowMotionRecording.

private void startSlowMotionRecording(boolean useMediaRecorder, int videoFrameRate, int captureRate, Range<Integer> fpsRange, CameraCaptureSession.CaptureCallback listener, boolean useHighSpeedSession) throws Exception {
    List<Surface> outputSurfaces = new ArrayList<Surface>(2);
    assertTrue("Both preview and recording surfaces should be valid", mPreviewSurface.isValid() && mRecordingSurface.isValid());
    outputSurfaces.add(mPreviewSurface);
    outputSurfaces.add(mRecordingSurface);
    // Video snapshot surface
    if (mReaderSurface != null) {
        outputSurfaces.add(mReaderSurface);
    }
    mSessionListener = new BlockingSessionCallback();
    mSession = configureCameraSession(mCamera, outputSurfaces, useHighSpeedSession, mSessionListener, mHandler);
    // Create slow motion request list
    List<CaptureRequest> slowMoRequests = null;
    if (useHighSpeedSession) {
        CaptureRequest.Builder requestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        requestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
        requestBuilder.addTarget(mPreviewSurface);
        requestBuilder.addTarget(mRecordingSurface);
        slowMoRequests = ((CameraConstrainedHighSpeedCaptureSession) mSession).createHighSpeedRequestList(requestBuilder.build());
    } else {
        CaptureRequest.Builder recordingRequestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        recordingRequestBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_USE_SCENE_MODE);
        recordingRequestBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO);
        CaptureRequest.Builder recordingOnlyBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        recordingOnlyBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_USE_SCENE_MODE);
        recordingOnlyBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO);
        int slowMotionFactor = captureRate / videoFrameRate;
        // Make sure camera output frame rate is set to correct value.
        recordingRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
        recordingRequestBuilder.addTarget(mRecordingSurface);
        recordingRequestBuilder.addTarget(mPreviewSurface);
        recordingOnlyBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
        recordingOnlyBuilder.addTarget(mRecordingSurface);
        slowMoRequests = new ArrayList<CaptureRequest>();
        // Preview + recording.
        slowMoRequests.add(recordingRequestBuilder.build());
        for (int i = 0; i < slowMotionFactor - 1; i++) {
            // Recording only.
            slowMoRequests.add(recordingOnlyBuilder.build());
        }
    }
    mSession.setRepeatingBurst(slowMoRequests, listener, mHandler);
    if (useMediaRecorder) {
        mMediaRecorder.start();
    } else {
    // TODO: need implement MediaCodec path.
    }
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) ArrayList(java.util.ArrayList) CaptureRequest(android.hardware.camera2.CaptureRequest) Surface(android.view.Surface)

Example 3 with CameraConstrainedHighSpeedCaptureSession

use of android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession in project OpenCamera by ageback.

the class CameraController2 method setRepeatingRequest.

private void setRepeatingRequest(CaptureRequest request) throws CameraAccessException {
    if (MyDebug.LOG)
        Log.d(TAG, "setRepeatingRequest");
    if (camera == null || captureSession == null) {
        if (MyDebug.LOG)
            Log.d(TAG, "no camera or capture session");
        return;
    }
    try {
        if (is_video_high_speed && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            CameraConstrainedHighSpeedCaptureSession captureSessionHighSpeed = (CameraConstrainedHighSpeedCaptureSession) captureSession;
            List<CaptureRequest> mPreviewBuilderBurst = captureSessionHighSpeed.createHighSpeedRequestList(request);
            captureSessionHighSpeed.setRepeatingBurst(mPreviewBuilderBurst, previewCaptureCallback, handler);
        } else {
            captureSession.setRepeatingRequest(request, previewCaptureCallback, handler);
        }
        if (MyDebug.LOG)
            Log.d(TAG, "setRepeatingRequest done");
    } catch (IllegalStateException e) {
        if (MyDebug.LOG)
            Log.d(TAG, "captureSession already closed!");
        e.printStackTrace();
    // got this as a Google Play exception (from onCaptureCompleted->processCompleted) - this means the capture session is already closed
    }
}
Also used : CaptureRequest(android.hardware.camera2.CaptureRequest) CameraConstrainedHighSpeedCaptureSession(android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession)

Example 4 with CameraConstrainedHighSpeedCaptureSession

use of android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession in project android_packages_apps_Snap by LineageOS.

the class Camera2GraphView method applyZoomAndUpdate.

private void applyZoomAndUpdate(int id) {
    if (!checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
        return;
    }
    applyZoom(mPreviewRequestBuilder[id], id);
    try {
        if (id == MONO_ID && !canStartMonoPreview()) {
            mCaptureSession[id].capture(mPreviewRequestBuilder[id].build(), mCaptureCallback, mCameraHandler);
        } else {
            CameraCaptureSession session = mCaptureSession[id];
            if (session instanceof CameraConstrainedHighSpeedCaptureSession) {
                List list = CameraUtil.createHighSpeedRequestList(mPreviewRequestBuilder[id].build(), id);
                ((CameraConstrainedHighSpeedCaptureSession) session).setRepeatingBurst(list, mCaptureCallback, mCameraHandler);
            } else {
                mCaptureSession[id].setRepeatingRequest(mPreviewRequestBuilder[id].build(), mCaptureCallback, mCameraHandler);
            }
        }
    } catch (CameraAccessException | IllegalStateException e) {
        e.printStackTrace();
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession) CameraConstrainedHighSpeedCaptureSession(android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession)

Example 5 with CameraConstrainedHighSpeedCaptureSession

use of android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession in project platform_frameworks_base by android.

the class Camera2RecordingTest method startSlowMotionRecording.

private void startSlowMotionRecording(boolean useMediaRecorder, int videoFrameRate, int captureRate, Range<Integer> fpsRange, CameraCaptureSession.CaptureCallback listener, boolean useHighSpeedSession) throws Exception {
    List<Surface> outputSurfaces = new ArrayList<Surface>(2);
    assertTrue("Both preview and recording surfaces should be valid", mPreviewSurface.isValid() && mRecordingSurface.isValid());
    outputSurfaces.add(mPreviewSurface);
    outputSurfaces.add(mRecordingSurface);
    // Video snapshot surface
    if (mReaderSurface != null) {
        outputSurfaces.add(mReaderSurface);
    }
    mSessionListener = new BlockingSessionCallback();
    mSession = configureCameraSession(mCamera, outputSurfaces, useHighSpeedSession, mSessionListener, mHandler);
    // Create slow motion request list
    List<CaptureRequest> slowMoRequests = null;
    if (useHighSpeedSession) {
        CaptureRequest.Builder requestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        requestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
        requestBuilder.addTarget(mPreviewSurface);
        requestBuilder.addTarget(mRecordingSurface);
        slowMoRequests = ((CameraConstrainedHighSpeedCaptureSession) mSession).createHighSpeedRequestList(requestBuilder.build());
    } else {
        CaptureRequest.Builder recordingRequestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        recordingRequestBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_USE_SCENE_MODE);
        recordingRequestBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO);
        CaptureRequest.Builder recordingOnlyBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        recordingOnlyBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_USE_SCENE_MODE);
        recordingOnlyBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO);
        int slowMotionFactor = captureRate / videoFrameRate;
        // Make sure camera output frame rate is set to correct value.
        recordingRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
        recordingRequestBuilder.addTarget(mRecordingSurface);
        recordingRequestBuilder.addTarget(mPreviewSurface);
        recordingOnlyBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
        recordingOnlyBuilder.addTarget(mRecordingSurface);
        slowMoRequests = new ArrayList<CaptureRequest>();
        // Preview + recording.
        slowMoRequests.add(recordingRequestBuilder.build());
        for (int i = 0; i < slowMotionFactor - 1; i++) {
            // Recording only.
            slowMoRequests.add(recordingOnlyBuilder.build());
        }
    }
    mSession.setRepeatingBurst(slowMoRequests, listener, mHandler);
    if (useMediaRecorder) {
        mMediaRecorder.start();
    } else {
    // TODO: need implement MediaCodec path.
    }
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) ArrayList(java.util.ArrayList) CaptureRequest(android.hardware.camera2.CaptureRequest) Surface(android.view.Surface)

Aggregations

ArrayList (java.util.ArrayList)7 CaptureRequest (android.hardware.camera2.CaptureRequest)6 Surface (android.view.Surface)6 BlockingSessionCallback (com.android.ex.camera2.blocking.BlockingSessionCallback)5 CameraConstrainedHighSpeedCaptureSession (android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession)3 CameraAccessException (android.hardware.camera2.CameraAccessException)2 CameraCaptureSession (android.hardware.camera2.CameraCaptureSession)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Size (android.util.Size)1 IOException (java.io.IOException)1