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 17package com.android.mediaframeworktest.stress; 18 19import com.android.mediaframeworktest.MediaFrameworkTest; 20 21import android.app.Activity; 22import android.app.Instrumentation; 23import android.content.Intent; 24import android.hardware.Camera; 25import android.media.MediaPlayer; 26import android.media.MediaRecorder; 27import android.os.Environment; 28import android.test.ActivityInstrumentationTestCase2; 29import android.test.suitebuilder.annotation.LargeTest; 30import android.util.Log; 31import android.view.SurfaceHolder; 32 33import com.android.mediaframeworktest.MediaNames; 34import com.android.mediaframeworktest.functional.CodecTest; 35 36import java.io.BufferedWriter; 37import java.io.File; 38import java.io.FileWriter; 39import java.io.Writer; 40 41import android.test.AndroidTestCase; 42import android.test.InstrumentationTestCase; 43 44/** 45 * Junit / Instrumentation test case for the media player 46 */ 47public class MediaPlayerStressTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> { 48 private String TAG = "MediaPlayerStressTest"; 49 50 public MediaPlayerStressTest() { 51 super("com.android.mediaframeworktest", MediaFrameworkTest.class); 52 } 53 54 protected void setUp() throws Exception { 55 //Insert a 2 second before launching the test activity. This is 56 //the workaround for the race condition of requesting the updated surface. 57 Thread.sleep(2000); 58 getActivity(); 59 super.setUp(); 60 } 61 62 private int mTotalPlaybackError = 0; 63 private int mTotalComplete = 0; 64 private int mTotalInfoUnknown = 0; 65 private int mTotalVideoTrackLagging = 0; 66 private int mTotalBadInterleaving = 0; 67 private int mTotalNotSeekable = 0; 68 private int mTotalMetaDataUpdate = 0; 69 70 //Test result output file 71 private static final String PLAYBACK_RESULT = "PlaybackTestResult.txt"; 72 73 private void writeTestOutput(String filename, Writer output) throws Exception{ 74 output.write("File Name: " + filename); 75 output.write(" Complete: " + CodecTest.onCompleteSuccess); 76 output.write(" Error: " + CodecTest.mPlaybackError); 77 output.write(" Unknown Info: " + CodecTest.mMediaInfoUnknownCount); 78 output.write(" Track Lagging: " + CodecTest.mMediaInfoVideoTrackLaggingCount); 79 output.write(" Bad Interleaving: " + CodecTest.mMediaInfoBadInterleavingCount); 80 output.write(" Not Seekable: " + CodecTest.mMediaInfoNotSeekableCount); 81 output.write(" Info Meta data update: " + CodecTest.mMediaInfoMetdataUpdateCount); 82 output.write("\n"); 83 } 84 85 private void writeTestSummary(Writer output) throws Exception{ 86 output.write("Total Result:\n"); 87 output.write("Total Complete: " + mTotalComplete + "\n"); 88 output.write("Total Error: " + mTotalPlaybackError + "\n"); 89 output.write("Total Unknown Info: " + mTotalInfoUnknown + "\n"); 90 output.write("Total Track Lagging: " + mTotalVideoTrackLagging + "\n" ); 91 output.write("Total Bad Interleaving: " + mTotalBadInterleaving + "\n"); 92 output.write("Total Not Seekable: " + mTotalNotSeekable + "\n"); 93 output.write("Total Info Meta data update: " + mTotalMetaDataUpdate + "\n"); 94 output.write("\n"); 95 } 96 97 private void updateTestResult(){ 98 if (CodecTest.onCompleteSuccess){ 99 mTotalComplete++; 100 } 101 else if (CodecTest.mPlaybackError){ 102 mTotalPlaybackError++; 103 } 104 mTotalInfoUnknown += CodecTest.mMediaInfoUnknownCount; 105 mTotalVideoTrackLagging += CodecTest.mMediaInfoVideoTrackLaggingCount; 106 mTotalBadInterleaving += CodecTest.mMediaInfoBadInterleavingCount; 107 mTotalNotSeekable += CodecTest.mMediaInfoNotSeekableCount; 108 mTotalMetaDataUpdate += CodecTest.mMediaInfoMetdataUpdateCount; 109 } 110 111 //Test that will start the playback for all the videos 112 //under the samples folder 113 @LargeTest 114 public void testVideoPlayback() throws Exception { 115 String fileWithError = "Filename:\n"; 116 File playbackOutput = new File(Environment.getExternalStorageDirectory(), PLAYBACK_RESULT); 117 Writer output = new BufferedWriter(new FileWriter(playbackOutput, true)); 118 119 boolean testResult = true; 120 // load directory files 121 boolean onCompleteSuccess = false; 122 File dir = new File(MediaNames.MEDIA_SAMPLE_POOL); 123 String[] children = dir.list(); 124 if (children == null) { 125 Log.v("MediaPlayerApiTest:testMediaSamples", "dir is empty"); 126 return; 127 } else { 128 for (int i = 0; i < children.length; i++) { 129 //Get filename of directory 130 String filename = children[i]; 131 onCompleteSuccess = 132 CodecTest.playMediaSamples(dir + "/" + filename); 133 if (!onCompleteSuccess){ 134 //Don't fail the test right away, print out the failure file. 135 fileWithError += filename + '\n'; 136 Log.v(TAG, "Failure File : " + fileWithError); 137 testResult = false; 138 } 139 Thread.sleep(3000); 140 //Write test result to an output file 141 writeTestOutput(filename,output); 142 //Get the summary 143 updateTestResult(); 144 } 145 writeTestSummary(output); 146 output.close(); 147 assertTrue("testMediaSamples", testResult); 148 } 149 } 150}