Search in sources :

Example 41 with BlockingSessionCallback

use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by DirtyUnicorns.

the class Camera2RecordingTest method startRecording.

private void startRecording(boolean useMediaRecorder, CameraCaptureSession.CaptureCallback listener, boolean useVideoStab) throws Exception {
    if (!mStaticInfo.isVideoStabilizationSupported() && useVideoStab) {
        throw new IllegalArgumentException("Video stabilization is not supported");
    }
    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, mSessionListener, mHandler);
    CaptureRequest.Builder recordingRequestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
    // Make sure camera output frame rate is set to correct value.
    Range<Integer> fpsRange = Range.create(mVideoFrameRate, mVideoFrameRate);
    recordingRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
    if (useVideoStab) {
        recordingRequestBuilder.set(CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE, CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE_ON);
    }
    recordingRequestBuilder.addTarget(mRecordingSurface);
    recordingRequestBuilder.addTarget(mPreviewSurface);
    mSession.setRepeatingRequest(recordingRequestBuilder.build(), listener, mHandler);
    if (useMediaRecorder) {
        mMediaRecorder.start();
    } else {
    // TODO: need implement MediaCodec path.
    }
    mRecordingStartTime = SystemClock.elapsedRealtime();
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) ArrayList(java.util.ArrayList) CaptureRequest(android.hardware.camera2.CaptureRequest) Surface(android.view.Surface)

Example 42 with BlockingSessionCallback

use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by DirtyUnicorns.

the class Camera2SwitchPreviewTest method prepareVideoPreview.

protected void prepareVideoPreview(CaptureRequest.Builder previewRequest, CaptureRequest.Builder recordingRequest, CaptureCallback resultListener, ImageReader.OnImageAvailableListener imageListener) throws Exception {
    // Configure output streams with preview and jpeg streams.
    List<Surface> outputSurfaces = new ArrayList<Surface>();
    outputSurfaces.add(mPreviewSurface);
    outputSurfaces.add(mRecordingSurface);
    mSessionListener = new BlockingSessionCallback();
    mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
    previewRequest.addTarget(mPreviewSurface);
    recordingRequest.addTarget(mPreviewSurface);
    recordingRequest.addTarget(mRecordingSurface);
    // Start preview.
    mSession.setRepeatingRequest(previewRequest.build(), null, mHandler);
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) ArrayList(java.util.ArrayList) Surface(android.view.Surface)

Example 43 with BlockingSessionCallback

use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by DirtyUnicorns.

the class Camera2SwitchPreviewTest method prepareCapturePreview.

protected void prepareCapturePreview(CaptureRequest.Builder previewRequest, CaptureRequest.Builder stillRequest, CaptureCallback resultListener, ImageReader.OnImageAvailableListener imageListener) throws Exception {
    Size captureSz = mOrderedStillSizes.get(0);
    Size previewSz = mOrderedPreviewSizes.get(1);
    if (VERBOSE) {
        Log.v(TAG, String.format("Prepare single capture (%s) and preview (%s)", captureSz.toString(), previewSz.toString()));
    }
    // Update preview size.
    updatePreviewSurface(previewSz);
    // Create ImageReader.
    createImageReader(captureSz, ImageFormat.JPEG, MAX_READER_IMAGES, imageListener);
    // Configure output streams with preview and jpeg streams.
    List<Surface> outputSurfaces = new ArrayList<Surface>();
    outputSurfaces.add(mPreviewSurface);
    outputSurfaces.add(mReaderSurface);
    mSessionListener = new BlockingSessionCallback();
    mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
    // Configure the requests.
    previewRequest.addTarget(mPreviewSurface);
    stillRequest.addTarget(mPreviewSurface);
    stillRequest.addTarget(mReaderSurface);
    // Start preview.
    mSession.setRepeatingRequest(previewRequest.build(), resultListener, mHandler);
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) Size(android.util.Size) ArrayList(java.util.ArrayList) Surface(android.view.Surface)

Example 44 with BlockingSessionCallback

use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by ResurrectionRemix.

the class Camera2SurfaceViewTestCase method prepareCaptureAndStartPreview.

/**
     * Setup single capture configuration and start preview.
     *
     * @param previewRequest The capture request to be used for preview
     * @param stillRequest The capture request to be used for still capture
     * @param previewSz Preview size
     * @param captureSz Still capture size
     * @param format The single capture image format
     * @param resultListener Capture result listener
     * @param maxNumImages The max number of images set to the image reader
     * @param imageListener The single capture capture image listener
     */
protected void prepareCaptureAndStartPreview(CaptureRequest.Builder previewRequest, CaptureRequest.Builder stillRequest, Size previewSz, Size captureSz, int format, CaptureCallback resultListener, int maxNumImages, ImageReader.OnImageAvailableListener imageListener) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, String.format("Prepare single capture (%s) and preview (%s)", captureSz.toString(), previewSz.toString()));
    }
    // Update preview size.
    updatePreviewSurface(previewSz);
    // Create ImageReader.
    createImageReader(captureSz, format, maxNumImages, imageListener);
    // Configure output streams with preview and jpeg streams.
    List<Surface> outputSurfaces = new ArrayList<Surface>();
    outputSurfaces.add(mPreviewSurface);
    outputSurfaces.add(mReaderSurface);
    mSessionListener = new BlockingSessionCallback();
    mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
    // Configure the requests.
    previewRequest.addTarget(mPreviewSurface);
    stillRequest.addTarget(mPreviewSurface);
    stillRequest.addTarget(mReaderSurface);
    // Start preview.
    mSession.setRepeatingRequest(previewRequest.build(), resultListener, mHandler);
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) ArrayList(java.util.ArrayList) Surface(android.view.Surface)

Example 45 with BlockingSessionCallback

use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by ResurrectionRemix.

the class Camera2SwitchPreviewTest method prepareVideoPreview.

protected void prepareVideoPreview(CaptureRequest.Builder previewRequest, CaptureRequest.Builder recordingRequest, CaptureCallback resultListener, ImageReader.OnImageAvailableListener imageListener) throws Exception {
    // Configure output streams with preview and jpeg streams.
    List<Surface> outputSurfaces = new ArrayList<Surface>();
    outputSurfaces.add(mPreviewSurface);
    outputSurfaces.add(mRecordingSurface);
    mSessionListener = new BlockingSessionCallback();
    mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
    previewRequest.addTarget(mPreviewSurface);
    recordingRequest.addTarget(mPreviewSurface);
    recordingRequest.addTarget(mRecordingSurface);
    // Start preview.
    mSession.setRepeatingRequest(previewRequest.build(), null, mHandler);
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) ArrayList(java.util.ArrayList) Surface(android.view.Surface)

Aggregations

BlockingSessionCallback (com.android.ex.camera2.blocking.BlockingSessionCallback)54 Surface (android.view.Surface)44 ArrayList (java.util.ArrayList)44 CaptureRequest (android.hardware.camera2.CaptureRequest)19 CameraCaptureSession (android.hardware.camera2.CameraCaptureSession)10 Size (android.util.Size)10 CaptureResult (android.hardware.camera2.CaptureResult)5 DngCreator (android.hardware.camera2.DngCreator)5 InputConfiguration (android.hardware.camera2.params.InputConfiguration)5 Image (android.media.Image)5 ImageReader (android.media.ImageReader)5 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)5 SimpleImageReaderListener (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener)5 SimpleImageWriterListener (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageWriterListener)5 CameraTestUtils.basicValidateJpegImage (com.android.mediaframeworktest.helpers.CameraTestUtils.basicValidateJpegImage)5 CameraTestUtils.getDataFromImage (com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage)5 CameraTestUtils.makeImageReader (com.android.mediaframeworktest.helpers.CameraTestUtils.makeImageReader)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 CameraAccessException (android.hardware.camera2.CameraAccessException)4 Handler (android.os.Handler)4