integrate media stress test : MediaPlay and MediaRecord only
- media files are copied manually before test
- one test class per each resolution and format
- support of format is checked for each test case, and not-supported format
  will be just passed.

Change-Id: I7828a27fdd7e9396cfbdf0c8cfe9c8e950d95316
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index ca2ad26..a30e6c3 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -58,6 +58,7 @@
 	CtsHoloTestCases \
 	CtsJniTestCases \
 	CtsLocationTestCases \
+	CtsMediaStressTestCases \
 	CtsMediaTestCases \
 	CtsNdefTestCases \
 	CtsNetTestCases \
diff --git a/tests/tests/mediastress/Android.mk b/tests/tests/mediastress/Android.mk
new file mode 100644
index 0000000..9ed59c5
--- /dev/null
+++ b/tests/tests/mediastress/Android.mk
@@ -0,0 +1,31 @@
+# Copyright (C) 2012 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.
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+# don't include this package in any target
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CtsMediaStressTestCases
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/mediastress/AndroidManifest.xml b/tests/tests/mediastress/AndroidManifest.xml
new file mode 100644
index 0000000..5a4569c
--- /dev/null
+++ b/tests/tests/mediastress/AndroidManifest.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        package="com.android.cts.mediastress">
+
+    <uses-permission android:name="android.permission.CAMERA" />
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
+    <uses-permission android:name="android.permission.RECORD_AUDIO" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+
+    <application>
+        <uses-library android:name="android.test.runner" />
+        <activity android:label="@string/app_name"
+                android:name="android.mediastress.cts.MediaFrameworkTest"
+                android:screenOrientation="landscape">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER"/>
+            </intent-filter>
+        </activity>
+    </application>
+    <instrumentation android:name="android.test.InstrumentationTestRunner"
+            android:targetPackage="com.android.cts.mediastress"
+            android:label="Media stress tests InstrumentationRunner" />
+
+</manifest>
diff --git a/tests/tests/mediastress/res/layout/surface_view.xml b/tests/tests/mediastress/res/layout/surface_view.xml
new file mode 100644
index 0000000..97f1dd4
--- /dev/null
+++ b/tests/tests/mediastress/res/layout/surface_view.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:orientation="vertical">
+
+    <FrameLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+        <SurfaceView
+                android:id="@+id/surface_view"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:layout_centerInParent="true" />
+
+        <ImageView android:id="@+id/overlay_layer"
+                android:layout_width="0dip"
+                android:layout_height="392dip"/>
+
+        <VideoView
+                android:id="@+id/video_view"
+                android:layout_width="320px"
+                android:layout_height="240px"  />
+
+    </FrameLayout>
+
+</LinearLayout>
diff --git a/tests/tests/mediastress/res/values/strings.xml b/tests/tests/mediastress/res/values/strings.xml
new file mode 100644
index 0000000..32c58e0
--- /dev/null
+++ b/tests/tests/mediastress/res/values/strings.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<resources>
+    <string name="app_name">MediaStressTest</string>
+    <string name="open_url">Open</string>
+</resources>
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/CodecTest.java b/tests/tests/mediastress/src/android/mediastress/cts/CodecTest.java
new file mode 100644
index 0000000..c349ac0
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/CodecTest.java
@@ -0,0 +1,817 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+import android.content.res.AssetFileDescriptor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.media.MediaMetadataRetriever;
+import android.media.MediaPlayer;
+import android.media.MediaRecorder;
+import android.os.Looper;
+import android.os.SystemClock;
+import android.util.Log;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Junit / Instrumentation test case for the media player api
+ */
+public class CodecTest {
+    private static String TAG = "CodecTest";
+    private static MediaPlayer mMediaPlayer;
+    private MediaPlayer.OnPreparedListener mOnPreparedListener;
+
+    private static int WAIT_FOR_COMMAND_TO_COMPLETE = 60000;  //1 min max.
+    private static boolean mInitialized = false;
+    private static boolean mPrepareReset = false;
+    private static Looper mLooper = null;
+    private static final Object mLock = new Object();
+    private static final Object mPrepareDone = new Object();
+    private static final Object mVideoSizeChanged = new Object();
+    private static final Object mOnCompletion = new Object();
+    private static boolean mOnPrepareSuccess = false;
+    private static final long PAUSE_WAIT_TIME = 3000;
+    private static final long WAIT_TIME = 2000;
+    private static final int SEEK_TIME = 10000;
+
+    public static boolean mOnCompleteSuccess = false;
+    public static boolean mPlaybackError = false;
+    public static int mMediaInfoUnknownCount = 0;
+    public static int mMediaInfoVideoTrackLaggingCount = 0;
+    public static int mMediaInfoBadInterleavingCount = 0;
+    public static int mMediaInfoNotSeekableCount = 0;
+    public static int mMediaInfoMetdataUpdateCount = 0;
+
+    public static String printCpuInfo() {
+        String cm = "dumpsys cpuinfo";
+        String cpuinfo = 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);
+            }
+            cpuinfo = sb.toString();
+        } catch (IOException e) {
+            Log.v(TAG, e.toString());
+        }
+        return cpuinfo;
+    }
+
+
+    public static int getDuration(String filePath) {
+        Log.v(TAG, "getDuration - " + filePath);
+        MediaPlayer mp = new MediaPlayer();
+        try {
+            mp.setDataSource(filePath);
+            mp.prepare();
+        } catch (Exception e) {
+            Log.v(TAG, e.toString());
+        }
+        int duration = mp.getDuration();
+        Log.v(TAG, "Duration " + duration);
+        mp.release();
+        Log.v(TAG, "release");
+        return duration;
+    }
+
+    public static boolean getCurrentPosition(String filePath) {
+        Log.v(TAG, "GetCurrentPosition - " + filePath);
+        int currentPosition = 0;
+        long t1=0;
+        long t2 =0;
+        MediaPlayer mp = new MediaPlayer();
+        try {
+            mp.setDataSource(filePath);
+            Log.v(TAG, "start playback");
+            mp.prepare();
+            mp.start();
+            t1=SystemClock.uptimeMillis();
+            Thread.sleep(10000);
+            mp.pause();
+            Thread.sleep(PAUSE_WAIT_TIME);
+            t2=SystemClock.uptimeMillis();
+        } catch (Exception e) {
+            Log.v(TAG, e.toString());
+        }
+        currentPosition = mp.getCurrentPosition();
+        mp.stop();
+        mp.release();
+        Log.v(TAG, "mp currentPositon = " + currentPosition + " play duration = " + (t2-t1));
+
+        if ((currentPosition < ((t2-t1) *1.2)) && (currentPosition > 0))
+            return true;
+        else
+            return false;
+    }
+
+    public static boolean seekTo(String filePath) {
+        Log.v(TAG, "seekTo " + filePath);
+        int currentPosition = 0;
+        MediaPlayer mp = new MediaPlayer();
+        try {
+            mp.setDataSource(filePath);
+            mp.prepare();
+            mp.start();
+            mp.seekTo(SEEK_TIME);
+            Thread.sleep(WAIT_TIME);
+            currentPosition = mp.getCurrentPosition();
+        } catch (Exception e) {
+            Log.v(TAG, e.getMessage());
+        }
+        mp.stop();
+        mp.release();
+        Log.v(TAG, "CurrentPosition = " + currentPosition);
+        //The currentposition should be at least greater than the 80% of seek time
+        if ((currentPosition > SEEK_TIME *0.8))
+            return true;
+        else
+            return false;
+    }
+
+    public static boolean setLooping(String filePath) {
+        int currentPosition = 0;
+        int duration = 0;
+        long t1 =0;
+        long t2 =0;
+        Log.v (TAG, "SetLooping - " + filePath);
+        MediaPlayer mp = new MediaPlayer();
+        try {
+            mp.setDataSource(filePath);
+            mp.prepare();
+            duration = mp.getDuration();
+            Log.v(TAG, "setLooping duration " + duration);
+            mp.setLooping(true);
+            mp.start();
+            Thread.sleep(5000);
+            mp.seekTo(duration - 5000);
+            t1=SystemClock.uptimeMillis();
+            Thread.sleep(20000);
+            t2=SystemClock.uptimeMillis();
+            Log.v(TAG, "pause");
+            //Bug# 1106852 - IllegalStateException will be thrown if pause is called
+            //in here
+            //mp.pause();
+            currentPosition = mp.getCurrentPosition();
+            Log.v(TAG, "looping position " + currentPosition + "duration = " + (t2-t1));
+        } catch (Exception e) {
+            Log.v(TAG, "Exception : " + e.toString());
+        }
+        mp.stop();
+        mp.release();
+        //The current position should be within 20% of the sleep time
+        //and should be greater than zero.
+        if ((currentPosition < ((t2-t1-5000)*1.2)) && currentPosition > 0)
+            return true;
+        else
+            return false;
+    }
+
+    public static boolean pause(String filePath) throws Exception {
+        Log.v(TAG, "pause - " + filePath);
+        boolean misPlaying = true;
+        boolean pauseResult = false;
+        long t1=0;
+        long t2=0;
+        MediaPlayer mp = new MediaPlayer();
+        mp.setDataSource(filePath);
+        mp.prepare();
+        int duration = mp.getDuration();
+        mp.start();
+        t1=SystemClock.uptimeMillis();
+        Thread.sleep(5000);
+        mp.pause();
+        Thread.sleep(PAUSE_WAIT_TIME);
+        t2=SystemClock.uptimeMillis();
+        misPlaying = mp.isPlaying();
+        int curPosition = mp.getCurrentPosition();
+        Log.v(TAG, filePath + " pause currentPositon " + curPosition);
+        Log.v(TAG, "isPlaying "+ misPlaying + " wait time " + (t2 - t1) );
+        String cpuinfo = printCpuInfo();
+        Log.v(TAG, cpuinfo);
+        if ((curPosition>0) && (curPosition < ((t2-t1) * 1.3)) && (misPlaying == false))
+            pauseResult = true;
+        mp.stop();
+        mp.release();
+        return pauseResult;
+    }
+
+    public static void prepareStopRelease(String filePath) throws Exception {
+        Log.v(TAG, "prepareStopRelease" + filePath);
+        MediaPlayer mp = new MediaPlayer();
+        mp.setDataSource(filePath);
+        mp.prepare();
+        mp.stop();
+        mp.release();
+    }
+
+    public static void preparePauseRelease(String filePath) throws Exception {
+        Log.v(TAG, "preparePauseRelease" + filePath);
+        MediaPlayer mp = new MediaPlayer();
+        mp.setDataSource(filePath);
+        mp.prepare();
+        mp.pause();
+        mp.release();
+    }
+
+    static MediaPlayer.OnVideoSizeChangedListener mOnVideoSizeChangedListener =
+        new MediaPlayer.OnVideoSizeChangedListener() {
+            public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
+                synchronized (mVideoSizeChanged) {
+                    Log.v(TAG, "sizechanged notification received ...");
+                    mVideoSizeChanged.notify();
+                }
+            }
+    };
+
+    //Register the videoSizeChanged listener
+    public static int videoHeight(String filePath) throws Exception {
+        Log.v(TAG, "videoHeight - " + filePath);
+        int videoHeight = 0;
+        synchronized (mLock) {
+            initializeMessageLooper();
+            try {
+                mLock.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
+            } catch(Exception e) {
+                Log.v(TAG, "looper was interrupted.");
+                return 0;
+            }
+        }
+        try {
+            mMediaPlayer.setDataSource(filePath);
+            mMediaPlayer.setDisplay(MediaFrameworkTest.getSurfaceView().getHolder());
+            mMediaPlayer.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener);
+            synchronized (mVideoSizeChanged) {
+                try {
+                    mMediaPlayer.prepare();
+                    mMediaPlayer.start();
+                    mVideoSizeChanged.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
+                } catch (Exception e) {
+                    Log.v(TAG, "wait was interrupted");
+                }
+            }
+            videoHeight = mMediaPlayer.getVideoHeight();
+            terminateMessageLooper();
+        } catch (Exception e) {
+            Log.e(TAG, e.getMessage());
+        }
+
+        return videoHeight;
+    }
+
+    //Register the videoSizeChanged listener
+    public static int videoWidth(String filePath) throws Exception {
+        Log.v(TAG, "videoWidth - " + filePath);
+        int videoWidth = 0;
+
+        synchronized (mLock) {
+            initializeMessageLooper();
+            try {
+                mLock.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
+            } catch(Exception e) {
+                Log.v(TAG, "looper was interrupted.");
+                return 0;
+            }
+        }
+        try {
+            mMediaPlayer.setDataSource(filePath);
+            mMediaPlayer.setDisplay(MediaFrameworkTest.getSurfaceView().getHolder());
+            mMediaPlayer.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener);
+            synchronized (mVideoSizeChanged) {
+                try {
+                    mMediaPlayer.prepare();
+                    mMediaPlayer.start();
+                    mVideoSizeChanged.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
+                } catch (Exception e) {
+                    Log.v(TAG, "wait was interrupted");
+                }
+            }
+            videoWidth = mMediaPlayer.getVideoWidth();
+            terminateMessageLooper();
+        } catch (Exception e) {
+            Log.e(TAG, e.getMessage());
+        }
+        return videoWidth;
+    }
+
+    //This also test the streaming video which may take a long
+    //time to start the playback.
+    public static boolean videoSeekTo(String filePath) throws Exception {
+        Log.v(TAG, "videoSeekTo - " + filePath);
+        int currentPosition = 0;
+        int duration = 0;
+        boolean videoResult = false;
+        MediaPlayer mp = new MediaPlayer();
+        mp.setDataSource(filePath);
+        mp.setDisplay(MediaFrameworkTest.getSurfaceView().getHolder());
+        mp.prepare();
+        mp.start();
+
+        Thread.sleep(5000);
+        duration = mp.getDuration();
+        Log.v(TAG, "video duration " + duration);
+        mp.pause();
+        Thread.sleep(PAUSE_WAIT_TIME);
+        mp.seekTo(duration - 20000 );
+        mp.start();
+        Thread.sleep(1000);
+        mp.pause();
+        Thread.sleep(PAUSE_WAIT_TIME);
+        mp.seekTo(duration/2);
+        mp.start();
+        Thread.sleep(10000);
+        currentPosition = mp.getCurrentPosition();
+        Log.v(TAG, "video currentPosition " + currentPosition);
+        mp.release();
+        if (currentPosition > (duration /2 )*0.9)
+            return true;
+        else
+            return false;
+
+    }
+
+    public static boolean seekToEnd(String filePath) {
+        Log.v(TAG, "seekToEnd - " + filePath);
+        int duration = 0;
+        int currentPosition = 0;
+        boolean isPlaying = false;
+        MediaPlayer mp = new MediaPlayer();
+        try {
+            mp.setDataSource(filePath);
+            Log.v(TAG, "start playback");
+            mp.prepare();
+            duration = mp.getDuration();
+            mp.seekTo(duration - 3000);
+            mp.start();
+            Thread.sleep(6000);
+        } catch (Exception e) {}
+        isPlaying = mp.isPlaying();
+        currentPosition = mp.getCurrentPosition();
+        Log.v(TAG, "seekToEnd currentPosition= " + currentPosition + " isPlaying = " + isPlaying);
+        mp.stop();
+        mp.release();
+        Log.v(TAG, "duration = " + duration);
+        if (currentPosition < 0.9 * duration || isPlaying)
+            return false;
+        else
+            return true;
+    }
+
+    public static boolean shortMediaStop(String filePath) {
+        Log.v(TAG, "shortMediaStop - " + filePath);
+        //This test is only for the short media file
+        int duration = 0;
+        int currentPosition = 0;
+        boolean isPlaying = false;
+        MediaPlayer mp = new MediaPlayer();
+        try {
+            mp.setDataSource(filePath);
+            Log.v(TAG, "start playback");
+            mp.prepare();
+            duration = mp.getDuration();
+            mp.start();
+            Thread.sleep(10000);
+        } catch (Exception e) {}
+        isPlaying = mp.isPlaying();
+        currentPosition = mp.getCurrentPosition();
+        Log.v(TAG, "seekToEnd currentPosition= " + currentPosition + " isPlaying = " + isPlaying);
+        mp.stop();
+        mp.release();
+        Log.v(TAG, "duration = " + duration);
+        if (currentPosition > duration || isPlaying)
+            return false;
+        else
+            return true;
+    }
+
+    public static boolean playToEnd(String filePath) {
+        Log.v(TAG, "shortMediaStop - " + filePath);
+        //This test is only for the short media file
+        int duration = 200000;
+        int updateDuration = 0;
+        int currentPosition = 0;
+        boolean isPlaying = false;
+        MediaPlayer mp = new MediaPlayer();
+        try {
+            Thread.sleep(5000);
+            mp.setDataSource(filePath);
+            Log.v(TAG, "start playback");
+            mp.prepare();
+            //duration = mp.getDuration();
+            mp.start();
+            Thread.sleep(50000);
+        } catch (Exception e){}
+        isPlaying = mp.isPlaying();
+        currentPosition = mp.getCurrentPosition();
+        //updateDuration = mp.getDuration();
+        Log.v(TAG, "seekToEnd currentPosition= " + currentPosition + " isPlaying = " + isPlaying);
+        mp.stop();
+        mp.release();
+        //Log.v(TAG, "duration = " + duration);
+        //Log.v(TAG, "Update duration = " + updateDuration);
+        if (currentPosition > duration || isPlaying)
+            return false;
+        else
+            return true;
+    }
+
+    public static boolean seektoBeforeStart(String filePath){
+        Log.v(TAG, "seektoBeforeStart - " + filePath);
+        //This test is only for the short media file
+        int duration = 0;
+        int currentPosition = 0;
+
+        MediaPlayer mp = new MediaPlayer();
+        try {
+            mp.setDataSource(filePath);
+            mp.prepare();
+            duration = mp.getDuration();
+            mp.seekTo(duration - 10000);
+            mp.start();
+            currentPosition=mp.getCurrentPosition();
+            mp.stop();
+            mp.release();
+        } catch (Exception e) {}
+        if (currentPosition < duration/2)
+            return false;
+        else
+            return true;
+    }
+
+    public static boolean mediaRecorderRecord(String filePath){
+        Log.v(TAG, "SoundRecording - " + filePath);
+        //This test is only for the short media file
+        int duration = 0;
+        try {
+            MediaRecorder mRecorder = new MediaRecorder();
+            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(500);
+            mRecorder.stop();
+            Log.v(TAG, "sound recorded");
+            mRecorder.release();
+        } catch (Exception e) {
+            Log.v(TAG, e.toString());
+        }
+
+        //Verify the recorded file
+        MediaPlayer mp = new MediaPlayer();
+        try {
+            mp.setDataSource(filePath);
+            mp.prepare();
+            duration = mp.getDuration();
+            Log.v(TAG,"Duration " + duration);
+            mp.release();
+        } catch (Exception e) {}
+        //Check the record media file length is greate than zero
+        if (duration > 0)
+            return true;
+        else
+            return false;
+
+    }
+
+    //Test for mediaMeta Data Thumbnail
+    public static boolean getThumbnail(String filePath, String goldenPath) {
+        Log.v(TAG, "getThumbnail - " + filePath);
+
+        int goldenHeight = 0;
+        int goldenWidth = 0;
+        int outputWidth = 0;
+        int outputHeight = 0;
+
+        //This test is only for the short media file
+        try {
+            BitmapFactory mBitmapFactory = new BitmapFactory();
+
+            MediaMetadataRetriever mMediaMetadataRetriever = new MediaMetadataRetriever();
+            try {
+                mMediaMetadataRetriever.setDataSource(filePath);
+            } catch(Exception e) {
+                e.printStackTrace();
+                return false;
+            }
+            Bitmap outThumbnail = mMediaMetadataRetriever.getFrameAtTime(-1);
+
+            //Verify the thumbnail
+            Bitmap goldenBitmap = mBitmapFactory.decodeFile(goldenPath);
+            outputWidth = outThumbnail.getWidth();
+            outputHeight = outThumbnail.getHeight();
+            goldenHeight = goldenBitmap.getHeight();
+            goldenWidth = goldenBitmap.getWidth();
+
+            //check the image dimension
+            if ((outputWidth != goldenWidth) || (outputHeight != goldenHeight))
+                return false;
+
+            // Check half line of pixel
+            int x = goldenHeight / 2;
+            for (int j = 1; j < goldenWidth / 2; j++) {
+                if (goldenBitmap.getPixel(x, j) != outThumbnail.getPixel(x, j)) {
+                    Log.v(TAG, "pixel = " + goldenBitmap.getPixel(x, j));
+                    return false;
+                }
+           }
+        } catch (Exception e) {
+            Log.v(TAG, e.toString());
+            return false;
+        }
+        return true;
+    }
+
+    //Load midi file from resources
+    public static boolean resourcesPlayback(AssetFileDescriptor afd, int expectedDuration) {
+        int duration = 0;
+        try {
+            MediaPlayer mp = new MediaPlayer();
+            mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
+            mp.prepare();
+            mp.start();
+            duration = mp.getDuration();
+            Thread.sleep(5000);
+            mp.release();
+        } catch (Exception e) {
+            Log.v(TAG,e.getMessage());
+        }
+        if (duration > expectedDuration)
+            return true;
+        else
+            return false;
+    }
+
+    public static boolean prepareAsyncReset(String filePath) {
+        //preparesAsync
+        try {
+            MediaPlayer mp = new MediaPlayer();
+            mp.setDataSource(filePath);
+            mp.prepareAsync();
+            mp.reset();
+            mp.release();
+        } catch (Exception e) {
+            Log.v(TAG,e.getMessage());
+            return false;
+        }
+        return true;
+    }
+
+
+    public static boolean isLooping(String filePath) {
+        MediaPlayer mp = null;
+
+        try {
+            mp = new MediaPlayer();
+            if (mp.isLooping()) {
+                Log.v(TAG, "MediaPlayer.isLooping() returned true after ctor");
+                return false;
+            }
+            mp.setDataSource(filePath);
+            mp.prepare();
+
+            mp.setLooping(true);
+            if (!mp.isLooping()) {
+                Log.v(TAG, "MediaPlayer.isLooping() returned false after setLooping(true)");
+                return false;
+            }
+
+            mp.setLooping(false);
+            if (mp.isLooping()) {
+                Log.v(TAG, "MediaPlayer.isLooping() returned true after setLooping(false)");
+                return false;
+            }
+        } catch (Exception e) {
+            Log.v(TAG, "Exception : " + e.toString());
+            return false;
+        } finally {
+            if (mp != null)
+                mp.release();
+        }
+
+        return true;
+    }
+
+    public static boolean isLoopingAfterReset(String filePath) {
+        MediaPlayer mp = null;
+        try {
+            mp = new MediaPlayer();
+            mp.setDataSource(filePath);
+            mp.prepare();
+
+            mp.setLooping(true);
+            mp.reset();
+            if (mp.isLooping()) {
+                Log.v(TAG, "MediaPlayer.isLooping() returned true after reset()");
+                return false;
+            }
+        } catch (Exception e){
+            Log.v(TAG, "Exception : " + e.toString());
+            return false;
+        } finally {
+            if (mp != null)
+                mp.release();
+        }
+
+        return true;
+    }
+
+    /*
+     * Initializes the message looper so that the mediaPlayer object can
+     * receive the callback messages.
+     */
+    private static void initializeMessageLooper() {
+        Log.v(TAG, "start looper");
+        new Thread() {
+            @Override
+            public void run() {
+                // Set up a looper to be used by camera.
+                Looper.prepare();
+                Log.v(TAG, "start loopRun");
+                // Save the looper so that we can terminate this thread
+                // after we are done with it.
+                mLooper = Looper.myLooper();
+                mMediaPlayer = new MediaPlayer();
+                synchronized (mLock) {
+                    mInitialized = true;
+                    mLock.notify();
+                }
+                Looper.loop();  // Blocks forever until Looper.quit() is called.
+                Log.v(TAG, "initializeMessageLooper: quit.");
+            }
+        }.start();
+    }
+
+    /*
+     * Terminates the message looper thread.
+     */
+    private static void terminateMessageLooper() {
+        mLooper.quit();
+        mMediaPlayer.release();
+    }
+
+    static MediaPlayer.OnPreparedListener mPreparedListener = new MediaPlayer.OnPreparedListener() {
+        public void onPrepared(MediaPlayer mp) {
+            synchronized (mPrepareDone) {
+                if(mPrepareReset) {
+                    Log.v(TAG, "call Reset");
+                    mMediaPlayer.reset();
+                }
+                Log.v(TAG, "notify the prepare callback");
+                mPrepareDone.notify();
+                mOnPrepareSuccess = true;
+            }
+        }
+    };
+
+    public static boolean prepareAsyncCallback(String filePath, boolean reset) throws Exception {
+        //Added the PrepareReset flag which allow us to switch to different
+        //test case.
+        if (reset) {
+            mPrepareReset = true;
+        }
+
+        synchronized (mLock) {
+            initializeMessageLooper();
+            try {
+                mLock.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
+            } catch(Exception e) {
+                Log.v(TAG, "looper was interrupted.");
+                return false;
+            }
+        }
+        try{
+            mMediaPlayer.setOnPreparedListener(mPreparedListener);
+            mMediaPlayer.setDataSource(filePath);
+            mMediaPlayer.setDisplay(MediaFrameworkTest.getSurfaceView().getHolder());
+            mMediaPlayer.prepareAsync();
+            synchronized (mPrepareDone) {
+                try {
+                    mPrepareDone.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
+                } catch (Exception e) {
+                    Log.v(TAG, "wait was interrupted.");
+                }
+            }
+            terminateMessageLooper();
+        }catch (Exception e) {
+            Log.v(TAG,e.getMessage());
+        }
+       return mOnPrepareSuccess;
+    }
+
+    static MediaPlayer.OnCompletionListener mCompletionListener = new MediaPlayer.OnCompletionListener() {
+        public void onCompletion(MediaPlayer mp) {
+            synchronized (mOnCompletion) {
+                Log.v(TAG, "notify the completion callback");
+                mOnCompletion.notify();
+                mOnCompleteSuccess = true;
+            }
+        }
+    };
+
+    static MediaPlayer.OnErrorListener mOnErrorListener = new MediaPlayer.OnErrorListener() {
+        public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
+            Log.v(TAG, "playback error");
+            mPlaybackError = true;
+            mp.reset();
+            synchronized (mOnCompletion) {
+                Log.v(TAG, "notify the completion callback");
+                mOnCompletion.notify();
+                mOnCompleteSuccess = false;
+            }
+            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:
+                    mMediaInfoUnknownCount++;
+                    break;
+                case MediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING:
+                    mMediaInfoVideoTrackLaggingCount++;
+                    break;
+                case MediaPlayer.MEDIA_INFO_BAD_INTERLEAVING:
+                    mMediaInfoBadInterleavingCount++;
+                    break;
+                case MediaPlayer.MEDIA_INFO_NOT_SEEKABLE:
+                    mMediaInfoNotSeekableCount++;
+                    break;
+                case MediaPlayer.MEDIA_INFO_METADATA_UPDATE:
+                    mMediaInfoMetdataUpdateCount++;
+                    break;
+            }
+            return true;
+        }
+    };
+
+    public static boolean playMediaSample(String fileName) throws Exception {
+        int duration = 0;
+        int curPosition = 0;
+        int nextPosition = 0;
+        int waittime = 0;
+        mOnCompleteSuccess = false;
+        mMediaInfoUnknownCount = 0;
+        mMediaInfoVideoTrackLaggingCount = 0;
+        mMediaInfoBadInterleavingCount = 0;
+        mMediaInfoNotSeekableCount = 0;
+        mMediaInfoMetdataUpdateCount = 0;
+        mPlaybackError = false;
+
+        initializeMessageLooper();
+        synchronized (mLock) {
+            try {
+                mLock.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
+            } catch(Exception e) {
+                Log.v(TAG, "looper was interrupted.");
+                return false;
+            }
+        }
+        try {
+            mMediaPlayer.setOnCompletionListener(mCompletionListener);
+            mMediaPlayer.setOnErrorListener(mOnErrorListener);
+            mMediaPlayer.setOnInfoListener(mInfoListener);
+            Log.v(TAG, "playMediaSample: sample file name " + fileName);
+            mMediaPlayer.setDataSource(fileName);
+            mMediaPlayer.setDisplay(MediaFrameworkTest.getSurfaceView().getHolder());
+            mMediaPlayer.prepare();
+            duration = mMediaPlayer.getDuration();
+            Log.v(TAG, "duration of media " + duration);
+            // start to play
+            mMediaPlayer.start();
+            waittime = duration - mMediaPlayer.getCurrentPosition();
+            synchronized(mOnCompletion) {
+                try {
+                    mOnCompletion.wait(waittime + 2000);
+                } catch (Exception e) {
+                    Log.v(TAG, "playMediaSamples are interrupted");
+                    return false;
+                }
+            }
+            terminateMessageLooper();
+        } catch (Exception e) {
+            Log.v(TAG, "playMediaSample Exception:" + e.getMessage());
+        }
+        return mOnCompleteSuccess;
+    }
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/H263QcifLongPlayerTest.java b/tests/tests/mediastress/src/android/mediastress/cts/H263QcifLongPlayerTest.java
new file mode 100644
index 0000000..6e47fe1
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/H263QcifLongPlayerTest.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+public class H263QcifLongPlayerTest extends MediaPlayerStressTest {
+    private final static String VIDEO_PATH_MIDDLE = "bbb_full/176x144/3gp_h263_libfaac/";
+    private final String[] mMedias = { // indentation shortened due to long file name
+        "bbb_full.ffmpeg.176x144.3gp.h263_56kbps_12fps.libfaac_mono_24kbps_11025Hz.3gp"
+    };
+
+    public void testPlay00() throws Exception {
+        doTestVideoPlaybackLong(0);
+    }
+
+    @Override
+    protected String getFullVideoClipName(int mediaNumber) {
+        return VIDEO_TOP_DIR + VIDEO_PATH_MIDDLE + mMedias[mediaNumber];
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/H263QcifShortPlayerTest.java b/tests/tests/mediastress/src/android/mediastress/cts/H263QcifShortPlayerTest.java
new file mode 100644
index 0000000..2035869
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/H263QcifShortPlayerTest.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+public class H263QcifShortPlayerTest extends MediaPlayerStressTest {
+    private final static String VIDEO_PATH_MIDDLE = "bbb_short/176x144/3gp_h263_libfaac/";
+    private final String[] mMedias = {
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_12fps.libfaac_mono_24kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_12fps.libfaac_mono_24kbps_22050Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_12fps.libfaac_stereo_128kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_12fps.libfaac_stereo_128kbps_22050Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_12fps.libfaac_stereo_24kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_12fps.libfaac_stereo_24kbps_22050Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_25fps.libfaac_mono_24kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_25fps.libfaac_mono_24kbps_22050Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_25fps.libfaac_stereo_128kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_25fps.libfaac_stereo_128kbps_22050Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_25fps.libfaac_stereo_24kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_300kbps_25fps.libfaac_stereo_24kbps_22050Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_12fps.libfaac_mono_24kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_12fps.libfaac_mono_24kbps_22050Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_12fps.libfaac_stereo_128kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_12fps.libfaac_stereo_128kbps_22050Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_12fps.libfaac_stereo_24kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_12fps.libfaac_stereo_24kbps_22050Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_25fps.libfaac_mono_24kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_25fps.libfaac_mono_24kbps_22050Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_25fps.libfaac_stereo_128kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_25fps.libfaac_stereo_128kbps_22050Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_25fps.libfaac_stereo_24kbps_11025Hz.3gp",
+        "bbb_short.ffmpeg.176x144.3gp.h263_56kbps_25fps.libfaac_stereo_24kbps_22050Hz.3gp"
+    };
+
+    public void testPlay00() throws Exception {
+        doTestVideoPlaybackShort(0);
+    }
+
+    public void testPlay01() throws Exception {
+        doTestVideoPlaybackShort(1);
+    }
+
+    public void testPlay02() throws Exception {
+        doTestVideoPlaybackShort(2);
+    }
+
+    public void testPlay03() throws Exception {
+        doTestVideoPlaybackShort(3);
+    }
+
+    public void testPlay04() throws Exception {
+        doTestVideoPlaybackShort(4);
+    }
+
+    public void testPlay05() throws Exception {
+        doTestVideoPlaybackShort(5);
+    }
+
+    public void testPlay06() throws Exception {
+        doTestVideoPlaybackShort(6);
+    }
+
+    public void testPlay07() throws Exception {
+        doTestVideoPlaybackShort(7);
+    }
+
+    public void testPlay08() throws Exception {
+        doTestVideoPlaybackShort(8);
+    }
+
+    public void testPlay09() throws Exception {
+        doTestVideoPlaybackShort(9);
+    }
+
+    public void testPlay10() throws Exception {
+        doTestVideoPlaybackShort(10);
+    }
+
+    public void testPlay11() throws Exception {
+        doTestVideoPlaybackShort(11);
+    }
+
+    public void testPlay12() throws Exception {
+        doTestVideoPlaybackShort(12);
+    }
+
+    public void testPlay13() throws Exception {
+        doTestVideoPlaybackShort(13);
+    }
+
+    public void testPlay14() throws Exception {
+        doTestVideoPlaybackShort(14);
+    }
+
+    public void testPlay15() throws Exception {
+        doTestVideoPlaybackShort(15);
+    }
+
+    public void testPlay16() throws Exception {
+        doTestVideoPlaybackShort(16);
+    }
+
+    public void testPlay17() throws Exception {
+        doTestVideoPlaybackShort(17);
+    }
+
+    public void testPlay18() throws Exception {
+        doTestVideoPlaybackShort(18);
+    }
+
+    public void testPlay19() throws Exception {
+        doTestVideoPlaybackShort(19);
+    }
+
+    public void testPlay20() throws Exception {
+        doTestVideoPlaybackShort(20);
+    }
+
+    public void testPlay21() throws Exception {
+        doTestVideoPlaybackShort(21);
+    }
+
+    public void testPlay22() throws Exception {
+        doTestVideoPlaybackShort(22);
+    }
+
+    public void testPlay23() throws Exception {
+        doTestVideoPlaybackShort(23);
+    }
+
+    @Override
+    protected String getFullVideoClipName(int mediaNumber) {
+        return VIDEO_TOP_DIR + VIDEO_PATH_MIDDLE + mMedias[mediaNumber];
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/H264R1080pAacLongPlayerTest.java b/tests/tests/mediastress/src/android/mediastress/cts/H264R1080pAacLongPlayerTest.java
new file mode 100644
index 0000000..b7f7564
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/H264R1080pAacLongPlayerTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+import android.media.CamcorderProfile;
+import android.media.MediaRecorder.AudioEncoder;
+import android.media.MediaRecorder.VideoEncoder;
+
+public class H264R1080pAacLongPlayerTest extends MediaPlayerStressTest {
+    private static final String VIDEO_PATH_MIDDLE = "bbb_full/1920x1080/mp4_libx264_libfaac/";
+    private final String[] mMedias = {
+        "bbb_full.ffmpeg.1920x1080.mp4.libx264_10000kbps_30fps.libfaac_stereo_192kbps_48000Hz.mp4"
+    };
+
+    public H264R1080pAacLongPlayerTest() {
+        super(CamcorderProfile.QUALITY_1080P, VideoEncoder.H264, AudioEncoder.AAC);
+    }
+
+    public void testPlay00() throws Exception {
+        doTestVideoPlaybackLong(0);
+    }
+
+    @Override
+    protected String getFullVideoClipName(int mediaNumber) {
+        return VIDEO_TOP_DIR + VIDEO_PATH_MIDDLE + mMedias[mediaNumber];
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/H264R1080pAacShortPlayerTest.java b/tests/tests/mediastress/src/android/mediastress/cts/H264R1080pAacShortPlayerTest.java
new file mode 100644
index 0000000..3b7da57
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/H264R1080pAacShortPlayerTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+import android.media.CamcorderProfile;
+import android.media.MediaRecorder.AudioEncoder;
+import android.media.MediaRecorder.VideoEncoder;
+
+public class H264R1080pAacShortPlayerTest extends MediaPlayerStressTest {
+    private static final String VIDEO_PATH_MIDDLE = "bbb_short/1920x1080/mp4_libx264_libfaac/";
+    private final String[] mMedias = {
+        "bbb_short.ffmpeg.1920x1080.mp4.libx264_10000kbps_30fps.libfaac_stereo_192kbps_48000Hz.mp4",
+        "bbb_short.ffmpeg.1920x1080.mp4.libx264_1750kbps_30fps.libfaac_stereo_192kbps_48000Hz.mp4",
+        "bbb_short.ffmpeg.1920x1080.mp4.libx264_5000kbps_30fps.libfaac_stereo_192kbps_48000Hz.mp4"
+    };
+
+    public H264R1080pAacShortPlayerTest() {
+        super(CamcorderProfile.QUALITY_1080P, VideoEncoder.H264, AudioEncoder.AAC);
+    }
+
+    public void testPlay00() throws Exception {
+        doTestVideoPlaybackShort(0);
+    }
+
+    public void testPlay01() throws Exception {
+        doTestVideoPlaybackShort(1);
+    }
+
+    public void testPlay02() throws Exception {
+        doTestVideoPlaybackShort(2);
+    }
+
+    @Override
+    protected String getFullVideoClipName(int mediaNumber) {
+        return VIDEO_TOP_DIR + VIDEO_PATH_MIDDLE + mMedias[mediaNumber];
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/H264R480pAacLongPlayerTest.java b/tests/tests/mediastress/src/android/mediastress/cts/H264R480pAacLongPlayerTest.java
new file mode 100644
index 0000000..f01aa75
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/H264R480pAacLongPlayerTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+import android.media.CamcorderProfile;
+import android.media.MediaRecorder.AudioEncoder;
+import android.media.MediaRecorder.VideoEncoder;
+
+public class H264R480pAacLongPlayerTest extends MediaPlayerStressTest {
+    private static final String VIDEO_PATH_MIDDLE = "bbb_full/720x480/mp4_libx264_libfaac/";
+    private final String[] mMedias = {
+        "bbb_full.ffmpeg.720x480.mp4.libx264_500kbps_25fps.libfaac_stereo_128kbps_44100Hz.mp4"
+    };
+
+    public H264R480pAacLongPlayerTest() {
+        super(CamcorderProfile.QUALITY_480P, VideoEncoder.H264, AudioEncoder.AAC);
+    }
+
+    public void testPlay00() throws Exception {
+        doTestVideoPlaybackLong(0);
+    }
+
+    @Override
+    protected String getFullVideoClipName(int mediaNumber) {
+        return VIDEO_TOP_DIR + VIDEO_PATH_MIDDLE + mMedias[mediaNumber];
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/H264R480pAacShortPlayerTest.java b/tests/tests/mediastress/src/android/mediastress/cts/H264R480pAacShortPlayerTest.java
new file mode 100644
index 0000000..81b80e5
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/H264R480pAacShortPlayerTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+import android.media.CamcorderProfile;
+import android.media.MediaRecorder.AudioEncoder;
+import android.media.MediaRecorder.VideoEncoder;
+
+public class H264R480pAacShortPlayerTest extends MediaPlayerStressTest {
+    private static final String VIDEO_PATH_MIDDLE = "bbb_short/720x480/mp4_libx264_libfaac/";
+    private final String[] mMedias = {
+        "bbb_short.ffmpeg.720x480.mp4.libx264_1000kbps_25fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.720x480.mp4.libx264_1000kbps_25fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.720x480.mp4.libx264_1000kbps_30fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.720x480.mp4.libx264_1000kbps_30fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.720x480.mp4.libx264_1350kbps_25fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.720x480.mp4.libx264_1350kbps_25fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.720x480.mp4.libx264_1350kbps_30fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.720x480.mp4.libx264_1350kbps_30fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.720x480.mp4.libx264_500kbps_25fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.720x480.mp4.libx264_500kbps_25fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.720x480.mp4.libx264_500kbps_30fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.720x480.mp4.libx264_500kbps_30fps.libfaac_stereo_192kbps_44100Hz.mp4"
+    };
+
+    public H264R480pAacShortPlayerTest() {
+        super(CamcorderProfile.QUALITY_480P, VideoEncoder.H264, AudioEncoder.AAC);
+    }
+
+    public void testPlay00() throws Exception {
+        doTestVideoPlaybackShort(0);
+    }
+
+    public void testPlay01() throws Exception {
+        doTestVideoPlaybackShort(1);
+    }
+
+    public void testPlay02() throws Exception {
+        doTestVideoPlaybackShort(2);
+    }
+
+    public void testPlay03() throws Exception {
+        doTestVideoPlaybackShort(3);
+    }
+
+    public void testPlay04() throws Exception {
+        doTestVideoPlaybackShort(4);
+    }
+
+    public void testPlay05() throws Exception {
+        doTestVideoPlaybackShort(5);
+    }
+
+    public void testPlay06() throws Exception {
+        doTestVideoPlaybackShort(6);
+    }
+
+    public void testPlay07() throws Exception {
+        doTestVideoPlaybackShort(7);
+    }
+
+    public void testPlay08() throws Exception {
+        doTestVideoPlaybackShort(8);
+    }
+
+    public void testPlay09() throws Exception {
+        doTestVideoPlaybackShort(9);
+    }
+
+    public void testPlay10() throws Exception {
+        doTestVideoPlaybackShort(10);
+    }
+
+    public void testPlay11() throws Exception {
+        doTestVideoPlaybackShort(11);
+    }
+
+    @Override
+    protected String getFullVideoClipName(int mediaNumber) {
+        return VIDEO_TOP_DIR + VIDEO_PATH_MIDDLE + mMedias[mediaNumber];
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/H264R480x360AacShortPlayerTest.java b/tests/tests/mediastress/src/android/mediastress/cts/H264R480x360AacShortPlayerTest.java
new file mode 100644
index 0000000..12e8f6d
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/H264R480x360AacShortPlayerTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+public class H264R480x360AacShortPlayerTest extends MediaPlayerStressTest {
+    private static final String VIDEO_PATH_MIDDLE = "bbb_short/480x360/mp4_libx264_libfaac/";
+    private final String[] mMedias = {
+        "bbb_short.ffmpeg.480x360.mp4.libx264_1000kbps_25fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.480x360.mp4.libx264_1000kbps_25fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.480x360.mp4.libx264_1000kbps_30fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.480x360.mp4.libx264_1000kbps_30fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.480x360.mp4.libx264_1350kbps_25fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.480x360.mp4.libx264_1350kbps_25fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.480x360.mp4.libx264_1350kbps_30fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.480x360.mp4.libx264_1350kbps_30fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.480x360.mp4.libx264_500kbps_25fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.480x360.mp4.libx264_500kbps_25fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.480x360.mp4.libx264_500kbps_30fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.480x360.mp4.libx264_500kbps_30fps.libfaac_stereo_192kbps_44100Hz.mp4"
+    };
+
+    public void testPlay00() throws Exception {
+        doTestVideoPlaybackShort(0);
+    }
+
+    public void testPlay01() throws Exception {
+        doTestVideoPlaybackShort(1);
+    }
+
+    public void testPlay02() throws Exception {
+        doTestVideoPlaybackShort(2);
+    }
+
+    public void testPlay03() throws Exception {
+        doTestVideoPlaybackShort(3);
+    }
+
+    public void testPlay04() throws Exception {
+        doTestVideoPlaybackShort(4);
+    }
+
+    public void testPlay05() throws Exception {
+        doTestVideoPlaybackShort(5);
+    }
+
+    public void testPlay06() throws Exception {
+        doTestVideoPlaybackShort(6);
+    }
+
+    public void testPlay07() throws Exception {
+        doTestVideoPlaybackShort(7);
+    }
+
+    public void testPlay08() throws Exception {
+        doTestVideoPlaybackShort(8);
+    }
+
+    public void testPlay09() throws Exception {
+        doTestVideoPlaybackShort(9);
+    }
+
+    public void testPlay10() throws Exception {
+        doTestVideoPlaybackShort(10);
+    }
+
+    public void testPlay11() throws Exception {
+        doTestVideoPlaybackShort(11);
+    }
+
+    @Override
+    protected String getFullVideoClipName(int mediaNumber) {
+        return VIDEO_TOP_DIR + VIDEO_PATH_MIDDLE + mMedias[mediaNumber];
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/H264R720pAacLongPlayerTest.java b/tests/tests/mediastress/src/android/mediastress/cts/H264R720pAacLongPlayerTest.java
new file mode 100644
index 0000000..3efec62
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/H264R720pAacLongPlayerTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+import android.media.CamcorderProfile;
+import android.media.MediaRecorder.AudioEncoder;
+import android.media.MediaRecorder.VideoEncoder;
+
+public class H264R720pAacLongPlayerTest extends MediaPlayerStressTest {
+    private static final String VIDEO_PATH_MIDDLE = "bbb_full/1280x720/mp4_libx264_libfaac/";
+    private final String[] mMedias = {
+        "bbb_full.ffmpeg.1280x720.mp4.libx264_1350kbps_25fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_full.ffmpeg.1280x720.mp4.libx264_1750kbps_30fps.libfaac_stereo_192kbps_48000Hz.mp4"
+    };
+
+    public H264R720pAacLongPlayerTest() {
+        super(CamcorderProfile.QUALITY_720P, VideoEncoder.H264, AudioEncoder.AAC);
+    }
+
+    public void testPlay00() throws Exception {
+        doTestVideoPlaybackLong(0);
+    }
+
+    public void testPlay01() throws Exception {
+        doTestVideoPlaybackLong(1);
+    }
+
+    @Override
+    protected String getFullVideoClipName(int mediaNumber) {
+        return VIDEO_TOP_DIR + VIDEO_PATH_MIDDLE + mMedias[mediaNumber];
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/H264R720pAacShortPlayerTest.java b/tests/tests/mediastress/src/android/mediastress/cts/H264R720pAacShortPlayerTest.java
new file mode 100644
index 0000000..e919a35
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/H264R720pAacShortPlayerTest.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+import android.media.CamcorderProfile;
+import android.media.MediaRecorder.AudioEncoder;
+import android.media.MediaRecorder.VideoEncoder;
+
+public class H264R720pAacShortPlayerTest extends MediaPlayerStressTest {
+    private static final String VIDEO_PATH_MIDDLE = "bbb_short/1280x720/mp4_libx264_libfaac/";
+    private final String[] mMedias = {
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_10000kbps_30fps.libfaac_stereo_192kbps_48000Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_1000kbps_25fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_1000kbps_25fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_1000kbps_30fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_1000kbps_30fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_1350kbps_25fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_1350kbps_25fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_1350kbps_30fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_1350kbps_30fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_1750kbps_30fps.libfaac_stereo_192kbps_48000Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_5000kbps_30fps.libfaac_stereo_192kbps_48000Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_500kbps_25fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_500kbps_25fps.libfaac_stereo_192kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_500kbps_30fps.libfaac_stereo_128kbps_44100Hz.mp4",
+        "bbb_short.ffmpeg.1280x720.mp4.libx264_500kbps_30fps.libfaac_stereo_192kbps_44100Hz.mp4"
+    };
+
+    public H264R720pAacShortPlayerTest() {
+        super(CamcorderProfile.QUALITY_720P, VideoEncoder.H264, AudioEncoder.AAC);
+    }
+
+    public void testPlay00() throws Exception {
+        doTestVideoPlaybackShort(0);
+    }
+
+    public void testPlay01() throws Exception {
+        doTestVideoPlaybackShort(1);
+    }
+
+    public void testPlay02() throws Exception {
+        doTestVideoPlaybackShort(2);
+    }
+
+    public void testPlay03() throws Exception {
+        doTestVideoPlaybackShort(3);
+    }
+
+    public void testPlay04() throws Exception {
+        doTestVideoPlaybackShort(4);
+    }
+
+    public void testPlay05() throws Exception {
+        doTestVideoPlaybackShort(5);
+    }
+
+    public void testPlay06() throws Exception {
+        doTestVideoPlaybackShort(6);
+    }
+
+    public void testPlay07() throws Exception {
+        doTestVideoPlaybackShort(7);
+    }
+
+    public void testPlay08() throws Exception {
+        doTestVideoPlaybackShort(8);
+    }
+
+    public void testPlay09() throws Exception {
+        doTestVideoPlaybackShort(9);
+    }
+
+    public void testPlay10() throws Exception {
+        doTestVideoPlaybackShort(10);
+    }
+
+    public void testPlay11() throws Exception {
+        doTestVideoPlaybackShort(11);
+    }
+
+    public void testPlay12() throws Exception {
+        doTestVideoPlaybackShort(12);
+    }
+
+    public void testPlay13() throws Exception {
+        doTestVideoPlaybackShort(13);
+    }
+
+    public void testPlay14() throws Exception {
+        doTestVideoPlaybackShort(14);
+    }
+
+    @Override
+    protected String getFullVideoClipName(int mediaNumber) {
+        return VIDEO_TOP_DIR + VIDEO_PATH_MIDDLE + mMedias[mediaNumber];
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/MediaFrameworkTest.java b/tests/tests/mediastress/src/android/mediastress/cts/MediaFrameworkTest.java
new file mode 100644
index 0000000..034eeeb
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/MediaFrameworkTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.PowerManager;
+import android.util.Log;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+
+import com.android.cts.mediastress.R;
+
+public class MediaFrameworkTest extends Activity implements SurfaceHolder.Callback {
+    private static String TAG = "MediaFrameworkTest";
+    private static SurfaceView mSurfaceView;
+
+    private Bitmap mDestBitmap;
+    private ImageView mOverlayView;
+
+    private PowerManager.WakeLock mWakeLock = null;
+
+    public static SurfaceView getSurfaceView() {
+        return mSurfaceView;
+    }
+
+    /** Called when the activity is first created. */
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        setContentView(R.layout.surface_view);
+        mSurfaceView = (SurfaceView)findViewById(R.id.surface_view);
+        mOverlayView = (ImageView)findViewById(R.id.overlay_layer);
+        ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams();
+        mSurfaceView.getHolder().addCallback(this);
+
+        mOverlayView.setLayoutParams(lp);
+        mDestBitmap = Bitmap.createBitmap((int)640, (int)480, Bitmap.Config.ARGB_8888);
+        mOverlayView.setImageBitmap(mDestBitmap);
+
+        //Acquire the full wake lock to keep the device up
+        PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
+        mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MediaFrameworkTest");
+        mWakeLock.acquire();
+    }
+
+    public void onStop(Bundle icicle) {
+        mWakeLock.release();
+    }
+
+    public void surfaceDestroyed(SurfaceHolder holder) {
+        //Can do nothing in here. The test case will fail if the surface destroyed.
+        Log.v(TAG, "Test application surface destroyed");
+    }
+
+    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+        //Do nothing in here. Just print out the log
+        Log.v(TAG, "Test application surface changed");
+    }
+
+    public void surfaceCreated(SurfaceHolder holder) {
+        holder.addCallback(this);
+        Log.v(TAG, "Test application surface created");
+    }
+
+    public void startPlayback(String filename){
+      String mimetype = "audio/mpeg";
+      Uri path = Uri.parse(filename);
+      Intent intent = new Intent(Intent.ACTION_VIEW);
+      intent.setDataAndType(path, mimetype);
+      startActivity(intent);
+    }
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/MediaPlayerStressTest.java b/tests/tests/mediastress/src/android/mediastress/cts/MediaPlayerStressTest.java
new file mode 100644
index 0000000..3678811
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/MediaPlayerStressTest.java
@@ -0,0 +1,171 @@
+/*
+ * 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 android.mediastress.cts;
+
+import android.app.Activity;
+import android.app.Instrumentation;
+import android.content.Intent;
+import android.media.CamcorderProfile;
+import android.media.MediaRecorder.AudioEncoder;
+import android.media.MediaRecorder.VideoEncoder;
+import android.os.Environment;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.Writer;
+
+import android.test.InstrumentationTestCase;
+
+/**
+ * Helper for implementing video playback stress test
+ */
+abstract class MediaPlayerStressTest extends InstrumentationTestCase {
+    protected static final String VIDEO_TOP_DIR = WorkDir.getMediaDirString();
+    protected static final int REPEAT_NUMBER_FOR_SHORT_CLIPS = 2;
+    protected static final int REPEAT_NUMBER_FOR_LONG_CLIPS = 1;
+    private static final String TAG = "MediaPlayerStressTest";
+    // whether a video format is supported or not.
+    private final boolean mSupported;
+
+    /**
+     * construct a test case with check of whether the format is supported or not.
+     * @param quality
+     * @param videoCodec
+     * @param audioCodec
+     */
+    protected MediaPlayerStressTest(int quality, int videoCodec, int audioCodec) {
+        mSupported = VideoPlayerCapability.formatSupported(quality, videoCodec, audioCodec);
+    }
+
+    protected MediaPlayerStressTest() {
+        mSupported = true; // supported if nothing specified
+    }
+
+    /**
+     * provides full path name of video clip for the given media number
+     * @param mediaNumber
+     * @return video file name
+     */
+    abstract protected String getFullVideoClipName(int mediaNumber);
+
+    private int mTotalPlaybackError;
+    private int mTotalComplete;
+    private int mTotalInfoUnknown;
+    private int mTotalVideoTrackLagging;
+    private int mTotalBadInterleaving;
+    private int mTotalNotSeekable;
+    private int mTotalMetaDataUpdate;
+
+    private void writeTestOutput(String filename, Writer output) throws Exception{
+        output.write("File Name: " + filename);
+        output.write(" Complete: " + CodecTest.mOnCompleteSuccess);
+        output.write(" Error: " + CodecTest.mPlaybackError);
+        output.write(" Unknown Info: " + CodecTest.mMediaInfoUnknownCount);
+        output.write(" Track Lagging: " +  CodecTest.mMediaInfoVideoTrackLaggingCount);
+        output.write(" Bad Interleaving: " + CodecTest.mMediaInfoBadInterleavingCount);
+        output.write(" Not Seekable: " + CodecTest.mMediaInfoNotSeekableCount);
+        output.write(" Info Meta data update: " + CodecTest.mMediaInfoMetdataUpdateCount);
+        output.write("\n");
+    }
+
+    private void writeTestSummary(Writer output) throws Exception{
+        output.write("Total Result:\n");
+        output.write("Total Complete: " + mTotalComplete + "\n");
+        output.write("Total Error: " + mTotalPlaybackError + "\n");
+        output.write("Total Unknown Info: " + mTotalInfoUnknown + "\n");
+        output.write("Total Track Lagging: " + mTotalVideoTrackLagging + "\n" );
+        output.write("Total Bad Interleaving: " + mTotalBadInterleaving + "\n");
+        output.write("Total Not Seekable: " + mTotalNotSeekable + "\n");
+        output.write("Total Info Meta data update: " + mTotalMetaDataUpdate + "\n");
+        output.write("\n");
+    }
+
+    private void updateTestResult(){
+        if (CodecTest.mOnCompleteSuccess){
+            mTotalComplete++;
+        }
+        else if (CodecTest.mPlaybackError){
+            mTotalPlaybackError++;
+        }
+        mTotalInfoUnknown += CodecTest.mMediaInfoUnknownCount;
+        mTotalVideoTrackLagging += CodecTest.mMediaInfoVideoTrackLaggingCount;
+        mTotalBadInterleaving += CodecTest.mMediaInfoBadInterleavingCount;
+        mTotalNotSeekable += CodecTest.mMediaInfoNotSeekableCount;
+        mTotalMetaDataUpdate += CodecTest.mMediaInfoMetdataUpdateCount;
+    }
+
+    /**
+     * runs video playback test for the given mediaNumber
+     * @param mediaNumber number of media to be used for playback.
+     *         This number is passed to getFullVideoClipName.
+     * @param  repeatCounter repeat playback for the given number
+     * @throws Exception
+     */
+    protected void doTestVideoPlayback(int mediaNumber, int repeatCounter) throws Exception {
+        if (!mSupported) {
+            return;
+        }
+
+        File playbackOutput = new File(WorkDir.getTopDir(), "PlaybackTestResult.txt");
+        Writer output = new BufferedWriter(new FileWriter(playbackOutput, true));
+
+        boolean testResult = true;
+        boolean onCompleteSuccess = false;
+
+        Instrumentation inst = getInstrumentation();
+        Intent intent = new Intent();
+
+        intent.setClass(inst.getTargetContext(), MediaFrameworkTest.class);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+        Activity act = inst.startActivitySync(intent);
+
+        String mediaName = getFullVideoClipName(mediaNumber);
+        for (int i = 0; i < repeatCounter; i++) {
+            Log.v(TAG, "start playing " + mediaName);
+            onCompleteSuccess =
+                CodecTest.playMediaSample(mediaName);
+            if (!onCompleteSuccess) {
+                //Don't fail the test right away, print out the failure file.
+                Log.v(TAG, "Failure File : " + mediaName);
+                testResult = false;
+            }
+        }
+        Thread.sleep(1000);
+
+        act.finish();
+        //Write test result to an output file
+        writeTestOutput(mediaName, output);
+        //Get the summary
+        updateTestResult();
+
+        writeTestSummary(output);
+        output.close();
+        assertTrue("playback " + mediaName, testResult);
+    }
+
+    protected void doTestVideoPlaybackShort(int mediaNumber) throws Exception {
+        doTestVideoPlayback(mediaNumber, REPEAT_NUMBER_FOR_SHORT_CLIPS);
+    }
+
+    protected void doTestVideoPlaybackLong(int mediaNumber) throws Exception {
+        doTestVideoPlayback(mediaNumber, REPEAT_NUMBER_FOR_LONG_CLIPS);
+    }
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/MediaRecorderStressTest.java b/tests/tests/mediastress/src/android/mediastress/cts/MediaRecorderStressTest.java
new file mode 100644
index 0000000..0ca8f99
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/MediaRecorderStressTest.java
@@ -0,0 +1,382 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+import android.hardware.Camera;
+import android.media.CamcorderProfile;
+import android.media.MediaPlayer;
+import android.media.MediaRecorder;
+import android.os.Handler;
+import android.os.Looper;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
+import android.view.SurfaceHolder;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.Writer;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> {
+
+    private static String TAG = "MediaRecorderStressTest";
+    private static final int NUMBER_OF_CAMERA_STRESS_LOOPS = 50;
+    private static final int NUMBER_OF_RECORDER_STRESS_LOOPS = 50;
+    private static final int NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS = 50;
+    private static final int NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER = 50;
+    private static final long WAIT_TIME_CAMERA_TEST = 3000;  // in ms
+    private static final long WAIT_TIME_RECORDER_TEST = 5000;  // in ms
+    private static final String OUTPUT_FILE = WorkDir.getTopDirString() + "temp";
+    private static final String OUTPUT_FILE_EXT = ".3gp";
+    private static final String MEDIA_STRESS_OUTPUT ="mediaStressOutput.txt";
+    private final CameraErrorCallback mCameraErrorCallback = new CameraErrorCallback();
+    private final RecorderErrorCallback mRecorderErrorCallback = new RecorderErrorCallback();
+    private final static int WAIT_TIMEOUT = 10000;
+
+    private MediaRecorder mRecorder;
+    private Camera mCamera;
+    private Thread mLooperThread;
+    private Handler mHandler;
+
+    private static int mCameraId;
+    private static int mProfileQuality = CamcorderProfile.QUALITY_HIGH;
+    private static CamcorderProfile profile =
+                        CamcorderProfile.get(mCameraId, mProfileQuality);
+
+    private int mIterations = 50;
+    private int mVideoEncoder;
+    private int mAudioEncoder;
+    private int mFrameRate;
+    private int mVideoWidth;
+    private int mVideoHeight;
+    private int mBitRate;
+    private boolean mRemoveVideo = true;
+    private int mRecordDuration = 5000;
+
+    public MediaRecorderStressTest() {
+        super(MediaFrameworkTest.class);
+    }
+
+    protected void setUp() throws Exception {
+        int cameraId = 0;
+        CamcorderProfile profile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
+        mVideoEncoder = profile.videoCodec;
+        mAudioEncoder = profile.audioCodec;
+        mFrameRate = profile.videoFrameRate;
+        mVideoWidth = profile.videoFrameWidth;
+        mVideoHeight = profile.videoFrameHeight;
+        mBitRate = profile.videoBitRate;
+
+        final Semaphore sem = new Semaphore(0);
+        mLooperThread = new Thread() {
+            @Override
+            public void run() {
+                Log.v(TAG, "starting looper");
+                Looper.prepare();
+                mHandler = new Handler();
+                sem.release();
+                Looper.loop();
+                Log.v(TAG, "quit looper");
+            }
+        };
+        mLooperThread.start();
+        if (!sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
+            fail("Failed to start the looper.");
+        }
+
+        getActivity();
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (mHandler != null) {
+            mHandler.getLooper().quit();
+            mHandler = null;
+        }
+        if (mLooperThread != null) {
+            mLooperThread.join(WAIT_TIMEOUT);
+            if (mLooperThread.isAlive()) {
+                fail("Failed to stop the looper.");
+            }
+            mLooperThread = null;
+        }
+
+        super.tearDown();
+    }
+
+    private void runOnLooper(final Runnable command) throws InterruptedException {
+        final Semaphore sem = new Semaphore(0);
+        mHandler.post(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    command.run();
+                } finally {
+                    sem.release();
+                }
+            }
+        });
+        if (! sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
+            fail("Failed to run the command on the looper.");
+        }
+    }
+
+    private final class CameraErrorCallback implements android.hardware.Camera.ErrorCallback {
+        public void onError(int error, android.hardware.Camera camera) {
+            assertTrue("Camera test mediaserver died", error !=
+                    android.hardware.Camera.CAMERA_ERROR_SERVER_DIED);
+        }
+    }
+
+    private final class RecorderErrorCallback implements MediaRecorder.OnErrorListener {
+        public void onError(MediaRecorder mr, int what, int extra) {
+            // fail the test case no matter what error come up
+            fail("mediaRecorder error");
+        }
+    }
+
+    //Test case for stressing the camera preview.
+    @LargeTest
+    public void testStressCamera() throws Exception {
+        SurfaceHolder mSurfaceHolder;
+        mSurfaceHolder = MediaFrameworkTest.getSurfaceView().getHolder();
+        File stressOutFile = new File(WorkDir.getTopDir(), MEDIA_STRESS_OUTPUT);
+        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
+        output.write("Camera start preview stress:\n");
+        output.write("Total number of loops:" +
+                NUMBER_OF_CAMERA_STRESS_LOOPS + "\n");
+
+        Log.v(TAG, "Start preview");
+        output.write("No of loop: ");
+
+        for (int i = 0; i< NUMBER_OF_CAMERA_STRESS_LOOPS; i++) {
+            runOnLooper(new Runnable() {
+                @Override
+                public void run() {
+                    mCamera = Camera.open();
+                }
+            });
+            mCamera.setErrorCallback(mCameraErrorCallback);
+            mCamera.setPreviewDisplay(mSurfaceHolder);
+            mCamera.startPreview();
+            Thread.sleep(WAIT_TIME_CAMERA_TEST);
+            mCamera.stopPreview();
+            mCamera.release();
+            output.write(" ," + i);
+        }
+
+        output.write("\n\n");
+        output.close();
+    }
+
+    //Test case for stressing the camera preview.
+    @LargeTest
+    public void testStressRecorder() throws Exception {
+        String filename;
+        SurfaceHolder mSurfaceHolder;
+        mSurfaceHolder = MediaFrameworkTest.getSurfaceView().getHolder();
+        File stressOutFile = new File(WorkDir.getTopDir(), MEDIA_STRESS_OUTPUT);
+        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
+        output.write("H263 video record- reset after prepare Stress test\n");
+        output.write("Total number of loops:" +
+                NUMBER_OF_RECORDER_STRESS_LOOPS + "\n");
+
+        output.write("No of loop: ");
+        Log.v(TAG, "Start preview");
+        for (int i = 0; i < NUMBER_OF_RECORDER_STRESS_LOOPS; i++) {
+            runOnLooper(new Runnable() {
+                @Override
+                public void run() {
+                    mRecorder = new MediaRecorder();
+                }
+            });
+            Log.v(TAG, "counter = " + i);
+            filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
+            Log.v(TAG, filename);
+            mRecorder.setOnErrorListener(mRecorderErrorCallback);
+            mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
+            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
+            mRecorder.setOutputFile(filename);
+            mRecorder.setVideoFrameRate(mFrameRate);
+            mRecorder.setVideoSize(176,144);
+            Log.v(TAG, "setEncoder");
+            mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
+            mSurfaceHolder = MediaFrameworkTest.getSurfaceView().getHolder();
+            Log.v(TAG, "setPreview");
+            mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
+            Log.v(TAG, "prepare");
+            mRecorder.prepare();
+            Log.v(TAG, "before release");
+            Thread.sleep(WAIT_TIME_RECORDER_TEST);
+            mRecorder.reset();
+            mRecorder.release();
+            output.write(", " + i);
+        }
+
+        output.write("\n\n");
+        output.close();
+    }
+
+    //Stress test case for switching camera and video recorder preview.
+    @LargeTest
+    public void testStressCameraSwitchRecorder() throws Exception {
+        String filename;
+        SurfaceHolder mSurfaceHolder;
+        mSurfaceHolder = MediaFrameworkTest.getSurfaceView().getHolder();
+        File stressOutFile = new File(WorkDir.getTopDir(), MEDIA_STRESS_OUTPUT);
+        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
+        output.write("Camera and video recorder preview switching\n");
+        output.write("Total number of loops:"
+                + NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER + "\n");
+
+        Log.v(TAG, "Start preview");
+        output.write("No of loop: ");
+        for (int i = 0; i < NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER; i++) {
+            runOnLooper(new Runnable() {
+                @Override
+                public void run() {
+                    mCamera = Camera.open();
+                }
+            });
+            mCamera.setErrorCallback(mCameraErrorCallback);
+            mCamera.setPreviewDisplay(mSurfaceHolder);
+            mCamera.startPreview();
+            Thread.sleep(WAIT_TIME_CAMERA_TEST);
+            mCamera.stopPreview();
+            mCamera.release();
+            mCamera = null;
+            Log.v(TAG, "release camera");
+            filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
+            Log.v(TAG, filename);
+            runOnLooper(new Runnable() {
+                @Override
+                public void run() {
+                    mRecorder = new MediaRecorder();
+                }
+            });
+            mRecorder.setOnErrorListener(mRecorderErrorCallback);
+            mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
+            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
+            mRecorder.setOutputFile(filename);
+            mRecorder.setVideoFrameRate(mFrameRate);
+            mRecorder.setVideoSize(176,144);
+            Log.v(TAG, "Media recorder setEncoder");
+            mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
+            Log.v(TAG, "mediaRecorder setPreview");
+            mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
+            Log.v(TAG, "prepare");
+            mRecorder.prepare();
+            Log.v(TAG, "before release");
+            Thread.sleep(WAIT_TIME_CAMERA_TEST);
+            mRecorder.release();
+            Log.v(TAG, "release video recorder");
+            output.write(", " + i);
+        }
+
+        output.write("\n\n");
+        output.close();
+    }
+
+    public void validateRecordedVideo(String recordedFile) throws Exception {
+        MediaPlayer mp = new MediaPlayer();
+        mp.setDataSource(recordedFile);
+        mp.prepare();
+        int duration = mp.getDuration();
+        if (duration <= 0){
+            assertTrue("stressRecordAndPlayback", false);
+        }
+        mp.release();
+    }
+
+    public void removeRecodedVideo(String filename){
+        File video = new File(filename);
+        Log.v(TAG, "remove recorded video " + filename);
+        video.delete();
+    }
+
+    //Stress test case for record a video and play right away.
+    @LargeTest
+    public void testStressRecordVideoAndPlayback() throws Exception {
+        String filename;
+        SurfaceHolder mSurfaceHolder;
+        mSurfaceHolder = MediaFrameworkTest.getSurfaceView().getHolder();
+        File stressOutFile = new File(WorkDir.getTopDir(), MEDIA_STRESS_OUTPUT);
+        Writer output = new BufferedWriter(
+                new FileWriter(stressOutFile, true));
+        output.write("Video record and play back stress test:\n");
+        output.write("Total number of loops:"
+                + NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS + "\n");
+
+        output.write("No of loop: ");
+        for (int i = 0; i < mIterations; i++){
+            filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
+            Log.v(TAG, filename);
+            runOnLooper(new Runnable() {
+                @Override
+                public void run() {
+                    mRecorder = new MediaRecorder();
+                }
+            });
+            Log.v(TAG, "iterations : " + mIterations);
+            Log.v(TAG, "videoEncoder : " + mVideoEncoder);
+            Log.v(TAG, "audioEncoder : " + mAudioEncoder);
+            Log.v(TAG, "frameRate : " + mFrameRate);
+            Log.v(TAG, "videoWidth : " + mVideoWidth);
+            Log.v(TAG, "videoHeight : " + mVideoHeight);
+            Log.v(TAG, "bitRate : " + mBitRate);
+            Log.v(TAG, "recordDuration : " + mRecordDuration);
+
+            mRecorder.setOnErrorListener(mRecorderErrorCallback);
+            mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
+            mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
+            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
+            mRecorder.setOutputFile(filename);
+            mRecorder.setVideoFrameRate(mFrameRate);
+            mRecorder.setVideoSize(mVideoWidth, mVideoHeight);
+            mRecorder.setVideoEncoder(mVideoEncoder);
+            mRecorder.setAudioEncoder(mAudioEncoder);
+            Log.v(TAG, "mediaRecorder setPreview");
+            mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
+            mRecorder.prepare();
+            mRecorder.start();
+            Thread.sleep(mRecordDuration);
+            Log.v(TAG, "Before stop");
+            mRecorder.stop();
+            mRecorder.release();
+            //start the playback
+            MediaPlayer mp = new MediaPlayer();
+            mp.setDataSource(filename);
+            mp.setDisplay(MediaFrameworkTest.getSurfaceView().getHolder());
+            mp.prepare();
+            mp.start();
+            Thread.sleep(mRecordDuration);
+            mp.release();
+            validateRecordedVideo(filename);
+            if (mRemoveVideo) {
+                removeRecodedVideo(filename);
+            }
+            output.write(", " + i);
+        }
+
+        output.write("\n\n");
+        output.close();
+    }
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/VideoPlayerCapability.java b/tests/tests/mediastress/src/android/mediastress/cts/VideoPlayerCapability.java
new file mode 100644
index 0000000..f8dd2aa
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/VideoPlayerCapability.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+import android.media.CamcorderProfile;
+import android.util.Log;
+
+import junit.framework.Assert;
+
+public class VideoPlayerCapability {
+    private static final String TAG = "VideoPlayCapability";
+
+    static boolean formatSupported(int quality, int videoCodec, int audioCodec) {
+        if (!CamcorderProfile.hasProfile(quality)) {
+            Log.i(TAG, "quality " + quality + " not supported");
+            return false;
+        }
+        CamcorderProfile profile = CamcorderProfile.get(quality);
+        Assert.assertNotNull(profile);
+        if ((profile.videoCodec == videoCodec) && (profile.audioCodec == audioCodec)) {
+            Log.i(TAG, "quality " + quality + " video codec " + videoCodec + " audio codec " +
+                    audioCodec + " supproted");
+            return true;
+        }
+        return false;
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/Vp8R480x360LongPlayerTest.java b/tests/tests/mediastress/src/android/mediastress/cts/Vp8R480x360LongPlayerTest.java
new file mode 100644
index 0000000..372f034
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/Vp8R480x360LongPlayerTest.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+public class Vp8R480x360LongPlayerTest extends MediaPlayerStressTest {
+    private static final String VIDEO_PATH_MIDDLE = "bbb_full/480x360/webm_libvpx_libvorbis/";
+    private final String[] mMedias = {
+        "bbb_full.ffmpeg.480x360.webm.libvpx_500kbps_25fps.libvorbis_stereo_128kbps_44100Hz.webm"
+    };
+
+    public void testPlay00() throws Exception {
+        doTestVideoPlaybackLong(0);
+    }
+
+    @Override
+    protected String getFullVideoClipName(int mediaNumber) {
+        return VIDEO_TOP_DIR + VIDEO_PATH_MIDDLE + mMedias[mediaNumber];
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/Vp8R480x360ShortPlayerTest.java b/tests/tests/mediastress/src/android/mediastress/cts/Vp8R480x360ShortPlayerTest.java
new file mode 100644
index 0000000..30b4d2e
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/Vp8R480x360ShortPlayerTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+public class Vp8R480x360ShortPlayerTest extends MediaPlayerStressTest {
+    private static final String VIDEO_PATH_MIDDLE = "bbb_short/480x360/webm_libvpx_libvorbis/";
+    private final String[] mMedias = {
+        "bbb_short.ffmpeg.480x360.webm.libvpx_1000kbps_25fps.libvorbis_stereo_128kbps_44100Hz.webm",
+        "bbb_short.ffmpeg.480x360.webm.libvpx_1000kbps_25fps.libvorbis_stereo_192kbps_44100Hz.webm",
+        "bbb_short.ffmpeg.480x360.webm.libvpx_1000kbps_30fps.libvorbis_stereo_128kbps_44100Hz.webm",
+        "bbb_short.ffmpeg.480x360.webm.libvpx_1000kbps_30fps.libvorbis_stereo_192kbps_44100Hz.webm",
+        "bbb_short.ffmpeg.480x360.webm.libvpx_1350kbps_25fps.libvorbis_stereo_128kbps_44100Hz.webm",
+        "bbb_short.ffmpeg.480x360.webm.libvpx_1350kbps_25fps.libvorbis_stereo_192kbps_44100Hz.webm",
+        "bbb_short.ffmpeg.480x360.webm.libvpx_1350kbps_30fps.libvorbis_stereo_128kbps_44100Hz.webm",
+        "bbb_short.ffmpeg.480x360.webm.libvpx_1350kbps_30fps.libvorbis_stereo_192kbps_44100Hz.webm",
+        "bbb_short.ffmpeg.480x360.webm.libvpx_500kbps_25fps.libvorbis_stereo_128kbps_44100Hz.webm",
+        "bbb_short.ffmpeg.480x360.webm.libvpx_500kbps_25fps.libvorbis_stereo_192kbps_44100Hz.webm",
+        "bbb_short.ffmpeg.480x360.webm.libvpx_500kbps_30fps.libvorbis_stereo_128kbps_44100Hz.webm",
+        "bbb_short.ffmpeg.480x360.webm.libvpx_500kbps_30fps.libvorbis_stereo_192kbps_44100Hz.webm"
+    };
+
+    public void testPlay00() throws Exception {
+        doTestVideoPlaybackShort(0);
+    }
+
+    public void testPlay01() throws Exception {
+        doTestVideoPlaybackShort(1);
+    }
+
+    public void testPlay02() throws Exception {
+        doTestVideoPlaybackShort(2);
+    }
+
+    public void testPlay03() throws Exception {
+        doTestVideoPlaybackShort(3);
+    }
+
+    public void testPlay04() throws Exception {
+        doTestVideoPlaybackShort(4);
+    }
+
+    public void testPlay05() throws Exception {
+        doTestVideoPlaybackShort(5);
+    }
+
+    public void testPlay06() throws Exception {
+        doTestVideoPlaybackShort(6);
+    }
+
+    public void testPlay07() throws Exception {
+        doTestVideoPlaybackShort(7);
+    }
+
+    public void testPlay08() throws Exception {
+        doTestVideoPlaybackShort(8);
+    }
+
+    public void testPlay09() throws Exception {
+        doTestVideoPlaybackShort(9);
+    }
+
+    public void testPlay10() throws Exception {
+        doTestVideoPlaybackShort(10);
+    }
+
+    public void testPlay11() throws Exception {
+        doTestVideoPlaybackShort(11);
+    }
+
+    @Override
+    protected String getFullVideoClipName(int mediaNumber) {
+        return VIDEO_TOP_DIR + VIDEO_PATH_MIDDLE + mMedias[mediaNumber];
+    }
+
+}
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/WorkDir.java b/tests/tests/mediastress/src/android/mediastress/cts/WorkDir.java
new file mode 100644
index 0000000..4a40fad
--- /dev/null
+++ b/tests/tests/mediastress/src/android/mediastress/cts/WorkDir.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 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 android.mediastress.cts;
+
+import android.os.Environment;
+
+import java.io.File;
+
+import junit.framework.Assert;
+
+public class WorkDir {
+    static final File getTopDir() {
+        Assert.assertEquals(Environment.getExternalStorageState(), Environment.MEDIA_MOUNTED);
+        return Environment.getExternalStorageDirectory();
+    }
+
+    static final String getTopDirString() {
+        return (getTopDir().getAbsolutePath() + File.separator);
+    }
+
+    static final String getMediaDirString() {
+        return (getTopDirString() + "test/");
+    }
+}