Search in sources :

Example 41 with TotalCaptureResult

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

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

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

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

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

the class Camera2ReprocessCaptureTest method testReprocessTimestamps.

/**
     * Test timestamps for reprocess requests. Reprocess request's shutter timestamp, result's
     * sensor timestamp, and output image's timestamp should match the reprocess input's timestamp.
     */
private void testReprocessTimestamps(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocessTimestamps: 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);
        // Prepare reprocess capture requests.
        ArrayList<CaptureRequest> reprocessRequests = new ArrayList<>(NUM_REPROCESS_CAPTURES);
        ArrayList<Long> expectedTimestamps = 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());
            // Reprocess result's timestamp should match input image's timestamp.
            expectedTimestamps.add(result.get(CaptureResult.SENSOR_TIMESTAMP));
        }
        // Submit reprocess requests.
        SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
        mSession.captureBurst(reprocessRequests, captureCallback, mHandler);
        // Verify we get the expected timestamps.
        for (int i = 0; i < reprocessRequests.size(); i++) {
            captureCallback.waitForCaptureStart(reprocessRequests.get(i), expectedTimestamps.get(i), CAPTURE_TIMEOUT_FRAMES);
        }
        TotalCaptureResult[] reprocessResults = captureCallback.getTotalCaptureResultsForRequests(reprocessRequests, CAPTURE_TIMEOUT_FRAMES);
        for (int i = 0; i < expectedTimestamps.size(); i++) {
            // Verify the result timestamps match the input image's timestamps.
            long expected = expectedTimestamps.get(i);
            long timestamp = reprocessResults[i].get(CaptureResult.SENSOR_TIMESTAMP);
            assertEquals("Reprocess result timestamp (" + timestamp + ") doesn't match input " + "image's timestamp (" + expected + ")", expected, timestamp);
            // Verify the reprocess output image timestamps match the input image's timestamps.
            Image image = getReprocessOutputImageReaderListener().getImage(CAPTURE_TIMEOUT_MS);
            timestamp = image.getTimestamp();
            image.close();
            assertEquals("Reprocess output timestamp (" + timestamp + ") doesn't match input " + "image's timestamp (" + expected + ")", expected, timestamp);
        }
        // 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 : ArrayList(java.util.ArrayList) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback) CameraTestUtils.getDataFromImage(com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage) Image(android.media.Image)

Example 44 with TotalCaptureResult

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

the class Camera2ReprocessCaptureTest method testReprocessMixedBurst.

/**
     * Test burst that is mixed with regular and reprocess capture requests.
     */
private void testReprocessMixedBurst(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat, Size previewSize, int numBurst) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocessMixedBurst: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat + " previewSize: " + previewSize + " numBurst: " + numBurst);
    }
    boolean enablePreview = (previewSize != null);
    ImageResultHolder[] imageResultHolders = new ImageResultHolder[0];
    try {
        // totalNumBurst = number of regular burst + number of reprocess burst.
        int totalNumBurst = numBurst * 2;
        if (enablePreview) {
            updatePreviewSurface(previewSize);
        } else {
            mPreviewSurface = null;
        }
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat, totalNumBurst);
        setupReprocessableSession(mPreviewSurface, /*numImageWriterImages*/
        numBurst);
        if (enablePreview) {
            startPreview(mPreviewSurface);
        }
        // Prepare an array of booleans indicating each capture's type (regular or reprocess)
        boolean[] isReprocessCaptures = new boolean[totalNumBurst];
        for (int i = 0; i < totalNumBurst; i++) {
            if ((i & 1) == 0) {
                isReprocessCaptures[i] = true;
            } else {
                isReprocessCaptures[i] = false;
            }
        }
        imageResultHolders = doMixedReprocessBurstCapture(isReprocessCaptures);
        for (ImageResultHolder holder : imageResultHolders) {
            Image reprocessedImage = holder.getImage();
            TotalCaptureResult result = holder.getTotalCaptureResult();
            mCollector.expectImageProperties("testReprocessMixedBurst", 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, "/testReprocessMixedBurst_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 45 with TotalCaptureResult

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

the class CameraMetadata method getKeysStatic.

/**
     * Return a list of all the Key<?> that are declared as a field inside of the class
     * {@code type}.
     *
     * <p>
     * Optionally, if {@code instance} is not null, then filter out any keys with null values.
     * </p>
     *
     * <p>
     * Optionally, if {@code filterTags} is not {@code null}, then filter out any keys
     * whose native {@code tag} is not in {@code filterTags}. The {@code filterTags} array will be
     * sorted as a side effect.
     * </p>
     */
/*package*/
@SuppressWarnings("unchecked")
static <TKey> ArrayList<TKey> getKeysStatic(Class<?> type, Class<TKey> keyClass, CameraMetadata<TKey> instance, int[] filterTags) {
    if (DEBUG)
        Log.v(TAG, "getKeysStatic for " + type);
    // TotalCaptureResult does not have any of the keys on it, use CaptureResult instead
    if (type.equals(TotalCaptureResult.class)) {
        type = CaptureResult.class;
    }
    if (filterTags != null) {
        Arrays.sort(filterTags);
    }
    ArrayList<TKey> keyList = new ArrayList<TKey>();
    Field[] fields = type.getDeclaredFields();
    for (Field field : fields) {
        // Filter for Keys that are public
        if (field.getType().isAssignableFrom(keyClass) && (field.getModifiers() & Modifier.PUBLIC) != 0) {
            TKey key;
            try {
                key = (TKey) field.get(instance);
            } catch (IllegalAccessException e) {
                throw new AssertionError("Can't get IllegalAccessException", e);
            } catch (IllegalArgumentException e) {
                throw new AssertionError("Can't get IllegalArgumentException", e);
            }
            if (instance == null || instance.getProtected(key) != null) {
                if (shouldKeyBeAdded(key, field, filterTags)) {
                    keyList.add(key);
                    if (DEBUG) {
                        Log.v(TAG, "getKeysStatic - key was added - " + key);
                    }
                } else if (DEBUG) {
                    Log.v(TAG, "getKeysStatic - key was filtered - " + key);
                }
            }
        }
    }
    ArrayList<TKey> vendorKeys = CameraMetadataNative.getAllVendorKeys(keyClass);
    if (vendorKeys != null) {
        for (TKey k : vendorKeys) {
            String keyName;
            if (k instanceof CaptureRequest.Key<?>) {
                keyName = ((CaptureRequest.Key<?>) k).getName();
            } else if (k instanceof CaptureResult.Key<?>) {
                keyName = ((CaptureResult.Key<?>) k).getName();
            } else if (k instanceof CameraCharacteristics.Key<?>) {
                keyName = ((CameraCharacteristics.Key<?>) k).getName();
            } else {
                continue;
            }
            if (filterTags == null || Arrays.binarySearch(filterTags, CameraMetadataNative.getTag(keyName)) >= 0) {
                keyList.add(k);
            }
        }
    }
    return keyList;
}
Also used : ArrayList(java.util.ArrayList) Field(java.lang.reflect.Field) PublicKey(android.hardware.camera2.impl.PublicKey) SyntheticKey(android.hardware.camera2.impl.SyntheticKey)

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