MediaProperties.java revision 83cd9dcf988b02366e095348883eca992bdbb0ed
1/* 2 * Copyright (C) 2010 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 17package android.media.videoeditor; 18 19import android.util.Pair; 20 21/** 22 * This class defines all properties of a media file such as supported height, aspect ratio, 23 * bitrate for export function. 24 * {@hide} 25 */ 26public class MediaProperties { 27 // Supported heights 28 public static final int HEIGHT_144 = 144; 29 public static final int HEIGHT_360 = 360; 30 public static final int HEIGHT_480 = 480; 31 public static final int HEIGHT_720 = 720; 32 public static final int HEIGHT_1080 = 1080; 33 34 // Supported aspect ratios 35 public static final int ASPECT_RATIO_UNDEFINED = 0; 36 public static final int ASPECT_RATIO_3_2 = 1; 37 public static final int ASPECT_RATIO_16_9 = 2; 38 public static final int ASPECT_RATIO_4_3 = 3; 39 public static final int ASPECT_RATIO_5_3 = 4; 40 public static final int ASPECT_RATIO_11_9 = 5; 41 42 // The array of supported aspect ratios 43 private static final int[] ASPECT_RATIOS = new int[] { 44 ASPECT_RATIO_3_2, 45 ASPECT_RATIO_16_9, 46 ASPECT_RATIO_4_3, 47 ASPECT_RATIO_5_3, 48 ASPECT_RATIO_11_9 49 }; 50 51 // Supported resolutions for specific aspect ratios 52 @SuppressWarnings({"unchecked"}) 53 private static final Pair<Integer, Integer>[] ASPECT_RATIO_3_2_RESOLUTIONS = 54 new Pair[] { 55 new Pair<Integer, Integer>(720, HEIGHT_480), 56 new Pair<Integer, Integer>(1080, HEIGHT_720) 57 }; 58 59 @SuppressWarnings({"unchecked"}) 60 private static final Pair<Integer, Integer>[] ASPECT_RATIO_4_3_RESOLUTIONS = 61 new Pair[] { 62 new Pair<Integer, Integer>(640, HEIGHT_480), 63 new Pair<Integer, Integer>(960, HEIGHT_720) 64 }; 65 66 @SuppressWarnings({"unchecked"}) 67 private static final Pair<Integer, Integer>[] ASPECT_RATIO_5_3_RESOLUTIONS = 68 new Pair[] { 69 new Pair<Integer, Integer>(800, HEIGHT_480) 70 }; 71 72 @SuppressWarnings({"unchecked"}) 73 private static final Pair<Integer, Integer>[] ASPECT_RATIO_11_9_RESOLUTIONS = 74 new Pair[] { 75 new Pair<Integer, Integer>(176, HEIGHT_144) 76 }; 77 78 @SuppressWarnings({"unchecked"}) 79 private static final Pair<Integer, Integer>[] ASPECT_RATIO_16_9_RESOLUTIONS = 80 new Pair[] { 81 new Pair<Integer, Integer>(640, HEIGHT_360), 82 new Pair<Integer, Integer>(854, HEIGHT_480), 83 new Pair<Integer, Integer>(1280, HEIGHT_720), 84 }; 85 86 87 // Bitrate values (in bits per second) 88 public static final int BITRATE_28K = 28000; 89 public static final int BITRATE_40K = 40000; 90 public static final int BITRATE_64K = 64000; 91 public static final int BITRATE_96K = 96000; 92 public static final int BITRATE_128K = 128000; 93 public static final int BITRATE_192K = 192000; 94 public static final int BITRATE_256K = 256000; 95 public static final int BITRATE_384K = 384000; 96 public static final int BITRATE_512K = 512000; 97 public static final int BITRATE_800K = 800000; 98 public static final int BITRATE_2M = 2000000; 99 public static final int BITRATE_5M = 5000000; 100 public static final int BITRATE_8M = 8000000; 101 102 // The array of supported bitrates 103 private static final int[] SUPPORTED_BITRATES = new int[] { 104 BITRATE_28K, 105 BITRATE_40K, 106 BITRATE_64K, 107 BITRATE_96K, 108 BITRATE_128K, 109 BITRATE_192K, 110 BITRATE_256K, 111 BITRATE_384K, 112 BITRATE_512K, 113 BITRATE_800K 114 }; 115 116 // Video codec types 117 public static final int VCODEC_H264BP = 1; 118 public static final int VCODEC_H264MP = 2; 119 public static final int VCODEC_H263 = 3; 120 public static final int VCODEC_MPEG4 = 4; 121 122 // The array of supported video codecs 123 private static final int[] SUPPORTED_VCODECS = new int[] { 124 VCODEC_H264BP, 125 VCODEC_H263, 126 VCODEC_MPEG4, 127 }; 128 129 // Audio codec types 130 public static final int ACODEC_AAC_LC = 1; 131 public static final int ACODEC_AMRNB = 2; 132 public static final int ACODEC_AMRWB = 3; 133 public static final int ACODEC_MP3 = 4; 134 public static final int ACODEC_OGG = 5; 135 136 // The array of supported video codecs 137 private static final int[] SUPPORTED_ACODECS = new int[] { 138 ACODEC_AAC_LC, 139 ACODEC_AMRNB, 140 ACODEC_AMRWB 141 }; 142 143 // File format types 144 public static final int FILE_UNSUPPORTED = 0; 145 public static final int FILE_3GP = 1; 146 public static final int FILE_MP4 = 2; 147 public static final int FILE_JPEG = 3; 148 public static final int FILE_PNG = 4; 149 150 // The array of the supported file formats 151 private static final int[] SUPPORTED_VIDEO_FILE_FORMATS = new int[] { 152 FILE_3GP, 153 FILE_MP4 154 }; 155 156 // The maximum count of audio tracks supported 157 public static final int AUDIO_MAX_TRACK_COUNT = 1; 158 159 // The maximum volume supported (100 means that no amplification is 160 // supported, i.e. attenuation only) 161 public static final int AUDIO_MAX_VOLUME_PERCENT = 100; 162 163 /** 164 * This class cannot be instantiated 165 */ 166 private MediaProperties() { 167 } 168 169 /** 170 * @return The array of supported aspect ratios 171 */ 172 public static int[] getAllSupportedAspectRatios() { 173 return ASPECT_RATIOS; 174 } 175 176 /** 177 * Get the supported resolutions for the specified aspect ratio. 178 * 179 * @param aspectRatio The aspect ratio for which the resolutions are requested 180 * 181 * @return The array of width and height pairs 182 */ 183 public static Pair<Integer, Integer>[] getSupportedResolutions(int aspectRatio) { 184 final Pair<Integer, Integer>[] resolutions; 185 switch(aspectRatio) { 186 case ASPECT_RATIO_3_2: { 187 resolutions = ASPECT_RATIO_3_2_RESOLUTIONS; 188 break; 189 } 190 191 case ASPECT_RATIO_4_3: { 192 resolutions = ASPECT_RATIO_4_3_RESOLUTIONS; 193 break; 194 } 195 196 case ASPECT_RATIO_5_3: { 197 resolutions = ASPECT_RATIO_5_3_RESOLUTIONS; 198 break; 199 } 200 201 case ASPECT_RATIO_11_9: { 202 resolutions = ASPECT_RATIO_11_9_RESOLUTIONS; 203 break; 204 } 205 206 case ASPECT_RATIO_16_9: { 207 resolutions = ASPECT_RATIO_16_9_RESOLUTIONS; 208 break; 209 } 210 211 default: { 212 throw new IllegalArgumentException("Unknown aspect ratio: " + aspectRatio); 213 } 214 } 215 216 return resolutions; 217 } 218 219 /** 220 * @return The array of supported video codecs 221 */ 222 public static int[] getSupportedVideoCodecs() { 223 return SUPPORTED_VCODECS; 224 } 225 226 /** 227 * @return The array of supported audio codecs 228 */ 229 public static int[] getSupportedAudioCodecs() { 230 return SUPPORTED_ACODECS; 231 } 232 233 /** 234 * @return The array of supported file formats 235 */ 236 public static int[] getSupportedVideoFileFormat() { 237 return SUPPORTED_VIDEO_FILE_FORMATS; 238 } 239 240 /** 241 * @return The array of supported video bitrates 242 */ 243 public static int[] getSupportedVideoBitrates() { 244 return SUPPORTED_BITRATES; 245 } 246 247 /** 248 * @return The maximum value for the audio volume 249 */ 250 public static int getSupportedMaxVolume() { 251 return MediaProperties.AUDIO_MAX_VOLUME_PERCENT; 252 } 253 254 /** 255 * @return The maximum number of audio tracks supported 256 */ 257 public static int getSupportedAudioTrackCount() { 258 return MediaProperties.AUDIO_MAX_TRACK_COUNT; 259 } 260} 261