summaryrefslogtreecommitdiffstats
path: root/media/tests
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 14:04:24 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 14:04:24 -0800
commit076357b8567458d4b6dfdcf839ef751634cd2bfb (patch)
treeefbb2fd6f1dc67d2d606382fc3b82983e7cb2e1f /media/tests
parent3dec7d563a2f3e1eb967ce2054a00b6620e3558c (diff)
downloadframeworks_base-076357b8567458d4b6dfdcf839ef751634cd2bfb.zip
frameworks_base-076357b8567458d4b6dfdcf839ef751634cd2bfb.tar.gz
frameworks_base-076357b8567458d4b6dfdcf839ef751634cd2bfb.tar.bz2
auto import from //depot/cupcake/@132589
Diffstat (limited to 'media/tests')
-rwxr-xr-xmedia/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java5
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java12
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java755
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java475
4 files changed, 153 insertions, 1094 deletions
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java
index 73688cc..453a165 100755
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java
@@ -47,9 +47,9 @@ public class MediaFrameworkTestRunner extends InstrumentationTestRunner {
suite.addTestSuite(MediaPlayerApiTest.class);
suite.addTestSuite(SimTonesTest.class);
suite.addTestSuite(MediaMetadataTest.class);
- suite.addTestSuite(CameraTest.class);
+ // suite.addTestSuite(CameraTest.class);
suite.addTestSuite(MediaRecorderTest.class);
- //suite.addTestSuite(MediaAudioTrackTest.class);
+ suite.addTestSuite(MediaAudioTrackTest.class);
return suite;
}
@@ -59,4 +59,3 @@ public class MediaFrameworkTestRunner extends InstrumentationTestRunner {
}
}
-
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java
index 59803f7..5981a13 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java
@@ -136,13 +136,11 @@ public class CameraTest extends ActivityInstrumentationTestCase<MediaFrameworkTe
//Implement the RawPictureCallback
private final class RawPictureCallback implements PictureCallback {
public void onPictureTaken(byte [] rawData, Camera camera) {
- // no support for raw data - success if we get the callback
- rawPictureCallbackResult = true;
- //if (rawData != null) {
- // rawPictureCallbackResult = true;
- //} else {
- // rawPictureCallbackResult = false;
- //}
+ if (rawData != null) {
+ rawPictureCallbackResult = true;
+ } else {
+ rawPictureCallbackResult = false;
+ }
Log.v(TAG, "RawPictureCallback callback");
}
};
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java
index 24edb65..b6a0848 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java
@@ -34,7 +34,7 @@ import android.test.suitebuilder.annotation.Suppress;
*/
public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> {
- private String TAG = "MediaAudioTrackTest";
+ private String TAG = "MediaAudioTrack";
public MediaAudioTrackTest() {
super("com.android.mediaframeworktest", MediaFrameworkTest.class);
@@ -50,18 +50,6 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
super.tearDown();
}
- private static void assumeTrue(String message, boolean cond) {
- assertTrue("(assume)"+message, cond);
- }
-
- private void log(String testName, String message) {
- Log.v(TAG, "["+testName+"] "+message);
- }
-
- private void loge(String testName, String message) {
- Log.e(TAG, "["+testName+"] "+message);
- }
-
//-----------------------------------------------------------------
// private class to hold test reslts
public class TestResults {
@@ -74,8 +62,7 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
// generic test methods
public TestResults constructorTestMultiSampleRate(
// parameters tested by this method
- int _inTest_streamType, int _inTest_mode,
- int _inTest_config, int _inTest_format,
+ int _inTest_streamType, int _inTest_mode, int _inTest_config,
// parameter-dependent expected results
int _expected_stateForMode) {
@@ -83,7 +70,7 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
String failedRates = "Failure for rate(s): ";
boolean localRes, finalRes = true;
- for (int i = 0 ; i < testSampleRates.length ; i++) {
+ for(int i = 0 ; i < testSampleRates.length ; i++) {
//Log.v("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] testing "+ testSampleRates[i]);
AudioTrack track = null;
try {
@@ -91,16 +78,15 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
_inTest_streamType,
testSampleRates[i],
_inTest_config,
- _inTest_format,
+ AudioFormat.ENCODING_PCM_16BIT,
AudioTrack.getMinBufferSize(testSampleRates[i],
- _inTest_config, _inTest_format),
+ _inTest_config, AudioFormat.ENCODING_PCM_16BIT),//testSampleRates[i]*4
_inTest_mode);
} catch(IllegalArgumentException iae) {
Log.e("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] exception at SR "
+ testSampleRates[i]+": \n" + iae);
- localRes = false;
}
- if (track != null) {
+ if(track != null) {
localRes = (track.getState() == _expected_stateForMode);
track.release();
}
@@ -112,11 +98,11 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
//log the error for the test runner
failedRates += Integer.toString(testSampleRates[i]) + "Hz ";
//log the error for logcat
- log("constructorTestMultiSampleRate", "failed to construct "
+ Log.e("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] failed to construct "
+"AudioTrack(streamType="+_inTest_streamType
+", sampleRateInHz=" + testSampleRates[i]
+", channelConfig=" + _inTest_config
- +", audioFormat=" + _inTest_format
+ +", audioFormat=AudioFormat.ENCODING_PCM_16BIT"
+", bufferSizeInBytes=" + AudioTrack.getMinBufferSize(testSampleRates[i],
_inTest_config, AudioFormat.ENCODING_PCM_16BIT)
+", mode="+ _inTest_mode );
@@ -132,16 +118,16 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
//----------------------------------
//-----------------------------------------------------------------
- // AudioTrack constructor and AudioTrack.getMinBufferSize(...) for 16bit PCM
+ // AudioTrack constructor and AudioTrack.getMinBufferSize(...)
//----------------------------------
//Test case 1: constructor for streaming AudioTrack, mono, 16bit at misc valid sample rates
- @LargeTest
+ @MediumTest
public void testConstructorMono16MusicStream() throws Exception {
TestResults res = constructorTestMultiSampleRate(
AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM,
- AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,
+ AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioTrack.STATE_INITIALIZED);
assertTrue("testConstructorMono16MusicStream: " + res.mResultLog, res.mResult);
@@ -149,12 +135,12 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
//Test case 2: constructor for streaming AudioTrack, stereo, 16bit at misc valid sample rates
- @LargeTest
+ @MediumTest
public void testConstructorStereo16MusicStream() throws Exception {
TestResults res = constructorTestMultiSampleRate(
AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM,
- AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT,
+ AudioFormat.CHANNEL_CONFIGURATION_STEREO,
AudioTrack.STATE_INITIALIZED);
assertTrue("testConstructorStereo16MusicStream: " + res.mResultLog, res.mResult);
@@ -162,12 +148,12 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
//Test case 3: constructor for static AudioTrack, mono, 16bit at misc valid sample rates
- @LargeTest
+ @MediumTest
public void testConstructorMono16MusicStatic() throws Exception {
TestResults res = constructorTestMultiSampleRate(
AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC,
- AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,
+ AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioTrack.STATE_NO_STATIC_DATA);
assertTrue("testConstructorMono16MusicStatic: " + res.mResultLog, res.mResult);
@@ -175,723 +161,16 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
//Test case 4: constructor for static AudioTrack, stereo, 16bit at misc valid sample rates
- @LargeTest
+ @MediumTest
public void testConstructorStereo16MusicStatic() throws Exception {
TestResults res = constructorTestMultiSampleRate(
AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC,
- AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT,
+ AudioFormat.CHANNEL_CONFIGURATION_STEREO,
AudioTrack.STATE_NO_STATIC_DATA);
assertTrue("testConstructorStereo16MusicStatic: " + res.mResultLog, res.mResult);
}
-
-
- //-----------------------------------------------------------------
- // AudioTrack constructor and AudioTrack.getMinBufferSize(...) for 8bit PCM
- //----------------------------------
-
- //Test case 1: constructor for streaming AudioTrack, mono, 8bit at misc valid sample rates
- @LargeTest
- public void testConstructorMono8MusicStream() throws Exception {
-
- TestResults res = constructorTestMultiSampleRate(
- AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM,
- AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT,
- AudioTrack.STATE_INITIALIZED);
-
- assertTrue("testConstructorMono8MusicStream: " + res.mResultLog, res.mResult);
- }
-
- //Test case 2: constructor for streaming AudioTrack, stereo, 8bit at misc valid sample rates
- @LargeTest
- public void testConstructorStereo8MusicStream() throws Exception {
-
- TestResults res = constructorTestMultiSampleRate(
- AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM,
- AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_8BIT,
- AudioTrack.STATE_INITIALIZED);
-
- assertTrue("testConstructorStereo8MusicStream: " + res.mResultLog, res.mResult);
- }
-
- //Test case 3: constructor for static AudioTrack, mono, 8bit at misc valid sample rates
- @LargeTest
- public void testConstructorMono8MusicStatic() throws Exception {
-
- TestResults res = constructorTestMultiSampleRate(
- AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC,
- AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT,
- AudioTrack.STATE_NO_STATIC_DATA);
-
- assertTrue("testConstructorMono8MusicStatic: " + res.mResultLog, res.mResult);
- }
-
- //Test case 4: constructor for static AudioTrack, stereo, 8bit at misc valid sample rates
- @LargeTest
- public void testConstructorStereo8MusicStatic() throws Exception {
-
- TestResults res = constructorTestMultiSampleRate(
- AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC,
- AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_8BIT,
- AudioTrack.STATE_NO_STATIC_DATA);
-
- assertTrue("testConstructorStereo8MusicStatic: " + res.mResultLog, res.mResult);
- }
-
-
- //-----------------------------------------------------------------
- // AudioTrack constructor for all stream types
- //----------------------------------
-
- //Test case 1: constructor for all stream types
- @LargeTest
- public void testConstructorStreamType() throws Exception {
- // constants for test
- final int TYPE_TEST_SR = 22050;
- final int TYPE_TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TYPE_TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TYPE_TEST_MODE = AudioTrack.MODE_STREAM;
- final int[] STREAM_TYPES = { AudioManager.STREAM_ALARM, AudioManager.STREAM_BLUETOOTH_SCO,
- AudioManager.STREAM_MUSIC, AudioManager.STREAM_NOTIFICATION,
- AudioManager.STREAM_RING, AudioManager.STREAM_SYSTEM,
- AudioManager.STREAM_VOICE_CALL };
- final String[] STREAM_NAMES = { "STREAM_ALARM", "STREAM_BLUETOOTH_SCO", "STREAM_MUSIC",
- "STREAM_NOTIFICATION", "STREAM_RING", "STREAM_SYSTEM", "STREAM_VOICE_CALL" };
-
- boolean localTestRes = true;
- AudioTrack track = null;
- // test: loop constructor on all stream types
- for (int i = 0 ; i < STREAM_TYPES.length ; i++)
- {
- try {
- //-------- initialization --------------
- track = new AudioTrack(STREAM_TYPES[i],
- TYPE_TEST_SR, TYPE_TEST_CONF, TYPE_TEST_FORMAT,
- AudioTrack.getMinBufferSize(TYPE_TEST_SR, TYPE_TEST_CONF, TYPE_TEST_FORMAT),
- TYPE_TEST_MODE);
- } catch (IllegalArgumentException iae) {
- loge("testConstructorStreamType", "exception for stream type "
- + STREAM_NAMES[i] + ": "+ iae);
- localTestRes = false;
- }
- //-------- test --------------
- if (track != null) {
- if (track.getState() != AudioTrack.STATE_INITIALIZED) {
- localTestRes = false;
- Log.e("MediaAudioTrackTest",
- "[ testConstructorStreamType ] failed for stream type "+STREAM_NAMES[i]);
- }
- //-------- tear down --------------
- track.release();
- }
- else {
- localTestRes = false;
- }
- }
- assertTrue("testConstructorStreamType", localTestRes);
- }
-
-
- //-----------------------------------------------------------------
- // Playback head position
- //----------------------------------
-
- //Test case 1: getPlaybackHeadPosition() at 0 after initialization
- @LargeTest
- public void testPlaybackHeadPositionAfterInit() throws Exception {
- // constants for test
- final String TEST_NAME = "testPlaybackHeadPositionAfterInit";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT), TEST_MODE);
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- assertTrue(TEST_NAME, track.getPlaybackHeadPosition() == 0);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 2: getPlaybackHeadPosition() increases after play()
- @LargeTest
- public void testPlaybackHeadPositionIncrease() throws Exception {
- // constants for test
- final String TEST_NAME = "testPlaybackHeadPositionIncrease";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize/2];
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- track.play();
- Thread.sleep(100);
- log(TEST_NAME, "position ="+ track.getPlaybackHeadPosition());
- assertTrue(TEST_NAME, track.getPlaybackHeadPosition() > 0);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 3: getPlaybackHeadPosition() is 0 after flush();
- @LargeTest
- public void testPlaybackHeadPositionAfterFlush() throws Exception {
- // constants for test
- final String TEST_NAME = "testPlaybackHeadPositionAfterFlush";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize/2];
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- track.play();
- Thread.sleep(100);
- track.stop();
- track.flush();
- log(TEST_NAME, "position ="+ track.getPlaybackHeadPosition());
- assertTrue(TEST_NAME, track.getPlaybackHeadPosition() == 0);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 3: getPlaybackHeadPosition() is 0 after stop();
- @LargeTest
- public void testPlaybackHeadPositionAfterStop() throws Exception {
- // constants for test
- final String TEST_NAME = "testPlaybackHeadPositionAfterStop";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize/2];
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- track.play();
- Thread.sleep(100);
- track.stop();
- Thread.sleep(100); // TODO: what is a sensible value?
- int pos = track.getPlaybackHeadPosition();
- log(TEST_NAME, "position ="+ pos);
- assertTrue(TEST_NAME, pos == 0);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 4: getPlaybackHeadPosition() is > 0 after play(); pause();
- @LargeTest
- public void testPlaybackHeadPositionAfterPause() throws Exception {
- // constants for test
- final String TEST_NAME = "testPlaybackHeadPositionAfterPause";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize/2];
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- track.play();
- Thread.sleep(100);
- track.pause();
- int pos = track.getPlaybackHeadPosition();
- log(TEST_NAME, "position ="+ pos);
- assertTrue(TEST_NAME, pos > 0);
- //-------- tear down --------------
- track.release();
- }
-
-
- //-----------------------------------------------------------------
- // Playback properties
- //----------------------------------
-
- //Test case 1: setStereoVolume() with max volume returns SUCCESS
- @LargeTest
- public void testSetStereoVolumeMax() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetStereoVolumeMax";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize/2];
- //-------- test --------------
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- track.play();
- float maxVol = AudioTrack.getMaxVolume();
- assertTrue(TEST_NAME, track.setStereoVolume(maxVol, maxVol) == AudioTrack.SUCCESS);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 2: setStereoVolume() with min volume returns SUCCESS
- @LargeTest
- public void testSetStereoVolumeMin() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetStereoVolumeMin";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize/2];
- //-------- test --------------
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- track.play();
- float minVol = AudioTrack.getMinVolume();
- assertTrue(TEST_NAME, track.setStereoVolume(minVol, minVol) == AudioTrack.SUCCESS);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 3: setStereoVolume() with mid volume returns SUCCESS
- @LargeTest
- public void testSetStereoVolumeMid() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetStereoVolumeMid";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize/2];
- //-------- test --------------
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- track.play();
- float midVol = (AudioTrack.getMaxVolume() - AudioTrack.getMinVolume()) / 2;
- assertTrue(TEST_NAME, track.setStereoVolume(midVol, midVol) == AudioTrack.SUCCESS);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 4: setPlaybackRate() with half the content rate returns SUCCESS
- @LargeTest
- public void testSetPlaybackRate() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetPlaybackRate";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize/2];
- //-------- test --------------
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- track.play();
- assertTrue(TEST_NAME, track.setPlaybackRate((int)(TEST_SR/2)) == AudioTrack.SUCCESS);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 5: setPlaybackRate(0) returns bad value error
- @LargeTest
- public void testSetPlaybackRateZero() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetPlaybackRateZero";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- assertTrue(TEST_NAME, track.setPlaybackRate(0) == AudioTrack.ERROR_BAD_VALUE);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 6: setPlaybackRate() accepts values twice the output sample rate
- @LargeTest
- public void testSetPlaybackRateTwiceOutputSR() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetPlaybackRateTwiceOutputSR";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize/2];
- int outputSR = AudioTrack.getNativeOutputSampleRate(TEST_STREAM_TYPE);
- //-------- test --------------
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- track.play();
- assertTrue(TEST_NAME, track.setPlaybackRate(2*outputSR) == AudioTrack.SUCCESS);
- //-------- tear down --------------
- track.release();
- }
-/*
- //Test case 7: setPlaybackRate() clips values over twice the output sample rate
- @LargeTest
- public void testSetPlaybackRateClip() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetPlaybackRateClip";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize/2];
- int outputSR = AudioTrack.getNativeOutputSampleRate(TEST_STREAM_TYPE);
- //-------- test --------------
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- track.play();
- track.setPlaybackRate(3*outputSR);
- assertTrue(TEST_NAME, track.getSampleRate() == 2*outputSR);
- //-------- tear down --------------
- track.release();
- }
-*/
- //Test case 8: setPlaybackRate() invalid operation if track not initialized
- @LargeTest
- public void testSetPlaybackRateUninit() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetPlaybackRateUninit";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STATIC;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA);
- assertTrue(TEST_NAME, track.setPlaybackRate(TEST_SR/2) == AudioTrack.ERROR_INVALID_OPERATION);
- //-------- tear down --------------
- track.release();
- }
-
- //-----------------------------------------------------------------
- // Playback progress
- //----------------------------------
-
- //Test case 1: setPlaybackHeadPosition() on playing track
- @LargeTest
- public void testSetPlaybackHeadPositionPlaying() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetPlaybackHeadPositionPlaying";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- 2*minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize];
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- track.play();
- assertTrue(TEST_NAME,
- track.setPlaybackHeadPosition(10) == AudioTrack.ERROR_INVALID_OPERATION);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 2: setPlaybackHeadPosition() on stopped track
- @LargeTest
- public void testSetPlaybackHeadPositionStopped() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetPlaybackHeadPositionStopped";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- 2*minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize];
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- track.play();
- track.stop();
- assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_STOPPED);
- assertTrue(TEST_NAME, track.setPlaybackHeadPosition(10) == AudioTrack.SUCCESS);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 3: setPlaybackHeadPosition() on paused track
- @LargeTest
- public void testSetPlaybackHeadPositionPaused() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetPlaybackHeadPositionPaused";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- 2*minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize];
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- track.play();
- track.pause();
- assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_PAUSED);
- assertTrue(TEST_NAME, track.setPlaybackHeadPosition(10) == AudioTrack.SUCCESS);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 4: setPlaybackHeadPosition() beyond what has been written
- @LargeTest
- public void testSetPlaybackHeadPositionTooFar() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetPlaybackHeadPositionTooFar";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- 2*minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize];
- // make up a frame index that's beyond what has been written: go from buffer size to frame
- // count (given the audio track properties), and add 77.
- int frameIndexTooFar = (2*minBuffSize/2) + 77;
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- track.write(data, 0, data.length);
- track.write(data, 0, data.length);
- track.play();
- track.stop();
- assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_STOPPED);
- assertTrue(TEST_NAME, track.setPlaybackHeadPosition(frameIndexTooFar) == AudioTrack.ERROR_BAD_VALUE);
- //-------- tear down --------------
- track.release();
- }
-
-
- //Test case 5: setLoopPoints() fails for MODE_STREAM
- @LargeTest
- public void testSetLoopPointsStream() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetLoopPointsStream";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STREAM;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- 2*minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize];
- //-------- test --------------
- track.write(data, 0, data.length);
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- assertTrue(TEST_NAME, track.setLoopPoints(2, 50, 2) == AudioTrack.ERROR_INVALID_OPERATION);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 6: setLoopPoints() fails start > end
- @LargeTest
- public void testSetLoopPointsStartAfterEnd() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetLoopPointsStartAfterEnd";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STATIC;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize];
- //-------- test --------------
- track.write(data, 0, data.length);
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- assertTrue(TEST_NAME, track.setLoopPoints(50, 0, 2) == AudioTrack.ERROR_BAD_VALUE);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 6: setLoopPoints() success
- @LargeTest
- public void testSetLoopPointsSuccess() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetLoopPointsSuccess";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STATIC;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize];
- //-------- test --------------
- track.write(data, 0, data.length);
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- assertTrue(TEST_NAME, track.setLoopPoints(0, 50, 2) == AudioTrack.SUCCESS);
- //-------- tear down --------------
- track.release();
- }
-
- //Test case 7: setLoopPoints() fails with loop length bigger than content
- @LargeTest
- public void testSetLoopPointsLoopTooLong() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetLoopPointsLoopTooLong";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STATIC;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize];
- int dataSizeInFrames = minBuffSize/2;
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA);
- track.write(data, 0, data.length);
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- assertTrue(TEST_NAME,
- track.setLoopPoints(10, dataSizeInFrames+20, 2) == AudioTrack.ERROR_BAD_VALUE);
- //-------- tear down --------------
- track.release();
- }
-/*
- //Test case 7: setLoopPoints() fails with start beyond what can be written for the track
- @LargeTest
- public void testSetLoopPointsStartTooFar() throws Exception {
- // constants for test
- final String TEST_NAME = "testSetLoopPointsStartTooFar";
- final int TEST_SR = 22050;
- final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO;
- final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
- final int TEST_MODE = AudioTrack.MODE_STATIC;
- final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
-
- //-------- initialization --------------
- int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
- AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize];
- int dataSizeInFrames = minBuffSize/2;//16bit data
- //-------- test --------------
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA);
- track.write(data, 0, data.length);
- assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
- assertTrue(TEST_NAME,
- track.setLoopPoints(dataSizeInFrames+20, dataSizeInFrames+50, 2)
- == AudioTrack.ERROR_BAD_VALUE);
- //-------- tear down --------------
- track.release();
- }
-*/
-
}
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java
index 2f0173d..b606f25 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java
@@ -1,17 +1,17 @@
/*
* Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package com.android.mediaframeworktest.performance;
@@ -19,358 +19,141 @@ package com.android.mediaframeworktest.performance;
import com.android.mediaframeworktest.MediaFrameworkTest;
import com.android.mediaframeworktest.MediaNames;
+import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.media.MediaPlayer;
-import android.media.MediaRecorder;
import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.Suppress;
import android.util.Log;
-import android.view.SurfaceHolder;
import java.io.FileDescriptor;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Writer;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.BufferedWriter;
-
import android.media.MediaMetadataRetriever;
/**
- * Junit / Instrumentation - performance measurement for media player and
- * recorder
- */
-public class MediaPlayerPerformance extends ActivityInstrumentationTestCase<MediaFrameworkTest> {
-
- private String TAG = "MediaFrameworkPerformance";
-
- private SQLiteDatabase mDB;
- private SurfaceHolder mSurfaceHolder = null;
- private static final int NUM_STRESS_LOOP = 10;
- private static final int NUM_PLAYBACk_IN_EACH_LOOP = 20;
- private static final long MEDIA_STRESS_WAIT_TIME = 5000; //5 seconds
- private static final String H263_VIDEO_PLAYBACK_MEMOUT =
- "/sdcard/h263VideoPlaybackMemOut.txt";
- private static final String H264_VIDEO_PLAYBACK_MEMOUT =
- "/sdcard/h264VideoPlaybackMemOut.txt";
- private static final String WMV_VIDEO_PLAYBACK_MEMOUT =
- "/sdcard/WmvVideoPlaybackMemOut.txt";
- private static final String H263_VIDEO_ONLY_RECORD_MEMOUT =
- "/sdcard/recordH263VideoOnlyMemOut.txt";
- private static final String MP4_VIDEO_ONLY_RECORD_MEMOUT =
- "/sdcard/recordMPEG4VideoOnlyMemOut.txt";
- private static final String H263_VIDEO_AUDIO_RECORD_MEMOUT =
- "/sdcard/recordVideoH263AudioMemOut.txt";
- private static final String AUDIO_ONLY_RECORD_MEMOUT =
- "/sdcard/recordAudioOnlyMemOut.txt";
-
-
- public MediaPlayerPerformance() {
- super("com.android.mediaframeworktest", MediaFrameworkTest.class);
- }
+ * Junit / Instrumentation test case for the media player api
+
+ */
+public class MediaPlayerPerformance extends ActivityInstrumentationTestCase<MediaFrameworkTest> {
+
+
+ private boolean mIsPlaying = true;
+ private String TAG = "MediaPlayerApiTest";
+ Context mContext;
+ private SQLiteDatabase mDB;
+
+
+ public MediaPlayerPerformance() {
+ super("com.android.mediaframeworktest", MediaFrameworkTest.class);
+ }
protected void setUp() throws Exception {
- super.setUp();
- }
-
- public void createDB() {
- mDB = SQLiteDatabase.openOrCreateDatabase("/sdcard/perf.db", null);
- mDB.execSQL("CREATE TABLE perfdata (_id INTEGER PRIMARY KEY," +
- "file TEXT," + "setdatatime LONG," + "preparetime LONG," +
- "playtime LONG" + ");");
- }
-
- public void audioPlaybackStartupTime(String[] testFile) {
- long t1 = 0;
- long t2 = 0;
- long t3 = 0;
- long t4 = 0;
- long setDataSourceDuration = 0;
- long prepareDuration = 0;
- long startDuration = 0;
- long totalSetDataTime = 0;
- long totalPrepareTime = 0;
- long totalStartDuration = 0;
-
- int numberOfFiles = testFile.length;
- Log.v(TAG, "File length " + numberOfFiles);
- for (int k = 0; k < numberOfFiles; k++) {
- MediaPlayer mp = new MediaPlayer();
- try {
- t1 = SystemClock.uptimeMillis();
- FileInputStream fis = new FileInputStream(testFile[k]);
- FileDescriptor fd = fis.getFD();
- mp.setDataSource(fd);
- fis.close();
- t2 = SystemClock.uptimeMillis();
- mp.prepare();
- t3 = SystemClock.uptimeMillis();
- mp.start();
- t4 = SystemClock.uptimeMillis();
- } catch (Exception e) {
- Log.v(TAG, e.toString());
- }
- setDataSourceDuration = t2 - t1;
- prepareDuration = t3 - t2;
- startDuration = t4 - t3;
- totalSetDataTime = totalSetDataTime + setDataSourceDuration;
- totalPrepareTime = totalPrepareTime + prepareDuration;
- totalStartDuration = totalStartDuration + startDuration;
- mDB.execSQL("INSERT INTO perfdata (file, setdatatime, preparetime," +
- " playtime) VALUES (" + '"' + testFile[k] + '"' + ',' +
- setDataSourceDuration + ',' + prepareDuration +
- ',' + startDuration + ");");
- Log.v(TAG, "File name " + testFile[k]);
- mp.stop();
- mp.release();
- }
- Log.v(TAG, "setDataSource average " + totalSetDataTime / numberOfFiles);
- Log.v(TAG, "prepare average " + totalPrepareTime / numberOfFiles);
- Log.v(TAG, "start average " + totalStartDuration / numberOfFiles);
-
- }
-
- @Suppress
+
+ super.setUp();
+ }
+
+ public void createDB(){
+ mDB = SQLiteDatabase.openOrCreateDatabase("/sdcard/perf.db",null);
+ mDB.execSQL("CREATE TABLE perfdata (_id INTEGER PRIMARY KEY,"
+ + "file TEXT," + "setdatatime LONG," +"preparetime LONG," +"playtime LONG" + ");");
+ }
+
+ public void audioPlaybackStartupTime(String[] testFile){
+ long t1 = 0;
+ long t2 = 0;
+ long t3 = 0;
+ long t4 =0;
+
+ long setDataSourceDuration = 0;
+ long prepareDuration = 0;
+ long startDuration=0;
+
+ long totalSetDataTime=0;
+ long totalPrepareTime=0;
+ long totalStartDuration=0;
+
+ int numberOfFiles = testFile.length;
+ Log.v(TAG, "File lenght " + numberOfFiles);
+ for (int k=0; k<numberOfFiles; k++){
+ MediaPlayer mp = new MediaPlayer();
+ try{
+ t1 = SystemClock.uptimeMillis();
+ FileInputStream fis = new FileInputStream(testFile[k]);
+ FileDescriptor fd = fis.getFD();
+ mp.setDataSource(fd);
+ fis.close();
+ t2 = SystemClock.uptimeMillis();
+ mp.prepare();
+ t3 = SystemClock.uptimeMillis();
+ mp.start();
+ t4 = SystemClock.uptimeMillis();
+ Thread.sleep(10000);
+ mp.pause();
+ }catch (Exception e){}
+ setDataSourceDuration = t2 -t1;
+ prepareDuration = t3 - t2;
+ startDuration = t4 - t3;
+ totalSetDataTime = totalSetDataTime + setDataSourceDuration;
+ totalPrepareTime = totalPrepareTime + prepareDuration;
+ totalStartDuration = totalStartDuration + startDuration;
+ mDB.execSQL("INSERT INTO perfdata (file, setdatatime, preparetime, playtime) VALUES (" + '"' + testFile[k] + '"' +','
+ +setDataSourceDuration+ ',' + prepareDuration + ',' + startDuration +");");
+ Log.v(TAG,"File name " + testFile[k]);
+ mp.stop();
+ mp.release();
+ }
+ Log.v (TAG, "setDataSource average " + totalSetDataTime/numberOfFiles);
+ Log.v (TAG, "prepare average " + totalPrepareTime/numberOfFiles);
+ Log.v (TAG, "start average " + totalStartDuration/numberOfFiles);
+
+ }
+
+ //Test cases for GetCurrentPosition
+ @LargeTest
public void testStartUpTime() throws Exception {
- createDB();
- audioPlaybackStartupTime(MediaNames.MP3FILES);
- audioPlaybackStartupTime(MediaNames.AACFILES);
-
- }
-
- public void wmametadatautility(String[] testFile) {
- long t1 = 0;
- long t2 = 0;
- long sum = 0;
- long duration = 0;
- MediaMetadataRetriever retriever = new MediaMetadataRetriever();
- String value;
- for (int i = 0, n = testFile.length; i < n; ++i) {
- try {
- t1 = SystemClock.uptimeMillis();
- retriever.setDataSource(testFile[i]);
- value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
- value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
- value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER);
- value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);
- value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
- value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
- value =
- retriever
- .extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER);
- t2 = SystemClock.uptimeMillis();
- duration = t2 - t1;
- Log.v(TAG, "Time taken = " + duration);
- sum = sum + duration;
- } catch (Exception e) {
- Log.v(TAG, e.getMessage());
- }
-
- }
- Log.v(TAG, "Average duration = " + sum / testFile.length);
- }
-
-
- // Note: This test is to assume the mediaserver's pid is 34
- public void mediaStressPlayback(String testFilePath) {
- for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) {
- MediaPlayer mp = new MediaPlayer();
- try {
- mp.setDataSource(testFilePath);
- mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
- mp.prepare();
- mp.start();
- Thread.sleep(MEDIA_STRESS_WAIT_TIME);
- mp.release();
- } catch (Exception e) {
- mp.release();
- Log.v(TAG, e.toString());
- }
- }
- }
-
- // Note: This test is to assume the mediaserver's pid is 34
- private void stressVideoRecord(int frameRate, int width, int height, int videoFormat,
- int outFormat, String outFile, boolean videoOnly) {
- // Video recording
- for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) {
- MediaRecorder mRecorder = new MediaRecorder();
- try {
- if (!videoOnly) {
- Log.v(TAG, "setAudioSource");
- mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
- }
- mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
- mRecorder.setOutputFormat(outFormat);
- Log.v(TAG, "output format " + outFormat);
- mRecorder.setOutputFile(outFile);
- mRecorder.setVideoFrameRate(frameRate);
- mRecorder.setVideoSize(width, height);
- Log.v(TAG, "setEncoder");
- mRecorder.setVideoEncoder(videoFormat);
- if (!videoOnly) {
- mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
- }
- mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
- mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
- mRecorder.prepare();
- mRecorder.start();
- Thread.sleep(MEDIA_STRESS_WAIT_TIME);
- mRecorder.stop();
- mRecorder.release();
- } catch (Exception e) {
- Log.v("record video failed ", e.toString());
- mRecorder.release();
- }
- }
- }
-
- public void stressAudioRecord(String filePath) {
- // This test is only for the short media file
- for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) {
- MediaRecorder mRecorder = new MediaRecorder();
- try {
- mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
- mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
- mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
- mRecorder.setOutputFile(filePath);
- mRecorder.prepare();
- mRecorder.start();
- Thread.sleep(MEDIA_STRESS_WAIT_TIME);
- mRecorder.stop();
- mRecorder.release();
- } catch (Exception e) {
- Log.v(TAG, e.toString());
- mRecorder.release();
- }
- }
- }
-
- //Write the ps output to the file
- public void getMemoryWriteToLog(Writer output) {
- String cm = "ps mediaserver";
- String memoryUsage = null;
- int ch;
- try {
- Process p = Runtime.getRuntime().exec(cm);
- InputStream in = p.getInputStream();
- StringBuffer sb = new StringBuffer(512);
- while ((ch = in.read()) != -1) {
- sb.append((char) ch);
- }
- memoryUsage = sb.toString();
- } catch (IOException e) {
- Log.v(TAG, e.toString());
- }
-
- String[] poList = memoryUsage.split("\r|\n|\r\n");
- String memusage = poList[1].concat("\n");
- Log.v(TAG, memusage);
- try {
- //Write to file output
- output.write(memusage);
- } catch (Exception e) {
- e.toString();
- }
- }
-
-
+ createDB();
+ audioPlaybackStartupTime(MediaNames.MP3FILES);
+ audioPlaybackStartupTime(MediaNames.AACFILES);
+
+ }
+
+ public void wmametadatautility(String[] testFile){
+ long t1 = 0;
+ long t2 = 0;
+ long sum = 0;
+ long duration = 0;
+ MediaMetadataRetriever retriever = new MediaMetadataRetriever();
+ String value;
+ for(int i = 0, n = testFile.length; i < n; ++i) {
+ try {
+ t1 = SystemClock.uptimeMillis();
+ retriever.setDataSource(testFile[i]);
+ value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
+ value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
+ value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER);
+ value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);
+ value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
+ value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
+ value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER);
+ t2 = SystemClock.uptimeMillis();
+ duration = t2 - t1;
+ Log.v(TAG, "Time taken = " + duration);
+ sum=sum+duration;
+ }
+ catch (Exception e){Log.v(TAG, e.getMessage());}
+
+ }
+ Log.v(TAG, "Average duration = " + sum/testFile.length);
+ }
+
@Suppress
public void testWmaParseTime() throws Exception {
- // createDB();
- wmametadatautility(MediaNames.WMASUPPORTED);
- }
-
-
- // Test case 1: Capture the memory usage after every 20 h263 playback
- @LargeTest
- public void testH263VideoPlaybackMemoryUsage() throws Exception {
- File h263MemoryOut = new File(H263_VIDEO_PLAYBACK_MEMOUT);
- Writer output = new BufferedWriter(new FileWriter(h263MemoryOut));
- for (int i = 0; i < NUM_STRESS_LOOP; i++) {
- mediaStressPlayback(MediaNames.VIDEO_HIGHRES_H263);
- getMemoryWriteToLog(output);
- }
- output.close();
- }
-
- // Test case 2: Capture the memory usage after every 20 h264 playback
- @LargeTest
- public void testH264VideoPlaybackMemoryUsage() throws Exception {
- File h264MemoryOut = new File(H264_VIDEO_PLAYBACK_MEMOUT);
- Writer output = new BufferedWriter(new FileWriter(h264MemoryOut));
- for (int i = 0; i < NUM_STRESS_LOOP; i++) {
- mediaStressPlayback(MediaNames.VIDEO_H264_AMR);
- getMemoryWriteToLog(output);
- }
- output.close();
- }
-
- // Test case 3: Capture the memory usage after each 20 WMV playback
- @LargeTest
- public void testWMVVideoPlaybackMemoryUsage() throws Exception {
- File wmvMemoryOut = new File(WMV_VIDEO_PLAYBACK_MEMOUT);
- Writer output = new BufferedWriter(new FileWriter(wmvMemoryOut));
- for (int i = 0; i < NUM_STRESS_LOOP; i++) {
- mediaStressPlayback(MediaNames.VIDEO_WMV);
- getMemoryWriteToLog(output);
- }
- output.close();
- }
-
- // Test case 4: Capture the memory usage after every 20 video only recorded
- @LargeTest
- public void testH263RecordVideoOnlyMemoryUsage() throws Exception {
- File videoH263RecordOnlyMemoryOut = new File(H263_VIDEO_ONLY_RECORD_MEMOUT);
- Writer output = new BufferedWriter(new FileWriter(videoH263RecordOnlyMemoryOut));
- for (int i = 0; i < NUM_STRESS_LOOP; i++) {
- stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.H263,
- MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, true);
- getMemoryWriteToLog(output);
- }
- output.close();
- }
-
- // Test case 5: Capture the memory usage after every 20 video only recorded
- @LargeTest
- public void testMpeg4RecordVideoOnlyMemoryUsage() throws Exception {
- File videoMp4RecordOnlyMemoryOut = new File(MP4_VIDEO_ONLY_RECORD_MEMOUT);
- Writer output = new BufferedWriter(new FileWriter(videoMp4RecordOnlyMemoryOut));
- for (int i = 0; i < NUM_STRESS_LOOP; i++) {
- stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.MPEG_4_SP,
- MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, true);
- getMemoryWriteToLog(output);
- }
- output.close();
- }
-
- // Test case 6: Capture the memory usage after every 20 video and audio recorded
- @LargeTest
- public void testRecordVidedAudioMemoryUsage() throws Exception {
- File videoRecordAudioMemoryOut = new File(H263_VIDEO_AUDIO_RECORD_MEMOUT);
- Writer output = new BufferedWriter(new FileWriter(videoRecordAudioMemoryOut));
- for (int i = 0; i < NUM_STRESS_LOOP; i++) {
- stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.H263,
- MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, false);
- getMemoryWriteToLog(output);
- }
- output.close();
- }
-
- // Test case 7: Capture the memory usage after every 20 audio only recorded
- @LargeTest
- public void testRecordAudioOnlyMemoryUsage() throws Exception {
- File audioOnlyMemoryOut = new File(AUDIO_ONLY_RECORD_MEMOUT);
- Writer output = new BufferedWriter(new FileWriter(audioOnlyMemoryOut));
- for (int i = 0; i < NUM_STRESS_LOOP; i++) {
- stressAudioRecord(MediaNames.RECORDER_OUTPUT);
- getMemoryWriteToLog(output);
- }
- output.close();
+ // createDB();
+ wmametadatautility(MediaNames.WMASUPPORTED);
}
+
+
}
+