Search in sources :

Example 46 with SimpleCaptureCallback

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

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

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

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

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

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

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

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)

Example 50 with SimpleCaptureCallback

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

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