Search in sources :

Example 21 with Range

use of android.util.Range in project android_frameworks_base by crdroidandroid.

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 22 with Range

use of android.util.Range in project android_frameworks_base by crdroidandroid.

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)

Example 23 with Range

use of android.util.Range in project android_frameworks_base by crdroidandroid.

the class Camera2SwitchPreviewTest method basicRecordingPreviewTestByCamera.

/**
     * Test camera recording preview by using each available CamcorderProfile for a
     * given camera. preview size is set to the video size.
     */
private void basicRecordingPreviewTestByCamera(int[] camcorderProfileList) throws Exception {
    Size maxPreviewSize = mOrderedPreviewSizes.get(0);
    List<Range<Integer>> fpsRanges = Arrays.asList(mStaticInfo.getAeAvailableTargetFpsRangesChecked());
    int cameraId = Integer.parseInt(mCamera.getId());
    int maxVideoFrameRate = -1;
    int profileId = camcorderProfileList[0];
    if (!CamcorderProfile.hasProfile(cameraId, profileId) || allowedUnsupported(cameraId, profileId)) {
        return;
    }
    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
        return;
    }
    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);
    CaptureRequest.Builder previewRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
    CaptureRequest.Builder recordingRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
    SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
    SimpleImageReaderListener imageListener = new SimpleImageReaderListener();
    prepareVideoPreview(previewRequest, recordingRequest, resultListener, imageListener);
    // Can reuse the MediaRecorder object after reset.
    mMediaRecorder.reset();
    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) SimpleImageReaderListener(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener) CaptureRequest(android.hardware.camera2.CaptureRequest) Range(android.util.Range) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback) Point(android.graphics.Point)

Example 24 with Range

use of android.util.Range in project android_frameworks_base by crdroidandroid.

the class SurfaceUtils method checkConstrainedHighSpeedSurfaces.

/**
     * Verify that that the surfaces are valid for high-speed recording mode,
     * and that the FPS range is supported
     *
     * @param surfaces the surfaces to verify as valid in terms of size and format
     * @param fpsRange the target high-speed FPS range to validate
     * @param config The stream configuration map for the device in question
     */
public static void checkConstrainedHighSpeedSurfaces(Collection<Surface> surfaces, Range<Integer> fpsRange, StreamConfigurationMap config) {
    if (surfaces == null || surfaces.size() == 0 || surfaces.size() > 2) {
        throw new IllegalArgumentException("Output target surface list must not be null and" + " the size must be 1 or 2");
    }
    List<Size> highSpeedSizes = null;
    if (fpsRange == null) {
        highSpeedSizes = Arrays.asList(config.getHighSpeedVideoSizes());
    } else {
        // Check the FPS range first if provided
        Range<Integer>[] highSpeedFpsRanges = config.getHighSpeedVideoFpsRanges();
        if (!Arrays.asList(highSpeedFpsRanges).contains(fpsRange)) {
            throw new IllegalArgumentException("Fps range " + fpsRange.toString() + " in the" + " request is not a supported high speed fps range " + Arrays.toString(highSpeedFpsRanges));
        }
        highSpeedSizes = Arrays.asList(config.getHighSpeedVideoSizesFor(fpsRange));
    }
    for (Surface surface : surfaces) {
        checkHighSpeedSurfaceFormat(surface);
        // Surface size must be supported high speed sizes.
        Size surfaceSize = SurfaceUtils.getSurfaceSize(surface);
        if (!highSpeedSizes.contains(surfaceSize)) {
            throw new IllegalArgumentException("Surface size " + surfaceSize.toString() + " is" + " not part of the high speed supported size list " + Arrays.toString(highSpeedSizes.toArray()));
        }
        // Each output surface must be either preview surface or recording surface.
        if (!SurfaceUtils.isSurfaceForPreview(surface) && !SurfaceUtils.isSurfaceForHwVideoEncoder(surface)) {
            throw new IllegalArgumentException("This output surface is neither preview nor " + "hardware video encoding surface");
        }
        if (SurfaceUtils.isSurfaceForPreview(surface) && SurfaceUtils.isSurfaceForHwVideoEncoder(surface)) {
            throw new IllegalArgumentException("This output surface can not be both preview" + " and hardware video encoding surface");
        }
    }
    // For 2 output surface case, they shouldn't be same type.
    if (surfaces.size() == 2) {
        // Up to here, each surface can only be either preview or recording.
        Iterator<Surface> iterator = surfaces.iterator();
        boolean isFirstSurfacePreview = SurfaceUtils.isSurfaceForPreview(iterator.next());
        boolean isSecondSurfacePreview = SurfaceUtils.isSurfaceForPreview(iterator.next());
        if (isFirstSurfacePreview == isSecondSurfacePreview) {
            throw new IllegalArgumentException("The 2 output surfaces must have different" + " type");
        }
    }
}
Also used : Size(android.util.Size) Range(android.util.Range) Surface(android.view.Surface)

Example 25 with Range

use of android.util.Range in project android_frameworks_base by crdroidandroid.

the class StreamConfigurationMap method appendHighSpeedVideoConfigurationsString.

private void appendHighSpeedVideoConfigurationsString(StringBuilder sb) {
    sb.append("HighSpeedVideoConfigurations(");
    Size[] sizes = getHighSpeedVideoSizes();
    for (Size size : sizes) {
        Range<Integer>[] ranges = getHighSpeedVideoFpsRangesFor(size);
        for (Range<Integer> range : ranges) {
            sb.append(String.format("[w:%d, h:%d, min_fps:%d, max_fps:%d], ", size.getWidth(), size.getHeight(), range.getLower(), range.getUpper()));
        }
    }
    // Remove the pending ", "
    if (sb.charAt(sb.length() - 1) == ' ') {
        sb.delete(sb.length() - 2, sb.length());
    }
    sb.append(")");
}
Also used : Size(android.util.Size) Range(android.util.Range)

Aggregations

Range (android.util.Range)55 Size (android.util.Size)40 Rational (android.util.Rational)15 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)15 Rect (android.graphics.Rect)10 CaptureRequest (android.hardware.camera2.CaptureRequest)10 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)10 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)10 CamcorderProfile (android.media.CamcorderProfile)10 SmallTest (android.test.suitebuilder.annotation.SmallTest)10 Point (android.graphics.Point)5 Camera (android.hardware.Camera)5 Parameters (android.hardware.Camera.Parameters)5 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)5 CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)5 Location (android.location.Location)5 MediaRecorder (android.media.MediaRecorder)5 Surface (android.view.Surface)5 SimpleImageReaderListener (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener)5 ArrayList (java.util.ArrayList)5