Search in sources :

Example 16 with CaptureResult

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

the class Camera2CaptureRequestTest method aeManualControlTest.

/**
     * Iterate through exposure times and sensitivities for manual AE control.
     * <p>
     * Use single request rather than repeating request to test manual exposure
     * value change per frame control.
     * </p>
     */
private void aeManualControlTest() throws Exception {
    CaptureRequest.Builder requestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CONTROL_AE_MODE_OFF);
    configurePreviewOutput(requestBuilder);
    SimpleCaptureCallback listener = new SimpleCaptureCallback();
    long[] expTimes = getExposureTimeTestValues();
    int[] sensitivities = getSensitivityTestValues();
    // Submit single request at a time, then verify the result.
    for (int i = 0; i < expTimes.length; i++) {
        for (int j = 0; j < sensitivities.length; j++) {
            if (VERBOSE) {
                Log.v(TAG, "Camera " + mCamera.getId() + ": Testing sensitivity " + sensitivities[j] + ", exposure time " + expTimes[i] + "ns");
            }
            changeExposure(requestBuilder, expTimes[i], sensitivities[j]);
            mSession.capture(requestBuilder.build(), listener, mHandler);
            // make sure timeout is long enough for long exposure time
            long timeout = WAIT_FOR_RESULT_TIMEOUT_MS + expTimes[i];
            CaptureResult result = listener.getCaptureResult(timeout);
            long resultExpTime = getValueNotNull(result, CaptureResult.SENSOR_EXPOSURE_TIME);
            int resultSensitivity = getValueNotNull(result, CaptureResult.SENSOR_SENSITIVITY);
            validateExposureTime(expTimes[i], resultExpTime);
            validateSensitivity(sensitivities[j], resultSensitivity);
            validateFrameDurationForCapture(result);
        }
    }
// TODO: Add another case to test where we can submit all requests, then wait for
// results, which will hide the pipeline latency. this is not only faster, but also
// test high speed per frame control and synchronization.
}
Also used : CaptureResult(android.hardware.camera2.CaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Example 17 with CaptureResult

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

the class Camera2SurfaceViewTestCase method waitForAnyResultValue.

/**
     * Wait for any expected result key values available in a certain number of results.
     *
     * <p>
     * Check the result immediately if numFramesWait is 0.
     * </p>
     *
     * @param listener The capture listener to get capture result.
     * @param resultKey The capture result key associated with the result value.
     * @param expectedValues The list of result value need to be waited for,
     * return immediately if the list is empty.
     * @param numResultsWait Number of frame to wait before times out.
     * @throws TimeoutRuntimeException If more than numResultsWait results are.
     * seen before the result matching myRequest arrives, or each individual wait
     * for result times out after {@value #WAIT_FOR_RESULT_TIMEOUT_MS}ms.
     */
protected static <T> void waitForAnyResultValue(SimpleCaptureCallback listener, CaptureResult.Key<T> resultKey, List<T> expectedValues, int numResultsWait) {
    if (numResultsWait < 0 || listener == null || expectedValues == null) {
        throw new IllegalArgumentException("Input must be non-negative number and listener/expectedValues " + "must be non-null");
    }
    int i = 0;
    CaptureResult result;
    do {
        result = listener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
        T value = result.get(resultKey);
        for (T expectedValue : expectedValues) {
            if (VERBOSE) {
                Log.v(TAG, "Current result value for key " + resultKey.getName() + " is: " + value.toString());
            }
            if (value.equals(expectedValue)) {
                return;
            }
        }
    } while (i++ < numResultsWait);
    throw new TimeoutRuntimeException("Unable to get the expected result value " + expectedValues + " for key " + resultKey.getName() + " after waiting for " + numResultsWait + " results");
}
Also used : CaptureResult(android.hardware.camera2.CaptureResult) TimeoutRuntimeException(com.android.ex.camera2.exceptions.TimeoutRuntimeException)

Example 18 with CaptureResult

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

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

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

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

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

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

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