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