Search in sources :

Example 36 with BlockingSessionCallback

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

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

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

the class CameraTestUtils method configureReprocessableCameraSession.

public static CameraCaptureSession configureReprocessableCameraSession(CameraDevice camera, InputConfiguration inputConfiguration, List<Surface> outputSurfaces, CameraCaptureSession.StateCallback listener, Handler handler) throws CameraAccessException {
    BlockingSessionCallback sessionListener = new BlockingSessionCallback(listener);
    camera.createReprocessableCaptureSession(inputConfiguration, outputSurfaces, sessionListener, handler);
    Integer[] sessionStates = { BlockingSessionCallback.SESSION_READY, BlockingSessionCallback.SESSION_CONFIGURE_FAILED };
    int state = sessionListener.getStateWaiter().waitForAnyOfStates(Arrays.asList(sessionStates), SESSION_CONFIGURE_TIMEOUT_MS);
    assertTrue("Creating a reprocessable session failed.", state == BlockingSessionCallback.SESSION_READY);
    CameraCaptureSession session = sessionListener.waitAndGetSession(SESSION_CONFIGURE_TIMEOUT_MS);
    assertTrue("Camera session should be a reprocessable session", session.isReprocessable());
    return session;
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession)

Example 38 with BlockingSessionCallback

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

the class Camera2Source method onOpen.

@Override
protected void onOpen() {
    mLooperThread = new CameraTestThread();
    Handler mHandler;
    try {
        mHandler = mLooperThread.start();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    try {
        String backCameraId = "0";
        BlockingCameraManager blkManager = new BlockingCameraManager(mCameraManager);
        mCamera = blkManager.openCamera(backCameraId, /*listener*/
        null, mHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } catch (BlockingOpenException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    Element ele = Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV);
    rgbConverter = ScriptIntrinsicYuvToRGB.create(mRS, ele);
    Type.Builder yuvBuilder = new Type.Builder(mRS, ele);
    yuvBuilder.setYuvFormat(ImageFormat.YUV_420_888);
    yuvBuilder.setX(mWidth);
    yuvBuilder.setY(mHeight);
    mAllocationIn = Allocation.createTyped(mRS, yuvBuilder.create(), Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_INPUT);
    mSurface = mAllocationIn.getSurface();
    mAllocationIn.setOnBufferAvailableListener(this);
    rgbConverter.setInput(mAllocationIn);
    mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
    mAllocationOut = Allocation.createFromBitmap(mRS, mBitmap);
    Log.v(TAG, "mcamera: " + mCamera);
    List<Surface> surfaces = new ArrayList<Surface>();
    surfaces.add(mSurface);
    CaptureRequest.Builder mCaptureRequest = null;
    try {
        BlockingSessionCallback blkSession = new BlockingSessionCallback();
        mCamera.createCaptureSession(surfaces, blkSession, mHandler);
        mCaptureRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mCaptureRequest.addTarget(mSurface);
        mCameraSession = blkSession.waitAndGetSession(SESSION_TIMEOUT_MS);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    try {
        mCameraSession.setRepeatingRequest(mCaptureRequest.build(), new MyCaptureCallback(), mHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    mProperties = null;
    try {
        mProperties = mCameraManager.getCameraCharacteristics(mCamera.getId());
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) Element(android.renderscript.Element) ArrayList(java.util.ArrayList) Handler(android.os.Handler) BlockingCameraManager(com.android.ex.camera2.blocking.BlockingCameraManager) BlockingOpenException(com.android.ex.camera2.blocking.BlockingCameraManager.BlockingOpenException) CameraAccessException(android.hardware.camera2.CameraAccessException) Surface(android.view.Surface) CameraAccessException(android.hardware.camera2.CameraAccessException) Type(android.renderscript.Type) FrameType(androidx.media.filterfw.FrameType) BlockingOpenException(com.android.ex.camera2.blocking.BlockingCameraManager.BlockingOpenException) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 39 with BlockingSessionCallback

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

the class Camera2SurfaceViewTestCase method configurePreviewOutput.

/**
     * Configure the preview output stream.
     *
     * @param request The request to be configured with preview surface
     */
protected void configurePreviewOutput(CaptureRequest.Builder request) throws CameraAccessException {
    List<Surface> outputSurfaces = new ArrayList<Surface>(/*capacity*/
    1);
    outputSurfaces.add(mPreviewSurface);
    mSessionListener = new BlockingSessionCallback();
    mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
    request.addTarget(mPreviewSurface);
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) ArrayList(java.util.ArrayList) Surface(android.view.Surface)

Example 40 with BlockingSessionCallback

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

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)

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