Search in sources :

Example 11 with SimpleCaptureCallback

use of com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback 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 12 with SimpleCaptureCallback

use of com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback in project android_frameworks_base by DirtyUnicorns.

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 13 with SimpleCaptureCallback

use of com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback in project android_frameworks_base by DirtyUnicorns.

the class Camera2ReprocessCaptureTest method testReprocessJpegExif.

/**
     * Test JPEG tags for reprocess requests. Reprocess result's JPEG tags and JPEG image's tags
     * match reprocess request's JPEG tags.
     */
private void testReprocessJpegExif(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocessJpegExif: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize);
    }
    Size[] thumbnailSizes = mStaticInfo.getAvailableThumbnailSizesChecked();
    Size[] testThumbnailSizes = new Size[EXIF_TEST_DATA.length];
    Arrays.fill(testThumbnailSizes, thumbnailSizes[thumbnailSizes.length - 1]);
    // Make sure thumbnail size (0, 0) is covered.
    testThumbnailSizes[0] = new Size(0, 0);
    try {
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, ImageFormat.JPEG, EXIF_TEST_DATA.length);
        setupReprocessableSession(/*previewSurface*/
        null, EXIF_TEST_DATA.length);
        // Prepare reprocess capture requests.
        ArrayList<CaptureRequest> reprocessRequests = new ArrayList<>(EXIF_TEST_DATA.length);
        for (int i = 0; i < EXIF_TEST_DATA.length; 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 jpeg keys
            setJpegKeys(builder, EXIF_TEST_DATA[i], testThumbnailSizes[i], mCollector);
            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 < EXIF_TEST_DATA.length; i++) {
            // Verify output image's and result's JPEG EXIF data.
            Image image = getReprocessOutputImageReaderListener().getImage(CAPTURE_TIMEOUT_MS);
            verifyJpegKeys(image, reprocessResults[i], reprocessOutputSize, testThumbnailSizes[i], EXIF_TEST_DATA[i], mStaticInfo, mCollector);
            image.close();
        }
    } finally {
        closeReprossibleSession();
        closeImageReaders();
    }
}
Also used : Size(android.util.Size) 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 14 with SimpleCaptureCallback

use of com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback 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 15 with SimpleCaptureCallback

use of com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback in project android_frameworks_base by DirtyUnicorns.

the class Camera2RecordingTest method constrainedHighSpeedRecording.

private void constrainedHighSpeedRecording() throws Exception {
    for (String id : mCameraIds) {
        try {
            Log.i(TAG, "Testing constrained high speed recording for camera " + id);
            // Re-use the MediaRecorder object for the same camera device.
            mMediaRecorder = new MediaRecorder();
            openDevice(id);
            if (!mStaticInfo.isConstrainedHighSpeedVideoSupported()) {
                Log.i(TAG, "Camera " + id + " doesn't support high speed recording, skipping.");
                continue;
            }
            // Test iteration starts...
            for (int iteration = 0; iteration < getIterationCount(); ++iteration) {
                Log.v(TAG, String.format("Constrained high speed recording: %d/%d", iteration + 1, getIterationCount()));
                StreamConfigurationMap config = mStaticInfo.getValueFromKeyNonNull(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
                Size[] highSpeedVideoSizes = config.getHighSpeedVideoSizes();
                for (Size size : highSpeedVideoSizes) {
                    List<Range<Integer>> fixedFpsRanges = getHighSpeedFixedFpsRangeForSize(config, size);
                    mCollector.expectTrue("Unable to find the fixed frame rate fps range for " + "size " + size, fixedFpsRanges.size() > 0);
                    // Test recording for each FPS range
                    for (Range<Integer> fpsRange : fixedFpsRanges) {
                        int captureRate = fpsRange.getLower();
                        final int VIDEO_FRAME_RATE = 30;
                        // Skip the test if the highest recording FPS supported by CamcorderProfile
                        if (fpsRange.getUpper() > getFpsFromHighSpeedProfileForSize(size)) {
                            Log.w(TAG, "high speed recording " + size + "@" + captureRate + "fps" + " is not supported by CamcorderProfile");
                            continue;
                        }
                        mOutMediaFileName = VIDEO_FILE_PATH + "/test_cslowMo_video_" + captureRate + "fps_" + id + "_" + size.toString() + ".mp4";
                        prepareRecording(size, VIDEO_FRAME_RATE, captureRate);
                        // prepare preview surface by using video size.
                        updatePreviewSurfaceWithVideo(size, captureRate);
                        // Start recording
                        SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
                        startSlowMotionRecording(/*useMediaRecorder*/
                        true, VIDEO_FRAME_RATE, captureRate, fpsRange, resultListener, /*useHighSpeedSession*/
                        true);
                        // Record certain duration.
                        SystemClock.sleep(RECORDING_DURATION_MS);
                        // Stop recording and preview
                        stopRecording(/*useMediaRecorder*/
                        true);
                        // Convert number of frames camera produced into the duration in unit of ms.
                        int durationMs = (int) (resultListener.getTotalNumFrames() * 1000.0f / VIDEO_FRAME_RATE);
                        // Validation.
                        validateRecording(size, durationMs);
                    }
                    getResultPrinter().printStatus(getIterationCount(), iteration + 1, id);
                    Thread.sleep(getTestWaitIntervalMs());
                }
            }
        } finally {
            closeDevice();
            releaseRecorder();
        }
    }
}
Also used : Size(android.util.Size) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap) MediaRecorder(android.media.MediaRecorder) Range(android.util.Range) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Aggregations

SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)70 CaptureRequest (android.hardware.camera2.CaptureRequest)60 Size (android.util.Size)35 ArrayList (java.util.ArrayList)35 CaptureResult (android.hardware.camera2.CaptureResult)25 TotalCaptureResult (android.hardware.camera2.TotalCaptureResult)25 Image (android.media.Image)25 SimpleImageReaderListener (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener)25 CameraTestUtils.getDataFromImage (com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage)20 CamcorderProfile (android.media.CamcorderProfile)15 Range (android.util.Range)15 Point (android.graphics.Point)10 CameraTestUtils.basicValidateJpegImage (com.android.mediaframeworktest.helpers.CameraTestUtils.basicValidateJpegImage)10 CaptureFailure (android.hardware.camera2.CaptureFailure)5 DngCreator (android.hardware.camera2.DngCreator)5 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)5 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)5 ImageReader (android.media.ImageReader)5 MediaRecorder (android.media.MediaRecorder)5 Surface (android.view.Surface)5