1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.mediaframeworktest.stress; 18 19 import com.android.mediaframeworktest.MediaFrameworkTest; 20 21 import android.app.Activity; 22 import android.app.Instrumentation; 23 import android.content.Intent; 24 import android.hardware.Camera; 25 import android.media.MediaPlayer; 26 import android.media.MediaRecorder; 27 import android.test.ActivityInstrumentationTestCase2; 28 import android.test.suitebuilder.annotation.LargeTest; 29 import android.util.Log; 30 import android.view.SurfaceHolder; 31 32 import com.android.mediaframeworktest.MediaNames; 33 import com.android.mediaframeworktest.functional.CodecTest; 34 35 import java.io.BufferedWriter; 36 import java.io.File; 37 import java.io.FileWriter; 38 import java.io.Writer; 39 40 import android.test.AndroidTestCase; 41 import android.test.InstrumentationTestCase; 42 43 /** 44 * Junit / Instrumentation test case for the media player 45 */ 46 public class MediaPlayerStressTest extends InstrumentationTestCase { 47 private String TAG = "MediaPlayerStressTest"; 48 49 public MediaPlayerStressTest() { 50 } 51 52 protected void setUp() throws Exception { 53 super.setUp(); 54 } 55 56 private int mTotalPlaybackError = 0; 57 private int mTotalComplete = 0; 58 private int mTotalInfoUnknown = 0; 59 private int mTotalVideoTrackLagging = 0; 60 private int mTotalBadInterleaving = 0; 61 private int mTotalNotSeekable = 0; 62 private int mTotalMetaDataUpdate = 0; 63 64 private void writeTestOutput(String filename, Writer output) throws Exception{ 65 output.write("File Name: " + filename); 66 output.write(" Complete: " + CodecTest.onCompleteSuccess); 67 output.write(" Error: " + CodecTest.mPlaybackError); 68 output.write(" Unknown Info: " + CodecTest.mMediaInfoUnknownCount); 69 output.write(" Track Lagging: " + CodecTest.mMediaInfoVideoTrackLaggingCount); 70 output.write(" Bad Interleaving: " + CodecTest.mMediaInfoBadInterleavingCount); 71 output.write(" Not Seekable: " + CodecTest.mMediaInfoNotSeekableCount); 72 output.write(" Info Meta data update: " + CodecTest.mMediaInfoMetdataUpdateCount); 73 output.write("\n"); 74 } 75 76 private void writeTestSummary(Writer output) throws Exception{ 77 output.write("Total Result:\n"); 78 output.write("Total Complete: " + mTotalComplete + "\n"); 79 output.write("Total Error: " + mTotalPlaybackError + "\n"); 80 output.write("Total Unknown Info: " + mTotalInfoUnknown + "\n"); 81 output.write("Total Track Lagging: " + mTotalVideoTrackLagging + "\n" ); 82 output.write("Total Bad Interleaving: " + mTotalBadInterleaving + "\n"); 83 output.write("Total Not Seekable: " + mTotalNotSeekable + "\n"); 84 output.write("Total Info Meta data update: " + mTotalMetaDataUpdate + "\n"); 85 output.write("\n"); 86 } 87 88 private void updateTestResult(){ 89 if (CodecTest.onCompleteSuccess){ 90 mTotalComplete++; 91 } 92 else if (CodecTest.mPlaybackError){ 93 mTotalPlaybackError++; 94 } 95 mTotalInfoUnknown += CodecTest.mMediaInfoUnknownCount; 96 mTotalVideoTrackLagging += CodecTest.mMediaInfoVideoTrackLaggingCount; 97 mTotalBadInterleaving += CodecTest.mMediaInfoBadInterleavingCount; 98 mTotalNotSeekable += CodecTest.mMediaInfoNotSeekableCount; 99 mTotalMetaDataUpdate += CodecTest.mMediaInfoMetdataUpdateCount; 100 } 101 102 //Test that will start the playback for all the videos 103 //under the samples folder 104 @LargeTest 105 public void testVideoPlayback() throws Exception { 106 String fileWithError = "Filename:\n"; 107 File playbackOutput = new File("/sdcard/PlaybackTestResult.txt"); 108 Writer output = new BufferedWriter(new FileWriter(playbackOutput, true)); 109 110 boolean testResult = true; 111 // load directory files 112 boolean onCompleteSuccess = false; 113 File dir = new File(MediaNames.MEDIA_SAMPLE_POOL); 114 115 Instrumentation inst = getInstrumentation(); 116 Intent intent = new Intent(); 117 118 intent.setClass(getInstrumentation().getTargetContext(), MediaFrameworkTest.class); 119 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 120 121 String[] children = dir.list(); 122 if (children == null) { 123 Log.v("MediaPlayerApiTest:testMediaSamples", "dir is empty"); 124 return; 125 } else { 126 for (int i = 0; i < children.length; i++) { 127 Activity act = inst.startActivitySync(intent); 128 //Get filename of directory 129 String filename = children[i]; 130 onCompleteSuccess = 131 CodecTest.playMediaSamples(dir + "/" + filename); 132 if (!onCompleteSuccess){ 133 //Don't fail the test right away, print out the failure file. 134 fileWithError += filename + '\n'; 135 Log.v(TAG, "Failure File : " + fileWithError); 136 testResult = false; 137 } 138 Thread.sleep(3000); 139 //Call onCreat to recreate the surface 140 act.finish(); 141 //Write test result to an output file 142 writeTestOutput(filename,output); 143 //Get the summary 144 updateTestResult(); 145 } 146 writeTestSummary(output); 147 output.close(); 148 assertTrue("testMediaSamples", testResult); 149 } 150 } 151 }