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