Search in sources :

Example 46 with SurfaceHolder

use of android.view.SurfaceHolder 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 47 with SurfaceHolder

use of android.view.SurfaceHolder 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 48 with SurfaceHolder

use of android.view.SurfaceHolder in project platform_frameworks_base by android.

the class CameraStressTest method testStressCameraZoom.

/**
     * Stress test iterating on the range of supported camera zoom levels
     */
@LargeTest
public void testStressCameraZoom() throws Exception {
    try {
        SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        Parameters params = mCameraTestHelper.getCameraParameters();
        if (!params.isSmoothZoomSupported() && !params.isZoomSupported()) {
            Log.v(TAG, "Device camera does not support zoom");
            fail("Camera zoom stress test failed due to unsupported feature");
        } else {
            Log.v(TAG, "Device camera does support zoom");
            Log.v(TAG, "Start preview");
            mOutput.write("Total number of loops: " + NUMBER_OF_ZOOM_LOOPS + "\n");
            mOutput.write("No of loops: ");
            int nextZoomLevel = 0;
            for (int i = 0; i < NUMBER_OF_ZOOM_LOOPS; i++) {
                runOnLooper(new Runnable() {

                    @Override
                    public void run() {
                        mCameraTestHelper.setupCameraTest();
                    }
                });
                mCameraTestHelper.startCameraPreview(surfaceHolder);
                params = mCameraTestHelper.mCamera.getParameters();
                int currentZoomLevel = params.getZoom();
                if (nextZoomLevel >= params.getMaxZoom()) {
                    nextZoomLevel = 0;
                }
                ++nextZoomLevel;
                if (params.isSmoothZoomSupported()) {
                    mCameraTestHelper.mCamera.startSmoothZoom(nextZoomLevel);
                } else {
                    params.setZoom(nextZoomLevel);
                    mCameraTestHelper.setParameters(params);
                }
                mCameraTestHelper.capturePhoto();
                if (i == 0) {
                    mOutput.write(Integer.toString(i));
                } else {
                    mOutput.write(", " + i);
                }
            }
        }
        mCameraTestHelper.cleanupTestImages();
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera zoom stress test Exception");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) Parameters(android.hardware.Camera.Parameters) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 49 with SurfaceHolder

use of android.view.SurfaceHolder in project platform_frameworks_base by android.

the class CameraStressTest method testStressCameraSceneModes.

/**
     * Stress test iterating on the various scene modes (action, night, party, etc.)
     */
@LargeTest
public void testStressCameraSceneModes() throws Exception {
    try {
        SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        Parameters params = mCameraTestHelper.getCameraParameters();
        List<String> supportedSceneModes = params.getSupportedSceneModes();
        assertNotNull("No scene modes supported", supportedSceneModes);
        mOutput.write("Total number of loops: " + (NUMBER_OF_SCENE_MODE_LOOPS * supportedSceneModes.size()) + "\n");
        Log.v(TAG, "Start preview");
        mOutput.write("No of loop: ");
        for (int i = 0; i < supportedSceneModes.size(); i++) {
            for (int j = 0; j < NUMBER_OF_SCENE_MODE_LOOPS; j++) {
                runOnLooper(new Runnable() {

                    @Override
                    public void run() {
                        mCameraTestHelper.setupCameraTest();
                    }
                });
                Log.v(TAG, "Setting scene mode to " + supportedSceneModes.get(i));
                params.setSceneMode(supportedSceneModes.get(i));
                mCameraTestHelper.setParameters(params);
                mCameraTestHelper.startCameraPreview(surfaceHolder);
                mCameraTestHelper.capturePhoto();
                if (i == 0 && j == 0) {
                    mOutput.write(Integer.toString(j + i * NUMBER_OF_SCENE_MODE_LOOPS));
                } else {
                    mOutput.write(", " + (j + i * NUMBER_OF_SCENE_MODE_LOOPS));
                }
            }
        }
        mCameraTestHelper.cleanupTestImages();
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera scene mode test Exception");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) Parameters(android.hardware.Camera.Parameters) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 50 with SurfaceHolder

use of android.view.SurfaceHolder in project platform_frameworks_base by android.

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)

Aggregations

SurfaceHolder (android.view.SurfaceHolder)189 SurfaceView (android.view.SurfaceView)62 LargeTest (android.test.suitebuilder.annotation.LargeTest)50 Parameters (android.hardware.Camera.Parameters)37 IOException (java.io.IOException)29 MediaPlayer (android.media.MediaPlayer)17 Surface (android.view.Surface)16 SurfaceTexture (android.graphics.SurfaceTexture)14 CamcorderProfile (android.media.CamcorderProfile)13 MediaRecorder (android.media.MediaRecorder)13 Camera (android.hardware.Camera)9 OverlayData (android.media.videoeditor.VideoEditor.OverlayData)9 Paint (android.graphics.Paint)8 AudioManager (android.media.AudioManager)8 SharedPreferences (android.content.SharedPreferences)7 MediaVideoItem (android.media.videoeditor.MediaVideoItem)7 CameraManager (com.google.zxing.client.android.camera.CameraManager)7 Intent (android.content.Intent)6 VideoEditor (android.media.videoeditor.VideoEditor)6 MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)6