MediaProperties.java revision 4b66f7a53f1b5a77c3ca1c12f256cdef078c1799
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 99 // The array of supported bitrates 100 private static final int[] SUPPORTED_BITRATES = new int[] { 101 BITRATE_28K, 102 BITRATE_40K, 103 BITRATE_64K, 104 BITRATE_96K, 105 BITRATE_128K, 106 BITRATE_192K, 107 BITRATE_256K, 108 BITRATE_384K, 109 BITRATE_512K, 110 BITRATE_800K 111 }; 112 113 // Video codec types 114 public static final int VCODEC_H264BP = 1; 115 public static final int VCODEC_H264MP = 2; 116 public static final int VCODEC_H263 = 3; 117 public static final int VCODEC_MPEG4 = 4; 118 119 // The array of supported video codecs 120 private static final int[] SUPPORTED_VCODECS = new int[] { 121 VCODEC_H264BP, 122 VCODEC_H263, 123 VCODEC_MPEG4, 124 }; 125 126 // Audio codec types 127 public static final int ACODEC_AAC_LC = 1; 128 public static final int ACODEC_AMRNB = 2; 129 public static final int ACODEC_AMRWB = 3; 130 public static final int ACODEC_MP3 = 4; 131 public static final int ACODEC_OGG = 5; 132 133 // The array of supported video codecs 134 private static final int[] SUPPORTED_ACODECS = new int[] { 135 ACODEC_AAC_LC, 136 ACODEC_AMRNB, 137 ACODEC_AMRWB 138 }; 139 140 // File format types 141 public static final int FILE_UNSUPPORTED = 0; 142 public static final int FILE_3GP = 1; 143 public static final int FILE_MP4 = 2; 144 public static final int FILE_JPEG = 3; 145 public static final int FILE_PNG = 4; 146 147 // The array of the supported file formats 148 private static final int[] SUPPORTED_VIDEO_FILE_FORMATS = new int[] { 149 FILE_3GP, 150 FILE_MP4 151 }; 152 153 // The maximum count of audio tracks supported 154 public static final int AUDIO_MAX_TRACK_COUNT = 1; 155 156 // The maximum volume supported (100 means that no amplification is 157 // supported, i.e. attenuation only) 158 public static final int AUDIO_MAX_VOLUME_PERCENT = 100; 159 160 /** 161 * This class cannot be instantiated 162 */ 163 private MediaProperties() { 164 } 165 166 /** 167 * @return The array of supported aspect ratios 168 */ 169 public static int[] getAllSupportedAspectRatios() { 170 return ASPECT_RATIOS; 171 } 172 173 /** 174 * Get the supported resolutions for the specified aspect ratio. 175 * 176 * @param aspectRatio The aspect ratio for which the resolutions are requested 177 * 178 * @return The array of width and height pairs 179 */ 180 public static Pair<Integer, Integer>[] getSupportedResolutions(int aspectRatio) { 181 final Pair<Integer, Integer>[] resolutions; 182 switch(aspectRatio) { 183 case ASPECT_RATIO_3_2: { 184 resolutions = ASPECT_RATIO_3_2_RESOLUTIONS; 185 break; 186 } 187 188 case ASPECT_RATIO_4_3: { 189 resolutions = ASPECT_RATIO_4_3_RESOLUTIONS; 190 break; 191 } 192 193 case ASPECT_RATIO_5_3: { 194 resolutions = ASPECT_RATIO_5_3_RESOLUTIONS; 195 break; 196 } 197 198 case ASPECT_RATIO_11_9: { 199 resolutions = ASPECT_RATIO_11_9_RESOLUTIONS; 200 break; 201 } 202 203 case ASPECT_RATIO_16_9: { 204 resolutions = ASPECT_RATIO_16_9_RESOLUTIONS; 205 break; 206 } 207 208 default: { 209 throw new IllegalArgumentException("Unknown aspect ratio: " + aspectRatio); 210 } 211 } 212 213 return resolutions; 214 } 215 216 /** 217 * @return The array of supported video codecs 218 */ 219 public static int[] getSupportedVideoCodecs() { 220 return SUPPORTED_VCODECS; 221 } 222 223 /** 224 * @return The array of supported audio codecs 225 */ 226 public static int[] getSupportedAudioCodecs() { 227 return SUPPORTED_ACODECS; 228 } 229 230 /** 231 * @return The array of supported file formats 232 */ 233 public static int[] getSupportedVideoFileFormat() { 234 return SUPPORTED_VIDEO_FILE_FORMATS; 235 } 236 237 /** 238 * @return The array of supported video bitrates 239 */ 240 public static int[] getSupportedVideoBitrates() { 241 return SUPPORTED_BITRATES; 242 } 243 244 /** 245 * @return The maximum value for the audio volume 246 */ 247 public static int getSupportedMaxVolume() { 248 return MediaProperties.AUDIO_MAX_VOLUME_PERCENT; 249 } 250 251 /** 252 * @return The maximum number of audio tracks supported 253 */ 254 public static int getSupportedAudioTrackCount() { 255 return MediaProperties.AUDIO_MAX_TRACK_COUNT; 256 } 257} 258