Search in sources :

Example 51 with SimpleCaptureCallback

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

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

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

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

the class Camera2StillCaptureTest method takePictureTestByCamera.

/**
     * Take a picture for a given set of 3A regions for a particular camera.
     * <p>
     * Before take a still capture, it triggers an auto focus and lock it first,
     * then wait for AWB to converge and lock it, then trigger a precapture
     * metering sequence and wait for AE converged. After capture is received, the
     * capture result and image are validated. If {@code addAeTriggerCancel} is true,
     * a precapture trigger cancel will be inserted between two adjacent triggers, which
     * should effective cancel the first trigger.
     * </p>
     *
     * @param aeRegions AE regions for this capture
     * @param awbRegions AWB regions for this capture
     * @param afRegions AF regions for this capture
     * @param addAeTriggerCancel If a AE precapture trigger cancel is sent after the trigger.
     */
private void takePictureTestByCamera(MeteringRectangle[] aeRegions, MeteringRectangle[] awbRegions, MeteringRectangle[] afRegions, boolean addAeTriggerCancel) throws Exception {
    boolean hasFocuser = mStaticInfo.hasFocuser();
    Size maxStillSz = mOrderedStillSizes.get(0);
    Size maxPreviewSz = mOrderedPreviewSizes.get(0);
    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);
    prepareStillCaptureAndStartPreview(previewRequest, stillRequest, maxPreviewSz, maxStillSz, resultListener, imageListener);
    // Set AE mode to ON_AUTO_FLASH if flash is available.
    if (mStaticInfo.hasFlash()) {
        previewRequest.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
        stillRequest.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
    }
    Camera2Focuser focuser = null;
    /**
         * Step 1: trigger an auto focus run, and wait for AF locked.
         */
    boolean canSetAfRegion = hasFocuser && (afRegions != null) && isRegionsSupportedFor3A(MAX_REGIONS_AF_INDEX);
    if (hasFocuser) {
        SimpleAutoFocusListener afListener = new SimpleAutoFocusListener();
        focuser = new Camera2Focuser(mCamera, mSession, mPreviewSurface, afListener, mStaticInfo.getCharacteristics(), mHandler);
        if (canSetAfRegion) {
            stillRequest.set(CaptureRequest.CONTROL_AF_REGIONS, afRegions);
        }
        focuser.startAutoFocus(afRegions);
        afListener.waitForAutoFocusDone(WAIT_FOR_FOCUS_DONE_TIMEOUT_MS);
    }
    /**
         * Have to get the current AF mode to be used for other 3A repeating
         * request, otherwise, the new AF mode in AE/AWB request could be
         * different with existing repeating requests being sent by focuser,
         * then it could make AF unlocked too early. Beside that, for still
         * capture, AF mode must not be different with the one in current
         * repeating request, otherwise, the still capture itself would trigger
         * an AF mode change, and the AF lock would be lost for this capture.
         */
    int currentAfMode = CaptureRequest.CONTROL_AF_MODE_OFF;
    if (hasFocuser) {
        currentAfMode = focuser.getCurrentAfMode();
    }
    previewRequest.set(CaptureRequest.CONTROL_AF_MODE, currentAfMode);
    stillRequest.set(CaptureRequest.CONTROL_AF_MODE, currentAfMode);
    /**
         * Step 2: AF is already locked, wait for AWB converged, then lock it.
         */
    resultListener = new SimpleCaptureCallback();
    boolean canSetAwbRegion = (awbRegions != null) && isRegionsSupportedFor3A(MAX_REGIONS_AWB_INDEX);
    if (canSetAwbRegion) {
        previewRequest.set(CaptureRequest.CONTROL_AWB_REGIONS, awbRegions);
        stillRequest.set(CaptureRequest.CONTROL_AWB_REGIONS, awbRegions);
    }
    mSession.setRepeatingRequest(previewRequest.build(), resultListener, mHandler);
    if (mStaticInfo.isHardwareLevelLimitedOrBetter()) {
        waitForResultValue(resultListener, CaptureResult.CONTROL_AWB_STATE, CaptureResult.CONTROL_AWB_STATE_CONVERGED, NUM_RESULTS_WAIT_TIMEOUT);
    } else {
        // LEGACY Devices don't have the AWB_STATE reported in results, so just wait
        waitForSettingsApplied(resultListener, NUM_FRAMES_WAITED_FOR_UNKNOWN_LATENCY);
    }
    boolean canSetAwbLock = mStaticInfo.isAwbLockSupported();
    if (canSetAwbLock) {
        previewRequest.set(CaptureRequest.CONTROL_AWB_LOCK, true);
    }
    mSession.setRepeatingRequest(previewRequest.build(), resultListener, mHandler);
    // Validate the next result immediately for region and mode.
    result = resultListener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
    mCollector.expectEquals("AWB mode in result and request should be same", previewRequest.get(CaptureRequest.CONTROL_AWB_MODE), result.get(CaptureResult.CONTROL_AWB_MODE));
    if (canSetAwbRegion) {
        MeteringRectangle[] resultAwbRegions = getValueNotNull(result, CaptureResult.CONTROL_AWB_REGIONS);
        mCollector.expectEquals("AWB regions in result and request should be same", awbRegions, resultAwbRegions);
    }
    /**
         * Step 3: trigger an AE precapture metering sequence and wait for AE converged.
         */
    resultListener = new SimpleCaptureCallback();
    boolean canSetAeRegion = (aeRegions != null) && isRegionsSupportedFor3A(MAX_REGIONS_AE_INDEX);
    if (canSetAeRegion) {
        previewRequest.set(CaptureRequest.CONTROL_AE_REGIONS, aeRegions);
        stillRequest.set(CaptureRequest.CONTROL_AE_REGIONS, aeRegions);
    }
    mSession.setRepeatingRequest(previewRequest.build(), resultListener, mHandler);
    previewRequest.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
    mSession.capture(previewRequest.build(), resultListener, mHandler);
    if (addAeTriggerCancel) {
        // Cancel the current precapture trigger, then send another trigger.
        // The camera device should behave as if the first trigger is not sent.
        // Wait one request to make the trigger start doing something before cancel.
        waitForNumResults(resultListener, /*numResultsWait*/
        1);
        previewRequest.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_CANCEL);
        mSession.capture(previewRequest.build(), resultListener, mHandler);
        waitForResultValue(resultListener, CaptureResult.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureResult.CONTROL_AE_PRECAPTURE_TRIGGER_CANCEL, NUM_FRAMES_WAITED_FOR_UNKNOWN_LATENCY);
        // Issue another trigger
        previewRequest.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        mSession.capture(previewRequest.build(), resultListener, mHandler);
    }
    waitForAeStable(resultListener, NUM_FRAMES_WAITED_FOR_UNKNOWN_LATENCY);
    // Validate the next result immediately for region and mode.
    result = resultListener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
    mCollector.expectEquals("AE mode in result and request should be same", previewRequest.get(CaptureRequest.CONTROL_AE_MODE), result.get(CaptureResult.CONTROL_AE_MODE));
    if (canSetAeRegion) {
        MeteringRectangle[] resultAeRegions = getValueNotNull(result, CaptureResult.CONTROL_AE_REGIONS);
        mCollector.expectMeteringRegionsAreSimilar("AE regions in result and request should be similar", aeRegions, resultAeRegions, METERING_REGION_ERROR_PERCENT_DELTA);
    }
    /**
         * Step 4: take a picture when all 3A are in good state.
         */
    resultListener = new SimpleCaptureCallback();
    CaptureRequest request = stillRequest.build();
    mSession.capture(request, resultListener, mHandler);
    // Validate the next result immediately for region and mode.
    result = resultListener.getCaptureResultForRequest(request, WAIT_FOR_RESULT_TIMEOUT_MS);
    mCollector.expectEquals("AF mode in result and request should be same", stillRequest.get(CaptureRequest.CONTROL_AF_MODE), result.get(CaptureResult.CONTROL_AF_MODE));
    if (canSetAfRegion) {
        MeteringRectangle[] resultAfRegions = getValueNotNull(result, CaptureResult.CONTROL_AF_REGIONS);
        mCollector.expectMeteringRegionsAreSimilar("AF regions in result and request should be similar", afRegions, resultAfRegions, METERING_REGION_ERROR_PERCENT_DELTA);
    }
    if (hasFocuser) {
        // Unlock auto focus.
        focuser.cancelAutoFocus();
    }
    // validate image
    Image image = imageListener.getImage(CAPTURE_IMAGE_TIMEOUT_MS);
    validateJpegCapture(image, maxStillSz);
    // Free image resources
    image.close();
    stopPreview();
}
Also used : Size(android.util.Size) CaptureResult(android.hardware.camera2.CaptureResult) MeteringRectangle(android.hardware.camera2.params.MeteringRectangle) SimpleImageReaderListener(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener) Camera2Focuser(com.android.mediaframeworktest.helpers.Camera2Focuser) CameraTestUtils.basicValidateJpegImage(com.android.mediaframeworktest.helpers.CameraTestUtils.basicValidateJpegImage) CameraTestUtils.getDataFromImage(com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage) Image(android.media.Image) Point(android.graphics.Point) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Example 54 with SimpleCaptureCallback

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

the class Camera2RecordingTest method videoSnapshotTestByCamera.

/**
     * Test video snapshot for each  available CamcorderProfile for a given camera.
     *
     * <p>
     * Preview size is set to the video size. For the burst test, frame drop and jittering
     * is not checked.
     * </p>
     *
     * @param burstTest Perform burst capture or single capture. For burst capture
     *                  {@value #BURST_VIDEO_SNAPSHOT_NUM} capture requests will be sent.
     */
private void videoSnapshotTestByCamera(boolean burstTest) throws Exception {
    final int NUM_SINGLE_SHOT_TEST = 5;
    final int FRAMEDROP_TOLERANCE = 8;
    final int FRAME_SIZE_15M = 15000000;
    final float FRAME_DROP_TOLERENCE_FACTOR = 1.5f;
    int kFrameDrop_Tolerence = FRAMEDROP_TOLERANCE;
    for (int profileId : mCamcorderProfileList) {
        int cameraId = Integer.parseInt(mCamera.getId());
        if (!CamcorderProfile.hasProfile(cameraId, profileId) || allowedUnsupported(cameraId, profileId)) {
            continue;
        }
        CamcorderProfile profile = CamcorderProfile.get(cameraId, profileId);
        Size videoSz = new Size(profile.videoFrameWidth, profile.videoFrameHeight);
        Size maxPreviewSize = mOrderedPreviewSizes.get(0);
        if (mStaticInfo.isHardwareLevelLegacy() && (videoSz.getWidth() > maxPreviewSize.getWidth() || videoSz.getHeight() > maxPreviewSize.getHeight())) {
            // Skip. Legacy mode can only do recording up to max preview size
            continue;
        }
        if (!mSupportedVideoSizes.contains(videoSz)) {
            mCollector.addMessage("Video size " + videoSz.toString() + " for profile ID " + profileId + " must be one of the camera device supported video size!");
            continue;
        }
        // For LEGACY, find closest supported smaller or equal JPEG size to the current video
        // size; if no size is smaller than the video, pick the smallest JPEG size.  The assert
        // for video size above guarantees that for LIMITED or FULL, we select videoSz here.
        // Also check for minFrameDuration here to make sure jpeg stream won't slow down
        // video capture
        Size videoSnapshotSz = mOrderedStillSizes.get(mOrderedStillSizes.size() - 1);
        // Allow a bit tolerance so we don't fail for a few nano seconds of difference
        final float FRAME_DURATION_TOLERANCE = 0.01f;
        long videoFrameDuration = (long) (1e9 / profile.videoFrameRate * (1.0 + FRAME_DURATION_TOLERANCE));
        HashMap<Size, Long> minFrameDurationMap = mStaticInfo.getAvailableMinFrameDurationsForFormatChecked(ImageFormat.JPEG);
        for (int i = mOrderedStillSizes.size() - 2; i >= 0; i--) {
            Size candidateSize = mOrderedStillSizes.get(i);
            if (mStaticInfo.isHardwareLevelLegacy()) {
                // Legacy level doesn't report min frame duration
                if (candidateSize.getWidth() <= videoSz.getWidth() && candidateSize.getHeight() <= videoSz.getHeight()) {
                    videoSnapshotSz = candidateSize;
                }
            } else {
                Long jpegFrameDuration = minFrameDurationMap.get(candidateSize);
                assertTrue("Cannot find minimum frame duration for jpeg size " + candidateSize, jpegFrameDuration != null);
                if (candidateSize.getWidth() <= videoSz.getWidth() && candidateSize.getHeight() <= videoSz.getHeight() && jpegFrameDuration <= videoFrameDuration) {
                    videoSnapshotSz = candidateSize;
                }
            }
        }
        /**
             * Only test full res snapshot when below conditions are all true.
             * 1. Camera is a FULL device
             * 2. video size is up to max preview size, which will be bounded by 1080p.
             * 3. Full resolution jpeg stream can keep up to video stream speed.
             *    When full res jpeg stream cannot keep up to video stream speed, search
             *    the largest jpeg size that can susptain video speed instead.
             */
        if (mStaticInfo.isHardwareLevelFull() && videoSz.getWidth() <= maxPreviewSize.getWidth() && videoSz.getHeight() <= maxPreviewSize.getHeight()) {
            for (Size jpegSize : mOrderedStillSizes) {
                Long jpegFrameDuration = minFrameDurationMap.get(jpegSize);
                assertTrue("Cannot find minimum frame duration for jpeg size " + jpegSize, jpegFrameDuration != null);
                if (jpegFrameDuration <= videoFrameDuration) {
                    videoSnapshotSz = jpegSize;
                    break;
                }
                if (jpegSize.equals(videoSz)) {
                    throw new AssertionFailedError("Cannot find adequate video snapshot size for video size" + videoSz);
                }
            }
        }
        Log.i(TAG, "Testing video snapshot size " + videoSnapshotSz + " for video size " + videoSz);
        if (videoSnapshotSz.getWidth() * videoSnapshotSz.getHeight() > FRAME_SIZE_15M)
            kFrameDrop_Tolerence = (int) (FRAMEDROP_TOLERANCE * FRAME_DROP_TOLERENCE_FACTOR);
        createImageReader(videoSnapshotSz, ImageFormat.JPEG, MAX_VIDEO_SNAPSHOT_IMAGES, /*listener*/
        null);
        if (VERBOSE) {
            Log.v(TAG, "Testing camera recording with video size " + videoSz.toString());
        }
        // Configure preview and recording surfaces.
        mOutMediaFileName = VIDEO_FILE_PATH + "/test_video.mp4";
        if (DEBUG_DUMP) {
            mOutMediaFileName = VIDEO_FILE_PATH + "/test_video_" + cameraId + "_" + videoSz.toString() + ".mp4";
        }
        int numTestIterations = burstTest ? 1 : NUM_SINGLE_SHOT_TEST;
        int totalDroppedFrames = 0;
        for (int numTested = 0; numTested < numTestIterations; numTested++) {
            prepareRecordingWithProfile(profile);
            // prepare video snapshot
            SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
            SimpleImageReaderListener imageListener = new SimpleImageReaderListener();
            CaptureRequest.Builder videoSnapshotRequestBuilder = mCamera.createCaptureRequest((mStaticInfo.isHardwareLevelLegacy()) ? CameraDevice.TEMPLATE_RECORD : CameraDevice.TEMPLATE_VIDEO_SNAPSHOT);
            // prepare preview surface by using video size.
            updatePreviewSurfaceWithVideo(videoSz, profile.videoFrameRate);
            prepareVideoSnapshot(videoSnapshotRequestBuilder, imageListener);
            CaptureRequest request = videoSnapshotRequestBuilder.build();
            // Start recording
            startRecording(/* useMediaRecorder */
            true, resultListener, /*useVideoStab*/
            false);
            long startTime = SystemClock.elapsedRealtime();
            // Record certain duration.
            SystemClock.sleep(RECORDING_DURATION_MS / 2);
            // take video snapshot
            if (burstTest) {
                List<CaptureRequest> requests = new ArrayList<CaptureRequest>(BURST_VIDEO_SNAPSHOT_NUM);
                for (int i = 0; i < BURST_VIDEO_SNAPSHOT_NUM; i++) {
                    requests.add(request);
                }
                mSession.captureBurst(requests, resultListener, mHandler);
            } else {
                mSession.capture(request, resultListener, mHandler);
            }
            // make sure recording is still going after video snapshot
            SystemClock.sleep(RECORDING_DURATION_MS / 2);
            // Stop recording and preview
            int durationMs = stopRecording(/* useMediaRecorder */
            true);
            // of frames to estimate duration
            if (!burstTest) {
                durationMs = (int) (resultListener.getTotalNumFrames() * 1000.0f / profile.videoFrameRate);
            }
            // Validation recorded video
            validateRecording(videoSz, durationMs);
            if (burstTest) {
                for (int i = 0; i < BURST_VIDEO_SNAPSHOT_NUM; i++) {
                    Image image = imageListener.getImage(CAPTURE_IMAGE_TIMEOUT_MS);
                    validateVideoSnapshotCapture(image, videoSnapshotSz);
                    image.close();
                }
            } else {
                // validate video snapshot image
                Image image = imageListener.getImage(CAPTURE_IMAGE_TIMEOUT_MS);
                validateVideoSnapshotCapture(image, videoSnapshotSz);
                // validate if there is framedrop around video snapshot
                totalDroppedFrames += validateFrameDropAroundVideoSnapshot(resultListener, image.getTimestamp());
                //TODO: validate jittering. Should move to PTS
                //validateJittering(resultListener);
                image.close();
            }
        }
        if (!burstTest) {
            Log.w(TAG, String.format("Camera %d Video size %s: Number of dropped frames " + "detected in %d trials is %d frames.", cameraId, videoSz.toString(), numTestIterations, totalDroppedFrames));
            mCollector.expectLessOrEqual(String.format("Camera %d Video size %s: Number of dropped frames %d must not" + " be larger than %d", cameraId, videoSz.toString(), totalDroppedFrames, kFrameDrop_Tolerence), kFrameDrop_Tolerence, totalDroppedFrames);
        }
        closeImageReader();
    }
}
Also used : Size(android.util.Size) ArrayList(java.util.ArrayList) CamcorderProfile(android.media.CamcorderProfile) SimpleImageReaderListener(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener) Image(android.media.Image) CaptureRequest(android.hardware.camera2.CaptureRequest) AssertionFailedError(junit.framework.AssertionFailedError) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Example 55 with SimpleCaptureCallback

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

the class Camera2RecordingTest method basicRecordingTestByCamera.

/**
     * Test camera recording by using each available CamcorderProfile for a
     * given camera. preview size is set to the video size.
     */
private void basicRecordingTestByCamera(int[] camcorderProfileList, boolean useVideoStab) throws Exception {
    Size maxPreviewSize = mOrderedPreviewSizes.get(0);
    List<Range<Integer>> fpsRanges = Arrays.asList(mStaticInfo.getAeAvailableTargetFpsRangesChecked());
    int cameraId = Integer.parseInt(mCamera.getId());
    int maxVideoFrameRate = -1;
    for (int profileId : camcorderProfileList) {
        if (!CamcorderProfile.hasProfile(cameraId, profileId) || allowedUnsupported(cameraId, profileId)) {
            continue;
        }
        CamcorderProfile profile = CamcorderProfile.get(cameraId, profileId);
        Size videoSz = new Size(profile.videoFrameWidth, profile.videoFrameHeight);
        Range<Integer> fpsRange = new Range(profile.videoFrameRate, profile.videoFrameRate);
        if (maxVideoFrameRate < profile.videoFrameRate) {
            maxVideoFrameRate = profile.videoFrameRate;
        }
        if (mStaticInfo.isHardwareLevelLegacy() && (videoSz.getWidth() > maxPreviewSize.getWidth() || videoSz.getHeight() > maxPreviewSize.getHeight())) {
            // Skip. Legacy mode can only do recording up to max preview size
            continue;
        }
        assertTrue("Video size " + videoSz.toString() + " for profile ID " + profileId + " must be one of the camera device supported video size!", mSupportedVideoSizes.contains(videoSz));
        assertTrue("Frame rate range " + fpsRange + " (for profile ID " + profileId + ") must be one of the camera device available FPS range!", fpsRanges.contains(fpsRange));
        if (VERBOSE) {
            Log.v(TAG, "Testing camera recording with video size " + videoSz.toString());
        }
        // Configure preview and recording surfaces.
        mOutMediaFileName = VIDEO_FILE_PATH + "/test_video.mp4";
        if (DEBUG_DUMP) {
            mOutMediaFileName = VIDEO_FILE_PATH + "/test_video_" + cameraId + "_" + videoSz.toString() + ".mp4";
        }
        prepareRecordingWithProfile(profile);
        // prepare preview surface by using video size.
        updatePreviewSurfaceWithVideo(videoSz, profile.videoFrameRate);
        // Start recording
        SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
        startRecording(/* useMediaRecorder */
        true, resultListener, useVideoStab);
        // 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 / profile.videoFrameRate);
        if (VERBOSE) {
            Log.v(TAG, "video frame rate: " + profile.videoFrameRate + ", num of frames produced: " + resultListener.getTotalNumFrames());
        }
        // Validation.
        validateRecording(videoSz, durationMs);
    }
    if (maxVideoFrameRate != -1) {
        // At least one CamcorderProfile is present, check FPS
        assertTrue("At least one CamcorderProfile must support >= 24 FPS", maxVideoFrameRate >= 24);
    }
}
Also used : Size(android.util.Size) CamcorderProfile(android.media.CamcorderProfile) 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