Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9cca1da6 authored by Yu Shan Emily Lau's avatar Yu Shan Emily Lau Committed by Android (Google) Code Review
Browse files

Merge "Remove the old media player stress test. Add the new playback stress...

Merge "Remove the old media player stress test. Add the new playback stress that which caputred the total number of crashes, frame drops from a list of video which side-loaded to the device."
parents 1fb7a75c a58389bd
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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>
+38 −0
Original line number Diff line number Diff line
/*
 * 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();
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -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;
    }

+50 −24
Original line number Diff line number Diff line
@@ -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;
+0 −25
Original line number Diff line number Diff line
@@ -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);
            }
       }
    }
}
Loading