Search in sources :

Example 21 with CaptureCallback

use of android.hardware.camera2.CameraCaptureSession.CaptureCallback in project android_frameworks_base by crdroidandroid.

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 22 with CaptureCallback

use of android.hardware.camera2.CameraCaptureSession.CaptureCallback in project android_frameworks_base by crdroidandroid.

the class Camera2Focuser method cancelAutoFocus.

/**
     * Cancel ongoing auto focus, unlock the auto-focus if it was locked, and
     * resume to passive continuous auto focus.
     *
     * @throws CameraAccessException
     */
public synchronized void cancelAutoFocus() throws CameraAccessException {
    mSuccess = false;
    mLocked = false;
    // reset the AF regions:
    setAfRegions(null);
    // Create request builders, the af regions are automatically updated.
    mRepeatingBuilder = createRequestBuilder();
    CaptureRequest.Builder requestBuilder = createRequestBuilder();
    mAutoFocus.setPassiveAutoFocus(/*picture*/
    true, mRepeatingBuilder);
    mAutoFocus.unlockAutoFocus(mRepeatingBuilder, requestBuilder);
    CaptureCallback listener = createCaptureListener();
    mSession.setRepeatingRequest(mRepeatingBuilder.build(), listener, mHandler);
    mSession.capture(requestBuilder.build(), listener, mHandler);
}
Also used : CaptureCallback(android.hardware.camera2.CameraCaptureSession.CaptureCallback) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 23 with CaptureCallback

use of android.hardware.camera2.CameraCaptureSession.CaptureCallback in project android_frameworks_base by AOSPA.

the class Camera2ReprocessCaptureTest method testReprocessAbort.

/**
     * Test aborting a burst reprocess capture and multiple single reprocess captures.
     */
private void testReprocessAbort(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocessAbort: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat);
    }
    try {
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat, NUM_REPROCESS_CAPTURES);
        setupReprocessableSession(/*previewSurface*/
        null, NUM_REPROCESS_CAPTURES);
        // Test two cases: submitting reprocess requests one by one and in a burst.
        boolean[] submitInBursts = { false, true };
        for (boolean submitInBurst : submitInBursts) {
            // Prepare reprocess capture requests.
            ArrayList<CaptureRequest> reprocessRequests = new ArrayList<>(NUM_REPROCESS_CAPTURES);
            for (int i = 0; i < NUM_REPROCESS_CAPTURES; i++) {
                TotalCaptureResult result = submitCaptureRequest(mFirstImageReader.getSurface(), /*inputResult*/
                null);
                mImageWriter.queueInputImage(mFirstImageReaderListener.getImage(CAPTURE_TIMEOUT_MS));
                CaptureRequest.Builder builder = mCamera.createReprocessCaptureRequest(result);
                builder.addTarget(getReprocessOutputImageReader().getSurface());
                reprocessRequests.add(builder.build());
            }
            SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
            // Submit reprocess capture requests.
            if (submitInBurst) {
                mSession.captureBurst(reprocessRequests, captureCallback, mHandler);
            } else {
                for (CaptureRequest request : reprocessRequests) {
                    mSession.capture(request, captureCallback, mHandler);
                }
            }
            // Abort after getting the first result
            TotalCaptureResult reprocessResult = captureCallback.getTotalCaptureResultForRequest(reprocessRequests.get(0), CAPTURE_TIMEOUT_FRAMES);
            mSession.abortCaptures();
            // Wait until the session is ready again.
            mSessionListener.getStateWaiter().waitForState(BlockingSessionCallback.SESSION_READY, SESSION_CLOSE_TIMEOUT_MS);
            // Gather all failed requests.
            ArrayList<CaptureFailure> failures = captureCallback.getCaptureFailures(NUM_REPROCESS_CAPTURES - 1);
            ArrayList<CaptureRequest> failedRequests = new ArrayList<>();
            for (CaptureFailure failure : failures) {
                failedRequests.add(failure.getRequest());
            }
            // For each request that didn't fail must have a valid result.
            for (int i = 1; i < reprocessRequests.size(); i++) {
                CaptureRequest request = reprocessRequests.get(i);
                if (!failedRequests.contains(request)) {
                    captureCallback.getTotalCaptureResultForRequest(request, CAPTURE_TIMEOUT_FRAMES);
                }
            }
            // Drain the image reader listeners.
            mFirstImageReaderListener.drain();
            if (!mShareOneImageReader) {
                mSecondImageReaderListener.drain();
            }
            // Make sure all input surfaces are released.
            for (int i = 0; i < NUM_REPROCESS_CAPTURES; i++) {
                mImageWriterListener.waitForImageReleased(CAPTURE_TIMEOUT_MS);
            }
        }
    } finally {
        closeReprossibleSession();
        closeImageReaders();
    }
}
Also used : CaptureFailure(android.hardware.camera2.CaptureFailure) ArrayList(java.util.ArrayList) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Example 24 with CaptureCallback

use of android.hardware.camera2.CameraCaptureSession.CaptureCallback in project android_frameworks_base by AOSPA.

the class Camera2Focuser method startAutoFocusFullActiveLocked.

private void startAutoFocusFullActiveLocked() throws CameraAccessException {
    // Create request builders, the af regions are automatically updated.
    mRepeatingBuilder = createRequestBuilder();
    CaptureRequest.Builder requestBuilder = createRequestBuilder();
    mAutoFocus.setActiveAutoFocus(mRepeatingBuilder, requestBuilder);
    if (mRepeatingBuilder.get(CaptureRequest.CONTROL_AF_TRIGGER) != CaptureRequest.CONTROL_AF_TRIGGER_IDLE) {
        throw new AssertionError("Wrong trigger set in repeating request");
    }
    if (requestBuilder.get(CaptureRequest.CONTROL_AF_TRIGGER) != CaptureRequest.CONTROL_AF_TRIGGER_START) {
        throw new AssertionError("Wrong trigger set in queued request");
    }
    mAutoFocus.resetState();
    CaptureCallback listener = createCaptureListener();
    mSession.setRepeatingRequest(mRepeatingBuilder.build(), listener, mHandler);
    mSession.capture(requestBuilder.build(), listener, mHandler);
}
Also used : CaptureCallback(android.hardware.camera2.CameraCaptureSession.CaptureCallback) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 25 with CaptureCallback

use of android.hardware.camera2.CameraCaptureSession.CaptureCallback in project android_frameworks_base by DirtyUnicorns.

the class CameraCaptureSessionImpl method captureBurst.

@Override
public synchronized int captureBurst(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 request : requests) {
        if (request.isReprocess()) {
            if (!isReprocessable()) {
                throw new IllegalArgumentException("This capture session cannot handle " + "reprocess requests");
            } else if (request.getReprocessableSessionId() != mId) {
                throw new IllegalArgumentException("Capture request was created for another " + "session");
            }
        }
    }
    checkNotClosed();
    handler = checkHandler(handler, callback);
    if (DEBUG) {
        CaptureRequest[] requestArray = requests.toArray(new CaptureRequest[0]);
        Log.v(TAG, mIdString + "captureBurst - requests " + Arrays.toString(requestArray) + ", callback " + callback + " handler " + handler);
    }
    return addPendingSequence(mDeviceImpl.captureBurst(requests, createCaptureCallbackProxy(handler, callback), mDeviceHandler));
}
Also used : CaptureRequest(android.hardware.camera2.CaptureRequest)

Aggregations

CaptureRequest (android.hardware.camera2.CaptureRequest)53 TotalCaptureResult (android.hardware.camera2.TotalCaptureResult)28 ArrayList (java.util.ArrayList)26 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)25 CaptureCallback (android.hardware.camera2.CameraCaptureSession.CaptureCallback)11 Image (android.media.Image)10 CameraTestUtils.getDataFromImage (com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage)10 CaptureFailure (android.hardware.camera2.CaptureFailure)6 Surface (android.view.Surface)6 SubmitInfo (android.hardware.camera2.utils.SubmitInfo)5 Size (android.util.Size)5 CameraCaptureSession (android.hardware.camera2.CameraCaptureSession)4 CameraAccessException (android.hardware.camera2.CameraAccessException)3 Activity (android.app.Activity)2 Point (android.graphics.Point)2 SuppressLint (android.annotation.SuppressLint)1 SurfaceTexture (android.graphics.SurfaceTexture)1 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)1 CameraManager (android.hardware.camera2.CameraManager)1 NonNull (android.support.annotation.NonNull)1