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 android.media.videoeditor;
     19 
     20 import android.media.videoeditor.VideoEditorProfile;
     21 import android.util.Pair;
     22 import java.lang.System;
     23 /**
     24  * This class defines all properties of a media file such as supported height,
     25  * aspect ratio, bitrate for export function.
     26  * {@hide}
     27  */
     28 public class MediaProperties {
     29     /**
     30      *  Supported heights
     31      */
     32     public static final int HEIGHT_144 = 144;
     33     public static final int HEIGHT_288 = 288;
     34     public static final int HEIGHT_360 = 360;
     35     public static final int HEIGHT_480 = 480;
     36     public static final int HEIGHT_720 = 720;
     37     public static final int HEIGHT_1080 = 1080;
     38 
     39     /**
     40      *  Supported aspect ratios
     41      */
     42     public static final int ASPECT_RATIO_UNDEFINED = 0;
     43     public static final int ASPECT_RATIO_3_2 = 1;
     44     public static final int ASPECT_RATIO_16_9 = 2;
     45     public static final int ASPECT_RATIO_4_3 = 3;
     46     public static final int ASPECT_RATIO_5_3 = 4;
     47     public static final int ASPECT_RATIO_11_9 = 5;
     48 
     49     /**
     50      *  The array of supported aspect ratios
     51      */
     52     private static final int[] ASPECT_RATIOS = new int[] {
     53         ASPECT_RATIO_3_2,
     54         ASPECT_RATIO_16_9,
     55         ASPECT_RATIO_4_3,
     56         ASPECT_RATIO_5_3,
     57         ASPECT_RATIO_11_9
     58     };
     59 
     60     /**
     61      *  Supported resolutions for specific aspect ratios
     62      */
     63     @SuppressWarnings({"unchecked"})
     64     private static final Pair<Integer, Integer>[] ASPECT_RATIO_3_2_RESOLUTIONS =
     65         new Pair[] {
     66         new Pair<Integer, Integer>(720, HEIGHT_480),
     67         new Pair<Integer, Integer>(1080, HEIGHT_720)
     68     };
     69 
     70     @SuppressWarnings({"unchecked"})
     71     private static final Pair<Integer, Integer>[] ASPECT_RATIO_4_3_RESOLUTIONS =
     72         new Pair[] {
     73         new Pair<Integer, Integer>(640, HEIGHT_480),
     74         new Pair<Integer, Integer>(960, HEIGHT_720)
     75     };
     76 
     77     @SuppressWarnings({"unchecked"})
     78     private static final Pair<Integer, Integer>[] ASPECT_RATIO_5_3_RESOLUTIONS =
     79         new Pair[] {
     80         new Pair<Integer, Integer>(800, HEIGHT_480)
     81     };
     82 
     83     @SuppressWarnings({"unchecked"})
     84     private static final Pair<Integer, Integer>[] ASPECT_RATIO_11_9_RESOLUTIONS =
     85         new Pair[] {
     86         new Pair<Integer, Integer>(176, HEIGHT_144),
     87         new Pair<Integer, Integer>(352, HEIGHT_288)
     88     };
     89 
     90     @SuppressWarnings({"unchecked"})
     91     private static final Pair<Integer, Integer>[] ASPECT_RATIO_16_9_RESOLUTIONS =
     92         new Pair[] {
     93         new Pair<Integer, Integer>(848, HEIGHT_480),
     94         new Pair<Integer, Integer>(1280, HEIGHT_720),
     95         new Pair<Integer, Integer>(1920, HEIGHT_1080),
     96     };
     97 
     98     /**
     99      *  Bitrate values (in bits per second)
    100      */
    101     public static final int BITRATE_28K = 28000;
    102     public static final int BITRATE_40K = 40000;
    103     public static final int BITRATE_64K = 64000;
    104     public static final int BITRATE_96K = 96000;
    105     public static final int BITRATE_128K = 128000;
    106     public static final int BITRATE_192K = 192000;
    107     public static final int BITRATE_256K = 256000;
    108     public static final int BITRATE_384K = 384000;
    109     public static final int BITRATE_512K = 512000;
    110     public static final int BITRATE_800K = 800000;
    111     public static final int BITRATE_2M = 2000000;
    112     public static final int BITRATE_5M = 5000000;
    113     public static final int BITRATE_8M = 8000000;
    114 
    115     /**
    116      *  The array of supported bitrates
    117      */
    118     private static final int[] SUPPORTED_BITRATES = new int[] {
    119         BITRATE_28K,
    120         BITRATE_40K,
    121         BITRATE_64K,
    122         BITRATE_96K,
    123         BITRATE_128K,
    124         BITRATE_192K,
    125         BITRATE_256K,
    126         BITRATE_384K,
    127         BITRATE_512K,
    128         BITRATE_800K,
    129         BITRATE_2M,
    130         BITRATE_5M,
    131         BITRATE_8M
    132     };
    133 
    134     /**
    135      *  Video codec types
    136      */
    137     public static final int VCODEC_H263 = 1;
    138     public static final int VCODEC_H264 = 2;
    139     public static final int VCODEC_MPEG4 = 3;
    140 
    141     /**
    142      *  The array of supported video codecs
    143      */
    144     private static final int[] SUPPORTED_VCODECS = new int[] {
    145         VCODEC_H264,
    146         VCODEC_H263,
    147         VCODEC_MPEG4,
    148     };
    149 
    150     /**
    151      *  The H264 profile, the values are same as the one in OMX_Video.h
    152      */
    153     public final class H264Profile {
    154         public static final int H264ProfileBaseline = 0x01; /**< Baseline profile */
    155         public static final int H264ProfileMain     = 0x02; /**< Main profile */
    156         public static final int H264ProfileExtended = 0x04; /**< Extended profile */
    157         public static final int H264ProfileHigh     = 0x08; /**< High profile */
    158         public static final int H264ProfileHigh10   = 0x10; /**< High 10 profile */
    159         public static final int H264ProfileHigh422  = 0x20; /**< High 4:2:2 profile */
    160         public static final int H264ProfileHigh444  = 0x40; /**< High 4:4:4 profile */
    161         public static final int H264ProfileUnknown  = 0x7FFFFFFF;
    162    }
    163     /**
    164      *  The H264 level, the values are same as the one in OMX_Video.h
    165      */
    166     public final class H264Level {
    167         public static final int H264Level1   = 0x01; /**< Level 1 */
    168         public static final int H264Level1b  = 0x02; /**< Level 1b */
    169         public static final int H264Level11  = 0x04; /**< Level 1.1 */
    170         public static final int H264Level12  = 0x08; /**< Level 1.2 */
    171         public static final int H264Level13  = 0x10; /**< Level 1.3 */
    172         public static final int H264Level2   = 0x20; /**< Level 2 */
    173         public static final int H264Level21  = 0x40; /**< Level 2.1 */
    174         public static final int H264Level22  = 0x80; /**< Level 2.2 */
    175         public static final int H264Level3   = 0x100; /**< Level 3 */
    176         public static final int H264Level31  = 0x200; /**< Level 3.1 */
    177         public static final int H264Level32  = 0x400; /**< Level 3.2 */
    178         public static final int H264Level4   = 0x800; /**< Level 4 */
    179         public static final int H264Level41  = 0x1000; /**< Level 4.1 */
    180         public static final int H264Level42  = 0x2000; /**< Level 4.2 */
    181         public static final int H264Level5   = 0x4000; /**< Level 5 */
    182         public static final int H264Level51  = 0x8000; /**< Level 5.1 */
    183         public static final int H264LevelUnknown = 0x7FFFFFFF;
    184     }
    185     /**
    186      *  The H263 profile, the values are same as the one in OMX_Video.h
    187      */
    188     public final class H263Profile {
    189         public static final int H263ProfileBaseline            = 0x01;
    190         public static final int H263ProfileH320Coding          = 0x02;
    191         public static final int H263ProfileBackwardCompatible  = 0x04;
    192         public static final int H263ProfileISWV2               = 0x08;
    193         public static final int H263ProfileISWV3               = 0x10;
    194         public static final int H263ProfileHighCompression     = 0x20;
    195         public static final int H263ProfileInternet            = 0x40;
    196         public static final int H263ProfileInterlace           = 0x80;
    197         public static final int H263ProfileHighLatency       = 0x100;
    198         public static final int H263ProfileUnknown          = 0x7FFFFFFF;
    199     }
    200     /**
    201      *  The H263 level, the values are same as the one in OMX_Video.h
    202      */
    203     public final class H263Level {
    204         public static final int H263Level10  = 0x01;
    205         public static final int H263Level20  = 0x02;
    206         public static final int H263Level30  = 0x04;
    207         public static final int H263Level40  = 0x08;
    208         public static final int H263Level45  = 0x10;
    209         public static final int H263Level50  = 0x20;
    210         public static final int H263Level60  = 0x40;
    211         public static final int H263Level70  = 0x80;
    212         public static final int H263LevelUnknown = 0x7FFFFFFF;
    213     }
    214     /**
    215      *  The mpeg4 profile, the values are same as the one in OMX_Video.h
    216      */
    217     public final class MPEG4Profile {
    218         public static final int MPEG4ProfileSimple           = 0x01;
    219         public static final int MPEG4ProfileSimpleScalable   = 0x02;
    220         public static final int MPEG4ProfileCore             = 0x04;
    221         public static final int MPEG4ProfileMain             = 0x08;
    222         public static final int MPEG4ProfileNbit             = 0x10;
    223         public static final int MPEG4ProfileScalableTexture  = 0x20;
    224         public static final int MPEG4ProfileSimpleFace       = 0x40;
    225         public static final int MPEG4ProfileSimpleFBA        = 0x80;
    226         public static final int MPEG4ProfileBasicAnimated    = 0x100;
    227         public static final int MPEG4ProfileHybrid           = 0x200;
    228         public static final int MPEG4ProfileAdvancedRealTime = 0x400;
    229         public static final int MPEG4ProfileCoreScalable     = 0x800;
    230         public static final int MPEG4ProfileAdvancedCoding   = 0x1000;
    231         public static final int MPEG4ProfileAdvancedCore     = 0x2000;
    232         public static final int MPEG4ProfileAdvancedScalable = 0x4000;
    233         public static final int MPEG4ProfileAdvancedSimple   = 0x8000;
    234         public static final int MPEG4ProfileUnknown          = 0x7FFFFFFF;
    235     }
    236     /**
    237      *  The mpeg4 level, the values are same as the one in OMX_Video.h
    238      */
    239     public final class MPEG4Level {
    240         public static final int MPEG4Level0  = 0x01; /**< Level 0 */
    241         public static final int MPEG4Level0b = 0x02; /**< Level 0b */
    242         public static final int MPEG4Level1  = 0x04; /**< Level 1 */
    243         public static final int MPEG4Level2  = 0x08; /**< Level 2 */
    244         public static final int MPEG4Level3  = 0x10; /**< Level 3 */
    245         public static final int MPEG4Level4  = 0x20; /**< Level 4 */
    246         public static final int MPEG4Level4a = 0x40; /**< Level 4a */
    247         public static final int MPEG4Level5  = 0x80; /**< Level 5 */
    248         public static final int MPEG4LevelUnknown = 0x7FFFFFFF;
    249     }
    250     /**
    251      *  Audio codec types
    252      */
    253     public static final int ACODEC_NO_AUDIO = 0;
    254     public static final int ACODEC_AMRNB = 1;
    255     public static final int ACODEC_AAC_LC = 2;
    256     public static final int ACODEC_AAC_PLUS = 3;
    257     public static final int ACODEC_ENHANCED_AAC_PLUS = 4;
    258     public static final int ACODEC_MP3 = 5;
    259     public static final int ACODEC_EVRC = 6;
    260     // 7 value is used for PCM
    261     public static final int ACODEC_AMRWB = 8;
    262     public static final int ACODEC_OGG = 9;
    263 
    264     /**
    265      *  The array of supported audio codecs
    266      */
    267     private static final int[] SUPPORTED_ACODECS = new int[] {
    268         ACODEC_AAC_LC,
    269         ACODEC_AMRNB,
    270         ACODEC_AMRWB
    271     };
    272 
    273     /**
    274      *  Samples per frame for each audio codec
    275      */
    276     public static final int SAMPLES_PER_FRAME_AAC = 1024;
    277     public static final int SAMPLES_PER_FRAME_MP3 = 1152;
    278     public static final int SAMPLES_PER_FRAME_AMRNB = 160;
    279     public static final int SAMPLES_PER_FRAME_AMRWB = 320;
    280 
    281     public static final int DEFAULT_SAMPLING_FREQUENCY = 32000;
    282     public static final int DEFAULT_CHANNEL_COUNT = 2;
    283 
    284     /**
    285      *  File format types
    286      */
    287     public static final int FILE_3GP = 0;
    288     public static final int FILE_MP4 = 1;
    289     public static final int FILE_AMR = 2;
    290     public static final int FILE_MP3 = 3;
    291     // 4 is for PCM
    292     public static final int FILE_JPEG = 5;
    293     // 6 is for BMP
    294     // 7 is for GIF
    295     public static final int FILE_PNG = 8;
    296     // 9 is for ARGB8888
    297     public static final int FILE_M4V = 10;
    298     public static final int FILE_UNSUPPORTED = 255;
    299 
    300     /**
    301      * Undefined video codec profiles
    302      */
    303     public static final int UNDEFINED_VIDEO_PROFILE = 255;
    304 
    305     /**
    306      * The array of the supported file formats
    307      */
    308     private static final int[] SUPPORTED_VIDEO_FILE_FORMATS = new int[] {
    309         FILE_3GP,
    310         FILE_MP4,
    311         FILE_M4V
    312     };
    313 
    314     /**
    315      * The maximum count of audio tracks supported
    316      */
    317     public static final int AUDIO_MAX_TRACK_COUNT = 1;
    318 
    319     /** The maximum volume supported (100 means that no amplification is
    320      * supported, i.e. attenuation only)
    321      */
    322     public static final int AUDIO_MAX_VOLUME_PERCENT = 100;
    323 
    324     /**
    325      * This class cannot be instantiated
    326      */
    327     private MediaProperties() {
    328     }
    329 
    330     /**
    331      * @return The array of supported aspect ratios
    332      */
    333     public static int[] getAllSupportedAspectRatios() {
    334         return ASPECT_RATIOS;
    335     }
    336 
    337     /**
    338      * Get the supported resolutions for the specified aspect ratio.
    339      *
    340      * @param aspectRatio The aspect ratio for which the resolutions are
    341      *        requested
    342      * @return The array of width and height pairs
    343      */
    344     public static Pair<Integer, Integer>[] getSupportedResolutions(int aspectRatio) {
    345         final Pair<Integer, Integer>[] resolutions;
    346         switch (aspectRatio) {
    347             case ASPECT_RATIO_3_2: {
    348                 resolutions = ASPECT_RATIO_3_2_RESOLUTIONS;
    349                 break;
    350             }
    351 
    352             case ASPECT_RATIO_4_3: {
    353                 resolutions = ASPECT_RATIO_4_3_RESOLUTIONS;
    354                 break;
    355             }
    356 
    357             case ASPECT_RATIO_5_3: {
    358                 resolutions = ASPECT_RATIO_5_3_RESOLUTIONS;
    359                 break;
    360             }
    361 
    362             case ASPECT_RATIO_11_9: {
    363                 resolutions = ASPECT_RATIO_11_9_RESOLUTIONS;
    364                 break;
    365             }
    366 
    367             case ASPECT_RATIO_16_9: {
    368                 resolutions = ASPECT_RATIO_16_9_RESOLUTIONS;
    369                 break;
    370             }
    371 
    372             default: {
    373                 throw new IllegalArgumentException("Unknown aspect ratio: " + aspectRatio);
    374             }
    375         }
    376 
    377         /** Check the platform specific maximum export resolution */
    378         VideoEditorProfile veProfile = VideoEditorProfile.get();
    379         if (veProfile == null) {
    380             throw new RuntimeException("Can't get the video editor profile");
    381         }
    382         final int maxWidth = veProfile.maxOutputVideoFrameWidth;
    383         final int maxHeight = veProfile.maxOutputVideoFrameHeight;
    384         Pair<Integer, Integer>[] tmpResolutions = new Pair[resolutions.length];
    385         int numSupportedResolution = 0;
    386         int i = 0;
    387 
    388         /** Get supported resolution list */
    389         for (i = 0; i < resolutions.length; i++) {
    390             if ((resolutions[i].first <= maxWidth) &&
    391                 (resolutions[i].second <= maxHeight)) {
    392                 tmpResolutions[numSupportedResolution] = resolutions[i];
    393                 numSupportedResolution++;
    394             }
    395         }
    396         final Pair<Integer, Integer>[] supportedResolutions =
    397             new Pair[numSupportedResolution];
    398         System.arraycopy(tmpResolutions, 0,
    399             supportedResolutions, 0, numSupportedResolution);
    400 
    401         return supportedResolutions;
    402     }
    403 
    404     /**
    405      * @return The array of supported video codecs
    406      */
    407     public static int[] getSupportedVideoCodecs() {
    408         return SUPPORTED_VCODECS;
    409     }
    410 
    411     /**
    412      * @return The array of supported audio codecs
    413      */
    414     public static int[] getSupportedAudioCodecs() {
    415         return SUPPORTED_ACODECS;
    416     }
    417 
    418     /**
    419      * @return The array of supported file formats
    420      */
    421     public static int[] getSupportedVideoFileFormat() {
    422         return SUPPORTED_VIDEO_FILE_FORMATS;
    423     }
    424 
    425     /**
    426      * @return The array of supported video bitrates
    427      */
    428     public static int[] getSupportedVideoBitrates() {
    429         return SUPPORTED_BITRATES;
    430     }
    431 
    432     /**
    433      * @return The maximum value for the audio volume
    434      */
    435     public static int getSupportedMaxVolume() {
    436         return MediaProperties.AUDIO_MAX_VOLUME_PERCENT;
    437     }
    438 
    439     /**
    440      * @return The maximum number of audio tracks supported
    441      */
    442     public static int getSupportedAudioTrackCount() {
    443         return MediaProperties.AUDIO_MAX_TRACK_COUNT;
    444     }
    445 }
    446