MediaProfiles.h revision 9783ed8f85af3d7c72030098acfed7e1d6638349
1/* 2 ** 3 ** Copyright 2010, The Android Open Source Project. 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18#ifndef ANDROID_MEDIAPROFILES_H 19#define ANDROID_MEDIAPROFILES_H 20 21#include <utils/threads.h> 22#include <media/mediarecorder.h> 23 24namespace android { 25 26enum camcorder_quality { 27 CAMCORDER_QUALITY_LOW = 0, 28 CAMCORDER_QUALITY_HIGH = 1, 29 CAMCORDER_QUALITY_QCIF = 2, 30 CAMCORDER_QUALITY_CIF = 3, 31 CAMCORDER_QUALITY_480P = 4, 32 CAMCORDER_QUALITY_720P = 5, 33 CAMCORDER_QUALITY_1080P = 6, 34 35 CAMCORDER_QUALITY_TIME_LAPSE_LOW = 1000, 36 CAMCORDER_QUALITY_TIME_LAPSE_HIGH = 1001, 37 CAMCORDER_QUALITY_TIME_LAPSE_QCIF = 1002, 38 CAMCORDER_QUALITY_TIME_LAPSE_CIF = 1003, 39 CAMCORDER_QUALITY_TIME_LAPSE_480P = 1004, 40 CAMCORDER_QUALITY_TIME_LAPSE_720P = 1005, 41 CAMCORDER_QUALITY_TIME_LAPSE_1080P = 1006 42}; 43 44enum video_decoder { 45 VIDEO_DECODER_WMV, 46}; 47 48enum audio_decoder { 49 AUDIO_DECODER_WMA, 50}; 51 52 53class MediaProfiles 54{ 55public: 56 57 /** 58 * Returns the singleton instance for subsequence queries. 59 * or NULL if error. 60 */ 61 static MediaProfiles* getInstance(); 62 63 /** 64 * Returns the value for the given param name for the given camera at 65 * the given quality level, or -1 if error. 66 * 67 * Supported param name are: 68 * duration - the recording duration. 69 * file.format - output file format. see mediarecorder.h for details 70 * vid.codec - video encoder. see mediarecorder.h for details. 71 * aud.codec - audio encoder. see mediarecorder.h for details. 72 * vid.width - video frame width 73 * vid.height - video frame height 74 * vid.fps - video frame rate 75 * vid.bps - video bit rate 76 * aud.bps - audio bit rate 77 * aud.hz - audio sample rate 78 * aud.ch - number of audio channels 79 */ 80 int getCamcorderProfileParamByName(const char *name, int cameraId, 81 camcorder_quality quality) const; 82 83 /** 84 * Returns true if a profile for the given camera at the given quality exists, 85 * or false if not. 86 */ 87 bool hasCamcorderProfile(int cameraId, camcorder_quality quality) const; 88 89 /** 90 * Returns the output file formats supported. 91 */ 92 Vector<output_format> getOutputFileFormats() const; 93 94 /** 95 * Returns the video encoders supported. 96 */ 97 Vector<video_encoder> getVideoEncoders() const; 98 99 /** 100 * Returns the value for the given param name for the given video encoder 101 * returned from getVideoEncoderByIndex or -1 if error. 102 * 103 * Supported param name are: 104 * enc.vid.width.min - min video frame width 105 * enc.vid.width.max - max video frame width 106 * enc.vid.height.min - min video frame height 107 * enc.vid.height.max - max video frame height 108 * enc.vid.bps.min - min bit rate in bits per second 109 * enc.vid.bps.max - max bit rate in bits per second 110 * enc.vid.fps.min - min frame rate in frames per second 111 * enc.vid.fps.max - max frame rate in frames per second 112 */ 113 int getVideoEncoderParamByName(const char *name, video_encoder codec) const; 114 115 /** 116 * Returns the audio encoders supported. 117 */ 118 Vector<audio_encoder> getAudioEncoders() const; 119 120 /** 121 * Returns the value for the given param name for the given audio encoder 122 * returned from getAudioEncoderByIndex or -1 if error. 123 * 124 * Supported param name are: 125 * enc.aud.ch.min - min number of channels 126 * enc.aud.ch.max - max number of channels 127 * enc.aud.bps.min - min bit rate in bits per second 128 * enc.aud.bps.max - max bit rate in bits per second 129 * enc.aud.hz.min - min sample rate in samples per second 130 * enc.aud.hz.max - max sample rate in samples per second 131 */ 132 int getAudioEncoderParamByName(const char *name, audio_encoder codec) const; 133 134 /** 135 * Returns the video decoders supported. 136 */ 137 Vector<video_decoder> getVideoDecoders() const; 138 139 /** 140 * Returns the audio decoders supported. 141 */ 142 Vector<audio_decoder> getAudioDecoders() const; 143 144 /** 145 * Returns the number of image encoding quality levels supported. 146 */ 147 Vector<int> getImageEncodingQualityLevels(int cameraId) const; 148 149private: 150 MediaProfiles& operator=(const MediaProfiles&); // Don't call me 151 MediaProfiles(const MediaProfiles&); // Don't call me 152 MediaProfiles() {} // Dummy default constructor 153 ~MediaProfiles(); // Don't delete me 154 155 struct VideoCodec { 156 VideoCodec(video_encoder codec, int bitRate, int frameWidth, int frameHeight, int frameRate) 157 : mCodec(codec), 158 mBitRate(bitRate), 159 mFrameWidth(frameWidth), 160 mFrameHeight(frameHeight), 161 mFrameRate(frameRate) {} 162 163 ~VideoCodec() {} 164 165 video_encoder mCodec; 166 int mBitRate; 167 int mFrameWidth; 168 int mFrameHeight; 169 int mFrameRate; 170 }; 171 172 struct AudioCodec { 173 AudioCodec(audio_encoder codec, int bitRate, int sampleRate, int channels) 174 : mCodec(codec), 175 mBitRate(bitRate), 176 mSampleRate(sampleRate), 177 mChannels(channels) {} 178 179 ~AudioCodec() {} 180 181 audio_encoder mCodec; 182 int mBitRate; 183 int mSampleRate; 184 int mChannels; 185 }; 186 187 struct CamcorderProfile { 188 CamcorderProfile() 189 : mCameraId(0), 190 mFileFormat(OUTPUT_FORMAT_THREE_GPP), 191 mQuality(CAMCORDER_QUALITY_HIGH), 192 mDuration(0), 193 mVideoCodec(0), 194 mAudioCodec(0) {} 195 196 ~CamcorderProfile() { 197 delete mVideoCodec; 198 delete mAudioCodec; 199 } 200 201 int mCameraId; 202 output_format mFileFormat; 203 camcorder_quality mQuality; 204 int mDuration; 205 VideoCodec *mVideoCodec; 206 AudioCodec *mAudioCodec; 207 }; 208 209 struct VideoEncoderCap { 210 // Ugly constructor 211 VideoEncoderCap(video_encoder codec, 212 int minBitRate, int maxBitRate, 213 int minFrameWidth, int maxFrameWidth, 214 int minFrameHeight, int maxFrameHeight, 215 int minFrameRate, int maxFrameRate) 216 : mCodec(codec), 217 mMinBitRate(minBitRate), mMaxBitRate(maxBitRate), 218 mMinFrameWidth(minFrameWidth), mMaxFrameWidth(maxFrameWidth), 219 mMinFrameHeight(minFrameHeight), mMaxFrameHeight(maxFrameHeight), 220 mMinFrameRate(minFrameRate), mMaxFrameRate(maxFrameRate) {} 221 222 ~VideoEncoderCap() {} 223 224 video_encoder mCodec; 225 int mMinBitRate, mMaxBitRate; 226 int mMinFrameWidth, mMaxFrameWidth; 227 int mMinFrameHeight, mMaxFrameHeight; 228 int mMinFrameRate, mMaxFrameRate; 229 }; 230 231 struct AudioEncoderCap { 232 // Ugly constructor 233 AudioEncoderCap(audio_encoder codec, 234 int minBitRate, int maxBitRate, 235 int minSampleRate, int maxSampleRate, 236 int minChannels, int maxChannels) 237 : mCodec(codec), 238 mMinBitRate(minBitRate), mMaxBitRate(maxBitRate), 239 mMinSampleRate(minSampleRate), mMaxSampleRate(maxSampleRate), 240 mMinChannels(minChannels), mMaxChannels(maxChannels) {} 241 242 ~AudioEncoderCap() {} 243 244 audio_encoder mCodec; 245 int mMinBitRate, mMaxBitRate; 246 int mMinSampleRate, mMaxSampleRate; 247 int mMinChannels, mMaxChannels; 248 }; 249 250 struct VideoDecoderCap { 251 VideoDecoderCap(video_decoder codec): mCodec(codec) {} 252 ~VideoDecoderCap() {} 253 254 video_decoder mCodec; 255 }; 256 257 struct AudioDecoderCap { 258 AudioDecoderCap(audio_decoder codec): mCodec(codec) {} 259 ~AudioDecoderCap() {} 260 261 audio_decoder mCodec; 262 }; 263 264 struct NameToTagMap { 265 const char* name; 266 int tag; 267 }; 268 269 struct ImageEncodingQualityLevels { 270 int mCameraId; 271 Vector<int> mLevels; 272 }; 273 274 int getCamcorderProfileIndex(int cameraId, camcorder_quality quality) const; 275 276 // Debug 277 static void logVideoCodec(const VideoCodec& codec); 278 static void logAudioCodec(const AudioCodec& codec); 279 static void logVideoEncoderCap(const VideoEncoderCap& cap); 280 static void logAudioEncoderCap(const AudioEncoderCap& cap); 281 static void logVideoDecoderCap(const VideoDecoderCap& cap); 282 static void logAudioDecoderCap(const AudioDecoderCap& cap); 283 284 // If the xml configuration file does exist, use the settings 285 // from the xml 286 static MediaProfiles* createInstanceFromXmlFile(const char *xml); 287 static output_format createEncoderOutputFileFormat(const char **atts); 288 static VideoCodec* createVideoCodec(const char **atts, MediaProfiles *profiles); 289 static AudioCodec* createAudioCodec(const char **atts, MediaProfiles *profiles); 290 static AudioDecoderCap* createAudioDecoderCap(const char **atts); 291 static VideoDecoderCap* createVideoDecoderCap(const char **atts); 292 static VideoEncoderCap* createVideoEncoderCap(const char **atts); 293 static AudioEncoderCap* createAudioEncoderCap(const char **atts); 294 static CamcorderProfile* createCamcorderProfile(int cameraId, const char **atts); 295 static int getCameraId(const char **atts); 296 297 ImageEncodingQualityLevels* findImageEncodingQualityLevels(int cameraId) const; 298 void addImageEncodingQualityLevel(int cameraId, const char** atts); 299 300 // Customized element tag handler for parsing the xml configuration file. 301 static void startElementHandler(void *userData, const char *name, const char **atts); 302 303 // If the xml configuration file does not exist, use hard-coded values 304 static MediaProfiles* createDefaultInstance(); 305 static CamcorderProfile *createDefaultCamcorderLowProfile(); 306 static CamcorderProfile *createDefaultCamcorderHighProfile(); 307 static CamcorderProfile *createDefaultCamcorderTimeLapseLowProfile(); 308 static CamcorderProfile *createDefaultCamcorderTimeLapseHighProfile(); 309 static void createDefaultCamcorderProfiles(MediaProfiles *profiles); 310 static void createDefaultVideoEncoders(MediaProfiles *profiles); 311 static void createDefaultAudioEncoders(MediaProfiles *profiles); 312 static void createDefaultVideoDecoders(MediaProfiles *profiles); 313 static void createDefaultAudioDecoders(MediaProfiles *profiles); 314 static void createDefaultEncoderOutputFileFormats(MediaProfiles *profiles); 315 static void createDefaultImageEncodingQualityLevels(MediaProfiles *profiles); 316 static void createDefaultImageDecodingMaxMemory(MediaProfiles *profiles); 317 static VideoEncoderCap* createDefaultH263VideoEncoderCap(); 318 static VideoEncoderCap* createDefaultM4vVideoEncoderCap(); 319 static AudioEncoderCap* createDefaultAmrNBEncoderCap(); 320 321 static int findTagForName(const NameToTagMap *map, size_t nMappings, const char *name); 322 323 // Mappings from name (for instance, codec name) to enum value 324 static const NameToTagMap sVideoEncoderNameMap[]; 325 static const NameToTagMap sAudioEncoderNameMap[]; 326 static const NameToTagMap sFileFormatMap[]; 327 static const NameToTagMap sVideoDecoderNameMap[]; 328 static const NameToTagMap sAudioDecoderNameMap[]; 329 static const NameToTagMap sCamcorderQualityNameMap[]; 330 331 static bool sIsInitialized; 332 static MediaProfiles *sInstance; 333 static Mutex sLock; 334 int mCurrentCameraId; 335 336 Vector<CamcorderProfile*> mCamcorderProfiles; 337 Vector<AudioEncoderCap*> mAudioEncoders; 338 Vector<VideoEncoderCap*> mVideoEncoders; 339 Vector<AudioDecoderCap*> mAudioDecoders; 340 Vector<VideoDecoderCap*> mVideoDecoders; 341 Vector<output_format> mEncoderOutputFileFormats; 342 Vector<ImageEncodingQualityLevels *> mImageEncodingQualityLevels; 343}; 344 345}; // namespace android 346 347#endif // ANDROID_MEDIAPROFILES_H 348 349