Skip to content

Commit b0016e2

Browse files
Yu Shan Emily LauAndroid (Google) Code Review
authored andcommitted
Merge "Added the runtime parameters for the mediarecorder stress test. Set the total number of the stress loops of camera preview memory test to 200." into froyo
2 parents d1055a2 + 48584d7 commit b0016e2

File tree

3 files changed

+126
-20
lines changed

3 files changed

+126
-20
lines changed

media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.android.mediaframeworktest;
1818

19+
import android.media.MediaRecorder;
20+
import android.os.Bundle;
1921
import android.test.InstrumentationTestRunner;
2022
import android.test.InstrumentationTestSuite;
2123
import com.android.mediaframeworktest.stress.MediaRecorderStressTest;
@@ -25,6 +27,17 @@
2527

2628
public class MediaRecorderStressTestRunner extends InstrumentationTestRunner {
2729

30+
// Default recorder settings
31+
public static int mIterations = 100;
32+
public static int mVideoEncoder = MediaRecorder.VideoEncoder.H263;
33+
public static int mAudioEncdoer = MediaRecorder.AudioEncoder.AMR_NB;
34+
public static int mFrameRate = 20;
35+
public static int mVideoWidth = 352;
36+
public static int mVideoHeight = 288;
37+
public static int mBitRate = 100;
38+
public static boolean mRemoveVideo = true;
39+
public static int mDuration = 10000;
40+
2841
@Override
2942
public TestSuite getAllTests() {
3043
TestSuite suite = new InstrumentationTestSuite(this);
@@ -37,4 +50,50 @@ public TestSuite getAllTests() {
3750
public ClassLoader getLoader() {
3851
return MediaRecorderStressTestRunner.class.getClassLoader();
3952
}
53+
54+
@Override
55+
public void onCreate(Bundle icicle) {
56+
super.onCreate(icicle);
57+
String iterations = (String) icicle.get("iterations");
58+
String video_encoder = (String) icicle.get("video_encoder");
59+
String audio_encoder = (String) icicle.get("audio_encoder");
60+
String frame_rate = (String) icicle.get("frame_rate");
61+
String video_width = (String) icicle.get("video_width");
62+
String video_height = (String) icicle.get("video_height");
63+
String bit_rate = (String) icicle.get("bit_rate");
64+
String record_duration = (String) icicle.get("record_duration");
65+
String remove_videos = (String) icicle.get("remove_videos");
66+
67+
if (iterations != null ) {
68+
mIterations = Integer.parseInt(iterations);
69+
}
70+
if ( video_encoder != null) {
71+
mVideoEncoder = Integer.parseInt(video_encoder);
72+
}
73+
if ( audio_encoder != null) {
74+
mAudioEncdoer = Integer.parseInt(audio_encoder);
75+
}
76+
if (frame_rate != null) {
77+
mFrameRate = Integer.parseInt(frame_rate);
78+
}
79+
if (video_width != null) {
80+
mVideoWidth = Integer.parseInt(video_width);
81+
}
82+
if (video_height != null) {
83+
mVideoHeight = Integer.parseInt(video_height);
84+
}
85+
if (bit_rate != null) {
86+
mBitRate = Integer.parseInt(bit_rate);
87+
}
88+
if (record_duration != null) {
89+
mDuration = Integer.parseInt(record_duration);
90+
}
91+
if (remove_videos != null) {
92+
if (remove_videos.compareTo("true") == 0) {
93+
mRemoveVideo = true;
94+
} else {
95+
mRemoveVideo = false;
96+
}
97+
}
98+
}
4099
}

media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,20 @@ private void waitForPreviewDone() {
237237
}
238238

239239
public void stressCameraPreview() {
240-
try {
241-
initializeMessageLooper();
242-
mCamera.setPreviewCallback(mRawPreviewCallback);
243-
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
244-
mCamera.setPreviewDisplay(mSurfaceHolder);
245-
mCamera.startPreview();
246-
waitForPreviewDone();
247-
Thread.sleep(1000);
248-
mCamera.stopPreview();
249-
terminateMessageLooper();
250-
} catch (Exception e) {
251-
Log.v(TAG, e.toString());
240+
for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) {
241+
try {
242+
initializeMessageLooper();
243+
mCamera.setPreviewCallback(mRawPreviewCallback);
244+
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
245+
mCamera.setPreviewDisplay(mSurfaceHolder);
246+
mCamera.startPreview();
247+
waitForPreviewDone();
248+
Thread.sleep(1000);
249+
mCamera.stopPreview();
250+
terminateMessageLooper();
251+
} catch (Exception e) {
252+
Log.v(TAG, e.toString());
253+
}
252254
}
253255
}
254256

media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import android.test.suitebuilder.annotation.LargeTest;
3333
import android.util.Log;
3434
import android.view.SurfaceHolder;
35+
import com.android.mediaframeworktest.MediaRecorderStressTestRunner;
3536

3637
/**
3738
* Junit / Instrumentation test case for the media player api
@@ -310,20 +311,51 @@ public void testStressCameraSwitchRecorder() throws Exception {
310311
output.close();
311312
}
312313

314+
public void validateRecordedVideo(String recorded_file) {
315+
try {
316+
MediaPlayer mp = new MediaPlayer();
317+
mp.setDataSource(recorded_file);
318+
mp.prepare();
319+
int duration = mp.getDuration();
320+
if (duration <= 0){
321+
assertTrue("stressRecordAndPlayback", false);
322+
}
323+
} catch (Exception e) {
324+
assertTrue("stressRecordAndPlayback", false);
325+
}
326+
}
327+
328+
public void removeRecodedVideo(String filename){
329+
File video = new File(filename);
330+
Log.v(TAG, "remove recorded video " + filename);
331+
video.delete();
332+
}
333+
313334
//Stress test case for record a video and play right away.
314335
@LargeTest
315336
public void testStressRecordVideoAndPlayback() throws Exception {
337+
int iterations = MediaRecorderStressTestRunner.mIterations;
338+
int video_encoder = MediaRecorderStressTestRunner.mVideoEncoder;
339+
int audio_encoder = MediaRecorderStressTestRunner.mAudioEncdoer;
340+
int frame_rate = MediaRecorderStressTestRunner.mFrameRate;
341+
int video_width = MediaRecorderStressTestRunner.mVideoWidth;
342+
int video_height = MediaRecorderStressTestRunner.mVideoHeight;
343+
int bit_rate = MediaRecorderStressTestRunner.mBitRate;
344+
boolean remove_video = MediaRecorderStressTestRunner.mRemoveVideo;
345+
int record_duration = MediaRecorderStressTestRunner.mDuration;
346+
316347
String filename;
317348
SurfaceHolder mSurfaceHolder;
318349
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
319350
File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
320-
Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
351+
Writer output = new BufferedWriter(
352+
new FileWriter(stressOutFile, true));
321353
output.write("Video record and play back stress test:\n");
322354
output.write("Total number of loops:"
323355
+ NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS + "\n");
324356
try {
325357
output.write("No of loop: ");
326-
for (int i = 0; i < NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS; i++){
358+
for (int i = 0; i < iterations; i++){
327359
filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
328360
Log.v(TAG, filename);
329361
synchronized (recorderlock) {
@@ -334,20 +366,29 @@ public void testStressRecordVideoAndPlayback() throws Exception {
334366
Log.v(TAG, "wait was interrupted.");
335367
}
336368
}
369+
Log.v(TAG, "iterations : " + iterations);
370+
Log.v(TAG, "video_encoder : " + video_encoder);
371+
Log.v(TAG, "audio_encoder : " + audio_encoder);
372+
Log.v(TAG, "frame_rate : " + frame_rate);
373+
Log.v(TAG, "video_width : " + video_width);
374+
Log.v(TAG, "video_height : " + video_height);
375+
Log.v(TAG, "bit rate : " + bit_rate);
376+
Log.v(TAG, "record_duration : " + record_duration);
377+
337378
mRecorder.setOnErrorListener(mRecorderErrorCallback);
338379
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
339380
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
340381
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
341382
mRecorder.setOutputFile(filename);
342-
mRecorder.setVideoFrameRate(20);
343-
mRecorder.setVideoSize(352,288);
344-
mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
345-
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
383+
mRecorder.setVideoFrameRate(frame_rate);
384+
mRecorder.setVideoSize(video_width, video_height);
385+
mRecorder.setVideoEncoder(video_encoder);
386+
mRecorder.setAudioEncoder(audio_encoder);
346387
Log.v(TAG, "mediaRecorder setPreview");
347388
mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
348389
mRecorder.prepare();
349390
mRecorder.start();
350-
Thread.sleep(WAIT_TIME_RECORD);
391+
Thread.sleep(record_duration);
351392
Log.v(TAG, "Before stop");
352393
mRecorder.stop();
353394
terminateRecorderMessageLooper();
@@ -357,8 +398,12 @@ public void testStressRecordVideoAndPlayback() throws Exception {
357398
mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
358399
mp.prepare();
359400
mp.start();
360-
Thread.sleep(WAIT_TIME_PLAYBACK);
401+
Thread.sleep(record_duration);
361402
mp.release();
403+
validateRecordedVideo(filename);
404+
if (remove_video) {
405+
removeRecodedVideo(filename);
406+
}
362407
output.write(", " + i);
363408
}
364409
} catch (Exception e) {

0 commit comments

Comments
 (0)