Search in sources :

Example 6 with CaptureResult

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

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)

Example 7 with CaptureResult

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

the class CameraMetadataTest method testCaptureResult.

@SmallTest
public void testCaptureResult() {
    mMetadata.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH);
    if (VERBOSE)
        mMetadata.dumpToLog();
    CaptureResult captureResult = new CaptureResult(mMetadata, /*sequenceId*/
    0);
    List<CaptureResult.Key<?>> allKeys = captureResult.getKeys();
    if (VERBOSE)
        Log.v(TAG, "testCaptureResult: key list size " + allKeys);
    for (CaptureResult.Key<?> key : captureResult.getKeys()) {
        if (VERBOSE) {
            Log.v(TAG, "testCaptureResult: key " + key + " value" + captureResult.get(key));
        }
    }
    // FIXME: android.statistics.faces counts as a key
    assertTrue(allKeys.size() >= 1);
    assertTrue(allKeys.contains(CaptureResult.CONTROL_AE_MODE));
    assertEquals(CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH, (int) captureResult.get(CaptureResult.CONTROL_AE_MODE));
}
Also used : CaptureResult(android.hardware.camera2.CaptureResult) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 8 with CaptureResult

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

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

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

the class CameraMetadataTest method testCaptureResult.

@SmallTest
public void testCaptureResult() {
    mMetadata.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH);
    if (VERBOSE)
        mMetadata.dumpToLog();
    CaptureResult captureResult = new CaptureResult(mMetadata, /*sequenceId*/
    0);
    List<CaptureResult.Key<?>> allKeys = captureResult.getKeys();
    if (VERBOSE)
        Log.v(TAG, "testCaptureResult: key list size " + allKeys);
    for (CaptureResult.Key<?> key : captureResult.getKeys()) {
        if (VERBOSE) {
            Log.v(TAG, "testCaptureResult: key " + key + " value" + captureResult.get(key));
        }
    }
    // FIXME: android.statistics.faces counts as a key
    assertTrue(allKeys.size() >= 1);
    assertTrue(allKeys.contains(CaptureResult.CONTROL_AE_MODE));
    assertEquals(CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH, (int) captureResult.get(CaptureResult.CONTROL_AE_MODE));
}
Also used : CaptureResult(android.hardware.camera2.CaptureResult) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 10 with CaptureResult

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

the class Camera2SwitchPreviewTest method stillCapturePreviewPreparer.

private void stillCapturePreviewPreparer(String id) throws Exception {
    CaptureResult result;
    SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
    SimpleImageReaderListener imageListener = new SimpleImageReaderListener();
    CaptureRequest.Builder previewRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
    CaptureRequest.Builder stillRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
    // Preview Setup:
    prepareCapturePreview(previewRequest, stillRequest, resultListener, imageListener);
    Thread.sleep(getTestWaitIntervalMs());
}
Also used : CaptureResult(android.hardware.camera2.CaptureResult) SimpleImageReaderListener(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Aggregations

CaptureResult (android.hardware.camera2.CaptureResult)40 CaptureRequest (android.hardware.camera2.CaptureRequest)25 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)25 SimpleImageReaderListener (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener)15 Image (android.media.Image)10 Size (android.util.Size)10 CameraTestUtils.basicValidateJpegImage (com.android.mediaframeworktest.helpers.CameraTestUtils.basicValidateJpegImage)10 CameraTestUtils.getDataFromImage (com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage)10 ArrayList (java.util.ArrayList)10 Point (android.graphics.Point)5 DngCreator (android.hardware.camera2.DngCreator)5 PublicKey (android.hardware.camera2.impl.PublicKey)5 SyntheticKey (android.hardware.camera2.impl.SyntheticKey)5 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)5 ImageReader (android.media.ImageReader)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 Surface (android.view.Surface)5 BlockingSessionCallback (com.android.ex.camera2.blocking.BlockingSessionCallback)5 TimeoutRuntimeException (com.android.ex.camera2.exceptions.TimeoutRuntimeException)5 Camera2Focuser (com.android.mediaframeworktest.helpers.Camera2Focuser)5