Search in sources :

Example 11 with CamcorderProfile

use of android.media.CamcorderProfile in project android_frameworks_base by ResurrectionRemix.

the class MediaRecorderStressTest method testStressTimeLapse.

// Test case for stressing time lapse
@LargeTest
public void testStressTimeLapse() throws Exception {
    SurfaceHolder mSurfaceHolder;
    mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    int recordDuration = MediaRecorderStressTestRunner.mTimeLapseDuration;
    boolean removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
    double captureRate = MediaRecorderStressTestRunner.mCaptureRate;
    Log.v(TAG, "Start camera time lapse stress:");
    mOutput.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
    try {
        for (int i = 0, n = Camera.getNumberOfCameras(); i < n; i++) {
            mOutput.write("No of loop: camera " + i);
            for (int j = 0; j < NUMBER_OF_TIME_LAPSE_LOOPS; j++) {
                String fileName = String.format("%s/temp%d_%d%s", Environment.getExternalStorageDirectory(), i, j, OUTPUT_FILE_EXT);
                Log.v(TAG, fileName);
                runOnLooper(new Runnable() {

                    @Override
                    public void run() {
                        mRecorder = new MediaRecorder();
                    }
                });
                // Set callback
                mRecorder.setOnErrorListener(mRecorderErrorCallback);
                // Set video source
                mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                // Set camcorder profile for time lapse
                CamcorderProfile profile = CamcorderProfile.get(j, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
                mRecorder.setProfile(profile);
                // Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc
                // http://developer.android.com/guide/topics/media/camera.html#time-lapse-video
                mRecorder.setCaptureRate(captureRate);
                // Set output file
                mRecorder.setOutputFile(fileName);
                // Set the preview display
                Log.v(TAG, "mediaRecorder setPreviewDisplay");
                mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
                mRecorder.prepare();
                mRecorder.start();
                Thread.sleep(recordDuration);
                Log.v(TAG, "Before stop");
                mRecorder.stop();
                mRecorder.release();
                // Start the playback
                MediaPlayer mp = new MediaPlayer();
                mp.setDataSource(fileName);
                mp.setDisplay(mSurfaceHolder);
                mp.prepare();
                mp.start();
                Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
                mp.release();
                validateRecordedVideo(fileName);
                if (removeVideo) {
                    removeRecordedVideo(fileName);
                }
                if (j == 0) {
                    mOutput.write(j + 1);
                } else {
                    mOutput.write(String.format(", %d", (j + 1)));
                }
            }
        }
    } catch (IllegalStateException e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test IllegalStateException");
    } catch (IOException e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test IOException");
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test Exception");
    }
}
Also used : CamcorderProfile(android.media.CamcorderProfile) IOException(java.io.IOException) IOException(java.io.IOException) SurfaceHolder(android.view.SurfaceHolder) MediaRecorder(android.media.MediaRecorder) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 12 with CamcorderProfile

use of android.media.CamcorderProfile in project Telecine by JakeWharton.

the class RecordingSession method getRecordingInfo.

private RecordingInfo getRecordingInfo() {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(WINDOW_SERVICE);
    wm.getDefaultDisplay().getRealMetrics(displayMetrics);
    int displayWidth = displayMetrics.widthPixels;
    int displayHeight = displayMetrics.heightPixels;
    int displayDensity = displayMetrics.densityDpi;
    Timber.d("Display size: %s x %s @ %s", displayWidth, displayHeight, displayDensity);
    Configuration configuration = context.getResources().getConfiguration();
    boolean isLandscape = configuration.orientation == ORIENTATION_LANDSCAPE;
    Timber.d("Display landscape: %s", isLandscape);
    // Get the best camera profile available. We assume MediaRecorder supports the highest.
    CamcorderProfile camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
    int cameraWidth = camcorderProfile != null ? camcorderProfile.videoFrameWidth : -1;
    int cameraHeight = camcorderProfile != null ? camcorderProfile.videoFrameHeight : -1;
    int cameraFrameRate = camcorderProfile != null ? camcorderProfile.videoFrameRate : 30;
    Timber.d("Camera size: %s x %s framerate: %s", cameraWidth, cameraHeight, cameraFrameRate);
    int sizePercentage = videoSizePercentage.get();
    Timber.d("Size percentage: %s", sizePercentage);
    return calculateRecordingInfo(displayWidth, displayHeight, displayDensity, isLandscape, cameraWidth, cameraHeight, cameraFrameRate, sizePercentage);
}
Also used : Configuration(android.content.res.Configuration) CamcorderProfile(android.media.CamcorderProfile) DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager)

Example 13 with CamcorderProfile

use of android.media.CamcorderProfile in project android_frameworks_base by AOSPA.

the class MediaRecorderStressTest method testStressTimeLapse.

// Test case for stressing time lapse
@LargeTest
public void testStressTimeLapse() throws Exception {
    SurfaceHolder mSurfaceHolder;
    mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    int recordDuration = MediaRecorderStressTestRunner.mTimeLapseDuration;
    boolean removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
    double captureRate = MediaRecorderStressTestRunner.mCaptureRate;
    Log.v(TAG, "Start camera time lapse stress:");
    mOutput.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
    try {
        for (int i = 0, n = Camera.getNumberOfCameras(); i < n; i++) {
            mOutput.write("No of loop: camera " + i);
            for (int j = 0; j < NUMBER_OF_TIME_LAPSE_LOOPS; j++) {
                String fileName = String.format("%s/temp%d_%d%s", Environment.getExternalStorageDirectory(), i, j, OUTPUT_FILE_EXT);
                Log.v(TAG, fileName);
                runOnLooper(new Runnable() {

                    @Override
                    public void run() {
                        mRecorder = new MediaRecorder();
                    }
                });
                // Set callback
                mRecorder.setOnErrorListener(mRecorderErrorCallback);
                // Set video source
                mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                // Set camcorder profile for time lapse
                CamcorderProfile profile = CamcorderProfile.get(j, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
                mRecorder.setProfile(profile);
                // Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc
                // http://developer.android.com/guide/topics/media/camera.html#time-lapse-video
                mRecorder.setCaptureRate(captureRate);
                // Set output file
                mRecorder.setOutputFile(fileName);
                // Set the preview display
                Log.v(TAG, "mediaRecorder setPreviewDisplay");
                mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
                mRecorder.prepare();
                mRecorder.start();
                Thread.sleep(recordDuration);
                Log.v(TAG, "Before stop");
                mRecorder.stop();
                mRecorder.release();
                // Start the playback
                MediaPlayer mp = new MediaPlayer();
                mp.setDataSource(fileName);
                mp.setDisplay(mSurfaceHolder);
                mp.prepare();
                mp.start();
                Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
                mp.release();
                validateRecordedVideo(fileName);
                if (removeVideo) {
                    removeRecordedVideo(fileName);
                }
                if (j == 0) {
                    mOutput.write(j + 1);
                } else {
                    mOutput.write(String.format(", %d", (j + 1)));
                }
            }
        }
    } catch (IllegalStateException e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test IllegalStateException");
    } catch (IOException e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test IOException");
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test Exception");
    }
}
Also used : CamcorderProfile(android.media.CamcorderProfile) IOException(java.io.IOException) IOException(java.io.IOException) SurfaceHolder(android.view.SurfaceHolder) MediaRecorder(android.media.MediaRecorder) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 14 with CamcorderProfile

use of android.media.CamcorderProfile in project android_frameworks_base by AOSPA.

the class MediaRecorderStressTest method recordVideoAndPlayback.

// Helper method for record & playback testing with different camcorder profiles
private void recordVideoAndPlayback(int profile) throws Exception {
    int iterations;
    int recordDuration;
    boolean removeVideo;
    int videoEncoder;
    int audioEncoder;
    int frameRate;
    int videoWidth;
    int videoHeight;
    int bitRate;
    if (profile != USE_TEST_RUNNER_PROFILE) {
        assertTrue(String.format("Camera doesn't support profile %d", profile), CamcorderProfile.hasProfile(CAMERA_ID, profile));
        CamcorderProfile camcorderProfile = CamcorderProfile.get(CAMERA_ID, profile);
        videoEncoder = camcorderProfile.videoCodec;
        audioEncoder = camcorderProfile.audioCodec;
        frameRate = camcorderProfile.videoFrameRate;
        videoWidth = camcorderProfile.videoFrameWidth;
        videoHeight = camcorderProfile.videoFrameHeight;
        bitRate = camcorderProfile.videoBitRate;
    } else {
        videoEncoder = MediaRecorderStressTestRunner.mVideoEncoder;
        audioEncoder = MediaRecorderStressTestRunner.mAudioEncoder;
        frameRate = MediaRecorderStressTestRunner.mFrameRate;
        videoWidth = MediaRecorderStressTestRunner.mVideoWidth;
        videoHeight = MediaRecorderStressTestRunner.mVideoHeight;
        bitRate = MediaRecorderStressTestRunner.mBitRate;
    }
    iterations = MediaRecorderStressTestRunner.mIterations;
    recordDuration = MediaRecorderStressTestRunner.mDuration;
    removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
    SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    mOutput.write("Total number of loops: " + iterations + "\n");
    try {
        mOutput.write("No of loop: ");
        for (int i = 0; i < iterations; i++) {
            String fileName = String.format("%s/temp%d%s", Environment.getExternalStorageDirectory(), i, OUTPUT_FILE_EXT);
            Log.v(TAG, fileName);
            runOnLooper(new Runnable() {

                @Override
                public void run() {
                    mRecorder = new MediaRecorder();
                }
            });
            Log.v(TAG, "iterations : " + iterations);
            Log.v(TAG, "video encoder : " + videoEncoder);
            Log.v(TAG, "audio encoder : " + audioEncoder);
            Log.v(TAG, "frame rate : " + frameRate);
            Log.v(TAG, "video width : " + videoWidth);
            Log.v(TAG, "video height : " + videoHeight);
            Log.v(TAG, "bit rate : " + bitRate);
            Log.v(TAG, "record duration : " + recordDuration);
            mRecorder.setOnErrorListener(mRecorderErrorCallback);
            mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
            mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            mRecorder.setOutputFile(fileName);
            mRecorder.setVideoFrameRate(frameRate);
            mRecorder.setVideoSize(videoWidth, videoHeight);
            mRecorder.setVideoEncoder(videoEncoder);
            mRecorder.setAudioEncoder(audioEncoder);
            mRecorder.setVideoEncodingBitRate(bitRate);
            Log.v(TAG, "mediaRecorder setPreview");
            mRecorder.setPreviewDisplay(surfaceHolder.getSurface());
            mRecorder.prepare();
            mRecorder.start();
            Thread.sleep(recordDuration);
            Log.v(TAG, "Before stop");
            mRecorder.stop();
            mRecorder.release();
            //start the playback
            MediaPlayer mp = new MediaPlayer();
            mp.setDataSource(fileName);
            mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
            mp.prepare();
            mp.start();
            Thread.sleep(recordDuration);
            mp.release();
            validateRecordedVideo(fileName);
            if (removeVideo) {
                removeRecordedVideo(fileName);
            }
            if (i == 0) {
                mOutput.write(i + 1);
            } else {
                mOutput.write(String.format(", %d", (i + 1)));
            }
        }
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Record and playback");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) CamcorderProfile(android.media.CamcorderProfile) MediaRecorder(android.media.MediaRecorder) IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Example 15 with CamcorderProfile

use of android.media.CamcorderProfile 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)

Aggregations

CamcorderProfile (android.media.CamcorderProfile)35 MediaRecorder (android.media.MediaRecorder)15 Size (android.util.Size)15 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)15 IOException (java.io.IOException)14 MediaPlayer (android.media.MediaPlayer)12 SurfaceHolder (android.view.SurfaceHolder)12 CaptureRequest (android.hardware.camera2.CaptureRequest)10 Range (android.util.Range)10 SimpleImageReaderListener (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener)10 Point (android.graphics.Point)7 LargeTest (android.test.suitebuilder.annotation.LargeTest)6 ArrayList (java.util.ArrayList)6 Image (android.media.Image)5 AssertionFailedError (junit.framework.AssertionFailedError)5 Activity (android.app.Activity)2 Camera (android.hardware.Camera)2 Uri (android.net.Uri)2 TargetApi (android.annotation.TargetApi)1 Intent (android.content.Intent)1