am e71bb772: am f9719d11: am daf9b7d1: am 3f72bf32: Merge "Refactoring the media recorder stress test. Added test cases for: - record & playback @ 1080p - record & playback @ 720p - record & playback @ 480p - record & playback @ custom Plus extending the record durati
* commit 'e71bb7722b26ba2ada948ce3dbd626f14aabeb68': Refactoring the media recorder stress test. Added test cases for: - record & playback @ 1080p - record & playback @ 720p - record & playback @ 480p - record & playback @ custom Plus extending the record duration to a full minute.
This commit is contained in:
@@ -33,18 +33,16 @@ public class MediaRecorderStressTestRunner extends InstrumentationTestRunner {
|
|||||||
// the test must be supported by the corresponding camera.
|
// the test must be supported by the corresponding camera.
|
||||||
public static int mCameraId = 0;
|
public static int mCameraId = 0;
|
||||||
public static int mProfileQuality = CamcorderProfile.QUALITY_HIGH;
|
public static int mProfileQuality = CamcorderProfile.QUALITY_HIGH;
|
||||||
public static CamcorderProfile profile =
|
public static CamcorderProfile profile = CamcorderProfile.get(mCameraId, mProfileQuality);
|
||||||
CamcorderProfile.get(mCameraId, mProfileQuality);
|
public static int mIterations = 15;
|
||||||
|
|
||||||
public static int mIterations = 100;
|
|
||||||
public static int mVideoEncoder = profile.videoCodec;
|
public static int mVideoEncoder = profile.videoCodec;
|
||||||
public static int mAudioEncdoer = profile.audioCodec;
|
public static int mAudioEncoder = profile.audioCodec;
|
||||||
public static int mFrameRate = profile.videoFrameRate;
|
public static int mFrameRate = profile.videoFrameRate;
|
||||||
public static int mVideoWidth = profile.videoFrameWidth;
|
public static int mVideoWidth = profile.videoFrameWidth;
|
||||||
public static int mVideoHeight = profile.videoFrameHeight;
|
public static int mVideoHeight = profile.videoFrameHeight;
|
||||||
public static int mBitRate = profile.videoBitRate;
|
public static int mBitRate = profile.videoBitRate;
|
||||||
public static boolean mRemoveVideo = true;
|
public static boolean mRemoveVideo = true;
|
||||||
public static int mDuration = 10 * 1000; // 10 seconds
|
public static int mDuration = 60 * 1000; // 60 seconds
|
||||||
public static int mTimeLapseDuration = 180 * 1000; // 3 minutes
|
public static int mTimeLapseDuration = 180 * 1000; // 3 minutes
|
||||||
public static double mCaptureRate = 0.5; // 2 sec timelapse interval
|
public static double mCaptureRate = 0.5; // 2 sec timelapse interval
|
||||||
|
|
||||||
@@ -64,41 +62,41 @@ public class MediaRecorderStressTestRunner extends InstrumentationTestRunner {
|
|||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
String iterations = (String) icicle.get("iterations");
|
String iterations = (String) icicle.get("iterations");
|
||||||
String video_encoder = (String) icicle.get("video_encoder");
|
String videoEncoder = (String) icicle.get("video_encoder");
|
||||||
String audio_encoder = (String) icicle.get("audio_encoder");
|
String audioEncoder = (String) icicle.get("audio_encoder");
|
||||||
String frame_rate = (String) icicle.get("frame_rate");
|
String frameRate = (String) icicle.get("frame_rate");
|
||||||
String video_width = (String) icicle.get("video_width");
|
String videoWidth = (String) icicle.get("video_width");
|
||||||
String video_height = (String) icicle.get("video_height");
|
String videoHeight = (String) icicle.get("video_height");
|
||||||
String bit_rate = (String) icicle.get("bit_rate");
|
String bitRate = (String) icicle.get("bit_rate");
|
||||||
String record_duration = (String) icicle.get("record_duration");
|
String recordDuration = (String) icicle.get("record_duration");
|
||||||
String remove_videos = (String) icicle.get("remove_videos");
|
String removeVideos = (String) icicle.get("remove_videos");
|
||||||
|
|
||||||
if (iterations != null ) {
|
if (iterations != null ) {
|
||||||
mIterations = Integer.parseInt(iterations);
|
mIterations = Integer.parseInt(iterations);
|
||||||
}
|
}
|
||||||
if ( video_encoder != null) {
|
if (videoEncoder != null) {
|
||||||
mVideoEncoder = Integer.parseInt(video_encoder);
|
mVideoEncoder = Integer.parseInt(videoEncoder);
|
||||||
}
|
}
|
||||||
if ( audio_encoder != null) {
|
if (audioEncoder != null) {
|
||||||
mAudioEncdoer = Integer.parseInt(audio_encoder);
|
mAudioEncoder = Integer.parseInt(audioEncoder);
|
||||||
}
|
}
|
||||||
if (frame_rate != null) {
|
if (frameRate != null) {
|
||||||
mFrameRate = Integer.parseInt(frame_rate);
|
mFrameRate = Integer.parseInt(frameRate);
|
||||||
}
|
}
|
||||||
if (video_width != null) {
|
if (videoWidth != null) {
|
||||||
mVideoWidth = Integer.parseInt(video_width);
|
mVideoWidth = Integer.parseInt(videoWidth);
|
||||||
}
|
}
|
||||||
if (video_height != null) {
|
if (videoHeight != null) {
|
||||||
mVideoHeight = Integer.parseInt(video_height);
|
mVideoHeight = Integer.parseInt(videoHeight);
|
||||||
}
|
}
|
||||||
if (bit_rate != null) {
|
if (bitRate != null) {
|
||||||
mBitRate = Integer.parseInt(bit_rate);
|
mBitRate = Integer.parseInt(bitRate);
|
||||||
}
|
}
|
||||||
if (record_duration != null) {
|
if (recordDuration != null) {
|
||||||
mDuration = Integer.parseInt(record_duration);
|
mDuration = Integer.parseInt(recordDuration);
|
||||||
}
|
}
|
||||||
if (remove_videos != null) {
|
if (removeVideos != null) {
|
||||||
if (remove_videos.compareTo("true") == 0) {
|
if (removeVideos.compareTo("true") == 0) {
|
||||||
mRemoveVideo = true;
|
mRemoveVideo = true;
|
||||||
} else {
|
} else {
|
||||||
mRemoveVideo = false;
|
mRemoveVideo = false;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import android.hardware.Camera;
|
|||||||
import android.media.CamcorderProfile;
|
import android.media.CamcorderProfile;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.media.MediaRecorder;
|
import android.media.MediaRecorder;
|
||||||
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
@@ -48,26 +49,26 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
private MediaRecorder mRecorder;
|
private MediaRecorder mRecorder;
|
||||||
private Camera mCamera;
|
private Camera mCamera;
|
||||||
|
|
||||||
|
private static final int CAMERA_ID = 0;
|
||||||
private static final int NUMBER_OF_CAMERA_STRESS_LOOPS = 100;
|
private static final int NUMBER_OF_CAMERA_STRESS_LOOPS = 100;
|
||||||
private static final int NUMBER_OF_RECORDER_STRESS_LOOPS = 100;
|
private static final int NUMBER_OF_RECORDER_STRESS_LOOPS = 100;
|
||||||
private static final int NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS = 50;
|
private static final int NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS = 50;
|
||||||
private static final int NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER = 200;
|
private static final int NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER = 200;
|
||||||
private static final int NUMBER_OF_TIME_LAPSE_LOOPS = 25;
|
private static final int NUMBER_OF_TIME_LAPSE_LOOPS = 25;
|
||||||
private static final int TIME_LAPSE_PLAYBACK_WAIT_TIME = 5* 1000; // 5 seconds
|
private static final int TIME_LAPSE_PLAYBACK_WAIT_TIME = 5* 1000; // 5 seconds
|
||||||
|
private static final int USE_TEST_RUNNER_PROFILE = -1;
|
||||||
|
private static final long WAIT_TIMEOUT = 10 * 1000; // 10 seconds
|
||||||
private static final long WAIT_TIME_CAMERA_TEST = 3 * 1000; // 3 seconds
|
private static final long WAIT_TIME_CAMERA_TEST = 3 * 1000; // 3 seconds
|
||||||
private static final long WAIT_TIME_RECORDER_TEST = 6 * 1000; // 6 seconds
|
private static final long WAIT_TIME_RECORDER_TEST = 6 * 1000; // 6 seconds
|
||||||
private static final String OUTPUT_FILE = "/sdcard/temp";
|
|
||||||
private static final String OUTPUT_FILE_EXT = ".3gp";
|
private static final String OUTPUT_FILE_EXT = ".3gp";
|
||||||
private static final String MEDIA_STRESS_OUTPUT =
|
private static final String MEDIA_STRESS_OUTPUT = "mediaStressOutput.txt";
|
||||||
"/sdcard/mediaStressOutput.txt";
|
|
||||||
private static final int CAMERA_ID = 0;
|
|
||||||
|
|
||||||
private final CameraErrorCallback mCameraErrorCallback = new CameraErrorCallback();
|
private final CameraErrorCallback mCameraErrorCallback = new CameraErrorCallback();
|
||||||
private final RecorderErrorCallback mRecorderErrorCallback = new RecorderErrorCallback();
|
private final RecorderErrorCallback mRecorderErrorCallback = new RecorderErrorCallback();
|
||||||
|
|
||||||
private final static int WAIT_TIMEOUT = 10 * 1000; // 10 seconds
|
|
||||||
private Thread mLooperThread;
|
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
private Thread mLooperThread;
|
||||||
|
private Writer mOutput;
|
||||||
|
|
||||||
public MediaRecorderStressTest() {
|
public MediaRecorderStressTest() {
|
||||||
super("com.android.mediaframeworktest", MediaFrameworkTest.class);
|
super("com.android.mediaframeworktest", MediaFrameworkTest.class);
|
||||||
@@ -95,6 +96,11 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
getActivity();
|
getActivity();
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
|
File stressOutFile = new File(String.format("%s/%s",
|
||||||
|
Environment.getExternalStorageDirectory(), MEDIA_STRESS_OUTPUT));
|
||||||
|
mOutput = new BufferedWriter(new FileWriter(stressOutFile, true));
|
||||||
|
mOutput.write(this.getName() + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -110,7 +116,8 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
}
|
}
|
||||||
mLooperThread = null;
|
mLooperThread = null;
|
||||||
}
|
}
|
||||||
|
mOutput.write("\n\n");
|
||||||
|
mOutput.close();
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,16 +140,13 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
|
|
||||||
private final class CameraErrorCallback implements android.hardware.Camera.ErrorCallback {
|
private final class CameraErrorCallback implements android.hardware.Camera.ErrorCallback {
|
||||||
public void onError(int error, android.hardware.Camera camera) {
|
public void onError(int error, android.hardware.Camera camera) {
|
||||||
if (error == android.hardware.Camera.CAMERA_ERROR_SERVER_DIED) {
|
fail(String.format("Camera error, code: %d", error));
|
||||||
assertTrue("Camera test mediaserver died", false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class RecorderErrorCallback implements MediaRecorder.OnErrorListener {
|
private final class RecorderErrorCallback implements MediaRecorder.OnErrorListener {
|
||||||
public void onError(MediaRecorder mr, int what, int extra) {
|
public void onError(MediaRecorder mr, int what, int extra) {
|
||||||
// fail the test case no matter what error come up
|
fail(String.format("Media recorder error, code: %d\textra: %d", what, extra));
|
||||||
assertTrue("mediaRecorder error", false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,14 +155,11 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
public void testStressCamera() throws Exception {
|
public void testStressCamera() throws Exception {
|
||||||
SurfaceHolder mSurfaceHolder;
|
SurfaceHolder mSurfaceHolder;
|
||||||
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
|
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
|
||||||
File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
|
Log.v(TAG, "Camera start preview stress test");
|
||||||
Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
|
mOutput.write("Total number of loops:" + NUMBER_OF_CAMERA_STRESS_LOOPS + "\n");
|
||||||
output.write("Camera start preview stress:\n");
|
|
||||||
output.write("Total number of loops:" +
|
|
||||||
NUMBER_OF_CAMERA_STRESS_LOOPS + "\n");
|
|
||||||
try {
|
try {
|
||||||
Log.v(TAG, "Start preview");
|
Log.v(TAG, "Start preview");
|
||||||
output.write("No of loop: ");
|
mOutput.write("No of loop: ");
|
||||||
|
|
||||||
for (int i = 0; i< NUMBER_OF_CAMERA_STRESS_LOOPS; i++) {
|
for (int i = 0; i< NUMBER_OF_CAMERA_STRESS_LOOPS; i++) {
|
||||||
runOnLooper(new Runnable() {
|
runOnLooper(new Runnable() {
|
||||||
@@ -173,29 +174,27 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
Thread.sleep(WAIT_TIME_CAMERA_TEST);
|
Thread.sleep(WAIT_TIME_CAMERA_TEST);
|
||||||
mCamera.stopPreview();
|
mCamera.stopPreview();
|
||||||
mCamera.release();
|
mCamera.release();
|
||||||
output.write(" ," + i);
|
if (i == 0) {
|
||||||
|
mOutput.write(i + 1);
|
||||||
|
} else {
|
||||||
|
mOutput.write(String.format(", %d", (i + 1)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertTrue("CameraStressTest", false);
|
Log.e(TAG, e.toString());
|
||||||
Log.v(TAG, e.toString());
|
fail("Camera startup preview stress test");
|
||||||
}
|
}
|
||||||
output.write("\n\n");
|
|
||||||
output.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Test case for stressing the camera preview.
|
//Test case for stressing the camera preview.
|
||||||
@LargeTest
|
@LargeTest
|
||||||
public void testStressRecorder() throws Exception {
|
public void testStressRecorder() throws Exception {
|
||||||
String filename;
|
|
||||||
SurfaceHolder mSurfaceHolder;
|
SurfaceHolder mSurfaceHolder;
|
||||||
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
|
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
|
||||||
File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
|
Log.v(TAG, "H263 video record: reset after prepare Stress test");
|
||||||
Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
|
mOutput.write("Total number of loops:" + NUMBER_OF_RECORDER_STRESS_LOOPS + "\n");
|
||||||
output.write("H263 video record- reset after prepare Stress test\n");
|
|
||||||
output.write("Total number of loops:" +
|
|
||||||
NUMBER_OF_RECORDER_STRESS_LOOPS + "\n");
|
|
||||||
try {
|
try {
|
||||||
output.write("No of loop: ");
|
mOutput.write("No of loop: ");
|
||||||
Log.v(TAG, "Start preview");
|
Log.v(TAG, "Start preview");
|
||||||
for (int i = 0; i < NUMBER_OF_RECORDER_STRESS_LOOPS; i++) {
|
for (int i = 0; i < NUMBER_OF_RECORDER_STRESS_LOOPS; i++) {
|
||||||
runOnLooper(new Runnable() {
|
runOnLooper(new Runnable() {
|
||||||
@@ -205,12 +204,15 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
Log.v(TAG, "counter = " + i);
|
Log.v(TAG, "counter = " + i);
|
||||||
filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
|
String fileName = String.format("%s/temp%d%s",
|
||||||
Log.v(TAG, filename);
|
Environment.getExternalStorageDirectory(),
|
||||||
|
i, OUTPUT_FILE_EXT);
|
||||||
|
|
||||||
|
Log.v(TAG, fileName);
|
||||||
mRecorder.setOnErrorListener(mRecorderErrorCallback);
|
mRecorder.setOnErrorListener(mRecorderErrorCallback);
|
||||||
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
|
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
|
||||||
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
||||||
mRecorder.setOutputFile(filename);
|
mRecorder.setOutputFile(fileName);
|
||||||
mRecorder.setVideoFrameRate(MediaRecorderStressTestRunner.mFrameRate);
|
mRecorder.setVideoFrameRate(MediaRecorderStressTestRunner.mFrameRate);
|
||||||
mRecorder.setVideoSize(176,144);
|
mRecorder.setVideoSize(176,144);
|
||||||
Log.v(TAG, "setEncoder");
|
Log.v(TAG, "setEncoder");
|
||||||
@@ -224,30 +226,29 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
Thread.sleep(WAIT_TIME_RECORDER_TEST);
|
Thread.sleep(WAIT_TIME_RECORDER_TEST);
|
||||||
mRecorder.reset();
|
mRecorder.reset();
|
||||||
mRecorder.release();
|
mRecorder.release();
|
||||||
output.write(", " + i);
|
if (i == 0) {
|
||||||
|
mOutput.write(i + 1);
|
||||||
|
} else {
|
||||||
|
mOutput.write(String.format(", %d", (i + 1)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertTrue("Recorder Stress test", false);
|
Log.e(TAG, e.toString());
|
||||||
Log.v(TAG, e.toString());
|
fail("H263 video recording stress test");
|
||||||
}
|
}
|
||||||
output.write("\n\n");
|
|
||||||
output.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Stress test case for switching camera and video recorder preview.
|
//Stress test case for switching camera and video recorder preview.
|
||||||
@LargeTest
|
@LargeTest
|
||||||
public void testStressCameraSwitchRecorder() throws Exception {
|
public void testStressCameraSwitchRecorder() throws Exception {
|
||||||
String filename;
|
|
||||||
SurfaceHolder mSurfaceHolder;
|
SurfaceHolder mSurfaceHolder;
|
||||||
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
|
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
|
||||||
File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
|
Log.v(TAG, "Camera and video recorder preview switching");
|
||||||
Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
|
mOutput.write("Total number of loops: " +
|
||||||
output.write("Camera and video recorder preview switching\n");
|
NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER + "\n");
|
||||||
output.write("Total number of loops:"
|
|
||||||
+ NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER + "\n");
|
|
||||||
try {
|
try {
|
||||||
Log.v(TAG, "Start preview");
|
Log.v(TAG, "Start preview");
|
||||||
output.write("No of loop: ");
|
mOutput.write("No of loop: ");
|
||||||
for (int i = 0; i < NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER; i++) {
|
for (int i = 0; i < NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER; i++) {
|
||||||
runOnLooper(new Runnable() {
|
runOnLooper(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -263,8 +264,10 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
mCamera.release();
|
mCamera.release();
|
||||||
mCamera = null;
|
mCamera = null;
|
||||||
Log.v(TAG, "release camera");
|
Log.v(TAG, "release camera");
|
||||||
filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
|
String fileName = String.format("%s/temp%d%s",
|
||||||
Log.v(TAG, filename);
|
Environment.getExternalStorageDirectory(),
|
||||||
|
i, OUTPUT_FILE_EXT);
|
||||||
|
Log.v(TAG, fileName);
|
||||||
runOnLooper(new Runnable() {
|
runOnLooper(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -274,7 +277,7 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
mRecorder.setOnErrorListener(mRecorderErrorCallback);
|
mRecorder.setOnErrorListener(mRecorderErrorCallback);
|
||||||
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
|
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
|
||||||
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
||||||
mRecorder.setOutputFile(filename);
|
mRecorder.setOutputFile(fileName);
|
||||||
mRecorder.setVideoFrameRate(MediaRecorderStressTestRunner.mFrameRate);
|
mRecorder.setVideoFrameRate(MediaRecorderStressTestRunner.mFrameRate);
|
||||||
mRecorder.setVideoSize(176,144);
|
mRecorder.setVideoSize(176,144);
|
||||||
Log.v(TAG, "Media recorder setEncoder");
|
Log.v(TAG, "Media recorder setEncoder");
|
||||||
@@ -287,117 +290,167 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
Thread.sleep(WAIT_TIME_CAMERA_TEST);
|
Thread.sleep(WAIT_TIME_CAMERA_TEST);
|
||||||
mRecorder.release();
|
mRecorder.release();
|
||||||
Log.v(TAG, "release video recorder");
|
Log.v(TAG, "release video recorder");
|
||||||
output.write(", " + i);
|
if (i == 0) {
|
||||||
|
mOutput.write(i + 1);
|
||||||
|
} else {
|
||||||
|
mOutput.write(String.format(", %d", (i + 1)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertTrue("Camer and recorder switch mode", false);
|
Log.e(TAG, e.toString());
|
||||||
Log.v(TAG, e.toString());
|
fail("Camera and recorder switch mode");
|
||||||
}
|
}
|
||||||
output.write("\n\n");
|
|
||||||
output.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validateRecordedVideo(String recorded_file) {
|
public void validateRecordedVideo(String recordedFile) {
|
||||||
try {
|
try {
|
||||||
MediaPlayer mp = new MediaPlayer();
|
MediaPlayer mp = new MediaPlayer();
|
||||||
mp.setDataSource(recorded_file);
|
mp.setDataSource(recordedFile);
|
||||||
mp.prepare();
|
mp.prepare();
|
||||||
int duration = mp.getDuration();
|
int duration = mp.getDuration();
|
||||||
if (duration <= 0){
|
if (duration <= 0){
|
||||||
assertTrue("stressRecordAndPlayback", false);
|
fail("stressRecordAndPlayback");
|
||||||
}
|
}
|
||||||
mp.release();
|
mp.release();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertTrue("stressRecordAndPlayback", false);
|
fail("stressRecordAndPlayback");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRecordedVideo(String filename){
|
public void removeRecordedVideo(String fileName){
|
||||||
File video = new File(filename);
|
File video = new File(fileName);
|
||||||
Log.v(TAG, "remove recorded video " + filename);
|
Log.v(TAG, "remove recorded video " + fileName);
|
||||||
video.delete();
|
video.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Stress test case for record a video and play right away.
|
// Helper method for record & playback testing with different camcorder profiles
|
||||||
@LargeTest
|
private void recordVideoAndPlayback(int profile) throws Exception {
|
||||||
public void testStressRecordVideoAndPlayback() throws Exception {
|
int iterations;
|
||||||
int iterations = MediaRecorderStressTestRunner.mIterations;
|
int recordDuration;
|
||||||
int video_encoder = MediaRecorderStressTestRunner.mVideoEncoder;
|
boolean removeVideo;
|
||||||
int audio_encoder = MediaRecorderStressTestRunner.mAudioEncdoer;
|
|
||||||
int frame_rate = MediaRecorderStressTestRunner.mFrameRate;
|
int videoEncoder;
|
||||||
int video_width = MediaRecorderStressTestRunner.mVideoWidth;
|
int audioEncoder;
|
||||||
int video_height = MediaRecorderStressTestRunner.mVideoHeight;
|
int frameRate;
|
||||||
int bit_rate = MediaRecorderStressTestRunner.mBitRate;
|
int videoWidth;
|
||||||
boolean remove_video = MediaRecorderStressTestRunner.mRemoveVideo;
|
int videoHeight;
|
||||||
int record_duration = MediaRecorderStressTestRunner.mDuration;
|
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");
|
||||||
|
|
||||||
String filename;
|
|
||||||
SurfaceHolder mSurfaceHolder;
|
|
||||||
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
|
|
||||||
File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
|
|
||||||
Writer output = new BufferedWriter(
|
|
||||||
new FileWriter(stressOutFile, true));
|
|
||||||
output.write("Video record and play back stress test:\n");
|
|
||||||
output.write("Total number of loops:"
|
|
||||||
+ NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS + "\n");
|
|
||||||
try {
|
try {
|
||||||
output.write("No of loop: ");
|
mOutput.write("No of loop: ");
|
||||||
for (int i = 0; i < iterations; i++){
|
for (int i = 0; i < iterations; i++) {
|
||||||
filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
|
String fileName = String.format("%s/temp%d%s",
|
||||||
Log.v(TAG, filename);
|
Environment.getExternalStorageDirectory(), i, OUTPUT_FILE_EXT);
|
||||||
|
Log.v(TAG, fileName);
|
||||||
|
|
||||||
runOnLooper(new Runnable() {
|
runOnLooper(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mRecorder = new MediaRecorder();
|
mRecorder = new MediaRecorder();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Log.v(TAG, "iterations : " + iterations);
|
Log.v(TAG, "iterations : " + iterations);
|
||||||
Log.v(TAG, "video_encoder : " + video_encoder);
|
Log.v(TAG, "video encoder : " + videoEncoder);
|
||||||
Log.v(TAG, "audio_encoder : " + audio_encoder);
|
Log.v(TAG, "audio encoder : " + audioEncoder);
|
||||||
Log.v(TAG, "frame_rate : " + frame_rate);
|
Log.v(TAG, "frame rate : " + frameRate);
|
||||||
Log.v(TAG, "video_width : " + video_width);
|
Log.v(TAG, "video width : " + videoWidth);
|
||||||
Log.v(TAG, "video_height : " + video_height);
|
Log.v(TAG, "video height : " + videoHeight);
|
||||||
Log.v(TAG, "bit rate : " + bit_rate);
|
Log.v(TAG, "bit rate : " + bitRate);
|
||||||
Log.v(TAG, "record_duration : " + record_duration);
|
Log.v(TAG, "record duration : " + recordDuration);
|
||||||
|
|
||||||
mRecorder.setOnErrorListener(mRecorderErrorCallback);
|
mRecorder.setOnErrorListener(mRecorderErrorCallback);
|
||||||
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
|
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
|
||||||
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
||||||
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
||||||
mRecorder.setOutputFile(filename);
|
mRecorder.setOutputFile(fileName);
|
||||||
mRecorder.setVideoFrameRate(frame_rate);
|
mRecorder.setVideoFrameRate(frameRate);
|
||||||
mRecorder.setVideoSize(video_width, video_height);
|
mRecorder.setVideoSize(videoWidth, videoHeight);
|
||||||
mRecorder.setVideoEncoder(video_encoder);
|
mRecorder.setVideoEncoder(videoEncoder);
|
||||||
mRecorder.setAudioEncoder(audio_encoder);
|
mRecorder.setAudioEncoder(audioEncoder);
|
||||||
mRecorder.setVideoEncodingBitRate(bit_rate);
|
mRecorder.setVideoEncodingBitRate(bitRate);
|
||||||
|
|
||||||
Log.v(TAG, "mediaRecorder setPreview");
|
Log.v(TAG, "mediaRecorder setPreview");
|
||||||
mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
|
mRecorder.setPreviewDisplay(surfaceHolder.getSurface());
|
||||||
mRecorder.prepare();
|
mRecorder.prepare();
|
||||||
mRecorder.start();
|
mRecorder.start();
|
||||||
Thread.sleep(record_duration);
|
Thread.sleep(recordDuration);
|
||||||
Log.v(TAG, "Before stop");
|
Log.v(TAG, "Before stop");
|
||||||
mRecorder.stop();
|
mRecorder.stop();
|
||||||
mRecorder.release();
|
mRecorder.release();
|
||||||
|
|
||||||
//start the playback
|
//start the playback
|
||||||
MediaPlayer mp = new MediaPlayer();
|
MediaPlayer mp = new MediaPlayer();
|
||||||
mp.setDataSource(filename);
|
mp.setDataSource(fileName);
|
||||||
mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
|
mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
|
||||||
mp.prepare();
|
mp.prepare();
|
||||||
mp.start();
|
mp.start();
|
||||||
Thread.sleep(record_duration);
|
Thread.sleep(recordDuration);
|
||||||
mp.release();
|
mp.release();
|
||||||
validateRecordedVideo(filename);
|
validateRecordedVideo(fileName);
|
||||||
if (remove_video) {
|
if (removeVideo) {
|
||||||
removeRecordedVideo(filename);
|
removeRecordedVideo(fileName);
|
||||||
|
}
|
||||||
|
if (i == 0) {
|
||||||
|
mOutput.write(i + 1);
|
||||||
|
} else {
|
||||||
|
mOutput.write(String.format(", %d", (i + 1)));
|
||||||
}
|
}
|
||||||
output.write(", " + i);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.v(TAG, e.toString());
|
Log.e(TAG, e.toString());
|
||||||
assertTrue("record and playback", false);
|
fail("Record and playback");
|
||||||
}
|
}
|
||||||
output.write("\n\n");
|
}
|
||||||
output.close();
|
|
||||||
|
// Record and playback stress test @ 1080P quality
|
||||||
|
@LargeTest
|
||||||
|
public void testStressRecordVideoAndPlayback1080P() throws Exception {
|
||||||
|
recordVideoAndPlayback(CamcorderProfile.QUALITY_1080P);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Record and playback stress test @ 720P quality
|
||||||
|
@LargeTest
|
||||||
|
public void testStressRecordVideoAndPlayback720P() throws Exception {
|
||||||
|
recordVideoAndPlayback(CamcorderProfile.QUALITY_720P);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Record and playback stress test @ 480P quality
|
||||||
|
@LargeTest
|
||||||
|
public void testStressRecordVideoAndPlayback480P() throws Exception {
|
||||||
|
recordVideoAndPlayback(CamcorderProfile.QUALITY_480P);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test method uses the codec info from the test runner. Use this
|
||||||
|
// for more granular control of video encoding.
|
||||||
|
@LargeTest
|
||||||
|
public void defaultStressRecordVideoAndPlayback() throws Exception {
|
||||||
|
recordVideoAndPlayback(USE_TEST_RUNNER_PROFILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test case for stressing time lapse
|
// Test case for stressing time lapse
|
||||||
@@ -405,21 +458,19 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
public void testStressTimeLapse() throws Exception {
|
public void testStressTimeLapse() throws Exception {
|
||||||
SurfaceHolder mSurfaceHolder;
|
SurfaceHolder mSurfaceHolder;
|
||||||
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
|
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
|
||||||
int record_duration = MediaRecorderStressTestRunner.mTimeLapseDuration;
|
int recordDuration = MediaRecorderStressTestRunner.mTimeLapseDuration;
|
||||||
boolean remove_video = MediaRecorderStressTestRunner.mRemoveVideo;
|
boolean removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
|
||||||
double captureRate = MediaRecorderStressTestRunner.mCaptureRate;
|
double captureRate = MediaRecorderStressTestRunner.mCaptureRate;
|
||||||
String filename;
|
Log.v(TAG, "Start camera time lapse stress:");
|
||||||
File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
|
mOutput.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
|
||||||
Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
|
|
||||||
output.write("Start camera time lapse stress:\n");
|
|
||||||
output.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (int j = 0, n = Camera.getNumberOfCameras(); j < n; j++) {
|
for (int i = 0, n = Camera.getNumberOfCameras(); i < n; i++) {
|
||||||
output.write("No of loop: camera " + j);
|
mOutput.write("No of loop: camera " + i);
|
||||||
for (int i = 0; i < NUMBER_OF_TIME_LAPSE_LOOPS; i++) {
|
for (int j = 0; j < NUMBER_OF_TIME_LAPSE_LOOPS; j++) {
|
||||||
filename = OUTPUT_FILE + j + "_" + i + OUTPUT_FILE_EXT;
|
String fileName = String.format("%s/temp%d_%d%s",
|
||||||
Log.v(TAG, filename);
|
Environment.getExternalStorageDirectory(), i, j, OUTPUT_FILE_EXT);
|
||||||
|
Log.v(TAG, fileName);
|
||||||
runOnLooper(new Runnable() {
|
runOnLooper(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -438,12 +489,12 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
CamcorderProfile.get(j, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
|
CamcorderProfile.get(j, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
|
||||||
mRecorder.setProfile(profile);
|
mRecorder.setProfile(profile);
|
||||||
|
|
||||||
// Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc.
|
// 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
|
// http://developer.android.com/guide/topics/media/camera.html#time-lapse-video
|
||||||
mRecorder.setCaptureRate(captureRate);
|
mRecorder.setCaptureRate(captureRate);
|
||||||
|
|
||||||
// Set output file
|
// Set output file
|
||||||
mRecorder.setOutputFile(filename);
|
mRecorder.setOutputFile(fileName);
|
||||||
|
|
||||||
// Set the preview display
|
// Set the preview display
|
||||||
Log.v(TAG, "mediaRecorder setPreviewDisplay");
|
Log.v(TAG, "mediaRecorder setPreviewDisplay");
|
||||||
@@ -451,40 +502,40 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
|
|||||||
|
|
||||||
mRecorder.prepare();
|
mRecorder.prepare();
|
||||||
mRecorder.start();
|
mRecorder.start();
|
||||||
Thread.sleep(record_duration);
|
Thread.sleep(recordDuration);
|
||||||
Log.v(TAG, "Before stop");
|
Log.v(TAG, "Before stop");
|
||||||
mRecorder.stop();
|
mRecorder.stop();
|
||||||
mRecorder.release();
|
mRecorder.release();
|
||||||
|
|
||||||
// Start the playback
|
// Start the playback
|
||||||
MediaPlayer mp = new MediaPlayer();
|
MediaPlayer mp = new MediaPlayer();
|
||||||
mp.setDataSource(filename);
|
mp.setDataSource(fileName);
|
||||||
mp.setDisplay(mSurfaceHolder);
|
mp.setDisplay(mSurfaceHolder);
|
||||||
mp.prepare();
|
mp.prepare();
|
||||||
mp.start();
|
mp.start();
|
||||||
Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
|
Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
|
||||||
mp.release();
|
mp.release();
|
||||||
validateRecordedVideo(filename);
|
validateRecordedVideo(fileName);
|
||||||
if (remove_video) {
|
if (removeVideo) {
|
||||||
removeRecordedVideo(filename);
|
removeRecordedVideo(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j == 0) {
|
||||||
|
mOutput.write(j + 1);
|
||||||
|
} else {
|
||||||
|
mOutput.write(String.format(", %d", (j + 1)));
|
||||||
}
|
}
|
||||||
output.write(", " + i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} 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");
|
||||||
}
|
}
|
||||||
catch (IllegalStateException e) {
|
|
||||||
assertTrue("Camera time lapse stress test IllegalStateException", false);
|
|
||||||
Log.v(TAG, e.toString());
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
assertTrue("Camera time lapse stress test IOException", false);
|
|
||||||
Log.v(TAG, e.toString());
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
assertTrue("Camera time lapse stress test Exception", false);
|
|
||||||
Log.v(TAG, e.toString());
|
|
||||||
}
|
|
||||||
output.write("\n\n");
|
|
||||||
output.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user