Make the cts test record a bit longer
The initial delay of the recording increases from 700 ms to 1000 ms, due to the change
of some audio assets. As a result, recording 1000 ms may end up recording nothing; hence
the expected stop failure.
This patch increases the recording duration from 1 second to 3 seconds, and changed some
hardcoded values to use constants for easier maintence in the future.
o related-to-bug: 6971305
Change-Id: I9642087fad74c696ee5882c25892095ed89ac62f
diff --git a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
index f31f552..8b1c741 100644
--- a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
@@ -44,7 +44,10 @@
private final String OUTPUT_PATH;
private final String OUTPUT_PATH2;
private static final float TOLERANCE = 0.0002f;
- private static final int RECORD_TIME = 3000;
+ private static final int RECORD_TIME_MS = 3000;
+ private static final int RECORD_TIME_LAPSE_MS = 4000;
+ private static final int RECORD_TIME_LONG_MS = 20000;
+ private static final int RECORDED_DUR_TOLERANCE_MS = 1000;
private static final int THREE_MINUTES = 180000;
private static final int VIDEO_WIDTH = 176;
private static final int VIDEO_HEIGHT = 144;
@@ -165,7 +168,7 @@
mMediaRecorder.setPreviewDisplay(mActivity.getSurfaceHolder().getSurface());
mMediaRecorder.prepare();
mMediaRecorder.start();
- Thread.sleep(1000);
+ Thread.sleep(RECORD_TIME_MS);
mMediaRecorder.stop();
checkOutputExist();
}
@@ -181,7 +184,7 @@
private void recordVideoUsingCamera(boolean timelapse) throws Exception {
int nCamera = Camera.getNumberOfCameras();
- int durMs = timelapse? 4000: 1000;
+ int durMs = timelapse? RECORD_TIME_LAPSE_MS: RECORD_TIME_MS;
for (int cameraId = 0; cameraId < nCamera; cameraId++) {
mCamera = Camera.open(cameraId);
recordVideoUsingCamera(mCamera, OUTPUT_PATH, durMs, timelapse);
@@ -366,7 +369,7 @@
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.prepare();
mMediaRecorder.start();
- Thread.sleep(RECORD_TIME);
+ Thread.sleep(RECORD_TIME_MS);
assertTrue(mOnInfoCalled);
}
@@ -374,7 +377,7 @@
if (!hasMicrophone()) {
return;
}
- testSetMaxDuration(20000, 1000);
+ testSetMaxDuration(RECORD_TIME_LONG_MS, RECORDED_DUR_TOLERANCE_MS);
}
private void testSetMaxDuration(long durationMs, long toleranceMs) throws Exception {
@@ -461,7 +464,7 @@
mMediaRecorder.setMaxFileSize(maxFileSize);
mMediaRecorder.prepare();
mMediaRecorder.start();
- Thread.sleep(RECORD_TIME);
+ Thread.sleep(RECORD_TIME_MS);
mMediaRecorder.stop();
assertTrue(outFile.exists());