Search in sources :

Example 11 with CaptureResult

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

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

use of android.hardware.camera2.CaptureResult 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 13 with CaptureResult

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

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)

Example 14 with CaptureResult

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

the class Camera2RecordingTest method validateFrameDropAroundVideoSnapshot.

/**
     * Validate if video snapshot causes frame drop.
     * Here frame drop is defined as frame duration >= 2 * expected frame duration.
     * Return the estimated number of frames dropped during video snapshot
     */
private int validateFrameDropAroundVideoSnapshot(SimpleCaptureCallback resultListener, long imageTimeStamp) {
    double expectedDurationMs = 1000.0 / mVideoFrameRate;
    CaptureResult prevResult = resultListener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
    long prevTS = getValueNotNull(prevResult, CaptureResult.SENSOR_TIMESTAMP);
    while (!resultListener.hasMoreResults()) {
        CaptureResult currentResult = resultListener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
        long currentTS = getValueNotNull(currentResult, CaptureResult.SENSOR_TIMESTAMP);
        if (currentTS == imageTimeStamp) {
            // validate the timestamp before and after, then return
            CaptureResult nextResult = resultListener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
            long nextTS = getValueNotNull(nextResult, CaptureResult.SENSOR_TIMESTAMP);
            double durationMs = (currentTS - prevTS) / 1000000.0;
            int totalFramesDropped = 0;
            // requirements for legacy mode unless this is fixed.
            if (!mStaticInfo.isHardwareLevelLegacy()) {
                mCollector.expectTrue(String.format("Video %dx%d Frame drop detected before video snapshot: " + "duration %.2fms (expected %.2fms)", mVideoSize.getWidth(), mVideoSize.getHeight(), durationMs, expectedDurationMs), durationMs <= (expectedDurationMs * MAX_NUM_FRAME_DROP_INTERVAL_ALLOWED));
                // Log a warning is there is any frame drop detected.
                if (durationMs >= expectedDurationMs * 2) {
                    Log.w(TAG, String.format("Video %dx%d Frame drop detected before video snapshot: " + "duration %.2fms (expected %.2fms)", mVideoSize.getWidth(), mVideoSize.getHeight(), durationMs, expectedDurationMs));
                }
                durationMs = (nextTS - currentTS) / 1000000.0;
                mCollector.expectTrue(String.format("Video %dx%d Frame drop detected after video snapshot: " + "duration %.2fms (expected %.2fms)", mVideoSize.getWidth(), mVideoSize.getHeight(), durationMs, expectedDurationMs), durationMs <= (expectedDurationMs * MAX_NUM_FRAME_DROP_INTERVAL_ALLOWED));
                // Log a warning is there is any frame drop detected.
                if (durationMs >= expectedDurationMs * 2) {
                    Log.w(TAG, String.format("Video %dx%d Frame drop detected after video snapshot: " + "duration %fms (expected %fms)", mVideoSize.getWidth(), mVideoSize.getHeight(), durationMs, expectedDurationMs));
                }
                double totalDurationMs = (nextTS - prevTS) / 1000000.0;
                // Minus 2 for the expected 2 frames interval
                totalFramesDropped = (int) (totalDurationMs / expectedDurationMs) - 2;
                if (totalFramesDropped < 0) {
                    Log.w(TAG, "totalFrameDropped is " + totalFramesDropped + ". Video frame rate might be too fast.");
                }
                totalFramesDropped = Math.max(0, totalFramesDropped);
            }
            return totalFramesDropped;
        }
        prevTS = currentTS;
    }
    throw new AssertionFailedError("Video snapshot timestamp does not match any of capture results!");
}
Also used : CaptureResult(android.hardware.camera2.CaptureResult) AssertionFailedError(junit.framework.AssertionFailedError)

Example 15 with CaptureResult

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

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)

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