blob: aa97874026414e79191cafd0a62ea2204b51ba88 [file] [log] [blame]
James Dongc3711942010-01-19 17:45:38 -08001/*
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 {
James Donge64d9a22010-03-31 13:56:29 -070027 CAMCORDER_QUALITY_LOW = 0,
Nipun Kwatra4af0dfd2010-09-06 15:59:02 -070028 CAMCORDER_QUALITY_HIGH = 1,
29 CAMCORDER_QUALITY_QCIF = 2,
Nipun Kwatra522632c2010-09-10 15:45:57 -070030 CAMCORDER_QUALITY_CIF = 3,
31 CAMCORDER_QUALITY_480P = 4,
32 CAMCORDER_QUALITY_720P = 5,
33 CAMCORDER_QUALITY_1080P = 6,
Nipun Kwatra4af0dfd2010-09-06 15:59:02 -070034
35 CAMCORDER_QUALITY_TIME_LAPSE_LOW = 1000,
36 CAMCORDER_QUALITY_TIME_LAPSE_HIGH = 1001,
37 CAMCORDER_QUALITY_TIME_LAPSE_QCIF = 1002,
Nipun Kwatra522632c2010-09-10 15:45:57 -070038 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
James Dongc3711942010-01-19 17:45:38 -080042};
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 /**
Chih-Chung Chang09b90052010-06-22 20:50:55 +080064 * Returns the value for the given param name for the given camera at
65 * the given quality level, or -1 if error.
James Dongc3711942010-01-19 17:45:38 -080066 *
67 * Supported param name are:
James Dong9b433f02010-02-23 17:21:44 -080068 * duration - the recording duration.
James Dongc3711942010-01-19 17:45:38 -080069 * file.format - output file format. see mediarecorder.h for details
James Donge7038ac2010-02-03 16:50:18 -080070 * vid.codec - video encoder. see mediarecorder.h for details.
71 * aud.codec - audio encoder. see mediarecorder.h for details.
James Dongc3711942010-01-19 17:45:38 -080072 * 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 */
Chih-Chung Chang09b90052010-06-22 20:50:55 +080080 int getCamcorderProfileParamByName(const char *name, int cameraId,
81 camcorder_quality quality) const;
James Dongc3711942010-01-19 17:45:38 -080082
83 /**
Nipun Kwatra9d619542010-09-09 16:25:08 -070084 * 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 /**
James Dongc3711942010-01-19 17:45:38 -080090 * 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
James Dong9b433f02010-02-23 17:21:44 -0800144 /**
145 * Returns the number of image encoding quality levels supported.
146 */
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800147 Vector<int> getImageEncodingQualityLevels(int cameraId) const;
James Dong9b433f02010-02-23 17:21:44 -0800148
James Dongc3711942010-01-19 17:45:38 -0800149private:
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()
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800189 : mCameraId(0),
190 mFileFormat(OUTPUT_FORMAT_THREE_GPP),
James Dongc3711942010-01-19 17:45:38 -0800191 mQuality(CAMCORDER_QUALITY_HIGH),
192 mDuration(0),
193 mVideoCodec(0),
194 mAudioCodec(0) {}
195
196 ~CamcorderProfile() {
197 delete mVideoCodec;
198 delete mAudioCodec;
199 }
200
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800201 int mCameraId;
James Dongc3711942010-01-19 17:45:38 -0800202 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
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800269 struct ImageEncodingQualityLevels {
270 int mCameraId;
271 Vector<int> mLevels;
272 };
273
Nipun Kwatra9d619542010-09-09 16:25:08 -0700274 int getCamcorderProfileIndex(int cameraId, camcorder_quality quality) const;
275
James Dongc3711942010-01-19 17:45:38 -0800276 // 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);
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800294 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);
James Dongc3711942010-01-19 17:45:38 -0800299
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();
Nipun Kwatrad48a15c2010-09-16 22:25:23 -0700305
306 static CamcorderProfile *createDefaultCamcorderQcifProfile(camcorder_quality quality);
307 static CamcorderProfile *createDefaultCamcorderCifProfile(camcorder_quality quality);
308 static void createDefaultCamcorderLowProfiles(
309 MediaProfiles::CamcorderProfile **lowProfile,
310 MediaProfiles::CamcorderProfile **lowSpecificProfile);
311 static void createDefaultCamcorderHighProfiles(
312 MediaProfiles::CamcorderProfile **highProfile,
313 MediaProfiles::CamcorderProfile **highSpecificProfile);
314
315 static CamcorderProfile *createDefaultCamcorderTimeLapseQcifProfile(camcorder_quality quality);
316 static CamcorderProfile *createDefaultCamcorderTimeLapse480pProfile(camcorder_quality quality);
317 static void createDefaultCamcorderTimeLapseLowProfiles(
318 MediaProfiles::CamcorderProfile **lowTimeLapseProfile,
319 MediaProfiles::CamcorderProfile **lowSpecificTimeLapseProfile);
320 static void createDefaultCamcorderTimeLapseHighProfiles(
321 MediaProfiles::CamcorderProfile **highTimeLapseProfile,
322 MediaProfiles::CamcorderProfile **highSpecificTimeLapseProfile);
323
James Dongc3711942010-01-19 17:45:38 -0800324 static void createDefaultCamcorderProfiles(MediaProfiles *profiles);
325 static void createDefaultVideoEncoders(MediaProfiles *profiles);
326 static void createDefaultAudioEncoders(MediaProfiles *profiles);
327 static void createDefaultVideoDecoders(MediaProfiles *profiles);
328 static void createDefaultAudioDecoders(MediaProfiles *profiles);
329 static void createDefaultEncoderOutputFileFormats(MediaProfiles *profiles);
James Dong9b433f02010-02-23 17:21:44 -0800330 static void createDefaultImageEncodingQualityLevels(MediaProfiles *profiles);
331 static void createDefaultImageDecodingMaxMemory(MediaProfiles *profiles);
James Dongc3711942010-01-19 17:45:38 -0800332 static VideoEncoderCap* createDefaultH263VideoEncoderCap();
333 static VideoEncoderCap* createDefaultM4vVideoEncoderCap();
334 static AudioEncoderCap* createDefaultAmrNBEncoderCap();
335
336 static int findTagForName(const NameToTagMap *map, size_t nMappings, const char *name);
337
338 // Mappings from name (for instance, codec name) to enum value
339 static const NameToTagMap sVideoEncoderNameMap[];
340 static const NameToTagMap sAudioEncoderNameMap[];
341 static const NameToTagMap sFileFormatMap[];
342 static const NameToTagMap sVideoDecoderNameMap[];
343 static const NameToTagMap sAudioDecoderNameMap[];
344 static const NameToTagMap sCamcorderQualityNameMap[];
345
346 static bool sIsInitialized;
347 static MediaProfiles *sInstance;
348 static Mutex sLock;
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800349 int mCurrentCameraId;
James Dongc3711942010-01-19 17:45:38 -0800350
351 Vector<CamcorderProfile*> mCamcorderProfiles;
352 Vector<AudioEncoderCap*> mAudioEncoders;
353 Vector<VideoEncoderCap*> mVideoEncoders;
354 Vector<AudioDecoderCap*> mAudioDecoders;
355 Vector<VideoDecoderCap*> mVideoDecoders;
356 Vector<output_format> mEncoderOutputFileFormats;
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800357 Vector<ImageEncodingQualityLevels *> mImageEncodingQualityLevels;
James Dongc3711942010-01-19 17:45:38 -0800358};
359
360}; // namespace android
361
362#endif // ANDROID_MEDIAPROFILES_H
363