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 24 namespace android { 25 26 enum camcorder_quality { 27 CAMCORDER_QUALITY_LOW = 0, 28 CAMCORDER_QUALITY_HIGH = 1 29 }; 30 31 enum video_decoder { 32 VIDEO_DECODER_WMV, 33 }; 34 35 enum audio_decoder { 36 AUDIO_DECODER_WMA, 37 }; 38 39 40 class MediaProfiles 41 { 42 public: 43 44 /** 45 * Returns the singleton instance for subsequence queries. 46 * or NULL if error. 47 */ 48 static MediaProfiles* getInstance(); 49 50 /** 51 * Returns the value for the given param name for the given camera at 52 * the given quality level, or -1 if error. 53 * 54 * Supported param name are: 55 * duration - the recording duration. 56 * file.format - output file format. see mediarecorder.h for details 57 * vid.codec - video encoder. see mediarecorder.h for details. 58 * aud.codec - audio encoder. see mediarecorder.h for details. 59 * vid.width - video frame width 60 * vid.height - video frame height 61 * vid.fps - video frame rate 62 * vid.bps - video bit rate 63 * aud.bps - audio bit rate 64 * aud.hz - audio sample rate 65 * aud.ch - number of audio channels 66 */ 67 int getCamcorderProfileParamByName(const char *name, int cameraId, 68 camcorder_quality quality) const; 69 70 /** 71 * Returns the output file formats supported. 72 */ 73 Vector<output_format> getOutputFileFormats() const; 74 75 /** 76 * Returns the video encoders supported. 77 */ 78 Vector<video_encoder> getVideoEncoders() const; 79 80 /** 81 * Returns the value for the given param name for the given video encoder 82 * returned from getVideoEncoderByIndex or -1 if error. 83 * 84 * Supported param name are: 85 * enc.vid.width.min - min video frame width 86 * enc.vid.width.max - max video frame width 87 * enc.vid.height.min - min video frame height 88 * enc.vid.height.max - max video frame height 89 * enc.vid.bps.min - min bit rate in bits per second 90 * enc.vid.bps.max - max bit rate in bits per second 91 * enc.vid.fps.min - min frame rate in frames per second 92 * enc.vid.fps.max - max frame rate in frames per second 93 */ 94 int getVideoEncoderParamByName(const char *name, video_encoder codec) const; 95 96 /** 97 * Returns the audio encoders supported. 98 */ 99 Vector<audio_encoder> getAudioEncoders() const; 100 101 /** 102 * Returns the value for the given param name for the given audio encoder 103 * returned from getAudioEncoderByIndex or -1 if error. 104 * 105 * Supported param name are: 106 * enc.aud.ch.min - min number of channels 107 * enc.aud.ch.max - max number of channels 108 * enc.aud.bps.min - min bit rate in bits per second 109 * enc.aud.bps.max - max bit rate in bits per second 110 * enc.aud.hz.min - min sample rate in samples per second 111 * enc.aud.hz.max - max sample rate in samples per second 112 */ 113 int getAudioEncoderParamByName(const char *name, audio_encoder codec) const; 114 115 /** 116 * Returns the video decoders supported. 117 */ 118 Vector<video_decoder> getVideoDecoders() const; 119 120 /** 121 * Returns the audio decoders supported. 122 */ 123 Vector<audio_decoder> getAudioDecoders() const; 124 125 /** 126 * Returns the number of image encoding quality levels supported. 127 */ 128 Vector<int> getImageEncodingQualityLevels(int cameraId) const; 129 130 private: 131 MediaProfiles& operator=(const MediaProfiles&); // Don't call me 132 MediaProfiles(const MediaProfiles&); // Don't call me 133 MediaProfiles() {} // Dummy default constructor 134 ~MediaProfiles(); // Don't delete me 135 136 struct VideoCodec { 137 VideoCodec(video_encoder codec, int bitRate, int frameWidth, int frameHeight, int frameRate) 138 : mCodec(codec), 139 mBitRate(bitRate), 140 mFrameWidth(frameWidth), 141 mFrameHeight(frameHeight), 142 mFrameRate(frameRate) {} 143 144 ~VideoCodec() {} 145 146 video_encoder mCodec; 147 int mBitRate; 148 int mFrameWidth; 149 int mFrameHeight; 150 int mFrameRate; 151 }; 152 153 struct AudioCodec { 154 AudioCodec(audio_encoder codec, int bitRate, int sampleRate, int channels) 155 : mCodec(codec), 156 mBitRate(bitRate), 157 mSampleRate(sampleRate), 158 mChannels(channels) {} 159 160 ~AudioCodec() {} 161 162 audio_encoder mCodec; 163 int mBitRate; 164 int mSampleRate; 165 int mChannels; 166 }; 167 168 struct CamcorderProfile { 169 CamcorderProfile() 170 : mCameraId(0), 171 mFileFormat(OUTPUT_FORMAT_THREE_GPP), 172 mQuality(CAMCORDER_QUALITY_HIGH), 173 mDuration(0), 174 mVideoCodec(0), 175 mAudioCodec(0) {} 176 177 ~CamcorderProfile() { 178 delete mVideoCodec; 179 delete mAudioCodec; 180 } 181 182 int mCameraId; 183 output_format mFileFormat; 184 camcorder_quality mQuality; 185 int mDuration; 186 VideoCodec *mVideoCodec; 187 AudioCodec *mAudioCodec; 188 }; 189 190 struct VideoEncoderCap { 191 // Ugly constructor 192 VideoEncoderCap(video_encoder codec, 193 int minBitRate, int maxBitRate, 194 int minFrameWidth, int maxFrameWidth, 195 int minFrameHeight, int maxFrameHeight, 196 int minFrameRate, int maxFrameRate) 197 : mCodec(codec), 198 mMinBitRate(minBitRate), mMaxBitRate(maxBitRate), 199 mMinFrameWidth(minFrameWidth), mMaxFrameWidth(maxFrameWidth), 200 mMinFrameHeight(minFrameHeight), mMaxFrameHeight(maxFrameHeight), 201 mMinFrameRate(minFrameRate), mMaxFrameRate(maxFrameRate) {} 202 203 ~VideoEncoderCap() {} 204 205 video_encoder mCodec; 206 int mMinBitRate, mMaxBitRate; 207 int mMinFrameWidth, mMaxFrameWidth; 208 int mMinFrameHeight, mMaxFrameHeight; 209 int mMinFrameRate, mMaxFrameRate; 210 }; 211 212 struct AudioEncoderCap { 213 // Ugly constructor 214 AudioEncoderCap(audio_encoder codec, 215 int minBitRate, int maxBitRate, 216 int minSampleRate, int maxSampleRate, 217 int minChannels, int maxChannels) 218 : mCodec(codec), 219 mMinBitRate(minBitRate), mMaxBitRate(maxBitRate), 220 mMinSampleRate(minSampleRate), mMaxSampleRate(maxSampleRate), 221 mMinChannels(minChannels), mMaxChannels(maxChannels) {} 222 223 ~AudioEncoderCap() {} 224 225 audio_encoder mCodec; 226 int mMinBitRate, mMaxBitRate; 227 int mMinSampleRate, mMaxSampleRate; 228 int mMinChannels, mMaxChannels; 229 }; 230 231 struct VideoDecoderCap { 232 VideoDecoderCap(video_decoder codec): mCodec(codec) {} 233 ~VideoDecoderCap() {} 234 235 video_decoder mCodec; 236 }; 237 238 struct AudioDecoderCap { 239 AudioDecoderCap(audio_decoder codec): mCodec(codec) {} 240 ~AudioDecoderCap() {} 241 242 audio_decoder mCodec; 243 }; 244 245 struct NameToTagMap { 246 const char* name; 247 int tag; 248 }; 249 250 struct ImageEncodingQualityLevels { 251 int mCameraId; 252 Vector<int> mLevels; 253 }; 254 255 // Debug 256 static void logVideoCodec(const VideoCodec& codec); 257 static void logAudioCodec(const AudioCodec& codec); 258 static void logVideoEncoderCap(const VideoEncoderCap& cap); 259 static void logAudioEncoderCap(const AudioEncoderCap& cap); 260 static void logVideoDecoderCap(const VideoDecoderCap& cap); 261 static void logAudioDecoderCap(const AudioDecoderCap& cap); 262 263 // If the xml configuration file does exist, use the settings 264 // from the xml 265 static MediaProfiles* createInstanceFromXmlFile(const char *xml); 266 static output_format createEncoderOutputFileFormat(const char **atts); 267 static VideoCodec* createVideoCodec(const char **atts, MediaProfiles *profiles); 268 static AudioCodec* createAudioCodec(const char **atts, MediaProfiles *profiles); 269 static AudioDecoderCap* createAudioDecoderCap(const char **atts); 270 static VideoDecoderCap* createVideoDecoderCap(const char **atts); 271 static VideoEncoderCap* createVideoEncoderCap(const char **atts); 272 static AudioEncoderCap* createAudioEncoderCap(const char **atts); 273 static CamcorderProfile* createCamcorderProfile(int cameraId, const char **atts); 274 static int getCameraId(const char **atts); 275 276 ImageEncodingQualityLevels* findImageEncodingQualityLevels(int cameraId) const; 277 void addImageEncodingQualityLevel(int cameraId, const char** atts); 278 279 // Customized element tag handler for parsing the xml configuration file. 280 static void startElementHandler(void *userData, const char *name, const char **atts); 281 282 // If the xml configuration file does not exist, use hard-coded values 283 static MediaProfiles* createDefaultInstance(); 284 static CamcorderProfile *createDefaultCamcorderLowProfile(); 285 static CamcorderProfile *createDefaultCamcorderHighProfile(); 286 static void createDefaultCamcorderProfiles(MediaProfiles *profiles); 287 static void createDefaultVideoEncoders(MediaProfiles *profiles); 288 static void createDefaultAudioEncoders(MediaProfiles *profiles); 289 static void createDefaultVideoDecoders(MediaProfiles *profiles); 290 static void createDefaultAudioDecoders(MediaProfiles *profiles); 291 static void createDefaultEncoderOutputFileFormats(MediaProfiles *profiles); 292 static void createDefaultImageEncodingQualityLevels(MediaProfiles *profiles); 293 static void createDefaultImageDecodingMaxMemory(MediaProfiles *profiles); 294 static VideoEncoderCap* createDefaultH263VideoEncoderCap(); 295 static VideoEncoderCap* createDefaultM4vVideoEncoderCap(); 296 static AudioEncoderCap* createDefaultAmrNBEncoderCap(); 297 298 static int findTagForName(const NameToTagMap *map, size_t nMappings, const char *name); 299 300 // Mappings from name (for instance, codec name) to enum value 301 static const NameToTagMap sVideoEncoderNameMap[]; 302 static const NameToTagMap sAudioEncoderNameMap[]; 303 static const NameToTagMap sFileFormatMap[]; 304 static const NameToTagMap sVideoDecoderNameMap[]; 305 static const NameToTagMap sAudioDecoderNameMap[]; 306 static const NameToTagMap sCamcorderQualityNameMap[]; 307 308 static bool sIsInitialized; 309 static MediaProfiles *sInstance; 310 static Mutex sLock; 311 int mCurrentCameraId; 312 313 Vector<CamcorderProfile*> mCamcorderProfiles; 314 Vector<AudioEncoderCap*> mAudioEncoders; 315 Vector<VideoEncoderCap*> mVideoEncoders; 316 Vector<AudioDecoderCap*> mAudioDecoders; 317 Vector<VideoDecoderCap*> mVideoDecoders; 318 Vector<output_format> mEncoderOutputFileFormats; 319 Vector<ImageEncodingQualityLevels *> mImageEncodingQualityLevels; 320 }; 321 322 }; // namespace android 323 324 #endif // ANDROID_MEDIAPROFILES_H 325 326