diff options
Diffstat (limited to 'media/tests')
6 files changed, 203 insertions, 147 deletions
diff --git a/media/tests/MediaFrameworkTest/AndroidManifest.xml b/media/tests/MediaFrameworkTest/AndroidManifest.xml index 2253eb2..c9d2628b 100644 --- a/media/tests/MediaFrameworkTest/AndroidManifest.xml +++ b/media/tests/MediaFrameworkTest/AndroidManifest.xml @@ -58,4 +58,9 @@ android:label="Media Power tests InstrumentationRunner"> </instrumentation> + <instrumentation android:name=".MediaPlayerStressTestRunner" + android:targetPackage="com.android.mediaframeworktest" + android:label="Media Power tests InstrumentationRunner"> + </instrumentation> + </manifest> diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaPlayerStressTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaPlayerStressTestRunner.java new file mode 100755 index 0000000..5438061 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaPlayerStressTestRunner.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011 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 + * + * 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. + */ + +package com.android.mediaframeworktest; + +import android.test.InstrumentationTestRunner; +import android.test.InstrumentationTestSuite; +import com.android.mediaframeworktest.stress.MediaPlayerStressTest; + +import junit.framework.TestSuite; + +public class MediaPlayerStressTestRunner extends InstrumentationTestRunner { + + @Override + public TestSuite getAllTests() { + TestSuite suite = new InstrumentationTestSuite(this); + suite.addTestSuite(MediaPlayerStressTest.class); + return suite; + } + + @Override + public ClassLoader getLoader() { + return MediaPlayerStressTestRunner.class.getClassLoader(); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java index 3e46e27..c15fbdb 100755 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java @@ -20,7 +20,6 @@ import android.media.MediaRecorder; import android.os.Bundle; import android.test.InstrumentationTestRunner; import android.test.InstrumentationTestSuite; -import com.android.mediaframeworktest.stress.MediaRecorderStressTest; import com.android.mediaframeworktest.stress.MediaPlayerStressTest; import junit.framework.TestSuite; @@ -42,7 +41,6 @@ public class MediaRecorderStressTestRunner extends InstrumentationTestRunner { public TestSuite getAllTests() { TestSuite suite = new InstrumentationTestSuite(this); suite.addTestSuite(MediaRecorderStressTest.class); - suite.addTestSuite(MediaPlayerStressTest.class); return suite; } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CodecTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CodecTest.java index 2eea206..cad7e53 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CodecTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CodecTest.java @@ -45,7 +45,7 @@ import java.util.Random; */ public class CodecTest { - private static String TAG = "MediaPlayerApiTest"; + private static String TAG = "CodecTest"; private static MediaPlayer mMediaPlayer; private MediaPlayer.OnPreparedListener mOnPreparedListener; @@ -58,7 +58,13 @@ public class CodecTest { private static final Object videoSizeChanged = new Object(); private static final Object onCompletion = new Object(); private static boolean onPrepareSuccess = false; - private static boolean onCompleteSuccess = false; + public static boolean onCompleteSuccess = false; + public static boolean mPlaybackError = false; + public static boolean mIsMediaInfoUnknown = false; + public static boolean mIsMediaInfoVideoTrackLagging = false; + public static boolean mIsMediaInfoBadInterleaving = false; + public static boolean mIsMediaInfoNotSeekable = false; + public static boolean mIsMediaInfoMetdataUpdate = false; public static String printCpuInfo(){ String cm = "dumpsys cpuinfo"; @@ -747,13 +753,52 @@ public class CodecTest { } }; + static MediaPlayer.OnErrorListener mOnErrorListener = new MediaPlayer.OnErrorListener() { + public boolean onError(MediaPlayer mp, int framework_err, int impl_err) { + mPlaybackError = true; + mp.reset(); + return true; + } + }; + + static MediaPlayer.OnInfoListener mInfoListener = new MediaPlayer.OnInfoListener() { + public boolean onInfo(MediaPlayer mp, int what, int extra) { + switch (what){ + case MediaPlayer.MEDIA_INFO_UNKNOWN: + mIsMediaInfoUnknown = true; + break; + case MediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING: + mIsMediaInfoVideoTrackLagging = true; + break; + case MediaPlayer.MEDIA_INFO_BAD_INTERLEAVING: + mIsMediaInfoBadInterleaving = true; + break; + case MediaPlayer.MEDIA_INFO_NOT_SEEKABLE: + mIsMediaInfoNotSeekable = true; + break; + case MediaPlayer.MEDIA_INFO_METADATA_UPDATE: + mIsMediaInfoMetdataUpdate = true; + break; + } + return true; + } + }; + // For each media file, forward twice and backward once, then play to the end public static boolean playMediaSamples(String filePath) throws Exception { int duration = 0; int curPosition = 0; int nextPosition = 0; int waittime = 0; - Random r = new Random(); + onCompleteSuccess = false; + mIsMediaInfoUnknown = false; + mIsMediaInfoVideoTrackLagging = false; + mIsMediaInfoBadInterleaving = false; + mIsMediaInfoNotSeekable = false; + mIsMediaInfoMetdataUpdate = false; + mPlaybackError = false; + String testResult; + initializeMessageLooper(); synchronized (lock) { try { @@ -765,37 +810,18 @@ public class CodecTest { } try { mMediaPlayer.setOnCompletionListener(mCompletionListener); + mMediaPlayer.setOnErrorListener(mOnErrorListener); Log.v(TAG, "playMediaSamples: sample file name " + filePath); mMediaPlayer.setDataSource(filePath); mMediaPlayer.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder()); mMediaPlayer.prepare(); duration = mMediaPlayer.getDuration(); - Log.v(TAG, "playMediaSamples: duration = " + duration); // start to play mMediaPlayer.start(); - // randomly play for time within (0, duration/3) - Thread.sleep(r.nextInt(duration/3)); - mMediaPlayer.pause(); - Log.v(TAG, "playMediaSamples: current position after pause: " - + mMediaPlayer.getCurrentPosition()); - // seek to position (0, 2/3*duration) - nextPosition = mMediaPlayer.getCurrentPosition() + r.nextInt(duration/3); - mMediaPlayer.seekTo(nextPosition); - Log.v(TAG, "playMediaSamples: current position after the first seek:" - + mMediaPlayer.getCurrentPosition()); - // play for another short time - mMediaPlayer.start(); - Thread.sleep(r.nextInt(duration/6)); - Log.v(TAG, "playMediaSamples: position after the second play:" - + mMediaPlayer.getCurrentPosition()); - // seek to a random position (0, duration) - mMediaPlayer.seekTo(r.nextInt(duration)); - Log.v(TAG, "playMediaSamples: current position after the second seek:" - + mMediaPlayer.getCurrentPosition()); waittime = duration - mMediaPlayer.getCurrentPosition(); synchronized(onCompletion){ try { - onCompletion.wait(waittime + 30000); + onCompletion.wait(waittime + 2000); }catch (Exception e) { Log.v(TAG, "playMediaSamples are interrupted"); return false; diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java index 64ffa4e..d22025c 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java @@ -483,29 +483,4 @@ public class MediaPlayerApiTest extends ActivityInstrumentationTestCase<MediaFra CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, true); assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess); } - - //Provide a tool to play all kinds of media files in a directory - @Suppress - @LargeTest - public void testMediaSamples() throws Exception { - // load directory files - boolean onCompleteSuccess = false; - File dir = new File(MediaNames.MEDIA_SAMPLE_POOL); - String[] children = dir.list(); - if (children == null) { - Log.v("MediaPlayerApiTest:testMediaSamples", "dir is empty"); - return; - } else { - for (int i = 0; i < children.length; i++) { - //Get filename of directory - String filename = children[i]; - Log.v("MediaPlayerApiTest", - "testMediaSamples: file to be played: " - + dir + "/" + filename); - onCompleteSuccess = - CodecTest.playMediaSamples(dir + "/" + filename); - assertTrue("testMediaSamples", onCompleteSuccess); - } - } - } } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaPlayerStressTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaPlayerStressTest.java index 95b7386..b694d16 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaPlayerStressTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaPlayerStressTest.java @@ -18,6 +18,9 @@ package com.android.mediaframeworktest.stress; import com.android.mediaframeworktest.MediaFrameworkTest; +import android.app.Activity; +import android.app.Instrumentation; +import android.content.Intent; import android.hardware.Camera; import android.media.MediaPlayer; import android.media.MediaRecorder; @@ -27,121 +30,132 @@ import android.util.Log; import android.view.SurfaceHolder; import com.android.mediaframeworktest.MediaNames; +import com.android.mediaframeworktest.functional.CodecTest; -import java.util.Random; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.Writer; + +import android.test.AndroidTestCase; +import android.test.InstrumentationTestCase; /** * Junit / Instrumentation test case for the media player */ -public class MediaPlayerStressTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> { +public class MediaPlayerStressTest extends InstrumentationTestCase { private String TAG = "MediaPlayerStressTest"; - private MediaRecorder mRecorder; - private Camera mCamera; - - private static final int NUMBER_OF_RANDOM_REPOSITION_AND_PLAY = 10; - private static final int NUMBER_OF_RANDOM_REPOSITION_AND_PLAY_SHORT = 5; - private static final int NUMBER_OF_STRESS_LOOPS = 500; - private static final int PLAYBACK_END_TOLERANCE = 30000; - private static final int WAIT_UNTIL_PLAYBACK_FINISH = 515000 ; public MediaPlayerStressTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); } protected void setUp() throws Exception { - getActivity(); super.setUp(); } - @LargeTest - public void testStressHWDecoderRelease() throws Exception { - SurfaceHolder mSurfaceHolder; - long randomseed = System.currentTimeMillis(); - Random generator = new Random(randomseed); - Log.v(TAG, "Random seed: " + randomseed); - int video_duration = MediaNames.STREAM_H264_480_360_1411k_DURATION; - int random_play_time; - - mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); - try { - //assertTrue(MediaFrameworkTest.checkStreamingServer()); - for (int i = 0; i < NUMBER_OF_STRESS_LOOPS; i++) { - MediaPlayer mp = new MediaPlayer(); - mp.setDataSource(MediaNames.STREAM_H264_480_360_1411k); - mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder()); - mp.prepare(); - mp.start(); - // seek and play - for (int j = 0; j < generator.nextInt(10); j++) { - random_play_time = - generator.nextInt(MediaNames.STREAM_H264_480_360_1411k_DURATION / 2); - Log.v(TAG, "Play time = " + random_play_time); - Thread.sleep(random_play_time); - int seek_time = MediaNames.STREAM_H264_480_360_1411k_DURATION / 2; - Log.v(TAG, "Seek time = " + seek_time); - mp.seekTo(seek_time); - } - mp.release(); - } + private int mTotalPlaybackError = 0; + private int mTotalComplete = 0; + private int mTotalInfoUnknown = 0; + private int mTotalVideoTrackLagging = 0; + private int mTotalBadInterleaving = 0; + private int mTotalNotSeekable = 0; + private int mTotalMetaDataUpdate = 0; + + private void writeTestOutput(String filename, Writer output) throws Exception{ + output.write("File Name: " + filename); + output.write(" Complete: " + CodecTest.onCompleteSuccess); + output.write(" Error: " + CodecTest.mPlaybackError); + output.write(" Unknown Info: " + CodecTest.mIsMediaInfoUnknown); + output.write(" Track Lagging: " + CodecTest.mIsMediaInfoVideoTrackLagging); + output.write(" BadInterleaving: " + CodecTest.mIsMediaInfoBadInterleaving); + output.write(" Not Seekable: " + CodecTest.mIsMediaInfoNotSeekable); + output.write(" Info Meta data update: " + CodecTest.mIsMediaInfoMetdataUpdate); + output.write("\n"); + } + + private void writeTestSummary(Writer output) throws Exception{ + output.write("Total Result:\n"); + output.write(" Complete: " + mTotalComplete); + output.write(" Error: " + mTotalPlaybackError); + output.write(" Unknown Info: " + mTotalInfoUnknown); + output.write(" Track Lagging: " + mTotalVideoTrackLagging ); + output.write(" BadInterleaving: " + mTotalBadInterleaving); + output.write(" Not Seekable: " + mTotalNotSeekable); + output.write(" Info Meta data update: " + mTotalMetaDataUpdate); + output.write("\n"); + } - } catch (Exception e) { - Log.v(TAG, e.toString()); - assertTrue("testStressHWDecoderRelease", false); + private void updateTestResult(){ + if (CodecTest.onCompleteSuccess){ + mTotalComplete++; + } + else if (CodecTest.mPlaybackError){ + mTotalPlaybackError++; + } + else if (CodecTest.mIsMediaInfoUnknown){ + mTotalInfoUnknown++; + } + else if (CodecTest.mIsMediaInfoVideoTrackLagging){ + mTotalVideoTrackLagging++; + } + else if (CodecTest.mIsMediaInfoBadInterleaving){ + mTotalBadInterleaving++; + } + else if (CodecTest.mIsMediaInfoNotSeekable){ + mTotalNotSeekable++; + } + else if (CodecTest.mIsMediaInfoMetdataUpdate){ + mTotalMetaDataUpdate++; } } + //Test that will start the playback for all the videos + //under the samples folder @LargeTest - public void testStressGetCurrentPosition() throws Exception { - SurfaceHolder mSurfaceHolder; - long randomseed = System.currentTimeMillis(); - Random generator = new Random(randomseed); - Log.v(TAG, "Random seed: " + randomseed); - int video_duration = MediaNames.VIDEO_H263_AMR_DURATION; - int random_play_time = 0; - int random_seek_time = 0; - int random_no_of_seek = 0; - - mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); - try { - for (int i = 0; i < NUMBER_OF_STRESS_LOOPS; i++) { - MediaPlayer mp = new MediaPlayer(); - mp.setDataSource(MediaNames.VIDEO_H263_AMR); - mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder()); - mp.prepare(); - mp.start(); - random_no_of_seek = generator.nextInt(10); - // make sure the seek at least run once. - if (random_no_of_seek == 0) { - random_no_of_seek = 1; - } - Log.v(TAG, "random_seek = " + random_no_of_seek); - // Play for 10 seconds then random seekTo - for (int j = 0; j < random_no_of_seek; j++) { - random_play_time = - generator.nextInt(video_duration / 100); - Log.v(TAG, "Play time = " + random_play_time); - Thread.sleep(random_play_time); - random_seek_time = - generator.nextInt(video_duration / 2); - Log.v(TAG, "Seek time = " + random_seek_time); - mp.seekTo(random_seek_time); + public void testVideoPlayback() throws Exception { + String fileWithError = "Filename:\n"; + File playbackOutput = new File("/sdcard/PlaybackTestResult.txt"); + Writer output = new BufferedWriter(new FileWriter(playbackOutput, true)); + + boolean testResult = true; + // load directory files + boolean onCompleteSuccess = false; + File dir = new File(MediaNames.MEDIA_SAMPLE_POOL); + + Instrumentation inst = getInstrumentation(); + Intent intent = new Intent(); + + intent.setClass(getInstrumentation().getTargetContext(), MediaFrameworkTest.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + String[] children = dir.list(); + if (children == null) { + Log.v("MediaPlayerApiTest:testMediaSamples", "dir is empty"); + return; + } else { + for (int i = 0; i < children.length; i++) { + Activity act = inst.startActivitySync(intent); + //Get filename of directory + String filename = children[i]; + onCompleteSuccess = + CodecTest.playMediaSamples(dir + "/" + filename); + if (!onCompleteSuccess){ + //Don't fail the test right away, print out the failure file. + fileWithError += filename + '\n'; + Log.v(TAG, "Failure File : " + fileWithError); + testResult = false; } - //Seek to 10s from the end of the video - mp.seekTo(video_duration - 10000); - //After reposition, play 30 seconds the video should be finished. - Thread.sleep(PLAYBACK_END_TOLERANCE); - Log.v(TAG, "CurrentPosition = " + mp.getCurrentPosition()); - if ( mp.isPlaying() || mp.getCurrentPosition() - > (video_duration)){ - assertTrue("Current PlayTime greater than duration", false); - } - mp.release(); + Thread.sleep(3000); + //Call onCreat to recreate the surface + act.finish(); + //Write test result to an output file + writeTestOutput(filename,output); + //Get the summary + updateTestResult(); } - - } catch (Exception e) { - Log.v(TAG, e.toString()); - assertTrue("testStressGetCurrentPosition", false); - } + writeTestSummary(output); + output.close(); + assertTrue("testMediaSamples", testResult); + } } -} - +}
\ No newline at end of file |