FileDocCategorySizeDatePackage
MediaRecorderStressTest.javaAPI DocAndroid 1.5 API8414Wed May 06 22:42:00 BST 2009com.android.mediaframeworktest.stress

MediaRecorderStressTest

public class MediaRecorderStressTest extends android.test.ActivityInstrumentationTestCase2
Junit / Instrumentation test case for the media player api

Fields Summary
private String
TAG
private android.media.MediaRecorder
mRecorder
private android.hardware.Camera
mCamera
private static final int
NUMBER_OF_CAMERA_STRESS_LOOPS
private static final int
NUMBER_OF_RECORDER_STRESS_LOOPS
private static final int
NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS
private static final int
NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER
private static final long
WAIT_TIME_CAMERA_TEST
private static final long
WAIT_TIME_RECORDER_TEST
private static final long
WAIT_TIME_RECORD
private static final long
WAIT_TIME_PLAYBACK
private static final String
OUTPUT_FILE
private static final String
OUTPUT_FILE_EXT
Constructors Summary
public MediaRecorderStressTest()

    
      
        super("com.android.mediaframeworktest", MediaFrameworkTest.class);
    
Methods Summary
protected voidsetUp()

        getActivity();
        super.setUp();      
    
public voidtestStressCamera()

        SurfaceHolder mSurfaceHolder;             
        mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        try {        
            Log.v(TAG, "Start preview");
            for (int i = 0; i< NUMBER_OF_CAMERA_STRESS_LOOPS; i++){
                mCamera = Camera.open();
                mCamera.setPreviewDisplay(mSurfaceHolder);
                mCamera.startPreview();
                Thread.sleep(WAIT_TIME_CAMERA_TEST);
                mCamera.stopPreview();
                mCamera.release();
            }
        } catch (Exception e) {
                Log.v(TAG, e.toString());
        }
    
public voidtestStressCameraSwitchRecorder()

        String filename;
        SurfaceHolder mSurfaceHolder;             
        mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        try {    
            Log.v(TAG, "Start preview");
            for (int i = 0; i < NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER; i++){
                mCamera = Camera.open();
                mCamera.setPreviewDisplay(mSurfaceHolder);
                mCamera.startPreview();
                Thread.sleep(WAIT_TIME_CAMERA_TEST);
                mCamera.stopPreview();
                mCamera.release();
                mCamera = null;
                Log.v(TAG, "release camera");
                filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
                Log.v(TAG, filename);
                mRecorder = new MediaRecorder();
                mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);          
                mRecorder.setOutputFile(filename);
                mRecorder.setVideoFrameRate(20);
                mRecorder.setVideoSize(176,144);
                Log.v(TAG, "Media recorder setEncoder");
                mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
                Log.v(TAG, "mediaRecorder setPreview");
                mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
                Log.v(TAG, "prepare");
                mRecorder.prepare();
                Log.v(TAG, "before release");
                Thread.sleep(WAIT_TIME_CAMERA_TEST);  
                mRecorder.release();
                Log.v(TAG, "release video recorder");                
            }
        } catch (Exception e) {
                Log.v(TAG, e.toString());
        }
    
public voidtestStressRecordVideoAndPlayback()

        String filename;
        SurfaceHolder mSurfaceHolder;             
        mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        try {    
            for (int i = 0; i < NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS; i++){
                filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
                Log.v(TAG, filename);
                mRecorder = new MediaRecorder();
                mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);          
                mRecorder.setOutputFile(filename);
                mRecorder.setVideoFrameRate(20);
                mRecorder.setVideoSize(352,288);
                mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
                mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                Log.v(TAG, "mediaRecorder setPreview");
                mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
                mRecorder.prepare();
                mRecorder.start();               
                Thread.sleep(WAIT_TIME_RECORD);
                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(WAIT_TIME_PLAYBACK);
                mp.release();
            }
        } catch (Exception e) {
                Log.v(TAG, e.toString());
        }
    
public voidtestStressRecorder()

        String filename;
        SurfaceHolder mSurfaceHolder;             
        mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        try {    
            Log.v(TAG, "Start preview");
            for (int i = 0; i < NUMBER_OF_RECORDER_STRESS_LOOPS; i++){
                Log.v(TAG, "counter = " + i);
                filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
                Log.v(TAG, filename);
                mRecorder = new MediaRecorder();
                mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);          
                mRecorder.setOutputFile(filename);
                mRecorder.setVideoFrameRate(20);
                mRecorder.setVideoSize(176,144);
                Log.v(TAG, "setEncoder");
                mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
                mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
                Log.v(TAG, "setPreview");
                mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
                Log.v(TAG, "prepare");
                mRecorder.prepare();
                Log.v(TAG, "before release");
                Thread.sleep(WAIT_TIME_RECORDER_TEST);  
                mRecorder.reset();
                mRecorder.release();
            }
        } catch (Exception e) {
                Log.v(TAG, e.toString());
        }