Search in sources :

Example 46 with Range

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

the class RangeTest method testEquals.

@SmallTest
public void testEquals() {
    Range<Float> oneHalf = Range.create(1.0f, 2.0f);
    Range<Float> oneHalf2 = new Range<Float>(1.0f, 2.0f);
    assertEquals(oneHalf, oneHalf2);
    assertHashCodeEquals(oneHalf, oneHalf2);
    Range<Float> twoThirds = new Range<Float>(2.0f, 3.0f);
    Range<Float> twoThirds2 = Range.create(2.0f, 3.0f);
    assertEquals(twoThirds, twoThirds2);
    assertHashCodeEquals(twoThirds, twoThirds2);
    Range<Rational> negativeOneTenthPositiveOneTenth = new Range<Rational>(new Rational(-1, 10), new Rational(1, 10));
    Range<Rational> negativeOneTenthPositiveOneTenth2 = Range.create(new Rational(-1, 10), new Rational(1, 10));
    assertEquals(negativeOneTenthPositiveOneTenth, negativeOneTenthPositiveOneTenth2);
    assertHashCodeEquals(negativeOneTenthPositiveOneTenth, negativeOneTenthPositiveOneTenth2);
}
Also used : Rational(android.util.Rational) Range(android.util.Range) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 47 with Range

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

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

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

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

use of android.util.Range 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)

Example 50 with Range

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

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)

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