blob: a3bbb7447f7aab29fe35de23b2862c39f4090a6e [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package com.android.mediaframeworktest.performance;
18
19import com.android.mediaframeworktest.MediaFrameworkTest;
20import com.android.mediaframeworktest.MediaNames;
21
22import android.database.sqlite.SQLiteDatabase;
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -080023import android.hardware.Camera;
24import android.hardware.Camera.PreviewCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.media.MediaPlayer;
26import android.media.MediaRecorder;
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -080027import android.os.Looper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.SystemClock;
29import android.test.ActivityInstrumentationTestCase;
30import android.test.suitebuilder.annotation.LargeTest;
31import android.test.suitebuilder.annotation.Suppress;
32import android.util.Log;
33import android.view.SurfaceHolder;
34
35import java.io.FileDescriptor;
36import java.io.FileInputStream;
37import java.io.FileOutputStream;
38import java.io.IOException;
39import java.io.InputStream;
40import java.io.Writer;
41import java.io.File;
42import java.io.FileWriter;
43import java.io.BufferedWriter;
44
45import android.media.MediaMetadataRetriever;
Yu Shan Emily Laua56e6532009-09-25 00:07:47 -070046import com.android.mediaframeworktest.MediaProfileReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -080048import android.hardware.Camera.PreviewCallback;
49
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050/**
51 * Junit / Instrumentation - performance measurement for media player and
52 * recorder
53 */
54public class MediaPlayerPerformance extends ActivityInstrumentationTestCase<MediaFrameworkTest> {
55
Xia Wang568d91b2009-05-04 20:30:04 -070056 private String TAG = "MediaPlayerPerformance";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
58 private SQLiteDatabase mDB;
59 private SurfaceHolder mSurfaceHolder = null;
Yu Shan Emily Lau32742022009-06-22 21:19:53 -070060 private static final int NUM_STRESS_LOOP = 10;
61 private static final int NUM_PLAYBACk_IN_EACH_LOOP = 20;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 private static final long MEDIA_STRESS_WAIT_TIME = 5000; //5 seconds
Yu Shan Emily Laua7460302009-06-19 11:07:40 -070063 private static final String MEDIA_MEMORY_OUTPUT =
64 "/sdcard/mediaMemOutput.txt";
65
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -070066 private static int mStartMemory = 0;
67 private static int mEndMemory = 0;
68 private static int mStartPid = 0;
69 private static int mEndPid = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -080071 private boolean mInitialized = false;
72 private Looper mLooper = null;
73 private RawPreviewCallback mRawPreviewCallback = new RawPreviewCallback();
74 private final Object lock = new Object();
75 private final Object previewDone = new Object();
76 private static int WAIT_FOR_COMMAND_TO_COMPLETE = 10000; // Milliseconds.
77
78 //the tolerant memory leak
79 private static int ENCODER_LIMIT = 150;
80 private static int DECODER_LIMIT = 150;
81 private static int CAMERA_LIMIT = 80;
82
83 Camera mCamera;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084
85 public MediaPlayerPerformance() {
86 super("com.android.mediaframeworktest", MediaFrameworkTest.class);
87 }
88
89 protected void setUp() throws Exception {
90 super.setUp();
91 }
92
93 public void createDB() {
94 mDB = SQLiteDatabase.openOrCreateDatabase("/sdcard/perf.db", null);
Xia Wang568d91b2009-05-04 20:30:04 -070095 mDB.execSQL("CREATE TABLE IF NOT EXISTS perfdata (_id INTEGER PRIMARY KEY," +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 "file TEXT," + "setdatatime LONG," + "preparetime LONG," +
97 "playtime LONG" + ");");
Xia Wang568d91b2009-05-04 20:30:04 -070098 //clean the table before adding new data
99 mDB.execSQL("DELETE FROM perfdata");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 }
101
102 public void audioPlaybackStartupTime(String[] testFile) {
103 long t1 = 0;
104 long t2 = 0;
105 long t3 = 0;
106 long t4 = 0;
107 long setDataSourceDuration = 0;
108 long prepareDuration = 0;
109 long startDuration = 0;
110 long totalSetDataTime = 0;
111 long totalPrepareTime = 0;
112 long totalStartDuration = 0;
113
114 int numberOfFiles = testFile.length;
115 Log.v(TAG, "File length " + numberOfFiles);
116 for (int k = 0; k < numberOfFiles; k++) {
117 MediaPlayer mp = new MediaPlayer();
118 try {
119 t1 = SystemClock.uptimeMillis();
120 FileInputStream fis = new FileInputStream(testFile[k]);
121 FileDescriptor fd = fis.getFD();
122 mp.setDataSource(fd);
123 fis.close();
124 t2 = SystemClock.uptimeMillis();
125 mp.prepare();
126 t3 = SystemClock.uptimeMillis();
127 mp.start();
128 t4 = SystemClock.uptimeMillis();
129 } catch (Exception e) {
130 Log.v(TAG, e.toString());
131 }
132 setDataSourceDuration = t2 - t1;
133 prepareDuration = t3 - t2;
134 startDuration = t4 - t3;
135 totalSetDataTime = totalSetDataTime + setDataSourceDuration;
136 totalPrepareTime = totalPrepareTime + prepareDuration;
137 totalStartDuration = totalStartDuration + startDuration;
138 mDB.execSQL("INSERT INTO perfdata (file, setdatatime, preparetime," +
139 " playtime) VALUES (" + '"' + testFile[k] + '"' + ',' +
140 setDataSourceDuration + ',' + prepareDuration +
141 ',' + startDuration + ");");
142 Log.v(TAG, "File name " + testFile[k]);
143 mp.stop();
144 mp.release();
145 }
146 Log.v(TAG, "setDataSource average " + totalSetDataTime / numberOfFiles);
147 Log.v(TAG, "prepare average " + totalPrepareTime / numberOfFiles);
148 Log.v(TAG, "start average " + totalStartDuration / numberOfFiles);
149
150 }
151
152 @Suppress
153 public void testStartUpTime() throws Exception {
154 createDB();
155 audioPlaybackStartupTime(MediaNames.MP3FILES);
156 audioPlaybackStartupTime(MediaNames.AACFILES);
157
Xia Wang568d91b2009-05-04 20:30:04 -0700158 //close the database after all transactions
159 if (mDB.isOpen()) {
160 mDB.close();
161 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 }
163
164 public void wmametadatautility(String[] testFile) {
165 long t1 = 0;
166 long t2 = 0;
167 long sum = 0;
168 long duration = 0;
169 MediaMetadataRetriever retriever = new MediaMetadataRetriever();
170 String value;
171 for (int i = 0, n = testFile.length; i < n; ++i) {
172 try {
173 t1 = SystemClock.uptimeMillis();
174 retriever.setDataSource(testFile[i]);
175 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
176 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
177 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER);
178 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);
179 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
180 value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
181 value =
182 retriever
183 .extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER);
184 t2 = SystemClock.uptimeMillis();
185 duration = t2 - t1;
186 Log.v(TAG, "Time taken = " + duration);
187 sum = sum + duration;
188 } catch (Exception e) {
189 Log.v(TAG, e.getMessage());
190 }
191
192 }
193 Log.v(TAG, "Average duration = " + sum / testFile.length);
194 }
195
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -0800196 private void initializeMessageLooper() {
197 new Thread() {
198 @Override
199 public void run() {
200 Looper.prepare();
201 Log.v(TAG, "start loopRun");
202 mLooper = Looper.myLooper();
203 mCamera = Camera.open();
204 synchronized (lock) {
205 mInitialized = true;
206 lock.notify();
207 }
208 Looper.loop();
209 Log.v(TAG, "initializeMessageLooper: quit.");
210 }
211 }.start();
212 }
213
214 private void terminateMessageLooper() {
215 mLooper.quit();
216 mCamera.release();
217 }
218
219 private final class RawPreviewCallback implements PreviewCallback {
220 public void onPreviewFrame(byte[] rawData, Camera camera) {
221 synchronized (previewDone) {
222 previewDone.notify();
223 }
224 }
225 }
226
227 public void stressCameraPreview() {
228 try {
229 synchronized (lock) {
230 initializeMessageLooper();
231 try {
232 lock.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
233 } catch (Exception e) {
234 Log.v(TAG, "runTestOnMethod: wait was interrupted.");
235 }
236 }
237 mCamera.setPreviewCallback(mRawPreviewCallback);
238 mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
239 mCamera.setPreviewDisplay(mSurfaceHolder);
240 mCamera.startPreview();
241 synchronized (previewDone) {
242 try {
243 previewDone.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
244 Log.v(TAG, "Preview Done");
245 } catch (Exception e) {
246 Log.v(TAG, "wait was interrupted.");
247 }
248 }
249 Thread.sleep(1000);
250 mCamera.stopPreview();
251 terminateMessageLooper();
252 } catch (Exception e) {
253 Log.v(TAG, e.toString());
254 }
255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256
257 // Note: This test is to assume the mediaserver's pid is 34
258 public void mediaStressPlayback(String testFilePath) {
259 for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) {
260 MediaPlayer mp = new MediaPlayer();
261 try {
262 mp.setDataSource(testFilePath);
263 mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
264 mp.prepare();
265 mp.start();
266 Thread.sleep(MEDIA_STRESS_WAIT_TIME);
267 mp.release();
268 } catch (Exception e) {
269 mp.release();
270 Log.v(TAG, e.toString());
271 }
272 }
273 }
274
275 // Note: This test is to assume the mediaserver's pid is 34
276 private void stressVideoRecord(int frameRate, int width, int height, int videoFormat,
277 int outFormat, String outFile, boolean videoOnly) {
278 // Video recording
279 for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) {
280 MediaRecorder mRecorder = new MediaRecorder();
281 try {
282 if (!videoOnly) {
283 Log.v(TAG, "setAudioSource");
284 mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
285 }
286 mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
287 mRecorder.setOutputFormat(outFormat);
288 Log.v(TAG, "output format " + outFormat);
289 mRecorder.setOutputFile(outFile);
290 mRecorder.setVideoFrameRate(frameRate);
291 mRecorder.setVideoSize(width, height);
292 Log.v(TAG, "setEncoder");
293 mRecorder.setVideoEncoder(videoFormat);
294 if (!videoOnly) {
295 mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
296 }
297 mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
298 mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
299 mRecorder.prepare();
300 mRecorder.start();
301 Thread.sleep(MEDIA_STRESS_WAIT_TIME);
302 mRecorder.stop();
303 mRecorder.release();
304 } catch (Exception e) {
305 Log.v("record video failed ", e.toString());
306 mRecorder.release();
307 }
308 }
309 }
310
311 public void stressAudioRecord(String filePath) {
312 // This test is only for the short media file
313 for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) {
314 MediaRecorder mRecorder = new MediaRecorder();
315 try {
316 mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
317 mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
318 mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
319 mRecorder.setOutputFile(filePath);
320 mRecorder.prepare();
321 mRecorder.start();
322 Thread.sleep(MEDIA_STRESS_WAIT_TIME);
323 mRecorder.stop();
324 mRecorder.release();
325 } catch (Exception e) {
326 Log.v(TAG, e.toString());
327 mRecorder.release();
328 }
329 }
330 }
331
332 //Write the ps output to the file
Yu Shan Emily Lauf465dc02010-01-21 12:38:02 -0800333 public void getMemoryWriteToLog(Writer output, int writeCount) {
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700334 String memusage = null;
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700335 try {
Yu Shan Emily Lauf465dc02010-01-21 12:38:02 -0800336 if (writeCount == 0) {
337 mStartMemory = getMediaserverVsize();
338 output.write("Start memory : " + mStartMemory + "\n");
339 }
340 memusage = captureMediaserverInfo();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700341 output.write(memusage);
Yu Shan Emily Lauf465dc02010-01-21 12:38:02 -0800342 if (writeCount == NUM_STRESS_LOOP - 1) {
343 mEndMemory = getMediaserverVsize();
344 output.write("End Memory :" + mEndMemory + "\n");
345 }
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700346 } catch (Exception e) {
347 e.toString();
348 }
349 }
350
351 public String captureMediaserverInfo() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 String cm = "ps mediaserver";
353 String memoryUsage = null;
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 int ch;
356 try {
357 Process p = Runtime.getRuntime().exec(cm);
358 InputStream in = p.getInputStream();
359 StringBuffer sb = new StringBuffer(512);
360 while ((ch = in.read()) != -1) {
361 sb.append((char) ch);
362 }
363 memoryUsage = sb.toString();
364 } catch (IOException e) {
365 Log.v(TAG, e.toString());
366 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 String[] poList = memoryUsage.split("\r|\n|\r\n");
368 String memusage = poList[1].concat("\n");
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700369 return memusage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 }
371
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700372 public int getMediaserverPid(){
373 String memoryUsage = null;
374 int pidvalue = 0;
375 memoryUsage = captureMediaserverInfo();
376 String[] poList2 = memoryUsage.split("\t|\\s+");
377 String pid = poList2[1];
378 pidvalue = Integer.parseInt(pid);
379 Log.v(TAG, "PID = " + pidvalue);
380 return pidvalue;
381 }
382
383 public int getMediaserverVsize(){
384 String memoryUsage = captureMediaserverInfo();
385 String[] poList2 = memoryUsage.split("\t|\\s+");
386 String vsize = poList2[3];
387 int vsizevalue = Integer.parseInt(vsize);
388 Log.v(TAG, "VSIZE = " + vsizevalue);
389 return vsizevalue;
390 }
391
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -0800392 public boolean validateMemoryResult(int startPid, int startMemory, Writer output, int limit)
393 throws Exception {
394 // Wait for 10 seconds to make sure the memory settle.
Yu Shan Emily Lau99910132009-10-15 17:32:41 -0700395 Thread.sleep(10000);
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700396 mEndPid = getMediaserverPid();
Yu Shan Emily Lau30daf092009-12-04 14:13:00 -0800397 int memDiff = mEndMemory - startMemory;
398 if (memDiff < 0)
399 memDiff = 0;
400 else
401 output.write("The total diff = " + memDiff);
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700402 output.write("\n\n");
Yu Shan Emily Lau30daf092009-12-04 14:13:00 -0800403 // mediaserver crash
404 if (startPid != mEndPid) {
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700405 output.write("mediaserver died. Test failed\n");
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700406 return false;
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700407 }
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -0800408 // memory leak greter than the tolerant
409 if (memDiff > limit) return false;
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700410 return true;
411 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412
413 @Suppress
414 public void testWmaParseTime() throws Exception {
415 // createDB();
416 wmametadatautility(MediaNames.WMASUPPORTED);
417 }
418
419
420 // Test case 1: Capture the memory usage after every 20 h263 playback
421 @LargeTest
422 public void testH263VideoPlaybackMemoryUsage() throws Exception {
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700423 boolean memoryResult = false;
424 mStartPid = getMediaserverPid();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700425
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700426 File h263MemoryOut = new File(MEDIA_MEMORY_OUTPUT);
427 Writer output = new BufferedWriter(new FileWriter(h263MemoryOut, true));
428 output.write("H263 Video Playback Only\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 for (int i = 0; i < NUM_STRESS_LOOP; i++) {
430 mediaStressPlayback(MediaNames.VIDEO_HIGHRES_H263);
Yu Shan Emily Lauf465dc02010-01-21 12:38:02 -0800431 getMemoryWriteToLog(output, i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 }
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700433 output.write("\n");
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -0800434 memoryResult = validateMemoryResult(mStartPid, mStartMemory, output, DECODER_LIMIT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 output.close();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700436 assertTrue("H263 playback memory test", memoryResult);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 }
438
439 // Test case 2: Capture the memory usage after every 20 h264 playback
440 @LargeTest
441 public void testH264VideoPlaybackMemoryUsage() throws Exception {
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700442 boolean memoryResult = false;
443 mStartPid = getMediaserverPid();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700444
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700445 File h264MemoryOut = new File(MEDIA_MEMORY_OUTPUT);
446 Writer output = new BufferedWriter(new FileWriter(h264MemoryOut, true));
447 output.write("H264 Video Playback only\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 for (int i = 0; i < NUM_STRESS_LOOP; i++) {
449 mediaStressPlayback(MediaNames.VIDEO_H264_AMR);
Yu Shan Emily Lauf465dc02010-01-21 12:38:02 -0800450 getMemoryWriteToLog(output, i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 }
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700452 output.write("\n");
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -0800453 memoryResult = validateMemoryResult(mStartPid, mStartMemory, output, DECODER_LIMIT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 output.close();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700455 assertTrue("H264 playback memory test", memoryResult);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 }
457
458 // Test case 3: Capture the memory usage after each 20 WMV playback
459 @LargeTest
460 public void testWMVVideoPlaybackMemoryUsage() throws Exception {
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700461 boolean memoryResult = false;
Yu Shan Emily Laua56e6532009-09-25 00:07:47 -0700462 if (MediaProfileReader.getWMVEnable()){
463 mStartPid = getMediaserverPid();
464 File wmvMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
465 Writer output = new BufferedWriter(new FileWriter(wmvMemoryOut, true));
466 output.write("WMV video playback only\n");
467 for (int i = 0; i < NUM_STRESS_LOOP; i++) {
468 mediaStressPlayback(MediaNames.VIDEO_WMV);
Yu Shan Emily Lauf465dc02010-01-21 12:38:02 -0800469 getMemoryWriteToLog(output, i);
Yu Shan Emily Lau3397f162009-08-06 17:35:51 -0700470 }
Yu Shan Emily Laua56e6532009-09-25 00:07:47 -0700471 output.write("\n");
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -0800472 memoryResult = validateMemoryResult(mStartPid, mStartMemory, output, DECODER_LIMIT);
Yu Shan Emily Laua56e6532009-09-25 00:07:47 -0700473 output.close();
474 assertTrue("wmv playback memory test", memoryResult);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 }
477
478 // Test case 4: Capture the memory usage after every 20 video only recorded
479 @LargeTest
480 public void testH263RecordVideoOnlyMemoryUsage() throws Exception {
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700481 boolean memoryResult = false;
482 mStartPid = getMediaserverPid();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700483
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700484 File videoH263RecordOnlyMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
485 Writer output = new BufferedWriter(new FileWriter(videoH263RecordOnlyMemoryOut, true));
486 output.write("H263 video record only\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 for (int i = 0; i < NUM_STRESS_LOOP; i++) {
488 stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.H263,
489 MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, true);
Yu Shan Emily Lauf465dc02010-01-21 12:38:02 -0800490 getMemoryWriteToLog(output, i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 }
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700492 output.write("\n");
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -0800493 memoryResult = validateMemoryResult(mStartPid, mStartMemory, output, ENCODER_LIMIT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 output.close();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700495 assertTrue("H263 record only memory test", memoryResult);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 }
497
498 // Test case 5: Capture the memory usage after every 20 video only recorded
499 @LargeTest
500 public void testMpeg4RecordVideoOnlyMemoryUsage() throws Exception {
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700501 boolean memoryResult = false;
502 mStartPid = getMediaserverPid();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700503
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700504 File videoMp4RecordOnlyMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
505 Writer output = new BufferedWriter(new FileWriter(videoMp4RecordOnlyMemoryOut, true));
506 output.write("MPEG4 video record only\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 for (int i = 0; i < NUM_STRESS_LOOP; i++) {
508 stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.MPEG_4_SP,
509 MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, true);
Yu Shan Emily Lauf465dc02010-01-21 12:38:02 -0800510 getMemoryWriteToLog(output, i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 }
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700512 output.write("\n");
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -0800513 memoryResult = validateMemoryResult(mStartPid, mStartMemory, output, ENCODER_LIMIT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 output.close();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700515 assertTrue("mpeg4 record only memory test", memoryResult);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 }
517
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700518 // Test case 6: Capture the memory usage after every 20 video and audio
519 // recorded
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 @LargeTest
521 public void testRecordVidedAudioMemoryUsage() throws Exception {
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700522 boolean memoryResult = false;
523 mStartPid = getMediaserverPid();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700524
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700525 File videoRecordAudioMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
526 Writer output = new BufferedWriter(new FileWriter(videoRecordAudioMemoryOut, true));
527 output.write("Audio and h263 video record\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 for (int i = 0; i < NUM_STRESS_LOOP; i++) {
529 stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.H263,
530 MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, false);
Yu Shan Emily Lauf465dc02010-01-21 12:38:02 -0800531 getMemoryWriteToLog(output, i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 }
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700533 output.write("\n");
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -0800534 memoryResult = validateMemoryResult(mStartPid, mStartMemory, output, ENCODER_LIMIT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 output.close();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700536 assertTrue("H263 audio video record memory test", memoryResult);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 }
538
539 // Test case 7: Capture the memory usage after every 20 audio only recorded
540 @LargeTest
541 public void testRecordAudioOnlyMemoryUsage() throws Exception {
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700542 boolean memoryResult = false;
543 mStartPid = getMediaserverPid();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700544
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700545 File audioOnlyMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
546 Writer output = new BufferedWriter(new FileWriter(audioOnlyMemoryOut, true));
547 output.write("Audio record only\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 for (int i = 0; i < NUM_STRESS_LOOP; i++) {
549 stressAudioRecord(MediaNames.RECORDER_OUTPUT);
Yu Shan Emily Lauf465dc02010-01-21 12:38:02 -0800550 getMemoryWriteToLog(output, i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 }
Yu Shan Emily Laua7460302009-06-19 11:07:40 -0700552 output.write("\n");
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -0800553 memoryResult = validateMemoryResult(mStartPid, mStartMemory, output, ENCODER_LIMIT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 output.close();
Yu Shan Emily Lau01c05962009-05-28 15:41:16 -0700555 assertTrue("audio record only memory test", memoryResult);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 }
Yu Shan Emily Lau30a13902010-03-01 19:24:05 -0800557
558 // Test case 8: Capture the memory usage after every 20 camera preview
559 @LargeTest
560 public void testCameraPreviewMemoryUsage() throws Exception {
561 boolean memoryResult = false;
562 mStartPid = getMediaserverPid();
563
564 File cameraPreviewMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
565 Writer output = new BufferedWriter(new FileWriter(cameraPreviewMemoryOut, true));
566 output.write("Camera Preview Only\n");
567 for (int i = 0; i < NUM_STRESS_LOOP; i++) {
568 stressCameraPreview();
569 getMemoryWriteToLog(output, i);
570 }
571 output.write("\n");
572 memoryResult = validateMemoryResult(mStartPid, mStartMemory, output, CAMERA_LIMIT);
573 output.close();
574 assertTrue("camera preview memory test", memoryResult);
575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576}