Search in sources :

Example 46 with CaptureRequest

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

the class CameraCaptureSessionImpl method setRepeatingBurst.

@Override
public synchronized int setRepeatingBurst(List<CaptureRequest> requests, CaptureCallback callback, Handler handler) throws CameraAccessException {
    if (requests == null) {
        throw new IllegalArgumentException("requests must not be null");
    } else if (requests.isEmpty()) {
        throw new IllegalArgumentException("requests must have at least one element");
    }
    for (CaptureRequest r : requests) {
        if (r.isReprocess()) {
            throw new IllegalArgumentException("repeating reprocess burst requests are not " + "supported");
        }
    }
    checkNotClosed();
    handler = checkHandler(handler, callback);
    if (DEBUG) {
        CaptureRequest[] requestArray = requests.toArray(new CaptureRequest[0]);
        Log.v(TAG, mIdString + "setRepeatingBurst - requests " + Arrays.toString(requestArray) + ", callback " + callback + " handler" + "" + handler);
    }
    return addPendingSequence(mDeviceImpl.setRepeatingBurst(requests, createCaptureCallbackProxy(handler, callback), mDeviceHandler));
}
Also used : CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 47 with CaptureRequest

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

the class CameraConstrainedHighSpeedCaptureSessionImpl method createHighSpeedRequestList.

@Override
public List<CaptureRequest> createHighSpeedRequestList(CaptureRequest request) throws CameraAccessException {
    if (request == null) {
        throw new IllegalArgumentException("Input capture request must not be null");
    }
    Collection<Surface> outputSurfaces = request.getTargets();
    Range<Integer> fpsRange = request.get(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE);
    StreamConfigurationMap config = mCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    SurfaceUtils.checkConstrainedHighSpeedSurfaces(outputSurfaces, fpsRange, config);
    // Request list size: to limit the preview to 30fps, need use maxFps/30; to maximize
    // the preview frame rate, should use maxBatch size for that high speed stream
    // configuration. We choose the former for now.
    int requestListSize = fpsRange.getUpper() / 30;
    List<CaptureRequest> requestList = new ArrayList<CaptureRequest>();
    // Prepare the Request builders: need carry over the request controls.
    // First, create a request builder that will only include preview or recording target.
    CameraMetadataNative requestMetadata = new CameraMetadataNative(request.getNativeCopy());
    // Note that after this step, the requestMetadata is mutated (swapped) and can not be used
    // for next request builder creation.
    CaptureRequest.Builder singleTargetRequestBuilder = new CaptureRequest.Builder(requestMetadata, /*reprocess*/
    false, CameraCaptureSession.SESSION_ID_NONE);
    // Overwrite the capture intent to make sure a good value is set.
    Iterator<Surface> iterator = outputSurfaces.iterator();
    Surface firstSurface = iterator.next();
    Surface secondSurface = null;
    if (outputSurfaces.size() == 1 && SurfaceUtils.isSurfaceForHwVideoEncoder(firstSurface)) {
        singleTargetRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW);
    } else {
        // Video only, or preview + video
        singleTargetRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_VIDEO_RECORD);
    }
    singleTargetRequestBuilder.setPartOfCHSRequestList(/*partOfCHSList*/
    true);
    // Second, Create a request builder that will include both preview and recording targets.
    CaptureRequest.Builder doubleTargetRequestBuilder = null;
    if (outputSurfaces.size() == 2) {
        // Have to create a new copy, the original one was mutated after a new
        // CaptureRequest.Builder creation.
        requestMetadata = new CameraMetadataNative(request.getNativeCopy());
        doubleTargetRequestBuilder = new CaptureRequest.Builder(requestMetadata, /*reprocess*/
        false, CameraCaptureSession.SESSION_ID_NONE);
        doubleTargetRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_VIDEO_RECORD);
        doubleTargetRequestBuilder.addTarget(firstSurface);
        secondSurface = iterator.next();
        doubleTargetRequestBuilder.addTarget(secondSurface);
        doubleTargetRequestBuilder.setPartOfCHSRequestList(/*partOfCHSList*/
        true);
        // Make sure singleTargetRequestBuilder contains only recording surface for
        // preview + recording case.
        Surface recordingSurface = firstSurface;
        if (!SurfaceUtils.isSurfaceForHwVideoEncoder(recordingSurface)) {
            recordingSurface = secondSurface;
        }
        singleTargetRequestBuilder.addTarget(recordingSurface);
    } else {
        // Single output case: either recording or preview.
        singleTargetRequestBuilder.addTarget(firstSurface);
    }
    // Generate the final request list.
    for (int i = 0; i < requestListSize; i++) {
        if (i == 0 && doubleTargetRequestBuilder != null) {
            // First request should be recording + preview request
            requestList.add(doubleTargetRequestBuilder.build());
        } else {
            requestList.add(singleTargetRequestBuilder.build());
        }
    }
    return Collections.unmodifiableList(requestList);
}
Also used : ArrayList(java.util.ArrayList) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap) Surface(android.view.Surface) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 48 with CaptureRequest

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

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

the class CameraDeviceBinderTest method testIdleCallback.

@SmallTest
public void testIdleCallback() throws Exception {
    int status;
    CaptureRequest request = createDefaultBuilder(/* needStream */
    true).build();
    // Try streaming
    SubmitInfo streamingInfo = submitCameraRequest(request, /* streaming */
    true);
    // Wait a bit to fill up the queue
    SystemClock.sleep(WAIT_FOR_WORK_MS);
    // Cancel and make sure we eventually quiesce
    long lastFrameNumber = mCameraUser.cancelRequest(streamingInfo.getRequestId());
    verify(mMockCb, timeout(WAIT_FOR_IDLE_TIMEOUT_MS).times(1)).onDeviceIdle();
    // 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);
    // And wait for more idle
    verify(mMockCb, timeout(WAIT_FOR_IDLE_TIMEOUT_MS).times(2)).onDeviceIdle();
}
Also used : SubmitInfo(android.hardware.camera2.utils.SubmitInfo) CaptureRequest(android.hardware.camera2.CaptureRequest) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 50 with CaptureRequest

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

the class CameraDeviceBinderTest method testCaptureStartedCallbacks.

@SmallTest
public void testCaptureStartedCallbacks() throws Exception {
    CaptureRequest request = createDefaultBuilder(/* needStream */
    true).build();
    ArgumentCaptor<Long> timestamps = ArgumentCaptor.forClass(Long.class);
    // Test both single request and streaming request.
    SubmitInfo requestInfo1 = submitCameraRequest(request, /* streaming */
    false);
    verify(mMockCb, timeout(WAIT_FOR_COMPLETE_TIMEOUT_MS).times(1)).onCaptureStarted(any(CaptureResultExtras.class), anyLong());
    SubmitInfo streamingInfo = submitCameraRequest(request, /* streaming */
    true);
    verify(mMockCb, timeout(WAIT_FOR_COMPLETE_TIMEOUT_MS).atLeast(NUM_CALLBACKS_CHECKED)).onCaptureStarted(any(CaptureResultExtras.class), timestamps.capture());
    // All timestamps should be larger than 0.
    long timestamp = 0;
    for (Long nextTimestamp : timestamps.getAllValues()) {
        Log.v(TAG, "next t: " + nextTimestamp + " current t: " + timestamp);
        assertTrue("Captures are out of order", timestamp < nextTimestamp);
        timestamp = nextTimestamp;
    }
}
Also used : SubmitInfo(android.hardware.camera2.utils.SubmitInfo) 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