Search in sources :

Example 71 with CaptureRequest

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

the class RequestQueue method submit.

/**
     * Add a the given burst to the queue.
     *
     * <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 synchronized SubmitInfo submit(CaptureRequest[] requests, boolean repeating) {
    int requestId = mCurrentRequestId++;
    BurstHolder burst = new BurstHolder(requestId, repeating, requests, mJpegSurfaceIds);
    long lastFrame = INVALID_FRAME;
    if (burst.isRepeating()) {
        Log.i(TAG, "Repeating capture request set.");
        if (mRepeatingRequest != null) {
            lastFrame = (mCurrentRepeatingFrameNumber == INVALID_FRAME) ? INVALID_FRAME : mCurrentRepeatingFrameNumber - 1;
        }
        mCurrentRepeatingFrameNumber = INVALID_FRAME;
        mRepeatingRequest = burst;
    } else {
        mRequestQueue.offer(burst);
        lastFrame = calculateLastFrame(burst.getRequestId());
    }
    SubmitInfo info = new SubmitInfo(requestId, lastFrame);
    return info;
}
Also used : SubmitInfo(android.hardware.camera2.utils.SubmitInfo)

Example 72 with CaptureRequest

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

the class LegacyCameraDevice method submitRequestList.

/**
     * Submit a burst of capture requests.
     *
     * @param requestList a list of capture requests to execute.
     * @param repeating {@code true} if this 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 submitRequestList(CaptureRequest[] requestList, boolean repeating) {
    if (requestList == null || requestList.length == 0) {
        Log.e(TAG, "submitRequestList - Empty/null requests are not allowed");
        throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - Empty/null requests are not allowed");
    }
    List<Long> surfaceIds;
    try {
        surfaceIds = (mConfiguredSurfaces == null) ? new ArrayList<Long>() : getSurfaceIds(mConfiguredSurfaces);
    } catch (BufferQueueAbandonedException e) {
        throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - configured surface is abandoned.");
    }
    // Make sure that there all requests have at least 1 surface; all surfaces are non-null
    for (CaptureRequest request : requestList) {
        if (request.getTargets().isEmpty()) {
            Log.e(TAG, "submitRequestList - " + "Each request must have at least one Surface target");
            throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - " + "Each request must have at least one Surface target");
        }
        for (Surface surface : request.getTargets()) {
            if (surface == null) {
                Log.e(TAG, "submitRequestList - Null Surface targets are not allowed");
                throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - Null Surface targets are not allowed");
            } else if (mConfiguredSurfaces == null) {
                Log.e(TAG, "submitRequestList - must configure " + " device with valid surfaces before submitting requests");
                throw new ServiceSpecificException(INVALID_OPERATION, "submitRequestList - must configure " + " device with valid surfaces before submitting requests");
            } else if (!containsSurfaceId(surface, surfaceIds)) {
                Log.e(TAG, "submitRequestList - cannot use a surface that wasn't configured");
                throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - cannot use a surface that wasn't configured");
            }
        }
    }
    // TODO: further validation of request here
    mIdle.close();
    return mRequestThreadManager.submitCaptureRequests(requestList, repeating);
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) ArrayList(java.util.ArrayList) CaptureRequest(android.hardware.camera2.CaptureRequest) Surface(android.view.Surface)

Example 73 with CaptureRequest

use of android.hardware.camera2.CaptureRequest in project material-camera by afollestad.

the class Camera2Fragment method captureStillPicture.

/**
     * Capture a still picture. This method should be called when we get a response in
     * {@link #mCaptureCallback} from both {@link #takeStillshot()}.
     */
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());
        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        setFlashMode(captureBuilder);
        // Orientation
        CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraDevice.getId());
        //noinspection ConstantConditions,ResourceType
        @Degrees.DegreeUnits final int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
        int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        // default camera orientation used to be 90 degrees, for Nexus 5X, 6P it is 270 degrees
        if (sensorOrientation == Degrees.DEGREES_270) {
            displayRotation += 2 % 3;
        }
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(displayRotation));
        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                Log.d("stillshot", "onCaptureCompleted");
                unlockFocus();
            }
        };
        mPreviewSession.stopRepeating();
        mPreviewSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
Also used : Activity(android.app.Activity) CameraManager(android.hardware.camera2.CameraManager) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession) Point(android.graphics.Point) CameraAccessException(android.hardware.camera2.CameraAccessException) NonNull(android.support.annotation.NonNull) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 74 with CaptureRequest

use of android.hardware.camera2.CaptureRequest in project platform_frameworks_base by android.

the class Camera2CaptureRequestTest method autoAeMultipleCapturesThenTestLock.

/**
     * Issue multiple auto AE captures, then lock AE, validate the AE lock vs.
     * the first capture result after the AE lock. The right AE lock behavior is:
     * When it is locked, it locks to the current exposure value, and all subsequent
     * request with lock ON will have the same exposure value locked.
     */
private void autoAeMultipleCapturesThenTestLock(CaptureRequest.Builder requestBuilder, int aeMode, int numCapturesDuringLock) throws Exception {
    if (numCapturesDuringLock < 1) {
        throw new IllegalArgumentException("numCapturesBeforeLock must be no less than 1");
    }
    if (VERBOSE) {
        Log.v(TAG, "Camera " + mCamera.getId() + ": Testing auto AE mode and lock for mode " + aeMode + " with " + numCapturesDuringLock + " captures before lock");
    }
    final int NUM_CAPTURES_BEFORE_LOCK = 2;
    SimpleCaptureCallback listener = new SimpleCaptureCallback();
    CaptureResult[] resultsDuringLock = new CaptureResult[numCapturesDuringLock];
    boolean canSetAeLock = mStaticInfo.isAeLockSupported();
    // Reset the AE lock to OFF, since we are reusing this builder many times
    if (canSetAeLock) {
        requestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false);
    }
    // Just send several captures with auto AE, lock off.
    CaptureRequest request = requestBuilder.build();
    for (int i = 0; i < NUM_CAPTURES_BEFORE_LOCK; i++) {
        mSession.capture(request, listener, mHandler);
    }
    waitForNumResults(listener, NUM_CAPTURES_BEFORE_LOCK);
    if (!canSetAeLock) {
        // Without AE lock, the remaining tests items won't work
        return;
    }
    // Then fire several capture to lock the AE.
    requestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, true);
    int requestCount = captureRequestsSynchronized(requestBuilder.build(), numCapturesDuringLock, listener, mHandler);
    int[] sensitivities = new int[numCapturesDuringLock];
    long[] expTimes = new long[numCapturesDuringLock];
    Arrays.fill(sensitivities, -1);
    Arrays.fill(expTimes, -1L);
    // Get the AE lock on result and validate the exposure values.
    waitForNumResults(listener, requestCount - numCapturesDuringLock);
    for (int i = 0; i < resultsDuringLock.length; i++) {
        resultsDuringLock[i] = listener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
    }
    for (int i = 0; i < numCapturesDuringLock; i++) {
        mCollector.expectKeyValueEquals(resultsDuringLock[i], CaptureResult.CONTROL_AE_LOCK, true);
    }
    // Can't read manual sensor/exposure settings without manual sensor
    if (mStaticInfo.isCapabilitySupported(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_READ_SENSOR_SETTINGS)) {
        int sensitivityLocked = getValueNotNull(resultsDuringLock[0], CaptureResult.SENSOR_SENSITIVITY);
        long expTimeLocked = getValueNotNull(resultsDuringLock[0], CaptureResult.SENSOR_EXPOSURE_TIME);
        for (int i = 1; i < resultsDuringLock.length; i++) {
            mCollector.expectKeyValueEquals(resultsDuringLock[i], CaptureResult.SENSOR_EXPOSURE_TIME, expTimeLocked);
            mCollector.expectKeyValueEquals(resultsDuringLock[i], CaptureResult.SENSOR_SENSITIVITY, sensitivityLocked);
        }
    }
}
Also used : CaptureResult(android.hardware.camera2.CaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Example 75 with CaptureRequest

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

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