Search in sources :

Example 91 with CaptureRequest

use of android.hardware.camera2.CaptureRequest in project android_frameworks_base by DirtyUnicorns.

the class RequestThreadManager method submitCaptureRequests.

/**
     * Submit the given burst of requests to be captured.
     *
     * <p>If the burst is repeating, replace the current repeating burst.</p>
     *
     * @param requests the burst of requests to add to the queue.
     * @param repeating true if the burst is repeating.
     * @return the submission info, including the new request id, and the last frame number, which
     *   contains either the frame number of the last frame that will be returned for this request,
     *   or the frame number of the last frame that will be returned for the current repeating
     *   request if this burst is set to be repeating.
     */
public SubmitInfo submitCaptureRequests(CaptureRequest[] requests, boolean repeating) {
    Handler handler = mRequestThread.waitAndGetHandler();
    SubmitInfo info;
    synchronized (mIdleLock) {
        info = mRequestQueue.submit(requests, repeating);
        handler.sendEmptyMessage(MSG_SUBMIT_CAPTURE_REQUEST);
    }
    return info;
}
Also used : SubmitInfo(android.hardware.camera2.utils.SubmitInfo) Handler(android.os.Handler)

Example 92 with CaptureRequest

use of android.hardware.camera2.CaptureRequest 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 93 with CaptureRequest

use of android.hardware.camera2.CaptureRequest in project android_frameworks_base by DirtyUnicorns.

the class CameraDeviceBinderTest method testSubmitStreamingRequest.

@SmallTest
public void testSubmitStreamingRequest() throws Exception {
    CaptureRequest.Builder builder = createDefaultBuilder(/* needStream */
    true);
    CaptureRequest request = builder.build();
    // Submit valid request once (non-streaming), and another time
    // (streaming)
    SubmitInfo requestInfo1 = submitCameraRequest(request, /* streaming */
    false);
    SubmitInfo requestInfoStreaming = submitCameraRequest(request, /* streaming */
    true);
    assertNotSame("Request IDs should be unique for multiple requests", requestInfo1.getRequestId(), requestInfoStreaming.getRequestId());
    try {
        long lastFrameNumber = mCameraUser.cancelRequest(-1);
        fail("Expected exception");
    } catch (ServiceSpecificException e) {
        assertEquals("Invalid request IDs should not be cancellable", ICameraService.ERROR_ILLEGAL_ARGUMENT, e.errorCode);
    }
    try {
        long lastFrameNumber = mCameraUser.cancelRequest(requestInfo1.getRequestId());
        fail("Expected exception");
    } catch (ServiceSpecificException e) {
        assertEquals("Non-streaming request IDs should not be cancellable", ICameraService.ERROR_ILLEGAL_ARGUMENT, e.errorCode);
    }
    long lastFrameNumber = mCameraUser.cancelRequest(requestInfoStreaming.getRequestId());
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) SubmitInfo(android.hardware.camera2.utils.SubmitInfo) CaptureRequest(android.hardware.camera2.CaptureRequest) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 94 with CaptureRequest

use of android.hardware.camera2.CaptureRequest in project android_frameworks_base by DirtyUnicorns.

the class CameraDeviceBinderTest method testFlush.

@SmallTest
public void testFlush() throws Exception {
    int status;
    // Initial flush should work
    long lastFrameNumber = mCameraUser.flush();
    // Then set up a stream
    CaptureRequest request = createDefaultBuilder(/* needStream */
    true).build();
    // Flush should still be a no-op, really
    lastFrameNumber = mCameraUser.flush();
    // Submit a few capture requests
    SubmitInfo requestInfo1 = submitCameraRequest(request, /* streaming */
    false);
    SubmitInfo requestInfo2 = submitCameraRequest(request, /* streaming */
    false);
    SubmitInfo requestInfo3 = submitCameraRequest(request, /* streaming */
    false);
    SubmitInfo requestInfo4 = submitCameraRequest(request, /* streaming */
    false);
    SubmitInfo requestInfo5 = submitCameraRequest(request, /* streaming */
    false);
    // Then flush and wait for idle
    lastFrameNumber = mCameraUser.flush();
    verify(mMockCb, timeout(WAIT_FOR_FLUSH_TIMEOUT_MS).times(1)).onDeviceIdle();
    // Now a streaming request
    SubmitInfo streamingInfo = submitCameraRequest(request, /* streaming */
    true);
    // Wait a bit to fill up the queue
    SystemClock.sleep(WAIT_FOR_WORK_MS);
    // Then flush and wait for the idle callback
    lastFrameNumber = mCameraUser.flush();
    verify(mMockCb, timeout(WAIT_FOR_FLUSH_TIMEOUT_MS).times(2)).onDeviceIdle();
// TODO: When errors are hooked up, count that errors + successful
// requests equal to 5.
}
Also used : SubmitInfo(android.hardware.camera2.utils.SubmitInfo) CaptureRequest(android.hardware.camera2.CaptureRequest) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 95 with CaptureRequest

use of android.hardware.camera2.CaptureRequest in project android_frameworks_base by DirtyUnicorns.

the class CameraDeviceBinderTest method testCaptureResultCallbacks.

@SmallTest
public void testCaptureResultCallbacks() throws Exception {
    IsMetadataNotEmpty matcher = new IsMetadataNotEmpty();
    CaptureRequest request = createDefaultBuilder(/* needStream */
    true).build();
    // Test both single request and streaming request.
    verify(mMockCb, timeout(WAIT_FOR_COMPLETE_TIMEOUT_MS).times(1)).onResultReceived(argThat(matcher), any(CaptureResultExtras.class));
    verify(mMockCb, timeout(WAIT_FOR_COMPLETE_TIMEOUT_MS).atLeast(NUM_CALLBACKS_CHECKED)).onResultReceived(argThat(matcher), any(CaptureResultExtras.class));
}
Also used : CaptureResultExtras(android.hardware.camera2.impl.CaptureResultExtras) CaptureRequest(android.hardware.camera2.CaptureRequest) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

CaptureRequest (android.hardware.camera2.CaptureRequest)126 ArrayList (java.util.ArrayList)60 SubmitInfo (android.hardware.camera2.utils.SubmitInfo)50 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)45 SmallTest (android.test.suitebuilder.annotation.SmallTest)35 Size (android.util.Size)35 TotalCaptureResult (android.hardware.camera2.TotalCaptureResult)26 Image (android.media.Image)25 Surface (android.view.Surface)25 CameraTestUtils.getDataFromImage (com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage)20 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)16 Rect (android.graphics.Rect)15 Camera (android.hardware.Camera)15 CaptureResult (android.hardware.camera2.CaptureResult)15 ServiceSpecificException (android.os.ServiceSpecificException)15 SimpleImageReaderListener (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener)15 Parameters (android.hardware.Camera.Parameters)10 CaptureResultExtras (android.hardware.camera2.impl.CaptureResultExtras)10 ZoomData (android.hardware.camera2.legacy.ParameterUtils.ZoomData)10 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)10