Home | History | Annotate | Download | only in stress
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.mediaframeworktest.stress;
     18 
     19 import java.io.BufferedWriter;
     20 import java.io.File;
     21 import java.io.FileOutputStream;
     22 import java.io.FileWriter;
     23 import java.io.Writer;
     24 import java.util.List;
     25 
     26 import android.graphics.Bitmap;
     27 import android.graphics.Rect;
     28 import android.media.videoeditor.AudioTrack;
     29 import android.media.videoeditor.EffectColor;
     30 import android.media.videoeditor.EffectKenBurns;
     31 import android.media.videoeditor.MediaImageItem;
     32 import android.media.videoeditor.MediaItem;
     33 import android.media.videoeditor.MediaProperties;
     34 import android.media.videoeditor.MediaVideoItem;
     35 import android.media.videoeditor.OverlayFrame;
     36 import android.media.videoeditor.Transition;
     37 import android.media.videoeditor.TransitionCrossfade;
     38 import android.media.videoeditor.TransitionAlpha;
     39 import android.media.videoeditor.TransitionFadeBlack;
     40 import android.media.videoeditor.TransitionSliding;
     41 import android.media.videoeditor.VideoEditor;
     42 import android.os.Environment;
     43 import android.test.ActivityInstrumentationTestCase;
     44 import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener;
     45 import android.os.Environment;
     46 import android.os.SystemClock;
     47 import android.test.ActivityInstrumentationTestCase;
     48 import android.media.videoeditor.VideoEditor.ExportProgressListener;
     49 import android.media.videoeditor.VideoEditorFactory;
     50 import android.media.videoeditor.ExtractAudioWaveformProgressListener;
     51 
     52 import android.os.Debug;
     53 import android.util.Log;
     54 import com.android.mediaframeworktest.MediaFrameworkPerfTestRunner;
     55 import com.android.mediaframeworktest.MediaFrameworkTest;
     56 import android.test.suitebuilder.annotation.LargeTest;
     57 import com.android.mediaframeworktest.VideoEditorHelper;
     58 import com.android.mediaframeworktest.MediaTestUtil;
     59 
     60 /**
     61  * Junit / Instrumentation - performance measurement for media player and
     62  * recorder
     63  */
     64 public class VideoEditorStressTest
     65         extends ActivityInstrumentationTestCase<MediaFrameworkTest> {
     66 
     67     private final String TAG = "VideoEditorStressTest";
     68 
     69     private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON;
     70 
     71     private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON;
     72 
     73     private final String VIDEOEDITOR_OUTPUT = PROJECT_LOCATION +
     74         "VideoEditorStressMemOutput.txt";
     75 
     76     private long BeginJavaMemory;
     77     private long AfterJavaMemory;
     78 
     79     private long BeginNativeMemory;
     80     private long AfterNativeMemory;
     81 
     82     public VideoEditorStressTest() {
     83         super("com.android.mediaframeworktest", MediaFrameworkTest.class);
     84         new File(VIDEOEDITOR_OUTPUT).delete();
     85     }
     86 
     87     private final String PROJECT_CLASS_NAME =
     88         "android.media.videoeditor.VideoEditorImpl";
     89     private VideoEditor mVideoEditor;
     90     private MediaTestUtil mMediaTestUtil;
     91     private VideoEditorHelper mVideoEditorHelper;
     92 
     93     @Override
     94     protected void setUp() throws Exception {
     95         // setup for each test case.
     96         super.setUp();
     97         getActivity();
     98         mMediaTestUtil = new MediaTestUtil(
     99             "/sdcard/VideoEditorMediaServerMemoryLog.txt",
    100              this.getName(), "mediaserver");
    101         mVideoEditorHelper = new VideoEditorHelper();
    102         // Create a random String which will be used as project path, where all
    103         // project related files will be stored.
    104         final String projectPath =
    105             mVideoEditorHelper.createRandomFile(PROJECT_LOCATION);
    106         mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath);
    107     }
    108 
    109     @Override
    110     protected void tearDown() throws Exception {
    111         final String[] loggingInfo = new String[1];
    112         mMediaTestUtil.getMemorySummary();
    113         loggingInfo[0] = "\n" +this.getName();
    114         writeTimingInfo(loggingInfo);
    115         loggingInfo[0] = " diff :  " + (AfterNativeMemory - BeginNativeMemory);
    116         writeTimingInfo(loggingInfo);
    117         mVideoEditorHelper.destroyVideoEditor(mVideoEditor);
    118         // Clean the directory created as project path
    119         mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath()));
    120         System.gc();
    121         super.tearDown();
    122     }
    123 
    124     private void writeTimingInfo(String[] information)
    125         throws Exception {
    126         File outFile = new File(VIDEOEDITOR_OUTPUT);
    127         Writer output = new BufferedWriter(new FileWriter(outFile, true));
    128         for (int i = 0; i < information.length; i++) {
    129             output.write(information[i]);
    130         }
    131         output.close();
    132     }
    133 
    134     private void writeTestCaseHeader(String testCaseName)
    135         throws Exception {
    136         File outFile = new File(VIDEOEDITOR_OUTPUT);
    137         Writer output = new BufferedWriter(new FileWriter(outFile, true));
    138         output.write("\n\n" + testCaseName + "\n");
    139         output.close();
    140     }
    141 
    142     private void getBeginMemory() throws Exception {
    143         System.gc();
    144         Thread.sleep(2500);
    145         BeginNativeMemory = Debug.getNativeHeapAllocatedSize();
    146         mMediaTestUtil.getStartMemoryLog();
    147     }
    148     private void getAfterMemory_updateLog(String[] loggingInfo, boolean when,
    149         int iteration)
    150         throws Exception {
    151         System.gc();
    152         Thread.sleep(2500);
    153         AfterNativeMemory = Debug.getNativeHeapAllocatedSize();
    154         if(when == false){
    155             loggingInfo[0] = "\n Before Remove: iteration No.= " + iteration +
    156                 "\t " + (AfterNativeMemory - BeginNativeMemory);
    157         } else {
    158             loggingInfo[0] = "\n After Remove: iteration No.= " + iteration +
    159                 "\t " + (AfterNativeMemory - BeginNativeMemory);
    160         }
    161         writeTimingInfo(loggingInfo);
    162         mMediaTestUtil.getMemoryLog();
    163     }
    164 
    165     /**
    166      * To stress test MediaItem(Video Item) adding functionality
    167      *
    168      * @throws Exception
    169      */
    170     @LargeTest
    171     public void testStressAddRemoveVideoItem() throws Exception {
    172         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    173 
    174         final String videoItemFileName1 = INPUT_FILE_PATH +
    175             "H264_BP_176x144_15fps_144kbps_AMRNB_8kHz_12.2kbps_m_1_17.3gp";
    176         final String videoItemFileName2 = INPUT_FILE_PATH +
    177             "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4";
    178         final String videoItemFileName3 = INPUT_FILE_PATH +
    179             "H263_profile0_176x144_15fps_128kbps_1_35.3gp";
    180         final String videoItemFileName4 = INPUT_FILE_PATH +
    181             "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp";
    182         final String[] loggingInfo = new String[1];
    183         writeTestCaseHeader("testStressAddRemoveVideoItem");
    184         int i = 0;
    185         getBeginMemory();
    186         for ( i = 0; i < 50; i++) {
    187             if (i % 4 == 0) {
    188                 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor,
    189                     "m1" + i, videoItemFileName1, renderingMode);
    190                 mediaItem1.setExtractBoundaries(0, 5000);
    191                 mVideoEditor.addMediaItem(mediaItem1);
    192             }
    193             if (i % 4 == 1) {
    194                 final MediaVideoItem mediaItem2 = new MediaVideoItem(mVideoEditor,
    195                     "m2" + i, videoItemFileName2, renderingMode);
    196                 mediaItem2.setExtractBoundaries(0, 10000);
    197                 mVideoEditor.addMediaItem(mediaItem2);
    198             }
    199             if (i % 4 == 2) {
    200                 final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor,
    201                     "m3" + i, videoItemFileName3, renderingMode);
    202                 mediaItem3.setExtractBoundaries(30000, 45000);
    203                 mVideoEditor.addMediaItem(mediaItem3);
    204             }
    205             if (i % 4 == 3) {
    206                 final MediaVideoItem mediaItem4 = new MediaVideoItem(mVideoEditor,
    207                     "m4" + i, videoItemFileName4, renderingMode);
    208                 mediaItem4.setExtractBoundaries(10000, 30000);
    209                 mVideoEditor.addMediaItem(mediaItem4);
    210             }
    211             if (i % 10 == 0) {
    212                 getAfterMemory_updateLog(loggingInfo, false, i);
    213             }
    214         }
    215         getAfterMemory_updateLog(loggingInfo, false, i);
    216 
    217         /** Remove items and check for memory leak if any */
    218         for ( i = 0; i < 50; i++) {
    219             if (i % 4 == 0) {
    220                 mVideoEditor.removeMediaItem("m1" + i);
    221             }
    222             if (i % 4 == 1) {
    223                 mVideoEditor.removeMediaItem("m2" + i);
    224             }
    225             if (i % 4 == 2) {
    226                 mVideoEditor.removeMediaItem("m3" + i);
    227             }
    228             if (i % 4 == 3) {
    229                 mVideoEditor.removeMediaItem("m4" + i);
    230             }
    231             if (i % 10 == 0) {
    232                 getAfterMemory_updateLog(loggingInfo, true, i);
    233             }
    234         }
    235         getAfterMemory_updateLog(loggingInfo, true, i);
    236     }
    237 
    238     /**
    239      * To stress test MediaItem(Image Item) adding functionality
    240      *
    241      * @throws Exception
    242      */
    243     @LargeTest
    244     public void testStressAddRemoveImageItem() throws Exception {
    245         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    246         final String ImageItemFileName1 = INPUT_FILE_PATH +
    247             "IMG_1600x1200.jpg";
    248         final String ImageItemFileName2 = INPUT_FILE_PATH +
    249             "IMG_640x480.jpg";
    250         final String ImageItemFileName3 = INPUT_FILE_PATH +
    251             "IMG_320x240.jpg";
    252         final String ImageItemFileName4 = INPUT_FILE_PATH +
    253             "IMG_176x144.jpg";
    254         final String[] loggingInfo = new String[1];
    255         int i = 0;
    256         writeTestCaseHeader("testStressAddRemoveImageItem");
    257         getBeginMemory();
    258         for ( i = 0; i < 50; i++) {
    259             if (i % 4 == 0) {
    260                 final MediaImageItem mediaItem1 = new MediaImageItem(mVideoEditor,
    261                     "m1"+ i, ImageItemFileName1, 5000, renderingMode);
    262                 mVideoEditor.addMediaItem(mediaItem1);
    263             }
    264             if (i % 4 == 1) {
    265                 final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor,
    266                     "m2"+ i, ImageItemFileName2, 10000, renderingMode);
    267                 mVideoEditor.addMediaItem(mediaItem2);
    268             }
    269             if (i % 4 == 2) {
    270                 final MediaImageItem mediaItem3 = new MediaImageItem(mVideoEditor,
    271                     "m3"+ i, ImageItemFileName3, 15000, renderingMode);
    272                 mVideoEditor.addMediaItem(mediaItem3);
    273             }
    274             if (i % 4 == 3) {
    275                 final MediaImageItem mediaItem4 = new MediaImageItem(mVideoEditor,
    276                     "m4"+ i, ImageItemFileName4, 20000, renderingMode);
    277                 mVideoEditor.addMediaItem(mediaItem4);
    278             }
    279             if (i % 10 == 0) {
    280                 getAfterMemory_updateLog(loggingInfo, false, i);
    281             }
    282         }
    283         getAfterMemory_updateLog(loggingInfo, false, i);
    284 
    285         /** Remove items and check for memory leak if any */
    286         for ( i = 0; i < 50; i++) {
    287             if (i % 4 == 0) {
    288                 mVideoEditor.removeMediaItem("m1"+i);
    289             }
    290             if (i % 4 == 1) {
    291                 mVideoEditor.removeMediaItem("m2"+i);
    292             }
    293             if (i % 4 == 2) {
    294                 mVideoEditor.removeMediaItem("m3"+i);
    295             }
    296             if (i % 4 == 3) {
    297                 mVideoEditor.removeMediaItem("m4"+i);
    298             }
    299             if (i % 10 == 0) {
    300                 getAfterMemory_updateLog(loggingInfo, true, i);
    301             }
    302         }
    303         getAfterMemory_updateLog(loggingInfo, true, i);
    304     }
    305 
    306     /**
    307      * To stress test transition
    308      *
    309      * @throws Exception
    310      */
    311     @LargeTest
    312     public void testStressAddRemoveTransition() throws Exception {
    313         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    314         final String VideoItemFileName1 = INPUT_FILE_PATH +
    315             "H264_BP_800x480_15fps_512kbps_1_17.mp4";
    316         final String ImageItemFileName2 = INPUT_FILE_PATH +
    317             "IMG_1600x1200.jpg";
    318         final String VideoItemFileName3 = INPUT_FILE_PATH +
    319             "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4";
    320         final String maskFilename = INPUT_FILE_PATH +
    321             "TransitionSpiral_QVGA.jpg";
    322         final String[] loggingInfo = new String[1];
    323         int i = 0;
    324         writeTestCaseHeader("testStressAddRemoveTransition");
    325         getBeginMemory();
    326         for ( i = 0; i < 50; i++) {
    327             if (i % 4 == 0) {
    328                 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor,
    329                     "m1"+i, VideoItemFileName1, renderingMode);
    330                 mVideoEditor.addMediaItem(mediaItem1);
    331                 mediaItem1.setExtractBoundaries(0, 10000);
    332                 final TransitionCrossfade tranCrossfade =
    333                     new TransitionCrossfade("transCF" + i, null,
    334                         mediaItem1, 5000, Transition.BEHAVIOR_MIDDLE_FAST);
    335                 mVideoEditor.addTransition(tranCrossfade);
    336             }
    337             if (i % 4 == 1) {
    338                 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor,
    339                     "m1"+i, VideoItemFileName1, renderingMode);
    340                 mVideoEditor.addMediaItem(mediaItem1);
    341                 mediaItem1.setExtractBoundaries(0, 10000);
    342 
    343                 final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor,
    344                     "m2" +i, ImageItemFileName2, 10000, renderingMode);
    345                 mVideoEditor.addMediaItem(mediaItem2);
    346 
    347                 final TransitionAlpha transitionAlpha =
    348                     mVideoEditorHelper.createTAlpha("transAlpha" + i, mediaItem1,
    349                         mediaItem2, 5000, Transition.BEHAVIOR_SPEED_UP,
    350                         maskFilename, 10, false);
    351                 transitionAlpha.setDuration(4000);
    352                 mVideoEditor.addTransition(transitionAlpha);
    353             }
    354             if (i % 4 == 2) {
    355                 final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor,
    356                     "m2" + i, ImageItemFileName2, 10000, renderingMode);
    357                 mVideoEditor.addMediaItem(mediaItem2);
    358 
    359                 final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor,
    360                     "m3" + i, VideoItemFileName3, renderingMode);
    361                 mVideoEditor.addMediaItem(mediaItem3);
    362 
    363                 mediaItem3.setExtractBoundaries(0, 10000);
    364                 final TransitionAlpha transitionAlpha =
    365                     mVideoEditorHelper.createTAlpha("transAlpha" + i, mediaItem2,
    366                         mediaItem3, 5000, Transition.BEHAVIOR_SPEED_UP,
    367                         maskFilename, 10, false);
    368                 transitionAlpha.setDuration(4000);
    369                 mVideoEditor.addTransition(transitionAlpha);
    370 
    371                 mediaItem3.setExtractBoundaries(0, 6000);
    372 
    373                 final TransitionSliding transition2And3 =
    374                     mVideoEditorHelper.createTSliding("transSlide" +i, mediaItem2,
    375                         mediaItem3, 3000, Transition.BEHAVIOR_MIDDLE_FAST,
    376                         TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN);
    377                 mVideoEditor.addTransition(transition2And3);
    378             }
    379             if (i % 4 == 3) {
    380                 final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor,
    381                     "m3" + i, VideoItemFileName3, renderingMode);
    382                 mVideoEditor.addMediaItem(mediaItem3);
    383                 mediaItem3.setExtractBoundaries(0, 5000);
    384 
    385                 final TransitionFadeBlack transition3 =
    386                     mVideoEditorHelper.createTFadeBlack("transFB" +i, mediaItem3,
    387                         null, 2500, Transition.BEHAVIOR_SPEED_UP);
    388                 transition3.setDuration(500);
    389                 mVideoEditor.addTransition(transition3);
    390             }
    391             if (i % 10 == 0) {
    392                 getAfterMemory_updateLog(loggingInfo, false, i);
    393             }
    394         }
    395         getAfterMemory_updateLog(loggingInfo, false, i);
    396 
    397         /** Remove items and check for memory leak if any */
    398         for ( i = 0; i < 50; i++) {
    399             if (i % 4 == 0) {
    400                 mVideoEditor.removeTransition("transCF" + i);
    401                 mVideoEditor.removeMediaItem("m1" + i);
    402             }
    403             if (i % 4 == 1) {
    404                 mVideoEditor.removeTransition("transAlpha" + i);
    405                 mVideoEditor.removeMediaItem("m1" + i);
    406                 mVideoEditor.removeMediaItem("m2" + i);
    407             }
    408             if (i % 4 == 2) {
    409                 mVideoEditor.removeTransition("transSlide" +i);
    410                 mVideoEditor.removeMediaItem("m2" + i);
    411                 mVideoEditor.removeMediaItem("m3" + i);
    412             }
    413             if (i % 4 == 3) {
    414                 mVideoEditor.removeMediaItem("m3" + i);
    415             }
    416             if (i % 10 == 0) {
    417                 getAfterMemory_updateLog(loggingInfo, true, i);
    418             }
    419         }
    420         getAfterMemory_updateLog(loggingInfo, true, i);
    421     }
    422 
    423     /**
    424      * To stress test overlay
    425      *
    426      * @throws Exception
    427      */
    428     @LargeTest
    429     public void testStressAddRemoveOverlay() throws Exception {
    430         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    431         final String VideoItemFileName1 = INPUT_FILE_PATH +
    432             "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4";
    433         final String ImageItemFileName2 = INPUT_FILE_PATH +
    434             "IMG_640x480.jpg";
    435         final String OverlayFile3 = INPUT_FILE_PATH +
    436             "IMG_640x480_Overlay1.png";
    437         final String OverlayFile4 = INPUT_FILE_PATH +
    438             "IMG_640x480_Overlay2.png";
    439         final String[] loggingInfo = new String[1];
    440         int i = 0;
    441         final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor,
    442             "m1", VideoItemFileName1, renderingMode);
    443         mVideoEditor.addMediaItem(mediaItem1);
    444 
    445         final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor,
    446             "m2", ImageItemFileName2, 10000, renderingMode);
    447         mVideoEditor.addMediaItem(mediaItem2);
    448         writeTestCaseHeader("testStressAddRemoveOverlay");
    449         getBeginMemory();
    450         for ( i = 0; i < 50; i++) {
    451             if (i % 3 == 0) {
    452                 mediaItem1.setExtractBoundaries(0, 10000);
    453                 final Bitmap mBitmap =  mVideoEditorHelper.getBitmap(
    454                     OverlayFile3, 640, 480);
    455                 final OverlayFrame overlayFrame =
    456                     mVideoEditorHelper.createOverlay(mediaItem1, "overlay" + i,
    457                         mBitmap, 1000, 5000);
    458                 mediaItem1.addOverlay(overlayFrame);
    459                 mediaItem1.removeOverlay("overlay"+i);
    460             }
    461             if (i % 3 == 1) {
    462                 final Bitmap mBitmap =  mVideoEditorHelper.getBitmap(
    463                     OverlayFile4, 640, 480);
    464                 final OverlayFrame overlayFrame =
    465                     mVideoEditorHelper.createOverlay(mediaItem2, "overlay" + i,
    466                         mBitmap, 1000, 5000);
    467                 mediaItem2.addOverlay(overlayFrame);
    468                 mediaItem2.removeOverlay("overlay"+i);
    469             }
    470             if (i % 3 == 2) {
    471                 mediaItem1.setExtractBoundaries(0, 10000);
    472                 final Bitmap mBitmap =  mVideoEditorHelper.getBitmap(
    473                     OverlayFile4, 640, 480);
    474                 final OverlayFrame overlayFrame =
    475                     mVideoEditorHelper.createOverlay(mediaItem1, "overlay" + i,
    476                         mBitmap, 0, mediaItem1.getDuration());
    477                 mediaItem1.addOverlay(overlayFrame);
    478                 mediaItem1.removeOverlay("overlay"+i);
    479             }
    480             if (i % 10 == 0) {
    481                 getAfterMemory_updateLog(loggingInfo, false, i);
    482             }
    483         }
    484         getAfterMemory_updateLog(loggingInfo, false, i);
    485     }
    486 
    487     /**
    488      * To stress test Effects
    489      *
    490      * @throws Exception
    491      */
    492     @LargeTest
    493     public void testStressAddRemoveEffects() throws Exception {
    494         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    495         final String VideoItemFileName1 = INPUT_FILE_PATH +
    496             "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp";
    497         final String ImageItemFileName2 = INPUT_FILE_PATH +
    498             "IMG_1600x1200.jpg";
    499         final String[] loggingInfo = new String[1];
    500         final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor,
    501             "m1", VideoItemFileName1, renderingMode);
    502         mVideoEditor.addMediaItem(mediaItem1);
    503         final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor,
    504             "m2", ImageItemFileName2, 10000, renderingMode);
    505         int i = 0;
    506         mVideoEditor.addMediaItem(mediaItem2);
    507         writeTestCaseHeader("testStressAddRemoveEffects");
    508         getBeginMemory();
    509         for ( i = 0; i < 50; i++) {
    510             if (i % 5 == 0) {
    511                 mediaItem1.setExtractBoundaries(10000, 30000);
    512                 final EffectColor effectColor1 =
    513                     mVideoEditorHelper.createEffectItem(mediaItem1, "effect1"+i,
    514                         10000, (mediaItem1.getTimelineDuration()-1000),
    515                         EffectColor.TYPE_COLOR, EffectColor.GREEN);
    516                 mediaItem1.addEffect(effectColor1);
    517             }
    518             if (i % 5 == 1) {
    519                 mediaItem2.setDuration(20000);
    520                 final EffectColor effectColor1 =
    521                     mVideoEditorHelper.createEffectItem(mediaItem2, "effect1"+i,
    522                         0, 4000, EffectColor.TYPE_GRADIENT, EffectColor.GRAY);
    523                 mediaItem2.addEffect(effectColor1);
    524             }
    525             if (i % 5 == 2) {
    526                 mediaItem1.setExtractBoundaries(10000, 30000);
    527                 final EffectColor effectColor1 =
    528                     mVideoEditorHelper.createEffectItem(mediaItem1, "effect1"+i,
    529                         (mediaItem1.getTimelineDuration() - 4000), 4000,
    530                         EffectColor.TYPE_SEPIA, 0);
    531                 mediaItem1.addEffect(effectColor1);
    532             }
    533             if (i % 5 == 3) {
    534                 mediaItem2.setDuration(20000);
    535                 final EffectColor effectColor1 =
    536                     mVideoEditorHelper.createEffectItem(mediaItem2, "effect1"+i,
    537                         10000, 4000, EffectColor.TYPE_NEGATIVE, 0);
    538                 mediaItem2.addEffect(effectColor1);
    539             }
    540             if (i % 5 == 4) {
    541                 mediaItem2.setDuration(20000);
    542                 final Rect startRect = new Rect((mediaItem2.getHeight() / 3),
    543                     (mediaItem2.getWidth() / 3), (mediaItem2.getHeight() / 2),
    544                     (mediaItem2.getWidth() / 2));
    545                 final Rect endRect = new Rect(0, 0, mediaItem2.getWidth(),
    546                     mediaItem2.getHeight());
    547                 final EffectKenBurns kbEffectOnMediaItem = new EffectKenBurns(
    548                     mediaItem2, "KBOnM2" + i, startRect, endRect, 500,
    549                     (mediaItem2.getDuration() - 500));
    550                 mediaItem2.addEffect(kbEffectOnMediaItem);
    551             }
    552             if (i % 10 == 0) {
    553                 getAfterMemory_updateLog(loggingInfo, false, i);
    554             }
    555         }
    556         getAfterMemory_updateLog(loggingInfo, false, i);
    557 
    558         /** Remove items and check for memory leak if any */
    559         for ( i = 0; i < 50; i++) {
    560             if (i % 5 == 0) {
    561                 mediaItem1.removeEffect("effect1"+i);
    562             }
    563             if (i % 5 == 1) {
    564                 mediaItem1.removeEffect("effect1"+i);
    565             }
    566             if (i % 5 == 2) {
    567                 mediaItem1.removeEffect("effect1"+i);
    568             }
    569             if (i % 5 == 3) {
    570                 mediaItem1.removeEffect("effect1"+i);
    571             }
    572             if (i % 5 == 4) {
    573                 mediaItem1.removeEffect("KBOnM2"+i);
    574             }
    575             if (i % 10 == 0) {
    576                 getAfterMemory_updateLog(loggingInfo, true, i);
    577             }
    578         }
    579         getAfterMemory_updateLog(loggingInfo, true, i);
    580     }
    581 
    582     /**
    583      * This method will test thumbnail list extraction in a loop = 200 for Video
    584      * Item
    585      *
    586      * @throws Exception
    587      */
    588     @LargeTest
    589     public void testStressThumbnailVideoItem() throws Exception {
    590         final String videoItemFileName = INPUT_FILE_PATH
    591                 + "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_64kps_m_0_27.3gp";
    592         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    593         final String[] loggingInfo = new String[1];
    594         int i = 0;
    595         final MediaVideoItem mediaVideoItem = new MediaVideoItem(mVideoEditor,
    596             "m1", videoItemFileName, renderingMode);
    597         writeTestCaseHeader("testStressThumbnailVideoItem");
    598         getBeginMemory();
    599         for ( i = 0; i < 50; i++) {
    600             if (i % 4 == 0) {
    601                 final Bitmap[] thumbNails =
    602                     mediaVideoItem.getThumbnailList(mediaVideoItem.getWidth()*3,
    603                         mediaVideoItem.getHeight()/2, i, 5000, 2);
    604                 // Recycle this Bitmap array
    605                 for (int i1 = 0; i1 < thumbNails.length; i1++) {
    606                     thumbNails[i1].recycle();
    607                 }
    608             }
    609             if (i % 4 == 1) {
    610                 final Bitmap[] thumbNails =
    611                     mediaVideoItem.getThumbnailList(mediaVideoItem.getWidth()/2,
    612                         mediaVideoItem.getHeight() * 3, i, 5000, 2);
    613                 // Recycle this Bitmap array
    614                 for (int i1 = 0; i1 < thumbNails.length; i1++) {
    615                     thumbNails[i1].recycle();
    616                 }
    617             }
    618             if (i % 4 == 2) {
    619                 final Bitmap[] thumbNails =
    620                     mediaVideoItem.getThumbnailList(mediaVideoItem.getWidth()*2,
    621                         mediaVideoItem.getHeight() / 3, i, 5000, 2);
    622                 // Recycle this Bitmap array
    623                 for (int i1 = 0; i1 < thumbNails.length; i1++) {
    624                     thumbNails[i1].recycle();
    625                 }
    626             }
    627             if (i % 4 == 3) {
    628                 final Bitmap[] thumbNails =
    629                     mediaVideoItem.getThumbnailList(mediaVideoItem.getWidth(),
    630                         mediaVideoItem.getHeight(), i, 5000, 2);
    631                 // Recycle this Bitmap array
    632                 for (int i1 = 0; i1 < thumbNails.length; i1++) {
    633                     thumbNails[i1].recycle();
    634                 }
    635             }
    636             if (i % 10 == 0) {
    637                 getAfterMemory_updateLog(loggingInfo, false, i);
    638             }
    639         }
    640         getAfterMemory_updateLog(loggingInfo, false, i);
    641     }
    642 
    643     /**
    644      * To stress test media properties
    645      *
    646      * @throws Exception
    647      */
    648     @LargeTest
    649     public void testStressMediaProperties() throws Exception {
    650         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    651         final String VideoItemFileName1 = INPUT_FILE_PATH +
    652             "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
    653         final String ImageItemFileName2 = INPUT_FILE_PATH +
    654             "IMG_640x480.jpg";
    655         final String AudioItemFileName3 = INPUT_FILE_PATH +
    656             "AACLC_44.1kHz_256kbps_s_1_17.mp4";
    657         final String[] loggingInfo = new String[1];
    658         int i = 0;
    659         final int videoAspectRatio = MediaProperties.ASPECT_RATIO_3_2;
    660         final int videoFileType = MediaProperties.FILE_MP4;
    661         final int videoCodecType = MediaProperties.VCODEC_H264;
    662         final int videoDuration = 77366;
    663         final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline;
    664         final int videoLevel = MediaProperties.H264Level.H264Level13;
    665         final int videoHeight = MediaProperties.HEIGHT_720;
    666         final int videoWidth = 1080;
    667 
    668         final int imageAspectRatio = MediaProperties.ASPECT_RATIO_4_3;
    669         final int imageFileType = MediaProperties.FILE_JPEG;
    670         final int imageWidth = 640;
    671         final int imageHeight = MediaProperties.HEIGHT_480;
    672 
    673         final int audioDuration = 77554;
    674         final int audioCodecType = MediaProperties.ACODEC_AAC_LC;
    675         final int audioSamplingFrequency = 44100;
    676         final int audioChannel = 2;
    677         writeTestCaseHeader("testStressMediaProperties");
    678         getBeginMemory();
    679         for ( i = 0; i < 50; i++) {
    680             if (i % 3 == 0) {
    681                 final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor,
    682                     "m1" + i, VideoItemFileName1, renderingMode);
    683                 mVideoEditor.addMediaItem(mediaItem1);
    684                 mediaItem1.setExtractBoundaries(0, 20000);
    685                 assertEquals("Aspect Ratio Mismatch",
    686                     videoAspectRatio, mediaItem1.getAspectRatio());
    687                 assertEquals("File Type Mismatch",
    688                     videoFileType, mediaItem1.getFileType());
    689                 assertEquals("VideoCodec Mismatch",
    690                     videoCodecType, mediaItem1.getVideoType());
    691                 assertEquals("duration Mismatch",
    692                     videoDuration, mediaItem1.getDuration());
    693                 assertEquals("Video Profile ",
    694                     videoProfile, mediaItem1.getVideoProfile());
    695                 assertEquals("Video Level ",
    696                     videoLevel, mediaItem1.getVideoLevel());
    697                 assertEquals("Video height ",
    698                     videoHeight, mediaItem1.getHeight());
    699                 assertEquals("Video width ",
    700                     videoWidth, mediaItem1.getWidth());
    701                 mVideoEditor.removeMediaItem("m1" + i);
    702             }
    703             if (i % 3 == 1) {
    704                 final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor,
    705                     "m2" + i, ImageItemFileName2, 10000, renderingMode);
    706                 mVideoEditor.addMediaItem(mediaItem2);
    707                 assertEquals("Aspect Ratio Mismatch",
    708                     imageAspectRatio, mediaItem2.getAspectRatio());
    709                 assertEquals("File Type Mismatch",
    710                     imageFileType, mediaItem2.getFileType());
    711                 assertEquals("Image height",
    712                     imageHeight, mediaItem2.getHeight());
    713                 assertEquals("Image width",
    714                     imageWidth, mediaItem2.getWidth());
    715                 mVideoEditor.removeMediaItem("m2" + i);
    716             }
    717             if (i % 3 == 2) {
    718                 final AudioTrack mediaItem3 = new AudioTrack(mVideoEditor,
    719                     "m3" + i, AudioItemFileName3);
    720                 mVideoEditor.addAudioTrack(mediaItem3);
    721                 assertEquals("AudioType Mismatch", audioCodecType,
    722                     mediaItem3.getAudioType());
    723                 assertEquals("Audio Sampling", audioSamplingFrequency,
    724                     mediaItem3.getAudioSamplingFrequency());
    725                 assertEquals("Audio Channels",
    726                     audioChannel, mediaItem3.getAudioChannels());
    727                 assertEquals("duration Mismatch", audioDuration,
    728                     mediaItem3.getDuration());
    729                 mVideoEditor.removeAudioTrack("m3" + i);
    730             }
    731             if (i % 10 == 0) {
    732                 getAfterMemory_updateLog(loggingInfo, false, i);
    733             }
    734         }
    735         getAfterMemory_updateLog(loggingInfo, false, i);
    736     }
    737 
    738     /**
    739      * To stress test insert and move of mediaitems
    740      *
    741      * @throws Exception
    742      */
    743     @LargeTest
    744     public void testStressInsertMovieItems() throws Exception {
    745         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    746         final String VideoItemFileName1 = INPUT_FILE_PATH +
    747             "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
    748         final String VideoItemFileName2 = INPUT_FILE_PATH +
    749             "H264_BP_800x480_15fps_512kbps_1_17.mp4";
    750         final String VideoItemFileName3 = INPUT_FILE_PATH +
    751             "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp";
    752         final String[] loggingInfo = new String[1];
    753         int i = 0;
    754         writeTestCaseHeader("testStressInsertMovieItems");
    755 
    756         final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor,
    757             "m1", VideoItemFileName1, renderingMode);
    758         mVideoEditor.addMediaItem(mediaItem1);
    759         mediaItem1.setExtractBoundaries(0, 10000);
    760 
    761         final MediaVideoItem mediaItem2 = new MediaVideoItem(mVideoEditor,
    762             "m2", VideoItemFileName2, renderingMode);
    763         mVideoEditor.addMediaItem(mediaItem2);
    764         mediaItem2.setExtractBoundaries(0, 15000);
    765 
    766         getBeginMemory();
    767         for ( i = 0; i < 50; i++) {
    768             final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor,
    769                 "m3" + i, VideoItemFileName3, renderingMode);
    770             mediaItem3.setExtractBoundaries(0, 15000);
    771             mVideoEditor.insertMediaItem(mediaItem3, "m1");
    772             mVideoEditor.moveMediaItem("m2", "m3" + i);
    773             if (i % 10 == 0) {
    774                 getAfterMemory_updateLog(loggingInfo, false, i);
    775             }
    776         }
    777         getAfterMemory_updateLog(loggingInfo, false, i);
    778 
    779         /** Remove items and check for memory leak if any */
    780         for ( i = 0; i < 50; i++) {
    781             mVideoEditor.removeMediaItem("m3" + i);
    782             if (i % 10 == 0) {
    783                 getAfterMemory_updateLog(loggingInfo, true, i);
    784             }
    785         }
    786         mVideoEditor.removeMediaItem("m2");
    787         mVideoEditor.removeMediaItem("m1");
    788         getAfterMemory_updateLog(loggingInfo, true, i);
    789     }
    790 
    791     /**
    792      * To stress test : load and save
    793      *
    794      * @throws Exception
    795      */
    796     @LargeTest
    797     public void testStressLoadAndSave() throws Exception {
    798         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    799         final String VideoItemFileName1 = INPUT_FILE_PATH +
    800             "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
    801         final String VideoItemFileName2 = INPUT_FILE_PATH +
    802             "H264_BP_800x480_15fps_512kbps_1_17.mp4";
    803         final String VideoItemFileName3 = INPUT_FILE_PATH +
    804             "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp";
    805         final String ImageItemFileName4 = INPUT_FILE_PATH +
    806             "IMG_640x480.jpg";
    807         final String ImageItemFileName5 = INPUT_FILE_PATH +
    808             "IMG_176x144.jpg";
    809         final String OverlayFile6 = INPUT_FILE_PATH +
    810             "IMG_640x480_Overlay1.png";
    811         final String[] loggingInfo = new String[1];
    812         int i = 0;
    813         final String[] projectPath = new String[10];
    814         writeTestCaseHeader("testStressLoadAndSave");
    815         getBeginMemory();
    816         for( i=0; i < 10; i++){
    817 
    818             projectPath[i] =
    819                 mVideoEditorHelper.createRandomFile(PROJECT_LOCATION);
    820             final VideoEditor mVideoEditor1 =
    821                 mVideoEditorHelper.createVideoEditor(projectPath[i]);
    822 
    823             final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor1,
    824                 "m1", VideoItemFileName1, renderingMode);
    825             mVideoEditor1.addMediaItem(mediaItem1);
    826             mediaItem1.setExtractBoundaries(0, 10000);
    827 
    828             final MediaVideoItem mediaItem2 = new MediaVideoItem(mVideoEditor1,
    829                 "m2", VideoItemFileName2, renderingMode);
    830             mVideoEditor1.addMediaItem(mediaItem2);
    831             mediaItem2.setExtractBoundaries(mediaItem2.getDuration()/4,
    832                 mediaItem2.getDuration()/2);
    833 
    834             final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor1,
    835                 "m3", VideoItemFileName3, renderingMode);
    836             mVideoEditor1.addMediaItem(mediaItem3);
    837             mediaItem3.setExtractBoundaries(mediaItem3.getDuration()/2,
    838                 mediaItem3.getDuration());
    839 
    840             final MediaImageItem mediaItem4 = new MediaImageItem(mVideoEditor1,
    841                 "m4", ImageItemFileName4, 5000, renderingMode);
    842             mVideoEditor1.addMediaItem(mediaItem4);
    843 
    844             final MediaImageItem mediaItem5 = new MediaImageItem(mVideoEditor1,
    845                 "m5", ImageItemFileName5, 5000, renderingMode);
    846             mVideoEditor1.addMediaItem(mediaItem5);
    847 
    848             final EffectColor effectColor1 =
    849                 mVideoEditorHelper.createEffectItem(mediaItem3, "effect1",
    850                     10000, 2000, EffectColor.TYPE_COLOR, EffectColor.GREEN);
    851             mediaItem3.addEffect(effectColor1);
    852 
    853             final Bitmap mBitmap =  mVideoEditorHelper.getBitmap(OverlayFile6,
    854                 640, 480);
    855             final OverlayFrame overlayFrame =
    856                 mVideoEditorHelper.createOverlay(mediaItem4, "overlay",
    857                     mBitmap, 4000, 1000);
    858             mediaItem4.addOverlay(overlayFrame);
    859 
    860             final TransitionCrossfade tranCrossfade =
    861                 new TransitionCrossfade("transCF", mediaItem1,
    862                     mediaItem2, 5000, Transition.BEHAVIOR_MIDDLE_FAST);
    863             mVideoEditor1.addTransition(tranCrossfade);
    864 
    865             final EffectColor effectColor2 =
    866                 mVideoEditorHelper.createEffectItem(mediaItem4, "effect2", 0,
    867                     mediaItem4.getDuration(), EffectColor.TYPE_COLOR,
    868                     EffectColor.PINK);
    869             mediaItem4.addEffect(effectColor2);
    870 
    871             mVideoEditor1.generatePreview(new MediaProcessingProgressListener() {
    872                 public void onProgress(Object item, int action, int progress) {
    873                 }
    874             });
    875 
    876             mVideoEditor1.save();
    877             mVideoEditor1.release();
    878 
    879             getAfterMemory_updateLog(loggingInfo, false, i);
    880         }
    881         getAfterMemory_updateLog(loggingInfo, false, i);
    882 
    883         /** Remove items and check for memory leak if any */
    884         for( i=0; i<10; i++){
    885             final VideoEditor mVideoEditor1b =
    886                 VideoEditorFactory.load(projectPath[i], true);
    887             List<MediaItem> mediaList = mVideoEditor1b.getAllMediaItems();
    888             assertEquals("Media Item List Size", 5, mediaList.size());
    889 
    890             mediaList.get(3).removeEffect("effect1");
    891             mediaList.get(3).removeEffect("effect2");
    892             mediaList.get(2).removeOverlay("overlay");
    893             mVideoEditor1b.removeTransition("transCF");
    894             mVideoEditor1b.removeMediaItem("m5");
    895             mVideoEditor1b.removeMediaItem("m4");
    896             mVideoEditor1b.removeMediaItem("m3");
    897             mVideoEditor1b.removeMediaItem("m2");
    898             mVideoEditor1b.removeMediaItem("m1");
    899             mVideoEditor1b.release();
    900             getAfterMemory_updateLog(loggingInfo, true, i);
    901         }
    902         getAfterMemory_updateLog(loggingInfo, true, i);
    903     }
    904 
    905     /**
    906      * To stress test : Multiple Export
    907      *
    908      * @throws Exception
    909      */
    910     @LargeTest
    911     public void testStressMultipleExport() throws Exception {
    912         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    913         final String VideoItemFileName1 = INPUT_FILE_PATH +
    914             "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
    915         final String VideoItemFileName2 = INPUT_FILE_PATH +
    916             "H264_BP_800x480_15fps_512kbps_1_17.mp4";
    917         final String[] loggingInfo = new String[1];
    918         final String outFilename = mVideoEditorHelper.createRandomFile(
    919             mVideoEditor.getPath() + "/") + ".3gp";
    920         int i = 0;
    921         writeTestCaseHeader("testStressMultipleExport");
    922         getBeginMemory();
    923         final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor,
    924             "m1", VideoItemFileName1, renderingMode);
    925         mVideoEditor.addMediaItem(mediaItem1);
    926         mediaItem1.setExtractBoundaries(0, 10000);
    927 
    928         final MediaVideoItem mediaItem2 = new MediaVideoItem(mVideoEditor,
    929             "m2", VideoItemFileName2, renderingMode);
    930         mVideoEditor.addMediaItem(mediaItem2);
    931         mediaItem2.setExtractBoundaries(0, 15000);
    932 
    933         for ( i = 0; i < 50; i++) {
    934             if(i%4 ==0){
    935                 final int aspectRatio = MediaProperties.ASPECT_RATIO_11_9;
    936                 mVideoEditor.setAspectRatio(aspectRatio);
    937                 mVideoEditor.export(outFilename, MediaProperties.HEIGHT_288,
    938                     MediaProperties.BITRATE_256K,MediaProperties.ACODEC_AAC_LC,
    939                         MediaProperties.VCODEC_H263,
    940                         new ExportProgressListener() {
    941                         public void onProgress(VideoEditor ve, String outFileName,
    942                             int progress) {
    943                         }
    944                     });
    945             }
    946             if(i%4 ==1){
    947                 final int aspectRatio = MediaProperties.ASPECT_RATIO_5_3;
    948                 mVideoEditor.setAspectRatio(aspectRatio);
    949                 mVideoEditor.export(outFilename, MediaProperties.HEIGHT_144,
    950                     MediaProperties.BITRATE_384K,MediaProperties.ACODEC_AAC_LC,
    951                         MediaProperties.VCODEC_MPEG4,
    952                         new ExportProgressListener() {
    953                         public void onProgress(VideoEditor ve, String outFileName,
    954                             int progress) {
    955                         }
    956                     });
    957             }
    958             if(i%4 ==2){
    959                 final int aspectRatio = MediaProperties.ASPECT_RATIO_11_9;
    960                 mVideoEditor.setAspectRatio(aspectRatio);
    961                 mVideoEditor.export(outFilename, MediaProperties.HEIGHT_144,
    962                     MediaProperties.BITRATE_512K,MediaProperties.ACODEC_AAC_LC,
    963                         MediaProperties.VCODEC_H264,
    964                         new ExportProgressListener() {
    965                         public void onProgress(VideoEditor ve, String outFileName,
    966                             int progress) {
    967                         }
    968                     });
    969             }
    970             if(i%4 ==3){
    971                 final int aspectRatio = MediaProperties.ASPECT_RATIO_3_2;
    972                 mVideoEditor.setAspectRatio(aspectRatio);
    973                 mVideoEditor.export(outFilename, MediaProperties.HEIGHT_480,
    974                     MediaProperties.BITRATE_800K,MediaProperties.ACODEC_AAC_LC,
    975                         MediaProperties.VCODEC_H264,
    976                         new ExportProgressListener() {
    977                         public void onProgress(VideoEditor ve, String outFileName,
    978                             int progress) {
    979                         }
    980                     });
    981             }
    982             if (i % 10 == 0) {
    983                 getAfterMemory_updateLog(loggingInfo, false, i);
    984             }
    985         }
    986         getAfterMemory_updateLog(loggingInfo, false, i);
    987 
    988         /** Remove items and check for memory leak if any */
    989         mVideoEditor.removeMediaItem("m2");
    990         mVideoEditor.removeMediaItem("m1");
    991 
    992         getAfterMemory_updateLog(loggingInfo, true, i);
    993     }
    994 
    995     /**
    996      * To stress test Media Item,Overlays,Transitions and Ken Burn
    997      *
    998      * @throws Exception
    999      */
   1000     @LargeTest
   1001     public void testStressOverlayTransKenBurn() throws Exception {
   1002         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
   1003         final String VideoItemFileName1 = INPUT_FILE_PATH +
   1004             "H264_BP_640x480_30fps_256kbps_1_17.mp4";
   1005         final String ImageItemFileName2 = INPUT_FILE_PATH +
   1006             "IMG_640x480.jpg";
   1007         final String OverlayFile3 = INPUT_FILE_PATH +
   1008             "IMG_640x480_Overlay1.png";
   1009         final String audioFilename4 = INPUT_FILE_PATH +
   1010             "AACLC_44.1kHz_256kbps_s_1_17.mp4";
   1011         int i = 0;
   1012         final String[] loggingInfo = new String[1];
   1013         writeTestCaseHeader("testStressOverlayTransKenBurn");
   1014         getBeginMemory();
   1015         for ( i = 0; i < 10; i++) {
   1016             final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor,
   1017                 "m1" + i, VideoItemFileName1, renderingMode);
   1018             mVideoEditor.addMediaItem(mediaItem1);
   1019             mediaItem1.setExtractBoundaries(0, 10000);
   1020 
   1021             final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor,
   1022                 "m2" + i, ImageItemFileName2, 10000, renderingMode);
   1023             mVideoEditor.addMediaItem(mediaItem2);
   1024 
   1025             final EffectColor effectColor1 =
   1026                 mVideoEditorHelper.createEffectItem(mediaItem1, "effect1"+i,
   1027                     (mediaItem1.getDuration() - 4000), 4000,
   1028                     EffectColor.TYPE_SEPIA, 0);
   1029             mediaItem1.addEffect(effectColor1);
   1030 
   1031             final TransitionCrossfade tranCrossfade =
   1032                 new TransitionCrossfade("transCF" + i, mediaItem1,
   1033                     mediaItem2, 4000, Transition.BEHAVIOR_MIDDLE_FAST);
   1034             mVideoEditor.addTransition(tranCrossfade);
   1035 
   1036             final Bitmap mBitmap =  mVideoEditorHelper.getBitmap(OverlayFile3,
   1037                 640, 480);
   1038             final OverlayFrame overlayFrame =
   1039                 mVideoEditorHelper.createOverlay(mediaItem1, "overlay" + i,
   1040                     mBitmap, 1000, 5000);
   1041             mediaItem1.addOverlay(overlayFrame);
   1042 
   1043             final Rect startRect = new Rect((mediaItem2.getHeight() / 3),
   1044                 (mediaItem2.getWidth() / 3), (mediaItem2.getHeight() / 2),
   1045                 (mediaItem2.getWidth() / 2));
   1046             final Rect endRect = new Rect(0, 0, mediaItem2.getWidth(),
   1047                 mediaItem2.getHeight());
   1048 
   1049             final EffectKenBurns kbEffectOnMediaItem = new EffectKenBurns(
   1050                 mediaItem2, "KBOnM2" + i, startRect, endRect, 500,
   1051                 (mediaItem2.getDuration()-500));
   1052             mediaItem2.addEffect(kbEffectOnMediaItem);
   1053 
   1054             if(i == 5) {
   1055                 final AudioTrack audioTrack1 = new AudioTrack(mVideoEditor,
   1056                     "Audio Track1", audioFilename4);
   1057                 mVideoEditor.addAudioTrack(audioTrack1);
   1058             }
   1059             getAfterMemory_updateLog(loggingInfo, false, i);
   1060         }
   1061         getAfterMemory_updateLog(loggingInfo, false, i);
   1062 
   1063         /** Remove items and check for memory leak if any */
   1064         for ( i = 0; i < 10; i++) {
   1065             MediaImageItem m2 = (MediaImageItem)mVideoEditor.getMediaItem("m2"+i);
   1066             MediaVideoItem m1 = (MediaVideoItem)mVideoEditor.getMediaItem("m1"+i);
   1067             m2.removeEffect("KBOnM2" + i);
   1068             m1.removeOverlay("overlay" + i);
   1069             mVideoEditor.removeTransition("transCF" + i);
   1070             m1.removeEffect("effect1" + i);
   1071             mVideoEditor.removeMediaItem("m2" + i);
   1072             mVideoEditor.removeMediaItem("m1" + i);
   1073             if(i == 5) {
   1074                 mVideoEditor.removeAudioTrack("Audio Track1");
   1075             }
   1076             getAfterMemory_updateLog(loggingInfo, true, i);
   1077         }
   1078         getAfterMemory_updateLog(loggingInfo, true, i);
   1079     }
   1080 
   1081     /**
   1082      * To test the performance : With an audio track with Video
   1083      *
   1084      * @throws Exception
   1085      */
   1086     @LargeTest
   1087     public void testStressAudioTrackVideo() throws Exception {
   1088         final String videoItemFileName1 = INPUT_FILE_PATH +
   1089             "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
   1090         final String audioFilename1 = INPUT_FILE_PATH +
   1091             "AACLC_44.1kHz_256kbps_s_1_17.mp4";
   1092         final String audioFilename2 = INPUT_FILE_PATH +
   1093             "AMRNB_8KHz_12.2Kbps_m_1_17.3gp";
   1094         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
   1095         final int audioVolume = 50;
   1096         final String[] loggingInfo = new String[1];
   1097         int i = 1;
   1098         writeTestCaseHeader("testStressAudioTrackVideo");
   1099         getBeginMemory();
   1100         final MediaVideoItem mediaVideoItem = new MediaVideoItem(mVideoEditor,
   1101             "mediaItem1", videoItemFileName1, renderingMode);
   1102         mVideoEditor.addMediaItem(mediaVideoItem);
   1103 
   1104         final AudioTrack audioTrack1 = new AudioTrack(mVideoEditor,
   1105             "Audio Track1", audioFilename1);
   1106         audioTrack1.disableDucking();
   1107         audioTrack1.setVolume(audioVolume);
   1108         mVideoEditor.addAudioTrack(audioTrack1);
   1109 
   1110         mVideoEditor.generatePreview(new MediaProcessingProgressListener() {
   1111             public void onProgress(Object item, int action, int progress) {
   1112             }
   1113         });
   1114 
   1115         mVideoEditor.removeAudioTrack("Audio Track1");
   1116 
   1117         final AudioTrack audioTrack2 = new AudioTrack(mVideoEditor,
   1118             "Audio Track2", audioFilename2);
   1119         audioTrack2.enableLoop();
   1120 
   1121         mVideoEditor.generatePreview(new MediaProcessingProgressListener() {
   1122             public void onProgress(Object item, int action, int progress) {
   1123             }
   1124         });
   1125         getAfterMemory_updateLog(loggingInfo, false, i);
   1126 
   1127         /** Remove items and check for memory leak if any */
   1128         mVideoEditor.removeMediaItem("mediaItem1");
   1129 
   1130         getAfterMemory_updateLog(loggingInfo, true, i);
   1131     }
   1132 
   1133     /**
   1134      * To Test Stress : Story Board creation with out preview or export
   1135      *
   1136      * @throws Exception
   1137      */
   1138     @LargeTest
   1139     public void testStressStoryBoard() throws Exception {
   1140         final String videoItemFileName1 = INPUT_FILE_PATH +
   1141             "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_161kbps_s_0_26.mp4";
   1142         final String videoItemFileName2 = INPUT_FILE_PATH +
   1143             "MPEG4_SP_854x480_15fps_256kbps_AACLC_16khz_48kbps_s_0_26.mp4";
   1144         final String videoItemFileName3= INPUT_FILE_PATH +
   1145             "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4";
   1146         final String imageItemFileName4 = INPUT_FILE_PATH +
   1147             "IMG_1600x1200.jpg";
   1148         final String imageItemFileName5 = INPUT_FILE_PATH +
   1149             "IMG_176x144.jpg";
   1150         final String audioFilename6 = INPUT_FILE_PATH +
   1151             "AMRNB_8KHz_12.2Kbps_m_1_17.3gp";
   1152         final String audioFilename7 = INPUT_FILE_PATH +
   1153             "AACLC_44.1kHz_256kbps_s_1_17.mp4";
   1154 
   1155         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
   1156         final int audioVolume = 50;
   1157         final String[] loggingInfo = new String[1];
   1158         int i = 1;
   1159 
   1160         writeTestCaseHeader("testStressStoryBoard");
   1161         getBeginMemory();
   1162         final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor,
   1163             "m1", videoItemFileName1, renderingMode);
   1164         mediaItem1.setExtractBoundaries(0, 10000);
   1165         mVideoEditor.addMediaItem(mediaItem1);
   1166 
   1167         final MediaVideoItem mediaItem2 = new MediaVideoItem(mVideoEditor,
   1168             "m2", videoItemFileName2, renderingMode);
   1169         mediaItem2.setExtractBoundaries(mediaItem2.getDuration()/4,
   1170             mediaItem2.getDuration()/2);
   1171         mVideoEditor.addMediaItem(mediaItem2);
   1172 
   1173         final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor,
   1174             "m3", videoItemFileName3, renderingMode);
   1175         mediaItem3.setExtractBoundaries(mediaItem3.getDuration()/2,
   1176             mediaItem3.getDuration());
   1177         mVideoEditor.addMediaItem(mediaItem3);
   1178 
   1179         final MediaImageItem mediaItem4 = new MediaImageItem(mVideoEditor,
   1180             "m4", imageItemFileName4, 5000, renderingMode);
   1181         mVideoEditor.addMediaItem(mediaItem4);
   1182 
   1183         final MediaImageItem mediaItem5 = new MediaImageItem(mVideoEditor,
   1184             "m5", imageItemFileName5, 5000, renderingMode);
   1185         mVideoEditor.addMediaItem(mediaItem5);
   1186 
   1187         final TransitionCrossfade tranCrossfade =
   1188             new TransitionCrossfade("transCF", mediaItem2, mediaItem3, 2500,
   1189                 Transition.BEHAVIOR_MIDDLE_FAST);
   1190         mVideoEditor.addTransition(tranCrossfade);
   1191 
   1192         final TransitionCrossfade tranCrossfade1 =
   1193             new TransitionCrossfade("transCF1", mediaItem3, mediaItem4, 2500,
   1194                 Transition.BEHAVIOR_MIDDLE_FAST);
   1195         mVideoEditor.addTransition(tranCrossfade1);
   1196 
   1197         final AudioTrack audioTrack1 = new AudioTrack(mVideoEditor,
   1198             "Audio Track1", audioFilename6);
   1199         mVideoEditor.addAudioTrack(audioTrack1);
   1200 
   1201         mVideoEditor.removeAudioTrack("Audio Track1");
   1202         final AudioTrack audioTrack2 = new AudioTrack(mVideoEditor,
   1203             "Audio Track2", audioFilename7);
   1204         mVideoEditor.addAudioTrack(audioTrack2);
   1205         audioTrack2.enableLoop();
   1206         getAfterMemory_updateLog(loggingInfo, false, i);
   1207 
   1208         /** Remove items and check for memory leak if any */
   1209         getBeginMemory();
   1210         mVideoEditor.removeAudioTrack("Audio Track2");
   1211         mVideoEditor.removeTransition("transCF");
   1212         mVideoEditor.removeTransition("transCF1");
   1213         mVideoEditor.removeMediaItem("m5");
   1214         mVideoEditor.removeMediaItem("m4");
   1215         mVideoEditor.removeMediaItem("m3");
   1216         mVideoEditor.removeMediaItem("m2");
   1217         mVideoEditor.removeMediaItem("m1");
   1218 
   1219         getAfterMemory_updateLog(loggingInfo, true, i);
   1220     }
   1221 
   1222      /**
   1223      * To test the performance : With an audio track Only
   1224      *
   1225      * @throws Exception
   1226      */
   1227     @LargeTest
   1228     public void testStressAudioTrackOnly() throws Exception {
   1229 
   1230         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
   1231         final String AudioItemFileName1 = INPUT_FILE_PATH +
   1232             "AACLC_44.1kHz_256kbps_s_1_17.mp4";
   1233         final String[] loggingInfo = new String[1];
   1234         int i = 0;
   1235         writeTestCaseHeader("testStressAudioTrackOnly");
   1236         getBeginMemory();
   1237         for ( i = 0; i < 50; i++) {
   1238             final AudioTrack mediaItem1 = new AudioTrack(mVideoEditor,
   1239                 "m1" + i, AudioItemFileName1);
   1240             mVideoEditor.addAudioTrack(mediaItem1);
   1241             mediaItem1.enableLoop();
   1242             mVideoEditor.removeAudioTrack("m1" + i);
   1243             if (i % 10 == 0) {
   1244                 getAfterMemory_updateLog(loggingInfo, false, i);
   1245             }
   1246         }
   1247         getAfterMemory_updateLog(loggingInfo, false, i);
   1248     }
   1249 
   1250     /**
   1251      * This method will test thumbnail list extraction in a loop = 200 for Image
   1252      * Item
   1253      *
   1254      * @throws Exception
   1255      */
   1256     @LargeTest
   1257     public void testStressThumbnailImageItem() throws Exception {
   1258         final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg";
   1259         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
   1260         final String[] loggingInfo = new String[1];
   1261         int i = 0;
   1262         final MediaImageItem mediaImageItem = new MediaImageItem(mVideoEditor,
   1263             "m1", imageItemFileName, 5000, renderingMode);
   1264         writeTestCaseHeader("testStressThumbnailImageItem");
   1265         getBeginMemory();
   1266         for ( i = 0; i < 50; i++) {
   1267             if (i % 4 == 0) {
   1268                 final Bitmap[] thumbNails = mediaImageItem.getThumbnailList(
   1269                     mediaImageItem.getWidth() / 2 ,
   1270                     mediaImageItem.getHeight() / 2, i, 5000, 2);
   1271                 // Recycle this Bitmap array
   1272                 for (int i1 = 0; i1 < thumbNails.length; i1++) {
   1273                     thumbNails[i1].recycle();
   1274                 }
   1275             }
   1276             if (i % 4 == 1) {
   1277                 final Bitmap[] thumbNails = mediaImageItem.getThumbnailList(
   1278                     mediaImageItem.getWidth() / 2,
   1279                     mediaImageItem.getHeight() * 3, i, 5000, 2);
   1280                 // Recycle this Bitmap array
   1281                 for (int i1 = 0; i1 < thumbNails.length; i1++) {
   1282                     thumbNails[i1].recycle();
   1283                 }
   1284             }
   1285             if (i % 4 == 2) {
   1286                 final Bitmap[] thumbNails = mediaImageItem.getThumbnailList(
   1287                     mediaImageItem.getWidth() * 2,
   1288                     mediaImageItem.getHeight() / 3, i, 5000, 2);
   1289                 // Recycle this Bitmap array
   1290                 for (int i1 = 0; i1 < thumbNails.length; i1++) {
   1291                     thumbNails[i1].recycle();
   1292                 }
   1293             }
   1294             if (i % 4 == 3) {
   1295                 final Bitmap[] thumbNails = mediaImageItem.getThumbnailList(
   1296                     mediaImageItem.getWidth(),
   1297                     mediaImageItem.getHeight(), i, 5000, 2);
   1298                 // Recycle this Bitmap array
   1299                 for (int i1 = 0; i1 < thumbNails.length; i1++) {
   1300                     thumbNails[i1].recycle();
   1301                 }
   1302             }
   1303             if (i % 10 == 0) {
   1304                 getAfterMemory_updateLog(loggingInfo, false, i);
   1305             }
   1306         }
   1307         getAfterMemory_updateLog(loggingInfo, false, i);
   1308     }
   1309 }
   1310