Search in sources :

Example 51 with CaptureRequest

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

the class Camera2StillCaptureTest method fullRawCaptureTestByCamera.

private void fullRawCaptureTestByCamera() throws Exception {
    Size maxPreviewSz = mOrderedPreviewSizes.get(0);
    Size maxStillSz = mOrderedStillSizes.get(0);
    SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
    SimpleImageReaderListener jpegListener = new SimpleImageReaderListener();
    SimpleImageReaderListener rawListener = new SimpleImageReaderListener();
    Size size = mStaticInfo.getRawDimensChecked();
    if (VERBOSE) {
        Log.v(TAG, "Testing multi capture with size " + size.toString() + ", preview size " + maxPreviewSz);
    }
    // Prepare raw capture and start preview.
    CaptureRequest.Builder previewBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
    CaptureRequest.Builder multiBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
    ImageReader rawReader = null;
    ImageReader jpegReader = null;
    try {
        // Create ImageReaders.
        rawReader = makeImageReader(size, ImageFormat.RAW_SENSOR, MAX_READER_IMAGES, rawListener, mHandler);
        jpegReader = makeImageReader(maxStillSz, ImageFormat.JPEG, MAX_READER_IMAGES, jpegListener, mHandler);
        updatePreviewSurface(maxPreviewSz);
        // Configure output streams with preview and jpeg streams.
        List<Surface> outputSurfaces = new ArrayList<Surface>();
        outputSurfaces.add(rawReader.getSurface());
        outputSurfaces.add(jpegReader.getSurface());
        outputSurfaces.add(mPreviewSurface);
        mSessionListener = new BlockingSessionCallback();
        mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
        // Configure the requests.
        previewBuilder.addTarget(mPreviewSurface);
        multiBuilder.addTarget(mPreviewSurface);
        multiBuilder.addTarget(rawReader.getSurface());
        multiBuilder.addTarget(jpegReader.getSurface());
        // Start preview.
        mSession.setRepeatingRequest(previewBuilder.build(), null, mHandler);
        // Poor man's 3A, wait 2 seconds for AE/AF (if any) to settle.
        // TODO: Do proper 3A trigger and lock (see testTakePictureTest).
        Thread.sleep(3000);
        multiBuilder.set(CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE, CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE_ON);
        CaptureRequest multiRequest = multiBuilder.build();
        mSession.capture(multiRequest, resultListener, mHandler);
        CaptureResult result = resultListener.getCaptureResultForRequest(multiRequest, NUM_RESULTS_WAIT_TIMEOUT);
        Image jpegImage = jpegListener.getImage(CAPTURE_IMAGE_TIMEOUT_MS);
        basicValidateJpegImage(jpegImage, maxStillSz);
        Image rawImage = rawListener.getImage(CAPTURE_IMAGE_TIMEOUT_MS);
        validateRaw16Image(rawImage, size);
        verifyRawCaptureResult(multiRequest, result);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try (DngCreator dngCreator = new DngCreator(mStaticInfo.getCharacteristics(), result)) {
            dngCreator.writeImage(outputStream, rawImage);
        }
        if (DEBUG) {
            byte[] rawBuffer = outputStream.toByteArray();
            String rawFileName = DEBUG_FILE_NAME_BASE + "/raw16_" + TAG + size.toString() + "_cam_" + mCamera.getId() + ".dng";
            Log.d(TAG, "Dump raw file into " + rawFileName);
            dumpFile(rawFileName, rawBuffer);
            byte[] jpegBuffer = getDataFromImage(jpegImage);
            String jpegFileName = DEBUG_FILE_NAME_BASE + "/jpeg_" + TAG + size.toString() + "_cam_" + mCamera.getId() + ".jpg";
            Log.d(TAG, "Dump jpeg file into " + rawFileName);
            dumpFile(jpegFileName, jpegBuffer);
        }
        stopPreview();
    } finally {
        CameraTestUtils.closeImageReader(rawReader);
        CameraTestUtils.closeImageReader(jpegReader);
        rawReader = null;
        jpegReader = null;
    }
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) Size(android.util.Size) DngCreator(android.hardware.camera2.DngCreator) CaptureResult(android.hardware.camera2.CaptureResult) ArrayList(java.util.ArrayList) SimpleImageReaderListener(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CameraTestUtils.basicValidateJpegImage(com.android.mediaframeworktest.helpers.CameraTestUtils.basicValidateJpegImage) CameraTestUtils.getDataFromImage(com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage) Image(android.media.Image) Surface(android.view.Surface) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback) CameraTestUtils.makeImageReader(com.android.mediaframeworktest.helpers.CameraTestUtils.makeImageReader) ImageReader(android.media.ImageReader)

Example 52 with CaptureRequest

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

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 53 with CaptureRequest

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

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 54 with CaptureRequest

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

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 55 with CaptureRequest

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

the class CameraDeviceImpl method submitCaptureRequest.

private int submitCaptureRequest(List<CaptureRequest> requestList, CaptureCallback callback, Handler handler, boolean repeating) throws CameraAccessException {
    // Need a valid handler, or current thread needs to have a looper, if
    // callback is valid
    handler = checkHandler(handler, callback);
    // Make sure that there all requests have at least 1 surface; all surfaces are non-null
    for (CaptureRequest request : requestList) {
        if (request.getTargets().isEmpty()) {
            throw new IllegalArgumentException("Each request must have at least one Surface target");
        }
        for (Surface surface : request.getTargets()) {
            if (surface == null) {
                throw new IllegalArgumentException("Null Surface targets are not allowed");
            }
        }
    }
    synchronized (mInterfaceLock) {
        checkIfCameraClosedOrInError();
        if (repeating) {
            stopRepeating();
        }
        SubmitInfo requestInfo;
        CaptureRequest[] requestArray = requestList.toArray(new CaptureRequest[requestList.size()]);
        requestInfo = mRemoteDevice.submitRequestList(requestArray, repeating);
        if (DEBUG) {
            Log.v(TAG, "last frame number " + requestInfo.getLastFrameNumber());
        }
        if (callback != null) {
            mCaptureCallbackMap.put(requestInfo.getRequestId(), new CaptureCallbackHolder(callback, requestList, handler, repeating, mNextSessionId - 1));
        } else {
            if (DEBUG) {
                Log.d(TAG, "Listen for request " + requestInfo.getRequestId() + " is null");
            }
        }
        if (repeating) {
            if (mRepeatingRequestId != REQUEST_ID_NONE) {
                checkEarlyTriggerSequenceComplete(mRepeatingRequestId, requestInfo.getLastFrameNumber());
            }
            mRepeatingRequestId = requestInfo.getRequestId();
        } else {
            mRequestLastFrameNumbersList.add(new RequestLastFrameNumbersHolder(requestList, requestInfo));
        }
        if (mIdle) {
            mDeviceHandler.post(mCallOnActive);
        }
        mIdle = false;
        return requestInfo.getRequestId();
    }
}
Also used : SubmitInfo(android.hardware.camera2.utils.SubmitInfo) 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