Home | History | Annotate | Download | only in videoeditor
      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 
     18 package com.android.mediaframeworktest.functional.videoeditor;
     19 
     20 import java.io.File;
     21 import java.io.IOException;
     22 
     23 import android.graphics.Bitmap;
     24 import android.media.videoeditor.MediaImageItem;
     25 import android.media.videoeditor.MediaItem;
     26 import android.media.videoeditor.MediaVideoItem;
     27 import android.media.videoeditor.VideoEditor;
     28 import android.os.Environment;
     29 import android.test.ActivityInstrumentationTestCase;
     30 import android.test.suitebuilder.annotation.LargeTest;
     31 import com.android.mediaframeworktest.MediaFrameworkTest;
     32 import com.android.mediaframeworktest.VideoEditorHelper;
     33 
     34 public class MediaItemThumbnailTest extends
     35     ActivityInstrumentationTestCase<MediaFrameworkTest> {
     36     private final String TAG = "MediaItemThumbailTest";
     37 
     38     private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON;
     39 
     40     private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON;
     41 
     42     private VideoEditor mVideoEditor;
     43 
     44     private VideoEditorHelper mVideoEditorHelper;
     45 
     46     public MediaItemThumbnailTest() {
     47         super("com.android.mediaframeworktest", MediaFrameworkTest.class);
     48     }
     49 
     50     @Override
     51     protected void setUp() throws Exception {
     52         // setup for each test case.
     53         super.setUp();
     54         mVideoEditorHelper = new VideoEditorHelper();
     55         // Create a random String which will be used as project path, where all
     56         // project related files will be stored.
     57         final String projectPath = mVideoEditorHelper.
     58             createRandomFile(PROJECT_LOCATION);
     59         mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath);
     60     }
     61 
     62     @Override
     63     protected void tearDown() throws Exception {
     64         mVideoEditorHelper.destroyVideoEditor(mVideoEditor);
     65         // Clean the directory created as project path
     66         mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath()));
     67         System.gc();
     68         super.tearDown();
     69     }
     70 
     71     protected void validateThumbnail(Bitmap thumbNailBmp, int outWidth,
     72         int outHeight) throws Exception {
     73         assertNotNull("Thumbnail Retrived is Null", thumbNailBmp);
     74         assertEquals("Thumbnail Height", outHeight, thumbNailBmp.getHeight());
     75         assertEquals("Thumbnail Width", outWidth, thumbNailBmp.getWidth());
     76         thumbNailBmp.recycle();
     77     }
     78 
     79     // -----------------------------------------------------------------
     80     // THUMBNAIL
     81     // -----------------------------------------------------------------
     82     /**
     83      * To test thumbnail / frame extraction on H.263 QCIF.
     84      */
     85     @LargeTest
     86     public void testThumbnailForH263QCIF() throws Exception {
     87         final String videoItemFilename = INPUT_FILE_PATH
     88             + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp";
     89         final int atTime = 0;
     90         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
     91         final MediaVideoItem mediaVideoItem =
     92             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
     93                 videoItemFilename, renderingMode);
     94 
     95         final int outWidth = (mediaVideoItem.getWidth() / 2);
     96         final int outHeight = mediaVideoItem.getHeight();
     97 
     98         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
     99             outHeight, atTime);
    100         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    101     }
    102 
    103     /**
    104      * To test thumbnail / frame extraction on MPEG4 VGA .
    105      */
    106     @LargeTest
    107     public void testThumbnailForMPEG4VGA() throws Exception {
    108         final String videoItemFilename = INPUT_FILE_PATH +
    109             "MPEG4_SP_640x480_30fps_512Kbps_0_23.3gp";
    110         final int atTime = 0;
    111         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    112         final MediaVideoItem mediaVideoItem =
    113             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    114                 videoItemFilename, renderingMode);
    115         final int outWidth = (mediaVideoItem.getWidth() / 2);
    116         final int outHeight = mediaVideoItem.getHeight();
    117         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    118             outHeight, atTime);
    119         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    120     }
    121 
    122     /**
    123      * To test thumbnail / frame extraction on MPEG4 NTSC.
    124      */
    125     @LargeTest
    126     public void testThumbnailForMPEG4NTSC() throws Exception {
    127         final String videoItemFilename = INPUT_FILE_PATH
    128             + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4";
    129         final int atTime = 0;
    130         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    131         final MediaVideoItem mediaVideoItem =
    132             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    133                 videoItemFilename, renderingMode);
    134         final int outWidth = mediaVideoItem.getWidth() / 2;
    135         final int outHeight = mediaVideoItem.getHeight() / 2;
    136         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    137             outHeight, atTime);
    138         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    139     }
    140 
    141     /**
    142      * To test thumbnail / frame extraction on MPEG4 WVGA.
    143      */
    144     @LargeTest
    145     public void testThumbnailForMPEG4WVGA() throws Exception {
    146 
    147         final String videoItemFilename = INPUT_FILE_PATH
    148             + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4";
    149         final int atTime = 0;
    150         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    151         final MediaVideoItem mediaVideoItem =
    152             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    153                 videoItemFilename, renderingMode);
    154         final int outWidth = mediaVideoItem.getWidth() * 2;
    155         final int outHeight = mediaVideoItem.getHeight();
    156         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    157             outHeight, atTime);
    158         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    159     }
    160 
    161     /**
    162      * To test thumbnail / frame extraction on MPEG4 QCIF.
    163      */
    164     @LargeTest
    165     public void testThumbnailForMPEG4QCIF() throws Exception {
    166         final String videoItemFilename = INPUT_FILE_PATH
    167             + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp";
    168         final int atTime = 0;
    169         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    170 
    171         final MediaVideoItem mediaVideoItem =
    172             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    173                 videoItemFilename, renderingMode);
    174         final int outWidth = mediaVideoItem.getWidth();
    175         final int outHeight = mediaVideoItem.getHeight() * 2;
    176         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    177             outHeight, atTime);
    178         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    179     }
    180 
    181     /**
    182      * To test thumbnail / frame extraction on H264 QCIF.
    183      */
    184     @LargeTest
    185     public void testThumbnailForH264QCIF() throws Exception {
    186         final String videoItemFilename = INPUT_FILE_PATH
    187             + "H264_BP_176x144_15fps_144kbps_AMRNB_8kHz_12.2kbps_m_1_17.3gp";
    188 
    189         final int atTime = 0;
    190         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    191         final MediaVideoItem mediaVideoItem =
    192             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    193                 videoItemFilename, renderingMode);
    194         final int outWidth = mediaVideoItem.getWidth() * 2;
    195         final int outHeight = mediaVideoItem.getHeight() * 2;
    196         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    197             outHeight, atTime);
    198         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    199     }
    200 
    201     /**
    202      * To test thumbnail / frame extraction on H264 VGA.
    203      */
    204     @LargeTest
    205     public void testThumbnailForH264VGA() throws Exception {
    206         final String videoItemFilename = INPUT_FILE_PATH +
    207             "H264_BP_640x480_30fps_192kbps_1_5.mp4";
    208         final int outWidth = 32;
    209         final int outHeight = 32;
    210         final int atTime = 0;
    211 
    212         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    213         final MediaVideoItem mediaVideoItem =
    214             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    215                 videoItemFilename, renderingMode);
    216 
    217         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    218             outHeight, atTime);
    219         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    220     }
    221     /**
    222      * To test thumbnail / frame extraction on H264 WVGA.
    223      */
    224     @LargeTest
    225     public void testThumbnailForH264WVGA() throws Exception {
    226         final String videoItemFilename = INPUT_FILE_PATH +
    227             "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4";
    228         final int outWidth = 64;
    229         final int outHeight = 64;
    230         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    231         final MediaVideoItem mediaVideoItem =
    232             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    233                 videoItemFilename, renderingMode);
    234         final long atTime = mediaVideoItem.getDuration() / 2;
    235         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    236             outHeight, atTime);
    237         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    238     }
    239 
    240     /**
    241      * To test thumbnail / frame extraction on H264 854x480.
    242      */
    243     @LargeTest
    244     public void testThumbnailForH264854_480() throws Exception {
    245         final String videoItemFilename = INPUT_FILE_PATH
    246             + "MPEG4_SP_854x480_15fps_256kbps_AACLC_16khz_48kbps_s_0_26.mp4";
    247         final int outWidth = 128;
    248         final int outHeight = 128;
    249         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    250         MediaVideoItem mediaVideoItem = null;
    251         mediaVideoItem =
    252             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    253                 videoItemFilename, renderingMode);
    254         final long atTime = mediaVideoItem.getDuration() - 1000;
    255         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    256             outHeight, atTime);
    257         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    258     }
    259 
    260     /**
    261      * To test thumbnail / frame extraction on H264 960x720.
    262      */
    263     @LargeTest
    264     public void testThumbnailForH264HD960() throws Exception {
    265         final String videoItemFilename = INPUT_FILE_PATH +
    266             "H264_BP_960x720_25fps_800kbps_AACLC_48Khz_192Kbps_s_1_17.mp4";
    267         final int outWidth = 75;
    268         final int outHeight = 75;
    269 
    270         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    271         final MediaVideoItem mediaVideoItem =
    272             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    273                 videoItemFilename, renderingMode);
    274         final long atTime = mediaVideoItem.getDuration() - 1000;
    275         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    276             outHeight, atTime);
    277         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    278     }
    279 
    280     /**
    281      * To test thumbnail / frame extraction on H264 1080x720 .
    282      */
    283     @LargeTest
    284     public void testThumbnailForH264HD1080() throws Exception {
    285         final String videoItemFilename = INPUT_FILE_PATH +
    286             "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
    287         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    288         final MediaVideoItem mediaVideoItem =
    289             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    290                 videoItemFilename, renderingMode);
    291         final int outWidth = mediaVideoItem.getWidth() / 2;
    292         final int outHeight = mediaVideoItem.getHeight() / 2;
    293         final long atTime = mediaVideoItem.getDuration() / 4;
    294         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    295             outHeight, atTime);
    296         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    297     }
    298 
    299     /**
    300      * Check the thumbnail / frame extraction precision at 0,100 and 200 ms
    301      */
    302     @LargeTest
    303     public void testThumbnailForH264VGADifferentDuration() throws Exception {
    304         final String videoItemFilename = INPUT_FILE_PATH +
    305             "H264_BP_640x480_30fps_256kbps_1_17.mp4";
    306         final int atTime = 0;
    307         final int atTime1 = 100;
    308         final int atTime2 = 200;
    309         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    310 
    311         final MediaVideoItem mediaVideoItem =
    312             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    313                 videoItemFilename, renderingMode);
    314         final int outWidth = mediaVideoItem.getWidth();
    315         final int outHeight = mediaVideoItem.getHeight();
    316 
    317         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    318             outHeight, atTime);
    319         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    320 
    321         // get Thumbnail @ 100ms
    322         final Bitmap thumbNailBmpAt100 =
    323             mediaVideoItem.getThumbnail(outWidth, outHeight, atTime1);
    324         validateThumbnail(thumbNailBmpAt100, outWidth, outHeight);
    325 
    326         // get Thumbnail @ 200ms
    327         final Bitmap thumbNailBmpAt200 = mediaVideoItem.getThumbnail(
    328             outWidth, outHeight, atTime2);
    329         validateThumbnail(thumbNailBmpAt200, outWidth, outHeight);
    330     }
    331 
    332     /**
    333      *Check the thumbnail / frame extraction precision at
    334      * FileDuration,FileDuration/2 + 100 andFileDuration/2 + 200 ms
    335      */
    336     @LargeTest
    337     public void testThumbnailForMP4VGA() throws Exception {
    338         final String videoItemFilename = INPUT_FILE_PATH +
    339             "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4";
    340         final MediaVideoItem mediaVideoItem =
    341             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    342                 videoItemFilename, MediaItem.RENDERING_MODE_BLACK_BORDER);
    343 
    344         final int outWidth = mediaVideoItem.getWidth();
    345         final int outHeight = mediaVideoItem.getHeight();
    346         final long atTime = mediaVideoItem.getDuration() / 2;
    347         final long atTime1 = atTime + 100;
    348         final long atTime2 = atTime + 200;
    349 
    350         // get Thumbnail @ duration/2
    351         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    352             outHeight, atTime);
    353         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    354 
    355         // get Thumbnail @ duration/2 + 100ms
    356         final Bitmap thumbNailBmpAt100 = mediaVideoItem.getThumbnail(
    357             outWidth, outHeight, atTime1);
    358         validateThumbnail(thumbNailBmpAt100, outWidth, outHeight);
    359 
    360         // get Thumbnail @ duration/2 + 200ms
    361         final Bitmap thumbNailBmpAt200 = mediaVideoItem.getThumbnail(
    362             outWidth, outHeight, atTime2);
    363         validateThumbnail(thumbNailBmpAt200, outWidth, outHeight);
    364     }
    365 
    366     /**
    367      * Check the thumbnail / frame extraction on JPEG file
    368      */
    369     @LargeTest
    370     public void testThumbnailForImage() throws Exception {
    371         final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.jpg";
    372         final int mediaDuration = 1000;
    373         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    374         boolean flagForException = false;
    375         int outWidth = 0;
    376         int outHeight = 0;
    377 
    378         final MediaImageItem mii = mVideoEditorHelper.createMediaItem(
    379             mVideoEditor, "m1", imageItemFilename, mediaDuration, renderingMode);
    380         assertNotNull("Media Image Item is Null",  mii);
    381         outWidth =  mii.getWidth() / 2;
    382         outHeight =  mii.getHeight() / 2;
    383 
    384         final Bitmap thumbNailBmp = mii.getThumbnail(outWidth,
    385             outHeight, mediaDuration);
    386         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    387     }
    388     /**
    389      *To test ThumbnailList for H263 QCIF
    390      */
    391     @LargeTest
    392     public void testThumbnailListH263QCIF() throws Exception {
    393         final String videoItemFilename = INPUT_FILE_PATH
    394             + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp";
    395         final int startTime = 0;
    396         final int tnCount = 10;
    397         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    398         final MediaVideoItem mediaVideoItem =
    399             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    400                 videoItemFilename, renderingMode);
    401 
    402         final int outWidth = mediaVideoItem.getWidth() / 4;
    403         final int outHeight = mediaVideoItem.getHeight() / 4;
    404         final long endTime = mediaVideoItem.getDuration() / 2;
    405 
    406         final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList(
    407             outWidth, outHeight, startTime, endTime, tnCount);
    408         assertNotNull("Thumbnail Retrived is Null", thumbNailBmp);
    409         assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length);
    410 
    411         for (int i = 0; i < thumbNailBmp.length; i++) {
    412             validateThumbnail(thumbNailBmp[i], outWidth, outHeight);
    413             thumbNailBmp[i] = null;
    414         }
    415     }
    416 
    417     /**
    418      *To test ThumbnailList for MPEG4 QCIF
    419      */
    420     @LargeTest
    421     public void testThumbnailListMPEG4QCIF() throws Exception {
    422         final String videoItemFilename = INPUT_FILE_PATH
    423             + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp";
    424         final int tnCount = 10;
    425         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    426 
    427         final MediaVideoItem mediaVideoItem =
    428             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    429                 videoItemFilename, renderingMode);
    430 
    431         final int outWidth = mediaVideoItem.getWidth() / 2;
    432         final int outHeight = mediaVideoItem.getHeight() / 2;
    433         final long startTime = mediaVideoItem.getDuration() / 2;
    434         final long endTime = mediaVideoItem.getDuration();
    435 
    436         final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList(
    437             outWidth, outHeight, startTime, endTime, tnCount);
    438 
    439         assertNotNull("Thumbnail Retrived is Null", thumbNailBmp);
    440         assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length);
    441         for (int i = 0; i < thumbNailBmp.length; i++) {
    442             validateThumbnail(thumbNailBmp[i], outWidth, outHeight);
    443             thumbNailBmp[i] = null;
    444         }
    445     }
    446 
    447     /**
    448      *To test ThumbnailList for H264 VGA
    449      */
    450     @LargeTest
    451     public void testThumbnailListH264VGA() throws Exception {
    452         final String videoItemFilename = INPUT_FILE_PATH +
    453             "H264_BP_640x480_30fps_256kbps_1_17.mp4";
    454         final int tnCount = 10;
    455         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    456         final MediaVideoItem mediaVideoItem =
    457             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    458                 videoItemFilename, renderingMode);
    459 
    460         final int outWidth = mediaVideoItem.getWidth() / 2;
    461         final int outHeight = mediaVideoItem.getHeight() / 2;
    462         final long startTime = mediaVideoItem.getDuration() / 3;
    463         final long endTime = mediaVideoItem.getDuration() / 2;
    464 
    465         final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList(
    466             outWidth, outHeight, startTime, endTime, tnCount);
    467         assertNotNull("Thumbnail Retrived is Null", thumbNailBmp);
    468         assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length);
    469         for (int i = 0; i < thumbNailBmp.length; i++) {
    470             validateThumbnail(thumbNailBmp[i], outWidth, outHeight);
    471             thumbNailBmp[i] = null;
    472         }
    473     }
    474 
    475     /**
    476      *To test ThumbnailList for H264 WVGA
    477      */
    478     @LargeTest
    479     public void testThumbnailListH264WVGA() throws Exception {
    480         final String videoItemFilename = INPUT_FILE_PATH +
    481             "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4";
    482         final int tnCount = 10;
    483         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    484         final MediaVideoItem mediaVideoItem =
    485             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    486                 videoItemFilename, renderingMode);
    487 
    488         final int outWidth = mediaVideoItem.getWidth() / 2;
    489         final int outHeight = mediaVideoItem.getHeight() / 2;
    490         final long startTime = mediaVideoItem.getDuration() / 3;
    491         final long endTime = mediaVideoItem.getDuration() / 2;
    492 
    493         final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList(
    494             outWidth, outHeight, startTime, endTime, tnCount);
    495         assertNotNull("Thumbnail Retrived is Null", thumbNailBmp);
    496         assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length);
    497         for (int i = 0; i < thumbNailBmp.length; i++) {
    498             validateThumbnail(thumbNailBmp[i], outWidth, outHeight);
    499             thumbNailBmp[i] = null;
    500         }
    501     }
    502 
    503     /**
    504      *To test ThumbnailList for H264 VGA ,Time exceeding file duration
    505      */
    506     @LargeTest
    507     public void testThumbnailH264VGAExceedingFileDuration() throws Exception {
    508         final String videoItemFilename = INPUT_FILE_PATH +
    509             "H264_BP_640x480_30fps_256kbps_1_17.mp4";
    510         boolean flagForException = false;
    511         int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    512 
    513         try {
    514             final MediaVideoItem mediaVideoItem =
    515                 mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    516                     videoItemFilename, renderingMode);
    517             final int outWidth = mediaVideoItem.getWidth() / 2;
    518             final int outHeight = mediaVideoItem.getHeight() / 2;
    519             final long atTime = mediaVideoItem.getDuration() + 2000;
    520             mediaVideoItem.getThumbnail(outWidth, outHeight, atTime);
    521         } catch (IllegalArgumentException e) {
    522             flagForException = true;
    523         }
    524         assertTrue("Exception in Extracting thumbanil with Invalid Time",
    525             flagForException);
    526     }
    527 
    528     /**
    529      *To test ThumbnailList for VGA Image
    530      */
    531     @LargeTest
    532     public void testThumbnailListVGAImage() throws Exception {
    533         final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.jpg";
    534         final int imageItemDuration = 10000;
    535         final int startTime = 0;
    536         final int endTime = 0;
    537         final int tnCount = 10;
    538         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    539 
    540         final MediaImageItem mediaImageItem =
    541             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    542                 imageItemFilename, imageItemDuration, renderingMode);
    543         final int outWidth = mediaImageItem.getWidth() / 2;
    544         final int outHeight = mediaImageItem.getHeight() / 2;
    545 
    546         final Bitmap thumbNailBmp[] = mediaImageItem.getThumbnailList
    547             (outWidth, outHeight, startTime, endTime, tnCount);
    548         assertNotNull("Thumbnail Retrived is Null", thumbNailBmp);
    549         assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length);
    550         for (int i = 0; i < thumbNailBmp.length; i++) {
    551             validateThumbnail(thumbNailBmp[i], outWidth, outHeight);
    552             thumbNailBmp[i] = null;
    553         }
    554     }
    555 
    556     /**
    557      *To test ThumbnailList for Invalid file path
    558      */
    559     @LargeTest
    560     public void testThumbnailForInvalidFilePath() throws Exception {
    561         final String imageItemFileName = INPUT_FILE_PATH + "/sdcard/abc.jpg";
    562         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    563         boolean flagForException = false;
    564         try{
    565         final MediaImageItem mii = new MediaImageItem(mVideoEditor, "m1",
    566             imageItemFileName, 3000, renderingMode);
    567         } catch (IllegalArgumentException e) {
    568             flagForException = true;
    569         } catch (IOException e) {
    570             flagForException = true;
    571         }
    572         assertTrue(" Invalid File Path", flagForException);
    573     }
    574 
    575     /**
    576      * To test thumbnail / frame extraction with setBoundaries
    577      */
    578     @LargeTest
    579     public void testThumbnailForMPEG4WVGAWithSetBoundaries() throws Exception {
    580         final String videoItemFilename = INPUT_FILE_PATH +
    581             "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4";
    582         final int atTime = 10000;
    583         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    584         final MediaVideoItem mediaVideoItem =
    585             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    586                 videoItemFilename, renderingMode);
    587 
    588         mediaVideoItem.setExtractBoundaries(1000,
    589             (mediaVideoItem.getDuration() - 21000));
    590 
    591         final int outWidth = (mediaVideoItem.getWidth() / 2);
    592         final int outHeight = (mediaVideoItem.getHeight() / 2);
    593         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth,
    594             outHeight, atTime);
    595         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    596     }
    597 
    598     /**
    599      *To test ThumbnailList for H264 WVGA with setExtractboundaries
    600      */
    601     @LargeTest
    602     public void testThumbnailListForH264WVGAWithSetBoundaries() throws Exception {
    603         final String videoItemFilename = INPUT_FILE_PATH +
    604             "H264_BP_800x480_15fps_512kbps_1_17.mp4";
    605         final int thumbNailStartTime = 10000;
    606         final int thumbNailEndTime = 12000;
    607         final int tnCount = 10;
    608         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    609         final MediaVideoItem mediaVideoItem =
    610             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    611                 videoItemFilename, renderingMode);
    612 
    613         final int outWidth = (mediaVideoItem.getWidth() / 2);
    614         final int outHeight = (mediaVideoItem.getHeight() / 2);
    615 
    616         mediaVideoItem.setExtractBoundaries(10000, 12000);
    617 
    618         final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList
    619             (outWidth, outHeight, thumbNailStartTime, thumbNailEndTime,
    620              tnCount);
    621         assertNotNull("Thumbnail Retrived is Null", thumbNailBmp);
    622         assertTrue("Thumbnail Size", (thumbNailBmp.length > 0) ? true : false);
    623         for (int i = 0; i < thumbNailBmp.length; i++) {
    624             validateThumbnail(thumbNailBmp[i], outWidth, outHeight);
    625             thumbNailBmp[i] = null;
    626         }
    627     }
    628 
    629     /**
    630      *To test ThumbnailList for H264 WVGA with count > frame available
    631      */
    632     @LargeTest
    633     public void testThumbnailListForH264WVGAWithCount() throws Exception {
    634         final String videoItemFilename = INPUT_FILE_PATH +
    635             "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4";
    636         final int tnCount = 70;
    637         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    638         final MediaVideoItem mediaVideoItem =
    639             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    640                 videoItemFilename, renderingMode);
    641 
    642         final int outWidth = (mediaVideoItem.getWidth() / 2);
    643         final int outHeight = (mediaVideoItem.getHeight() / 2);
    644         final long thumbNailStartTime = mediaVideoItem.getDuration() / 2;
    645         final long thumbNailEndTime = thumbNailStartTime + 4000;
    646         Bitmap thumbNailBmp[] = null;
    647         boolean flagForException = false;
    648         try{
    649             thumbNailBmp = mediaVideoItem.getThumbnailList(outWidth, outHeight,
    650                 thumbNailStartTime, thumbNailEndTime, tnCount);
    651         }catch (Exception e){
    652             assertTrue("Unable to get Thumbnail list", flagForException);
    653         }
    654         if (thumbNailBmp.length <= tnCount) {
    655             flagForException = true;
    656         }
    657         assertTrue("Thumbnail count more than asked", flagForException);
    658     }
    659 
    660     /**
    661      *To test ThumbnailList for H264 WVGA with startTime > End Time
    662      */
    663     @LargeTest
    664     public void testThumbnailListH264WVGAWithStartGreaterEnd() throws Exception {
    665         final String videoItemFilename = INPUT_FILE_PATH +
    666             "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4";
    667         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    668         final int tnCount = 10;
    669         boolean flagForException = false;
    670         final MediaVideoItem mediaVideoItem =
    671             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    672                 videoItemFilename, renderingMode);
    673         final int outWidth = (mediaVideoItem.getWidth() / 2);
    674         final int outHeight = (mediaVideoItem.getHeight() / 2);
    675         final long thumbNailStartTime = mediaVideoItem.getDuration() / 2;
    676         final long thumbNailEndTime = thumbNailStartTime - 1000;
    677         try{
    678             mediaVideoItem.getThumbnailList(outWidth, outHeight,
    679                 thumbNailStartTime, thumbNailEndTime, tnCount);
    680         } catch (IllegalArgumentException e) {
    681             flagForException = true;
    682         }
    683         assertTrue("Thumbnail Extraction where start time > end time",
    684             flagForException);
    685     }
    686 
    687     /**
    688      *To test ThumbnailList for H264 WVGA with startTime = End Time
    689      */
    690     @LargeTest
    691     public void testThumbnailListH264WVGAWithStartEqualEnd() throws Exception {
    692         final String videoItemFilename = INPUT_FILE_PATH +
    693             "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4";
    694         final int tnCount = 1;
    695         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    696 
    697         final MediaVideoItem mediaVideoItem =
    698             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    699                 videoItemFilename, renderingMode);
    700         final int outWidth = (mediaVideoItem.getWidth() / 2);
    701         final int outHeight = (mediaVideoItem.getHeight() / 2);
    702         final long thumbNailStartTime = mediaVideoItem.getDuration() / 2;
    703         final long thumbNailEndTime = thumbNailStartTime;
    704         final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList(outWidth,
    705             outHeight, thumbNailStartTime, thumbNailEndTime, tnCount);
    706         assertNotNull("Thumbnail Retrived is Null", thumbNailBmp);
    707         assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length);
    708         for (int i = 0; i < thumbNailBmp.length; i++) {
    709             validateThumbnail(thumbNailBmp[i], outWidth, outHeight);
    710             thumbNailBmp[i] = null;
    711         }
    712     }
    713 
    714     /**
    715      *To test ThumbnailList for file where video duration is less
    716      * than file duration.
    717      */
    718     @LargeTest
    719     public void testThumbnailForVideoDurationLessFileDuration() throws Exception {
    720         final String videoItemFilename = INPUT_FILE_PATH
    721             + "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_64kps_m_0_27.3gp";
    722         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    723             final MediaVideoItem mediaVideoItem =
    724                 mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    725                     videoItemFilename, renderingMode);
    726             final int outWidth = (mediaVideoItem.getWidth() / 2);
    727             final int outHeight = (mediaVideoItem.getHeight() / 2);
    728             final long atTime = mediaVideoItem.getDuration() - 2000;
    729             final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth,
    730                 outHeight, atTime);
    731         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    732 
    733     }
    734 
    735     /**
    736      *To test ThumbnailList for file which has video part corrupted
    737      */
    738     @LargeTest
    739     public void testThumbnailWithCorruptedVideoPart() throws Exception {
    740         final String videoItemFilename = INPUT_FILE_PATH +
    741             "corrupted_H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4";
    742         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    743         boolean flagForException = false;
    744 
    745         try {
    746             final MediaVideoItem mediaVideoItem =
    747                  mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    748                     videoItemFilename, renderingMode);
    749             final int outWidth = mediaVideoItem.getWidth();
    750             final int outHeight = mediaVideoItem.getHeight() * 2;
    751             final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail
    752                 (outWidth, outHeight, mediaVideoItem.getDuration()/2);
    753         } catch (IllegalArgumentException e) {
    754             flagForException = true;
    755         }
    756         assertTrue("Corrupted File cannot be read", flagForException);
    757     }
    758 
    759     /**
    760      * Check the thumbnail / frame list extraction for Height as Negative Value
    761      */
    762     @LargeTest
    763     public void testThumbnailWithNegativeHeight() throws Exception {
    764         final String videoItemFilename = INPUT_FILE_PATH
    765             + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp";
    766         final int tnCount = 10;
    767         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    768         boolean flagForException = false;
    769         try {
    770             final MediaVideoItem mediaVideoItem =
    771                 mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    772                     videoItemFilename, renderingMode);
    773             final int outWidth = (mediaVideoItem.getWidth() / 2);
    774             final int outHeight = -1;
    775             final long thumbNailStartTime =
    776                 mediaVideoItem.getBoundaryBeginTime()/2;
    777             final long thumbNailEndTime = mediaVideoItem.getBoundaryEndTime();
    778             mediaVideoItem.getThumbnailList(outWidth, outHeight,
    779                 thumbNailStartTime, thumbNailEndTime, tnCount);
    780         } catch (IllegalArgumentException e) {
    781             flagForException = true;
    782         }
    783         assertTrue("Thumbnail List with negative Height", flagForException);
    784     }
    785 
    786     /**
    787      * Check the thumbnail for Height as Zero
    788      */
    789     @LargeTest
    790     public void testThumbnailWithHeightAsZero() throws Exception {
    791         final String videoItemFilename = INPUT_FILE_PATH
    792             + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp";
    793         final int atTime = 100;
    794         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    795         boolean flagForException = false;
    796         try {
    797             final MediaVideoItem mediaVideoItem =
    798                 mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    799                     videoItemFilename, renderingMode);
    800             final int outWidth = (mediaVideoItem.getWidth() / 2);
    801             final int outHeight = -1;
    802             mediaVideoItem.getThumbnail(outWidth, outHeight, atTime);
    803         } catch (IllegalArgumentException e) {
    804             flagForException = true;
    805         }
    806         assertTrue("Thumbnail List with Zero Height", flagForException);
    807     }
    808 
    809     /**
    810      * Check the thumbnail for Height = 10
    811      */
    812     @LargeTest
    813     public void testThumbnailWithHeight() throws Exception {
    814         final String videoItemFilename = INPUT_FILE_PATH
    815             + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp";
    816         final int atTime = 1000;
    817         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    818             final MediaVideoItem mediaVideoItem =
    819                 mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    820                     videoItemFilename, renderingMode);
    821             final int outWidth = (mediaVideoItem.getWidth() / 2);
    822             final int outHeight = 10;
    823             final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth,
    824                 outHeight, atTime);
    825         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    826     }
    827 
    828     /**
    829      * Check the thumbnail / frame list extraction for Width as Negative Value
    830      */
    831     @LargeTest
    832     public void testThumbnailWithNegativeWidth() throws Exception {
    833         final String videoItemFilename = INPUT_FILE_PATH
    834             + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp";
    835         final int tnCount = 10;
    836         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    837         boolean flagForException = false;
    838         try {
    839             final MediaVideoItem mediaVideoItem =
    840                 mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    841                     videoItemFilename, renderingMode);
    842             final int outWidth = -1;
    843             final int outHeight = mediaVideoItem.getHeight();
    844             final long thumbNailStartTime =
    845                 mediaVideoItem.getBoundaryBeginTime()/2;
    846             final long thumbNailEndTime = mediaVideoItem.getBoundaryEndTime();
    847             mediaVideoItem.getThumbnailList(outWidth, outHeight, thumbNailStartTime,
    848                 thumbNailEndTime, tnCount);
    849         } catch (IllegalArgumentException e) {
    850             flagForException = true;
    851         }
    852         assertTrue("Thumbnail List with negative Height", flagForException);
    853     }
    854 
    855     /**
    856      * Check the thumbnail / frame list extraction for Width zero
    857      */
    858     @LargeTest
    859     public void testThumbnailWithWidthAsZero() throws Exception {
    860         final String videoItemFilename = INPUT_FILE_PATH
    861             + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp";
    862         final int atTime = 1000;
    863         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    864         boolean flagForException = false;
    865         try {
    866             final MediaVideoItem mediaVideoItem =
    867                 mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    868                     videoItemFilename, renderingMode);
    869             final int outWidth = 0;
    870             final int outHeight = mediaVideoItem.getHeight() / 2;
    871             mediaVideoItem.getThumbnail(outWidth, outHeight, atTime);
    872         } catch (IllegalArgumentException e) {
    873             flagForException = true;
    874         }
    875         assertTrue("Thumbnail List with Zero Width", flagForException);
    876     }
    877 
    878     /**
    879      * Check the thumbnail for Width = 10
    880      */
    881     @LargeTest
    882     public void testThumbnailWithWidth() throws Exception {
    883         final String videoItemFilename = INPUT_FILE_PATH
    884             + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp";
    885         final int atTime = 1000;
    886         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    887         final MediaVideoItem mediaVideoItem =
    888             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    889                 videoItemFilename, renderingMode);
    890         final int outWidth = 10;
    891         final int outHeight = mediaVideoItem.getHeight();
    892         final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth,
    893             outHeight, atTime);
    894         validateThumbnail(thumbNailBmp, outWidth, outHeight);
    895     }
    896 
    897     /**
    898      * To test thumbnail / frame extraction on MPEG4 (time beyond file duration).
    899      */
    900     @LargeTest
    901     public void testThumbnailMPEG4withMorethanFileDuration() throws Exception {
    902         final String videoItemFilename = INPUT_FILE_PATH
    903             + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp";
    904         boolean flagForException = false;
    905         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    906         final MediaVideoItem mediaVideoItem =
    907             mVideoEditorHelper.createMediaItem(mVideoEditor, "m1",
    908                 videoItemFilename, renderingMode);
    909         final int outWidth =  mediaVideoItem.getWidth()/2;
    910         final int outHeight =  mediaVideoItem.getHeight()/2;
    911         final long atTime = mediaVideoItem.getDuration() + 100;
    912         try{
    913             final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth,
    914             outHeight, atTime);
    915         } catch (IllegalArgumentException e) {
    916             flagForException = true;
    917         }
    918         assertTrue("Thumbnail duration is more than file duration",
    919             flagForException);
    920     }
    921 }
    922