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