Search in sources :

Example 26 with BlockingSessionCallback

use of com.android.ex.camera2.blocking.BlockingSessionCallback 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)

Example 27 with BlockingSessionCallback

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

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 28 with BlockingSessionCallback

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

the class Camera2ReprocessCaptureTest method setupReprocessableSession.

/**
     * Set up a reprocessable session and create an ImageWriter with the sessoin's input surface.
     */
private void setupReprocessableSession(Surface previewSurface, int numImageWriterImages) throws Exception {
    // create a reprocessable capture session
    List<Surface> outSurfaces = new ArrayList<Surface>();
    outSurfaces.add(mFirstImageReader.getSurface());
    if (!mShareOneImageReader) {
        outSurfaces.add(mSecondImageReader.getSurface());
    }
    if (previewSurface != null) {
        outSurfaces.add(previewSurface);
    }
    InputConfiguration inputConfig = new InputConfiguration(mFirstImageReader.getWidth(), mFirstImageReader.getHeight(), mFirstImageReader.getImageFormat());
    String inputConfigString = inputConfig.toString();
    if (VERBOSE) {
        Log.v(TAG, "InputConfiguration: " + inputConfigString);
    }
    assertTrue(String.format("inputConfig is wrong: %dx%d format %d. Expect %dx%d format %d", inputConfig.getWidth(), inputConfig.getHeight(), inputConfig.getFormat(), mFirstImageReader.getWidth(), mFirstImageReader.getHeight(), mFirstImageReader.getImageFormat()), inputConfig.getWidth() == mFirstImageReader.getWidth() && inputConfig.getHeight() == mFirstImageReader.getHeight() && inputConfig.getFormat() == mFirstImageReader.getImageFormat());
    mSessionListener = new BlockingSessionCallback();
    mSession = configureReprocessableCameraSession(mCamera, inputConfig, outSurfaces, mSessionListener, mHandler);
    // create an ImageWriter
    mInputSurface = mSession.getInputSurface();
    mImageWriter = ImageWriter.newInstance(mInputSurface, numImageWriterImages);
    mImageWriterListener = new SimpleImageWriterListener(mImageWriter);
    mImageWriter.setOnImageReleasedListener(mImageWriterListener, mHandler);
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) ArrayList(java.util.ArrayList) InputConfiguration(android.hardware.camera2.params.InputConfiguration) Surface(android.view.Surface) SimpleImageWriterListener(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageWriterListener)

Example 29 with BlockingSessionCallback

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

the class Camera2StillCaptureTest method fullRawCaptureTestByCamera.

private void fullRawCaptureTestByCamera() throws Exception {
    Size maxPreviewSz = mOrderedPreviewSizes.get(0);
    Size maxStillSz = mOrderedStillSizes.get(0);
    SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
    SimpleImageReaderListener jpegListener = new SimpleImageReaderListener();
    SimpleImageReaderListener rawListener = new SimpleImageReaderListener();
    Size size = mStaticInfo.getRawDimensChecked();
    if (VERBOSE) {
        Log.v(TAG, "Testing multi capture with size " + size.toString() + ", preview size " + maxPreviewSz);
    }
    // Prepare raw capture and start preview.
    CaptureRequest.Builder previewBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
    CaptureRequest.Builder multiBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
    ImageReader rawReader = null;
    ImageReader jpegReader = null;
    try {
        // Create ImageReaders.
        rawReader = makeImageReader(size, ImageFormat.RAW_SENSOR, MAX_READER_IMAGES, rawListener, mHandler);
        jpegReader = makeImageReader(maxStillSz, ImageFormat.JPEG, MAX_READER_IMAGES, jpegListener, mHandler);
        updatePreviewSurface(maxPreviewSz);
        // Configure output streams with preview and jpeg streams.
        List<Surface> outputSurfaces = new ArrayList<Surface>();
        outputSurfaces.add(rawReader.getSurface());
        outputSurfaces.add(jpegReader.getSurface());
        outputSurfaces.add(mPreviewSurface);
        mSessionListener = new BlockingSessionCallback();
        mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
        // Configure the requests.
        previewBuilder.addTarget(mPreviewSurface);
        multiBuilder.addTarget(mPreviewSurface);
        multiBuilder.addTarget(rawReader.getSurface());
        multiBuilder.addTarget(jpegReader.getSurface());
        // Start preview.
        mSession.setRepeatingRequest(previewBuilder.build(), null, mHandler);
        // Poor man's 3A, wait 2 seconds for AE/AF (if any) to settle.
        // TODO: Do proper 3A trigger and lock (see testTakePictureTest).
        Thread.sleep(3000);
        multiBuilder.set(CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE, CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE_ON);
        CaptureRequest multiRequest = multiBuilder.build();
        mSession.capture(multiRequest, resultListener, mHandler);
        CaptureResult result = resultListener.getCaptureResultForRequest(multiRequest, NUM_RESULTS_WAIT_TIMEOUT);
        Image jpegImage = jpegListener.getImage(CAPTURE_IMAGE_TIMEOUT_MS);
        basicValidateJpegImage(jpegImage, maxStillSz);
        Image rawImage = rawListener.getImage(CAPTURE_IMAGE_TIMEOUT_MS);
        validateRaw16Image(rawImage, size);
        verifyRawCaptureResult(multiRequest, result);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try (DngCreator dngCreator = new DngCreator(mStaticInfo.getCharacteristics(), result)) {
            dngCreator.writeImage(outputStream, rawImage);
        }
        if (DEBUG) {
            byte[] rawBuffer = outputStream.toByteArray();
            String rawFileName = DEBUG_FILE_NAME_BASE + "/raw16_" + TAG + size.toString() + "_cam_" + mCamera.getId() + ".dng";
            Log.d(TAG, "Dump raw file into " + rawFileName);
            dumpFile(rawFileName, rawBuffer);
            byte[] jpegBuffer = getDataFromImage(jpegImage);
            String jpegFileName = DEBUG_FILE_NAME_BASE + "/jpeg_" + TAG + size.toString() + "_cam_" + mCamera.getId() + ".jpg";
            Log.d(TAG, "Dump jpeg file into " + rawFileName);
            dumpFile(jpegFileName, jpegBuffer);
        }
        stopPreview();
    } finally {
        CameraTestUtils.closeImageReader(rawReader);
        CameraTestUtils.closeImageReader(jpegReader);
        rawReader = null;
        jpegReader = null;
    }
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) Size(android.util.Size) DngCreator(android.hardware.camera2.DngCreator) CaptureResult(android.hardware.camera2.CaptureResult) ArrayList(java.util.ArrayList) SimpleImageReaderListener(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CameraTestUtils.basicValidateJpegImage(com.android.mediaframeworktest.helpers.CameraTestUtils.basicValidateJpegImage) CameraTestUtils.getDataFromImage(com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage) Image(android.media.Image) Surface(android.view.Surface) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback) CameraTestUtils.makeImageReader(com.android.mediaframeworktest.helpers.CameraTestUtils.makeImageReader) ImageReader(android.media.ImageReader)

Example 30 with BlockingSessionCallback

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

the class CameraTestUtils method configureCameraSession.

/**
     * Configure a new camera session with output surfaces and type.
     *
     * @param camera The CameraDevice to be configured.
     * @param outputSurfaces The surface list that used for camera output.
     * @param listener The callback CameraDevice will notify when capture results are available.
     */
public static CameraCaptureSession configureCameraSession(CameraDevice camera, List<Surface> outputSurfaces, boolean isHighSpeed, CameraCaptureSession.StateCallback listener, Handler handler) throws CameraAccessException {
    BlockingSessionCallback sessionListener = new BlockingSessionCallback(listener);
    if (isHighSpeed) {
        camera.createConstrainedHighSpeedCaptureSession(outputSurfaces, sessionListener, handler);
    } else {
        camera.createCaptureSession(outputSurfaces, sessionListener, handler);
    }
    CameraCaptureSession session = sessionListener.waitAndGetSession(SESSION_CONFIGURE_TIMEOUT_MS);
    assertFalse("Camera session should not be a reprocessable session", session.isReprocessable());
    String sessionType = isHighSpeed ? "High Speed" : "Normal";
    assertTrue("Capture session type must be " + sessionType, isHighSpeed == CameraConstrainedHighSpeedCaptureSession.class.isAssignableFrom(session.getClass()));
    return session;
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession)

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