Search in sources :

Example 6 with TotalCaptureResult

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

the class Camera2ReprocessCaptureTest method testReprocessRequestKeys.

/**
     * Test the following keys in reprocess results match the keys in reprocess requests:
     *   1. EDGE_MODE
     *   2. NOISE_REDUCTION_MODE
     *   3. REPROCESS_EFFECTIVE_EXPOSURE_FACTOR (only for YUV reprocess)
     */
private void testReprocessRequestKeys(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocessRequestKeys: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat);
    }
    final Integer[] EDGE_MODES = { CaptureRequest.EDGE_MODE_FAST, CaptureRequest.EDGE_MODE_HIGH_QUALITY, CaptureRequest.EDGE_MODE_OFF, CaptureRequest.EDGE_MODE_ZERO_SHUTTER_LAG };
    final Integer[] NR_MODES = { CaptureRequest.NOISE_REDUCTION_MODE_HIGH_QUALITY, CaptureRequest.NOISE_REDUCTION_MODE_OFF, CaptureRequest.NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG, CaptureRequest.NOISE_REDUCTION_MODE_FAST };
    final Float[] EFFECTIVE_EXP_FACTORS = { null, 1.0f, 2.5f, 4.0f };
    int numFrames = EDGE_MODES.length;
    try {
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat, numFrames);
        setupReprocessableSession(/*previewSurface*/
        null, numFrames);
        // Prepare reprocess capture requests.
        ArrayList<CaptureRequest> reprocessRequests = new ArrayList<>(numFrames);
        for (int i = 0; i < numFrames; 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());
            // Set reprocess request keys
            builder.set(CaptureRequest.EDGE_MODE, EDGE_MODES[i]);
            builder.set(CaptureRequest.NOISE_REDUCTION_MODE, NR_MODES[i]);
            if (inputFormat == ImageFormat.YUV_420_888) {
                builder.set(CaptureRequest.REPROCESS_EFFECTIVE_EXPOSURE_FACTOR, EFFECTIVE_EXP_FACTORS[i]);
            }
            reprocessRequests.add(builder.build());
        }
        // Submit reprocess requests.
        SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
        mSession.captureBurst(reprocessRequests, captureCallback, mHandler);
        TotalCaptureResult[] reprocessResults = captureCallback.getTotalCaptureResultsForRequests(reprocessRequests, CAPTURE_TIMEOUT_FRAMES);
        for (int i = 0; i < numFrames; i++) {
            // Verify result's keys
            Integer resultEdgeMode = reprocessResults[i].get(CaptureResult.EDGE_MODE);
            Integer resultNoiseReductionMode = reprocessResults[i].get(CaptureResult.NOISE_REDUCTION_MODE);
            assertEquals("Reprocess result edge mode (" + resultEdgeMode + ") doesn't match requested edge mode (" + EDGE_MODES[i] + ")", resultEdgeMode, EDGE_MODES[i]);
            assertEquals("Reprocess result noise reduction mode (" + resultNoiseReductionMode + ") doesn't match requested noise reduction mode (" + NR_MODES[i] + ")", resultNoiseReductionMode, NR_MODES[i]);
            if (inputFormat == ImageFormat.YUV_420_888) {
                Float resultEffectiveExposureFactor = reprocessResults[i].get(CaptureResult.REPROCESS_EFFECTIVE_EXPOSURE_FACTOR);
                assertEquals("Reprocess effective exposure factor (" + resultEffectiveExposureFactor + ") doesn't match requested " + "effective exposure factor (" + EFFECTIVE_EXP_FACTORS[i] + ")", resultEffectiveExposureFactor, EFFECTIVE_EXP_FACTORS[i]);
            }
        }
    } finally {
        closeReprossibleSession();
        closeImageReaders();
    }
}
Also used : ArrayList(java.util.ArrayList) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Example 7 with TotalCaptureResult

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

the class Camera2ReprocessCaptureTest method testReprocessBurst.

/**
     * Test burst of reprocess capture requests.
     */
private void testReprocessBurst(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat, Size previewSize, int numBurst) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocessBurst: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat + " previewSize: " + previewSize + " numBurst: " + numBurst);
    }
    boolean enablePreview = (previewSize != null);
    ImageResultHolder[] imageResultHolders = new ImageResultHolder[0];
    try {
        if (enablePreview) {
            updatePreviewSurface(previewSize);
        } else {
            mPreviewSurface = null;
        }
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat, numBurst);
        setupReprocessableSession(mPreviewSurface, numBurst);
        if (enablePreview) {
            startPreview(mPreviewSurface);
        }
        imageResultHolders = doReprocessBurstCapture(numBurst);
        for (ImageResultHolder holder : imageResultHolders) {
            Image reprocessedImage = holder.getImage();
            TotalCaptureResult result = holder.getTotalCaptureResult();
            mCollector.expectImageProperties("testReprocessBurst", reprocessedImage, reprocessOutputFormat, reprocessOutputSize, result.get(CaptureResult.SENSOR_TIMESTAMP));
            if (DEBUG) {
                Log.d(TAG, String.format("camera %s in %dx%d %d out %dx%d %d", cameraId, inputSize.getWidth(), inputSize.getHeight(), inputFormat, reprocessOutputSize.getWidth(), reprocessOutputSize.getHeight(), reprocessOutputFormat));
                dumpImage(reprocessedImage, "/testReprocessBurst_camera" + cameraId + "_" + mDumpFrameCount);
                mDumpFrameCount++;
            }
        }
    } finally {
        for (ImageResultHolder holder : imageResultHolders) {
            holder.getImage().close();
        }
        closeReprossibleSession();
        closeImageReaders();
    }
}
Also used : TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CameraTestUtils.getDataFromImage(com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage) Image(android.media.Image)

Example 8 with TotalCaptureResult

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

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 9 with TotalCaptureResult

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

the class Camera2ReprocessCaptureTest method submitMixedCaptureBurstRequest.

/**
     * Submit a burst request mixed with regular and reprocess requests.
     *
     * @param outputs An array of output surfaces. One output surface will be used in one request
     *                so the length of the array is the number of requests in a burst request.
     * @param inputResults An array of input results. If it's null, all requests are regular
     *                     requests. If an element is null, that element represents a regular
     *                     request. If an element if not null, that element represents a reprocess
     *                     request.
     *
     */
private TotalCaptureResult[] submitMixedCaptureBurstRequest(Surface[] outputs, TotalCaptureResult[] inputResults) throws Exception {
    if (outputs == null || outputs.length <= 0) {
        throw new IllegalArgumentException("outputs must have at least 1 surface");
    } else if (inputResults != null && inputResults.length != outputs.length) {
        throw new IllegalArgumentException("The lengths of outputs and inputResults " + "don't match");
    }
    int numReprocessCaptures = 0;
    SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
    ArrayList<CaptureRequest> captureRequests = new ArrayList<>(outputs.length);
    // is based on inputResults array.
    for (int i = 0; i < outputs.length; i++) {
        CaptureRequest.Builder builder;
        boolean isReprocess = (inputResults != null && inputResults[i] != null);
        if (isReprocess) {
            builder = mCamera.createReprocessCaptureRequest(inputResults[i]);
            numReprocessCaptures++;
        } else {
            builder = mCamera.createCaptureRequest(CAPTURE_TEMPLATE);
        }
        builder.addTarget(outputs[i]);
        CaptureRequest request = builder.build();
        assertTrue("Capture request reprocess type " + request.isReprocess() + " is wrong.", request.isReprocess() == isReprocess);
        captureRequests.add(request);
    }
    if (captureRequests.size() == 1) {
        mSession.capture(captureRequests.get(0), captureCallback, mHandler);
    } else {
        mSession.captureBurst(captureRequests, captureCallback, mHandler);
    }
    TotalCaptureResult[] results;
    if (numReprocessCaptures == 0 || numReprocessCaptures == outputs.length) {
        results = new TotalCaptureResult[outputs.length];
        // If the requests are not mixed, they should come in order.
        for (int i = 0; i < results.length; i++) {
            results[i] = captureCallback.getTotalCaptureResultForRequest(captureRequests.get(i), CAPTURE_TIMEOUT_FRAMES);
        }
    } else {
        // If the requests are mixed, they may not come in order.
        results = captureCallback.getTotalCaptureResultsForRequests(captureRequests, CAPTURE_TIMEOUT_FRAMES * captureRequests.size());
    }
    // make sure all input surfaces are released.
    for (int i = 0; i < numReprocessCaptures; i++) {
        mImageWriterListener.waitForImageReleased(CAPTURE_TIMEOUT_MS);
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Example 10 with TotalCaptureResult

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

the class Camera2ReprocessCaptureTest method testReprocess.

/**
     * Test a sequences of reprocess capture requests.
     */
private void testReprocess(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat, Size previewSize, int numReprocessCaptures) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocess: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat + " previewSize: " + previewSize);
    }
    boolean enablePreview = (previewSize != null);
    try {
        if (enablePreview) {
            updatePreviewSurface(previewSize);
        } else {
            mPreviewSurface = null;
        }
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat, /*maxImages*/
        1);
        setupReprocessableSession(mPreviewSurface, /*numImageWriterImages*/
        1);
        if (enablePreview) {
            startPreview(mPreviewSurface);
        }
        for (int i = 0; i < numReprocessCaptures; i++) {
            ImageResultHolder imageResultHolder = null;
            try {
                imageResultHolder = doReprocessCapture();
                Image reprocessedImage = imageResultHolder.getImage();
                TotalCaptureResult result = imageResultHolder.getTotalCaptureResult();
                mCollector.expectImageProperties("testReprocess", reprocessedImage, reprocessOutputFormat, reprocessOutputSize, result.get(CaptureResult.SENSOR_TIMESTAMP));
                if (DEBUG) {
                    Log.d(TAG, String.format("camera %s in %dx%d %d out %dx%d %d", cameraId, inputSize.getWidth(), inputSize.getHeight(), inputFormat, reprocessOutputSize.getWidth(), reprocessOutputSize.getHeight(), reprocessOutputFormat));
                    dumpImage(reprocessedImage, "/testReprocess_camera" + cameraId + "_" + mDumpFrameCount);
                    mDumpFrameCount++;
                }
            } finally {
                if (imageResultHolder != null) {
                    imageResultHolder.getImage().close();
                }
            }
        }
    } finally {
        closeReprossibleSession();
        closeImageReaders();
    }
}
Also used : TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CameraTestUtils.getDataFromImage(com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage) Image(android.media.Image)

Aggregations

TotalCaptureResult (android.hardware.camera2.TotalCaptureResult)46 Image (android.media.Image)30 CameraTestUtils.getDataFromImage (com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage)30 ArrayList (java.util.ArrayList)30 CaptureRequest (android.hardware.camera2.CaptureRequest)26 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)25 CaptureFailure (android.hardware.camera2.CaptureFailure)5 PublicKey (android.hardware.camera2.impl.PublicKey)5 SyntheticKey (android.hardware.camera2.impl.SyntheticKey)5 Size (android.util.Size)5 Surface (android.view.Surface)5 Field (java.lang.reflect.Field)5 Activity (android.app.Activity)1 Point (android.graphics.Point)1 CameraAccessException (android.hardware.camera2.CameraAccessException)1 CameraCaptureSession (android.hardware.camera2.CameraCaptureSession)1 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)1 CameraManager (android.hardware.camera2.CameraManager)1 NonNull (android.support.annotation.NonNull)1