blob: 183bb1e59204128b5f17369da5934e68d12bdf1a [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 /**
Nipun Kwatra9d619542010-09-09 16:25:08 -070082 * Returns true if a profile for the given camera at the given quality exists,
83 * or false if not.
84 */
85 bool hasCamcorderProfile(int cameraId, camcorder_quality quality) const;
86
87 /**
James Dongc3711942010-01-19 17:45:38 -080088 * Returns the output file formats supported.
89 */
90 Vector<output_format> getOutputFileFormats() const;
91
92 /**
93 * Returns the video encoders supported.
94 */
95 Vector<video_encoder> getVideoEncoders() const;
96
97 /**
98 * Returns the value for the given param name for the given video encoder
99 * returned from getVideoEncoderByIndex or -1 if error.
100 *
101 * Supported param name are:
102 * enc.vid.width.min - min video frame width
103 * enc.vid.width.max - max video frame width
104 * enc.vid.height.min - min video frame height
105 * enc.vid.height.max - max video frame height
106 * enc.vid.bps.min - min bit rate in bits per second
107 * enc.vid.bps.max - max bit rate in bits per second
108 * enc.vid.fps.min - min frame rate in frames per second
109 * enc.vid.fps.max - max frame rate in frames per second
110 */
111 int getVideoEncoderParamByName(const char *name, video_encoder codec) const;
112
113 /**
114 * Returns the audio encoders supported.
115 */
116 Vector<audio_encoder> getAudioEncoders() const;
117
118 /**
119 * Returns the value for the given param name for the given audio encoder
120 * returned from getAudioEncoderByIndex or -1 if error.
121 *
122 * Supported param name are:
123 * enc.aud.ch.min - min number of channels
124 * enc.aud.ch.max - max number of channels
125 * enc.aud.bps.min - min bit rate in bits per second
126 * enc.aud.bps.max - max bit rate in bits per second
127 * enc.aud.hz.min - min sample rate in samples per second
128 * enc.aud.hz.max - max sample rate in samples per second
129 */
130 int getAudioEncoderParamByName(const char *name, audio_encoder codec) const;
131
132 /**
133 * Returns the video decoders supported.
134 */
135 Vector<video_decoder> getVideoDecoders() const;
136
137 /**
138 * Returns the audio decoders supported.
139 */
140 Vector<audio_decoder> getAudioDecoders() const;
141
James Dong9b433f02010-02-23 17:21:44 -0800142 /**
143 * Returns the number of image encoding quality levels supported.
144 */
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800145 Vector<int> getImageEncodingQualityLevels(int cameraId) const;
James Dong9b433f02010-02-23 17:21:44 -0800146
James Dongc3711942010-01-19 17:45:38 -0800147private:
148 MediaProfiles& operator=(const MediaProfiles&); // Don't call me
149 MediaProfiles(const MediaProfiles&); // Don't call me
150 MediaProfiles() {} // Dummy default constructor
151 ~MediaProfiles(); // Don't delete me
152
153 struct VideoCodec {
154 VideoCodec(video_encoder codec, int bitRate, int frameWidth, int frameHeight, int frameRate)
155 : mCodec(codec),
156 mBitRate(bitRate),
157 mFrameWidth(frameWidth),
158 mFrameHeight(frameHeight),
159 mFrameRate(frameRate) {}
160
161 ~VideoCodec() {}
162
163 video_encoder mCodec;
164 int mBitRate;
165 int mFrameWidth;
166 int mFrameHeight;
167 int mFrameRate;
168 };
169
170 struct AudioCodec {
171 AudioCodec(audio_encoder codec, int bitRate, int sampleRate, int channels)
172 : mCodec(codec),
173 mBitRate(bitRate),
174 mSampleRate(sampleRate),
175 mChannels(channels) {}
176
177 ~AudioCodec() {}
178
179 audio_encoder mCodec;
180 int mBitRate;
181 int mSampleRate;
182 int mChannels;
183 };
184
185 struct CamcorderProfile {
186 CamcorderProfile()
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800187 : mCameraId(0),
188 mFileFormat(OUTPUT_FORMAT_THREE_GPP),
James Dongc3711942010-01-19 17:45:38 -0800189 mQuality(CAMCORDER_QUALITY_HIGH),
190 mDuration(0),
191 mVideoCodec(0),
192 mAudioCodec(0) {}
193
194 ~CamcorderProfile() {
195 delete mVideoCodec;
196 delete mAudioCodec;
197 }
198
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800199 int mCameraId;
James Dongc3711942010-01-19 17:45:38 -0800200 output_format mFileFormat;
201 camcorder_quality mQuality;
202 int mDuration;
203 VideoCodec *mVideoCodec;
204 AudioCodec *mAudioCodec;
205 };
206
207 struct VideoEncoderCap {
208 // Ugly constructor
209 VideoEncoderCap(video_encoder codec,
210 int minBitRate, int maxBitRate,
211 int minFrameWidth, int maxFrameWidth,
212 int minFrameHeight, int maxFrameHeight,
213 int minFrameRate, int maxFrameRate)
214 : mCodec(codec),
215 mMinBitRate(minBitRate), mMaxBitRate(maxBitRate),
216 mMinFrameWidth(minFrameWidth), mMaxFrameWidth(maxFrameWidth),
217 mMinFrameHeight(minFrameHeight), mMaxFrameHeight(maxFrameHeight),
218 mMinFrameRate(minFrameRate), mMaxFrameRate(maxFrameRate) {}
219
220 ~VideoEncoderCap() {}
221
222 video_encoder mCodec;
223 int mMinBitRate, mMaxBitRate;
224 int mMinFrameWidth, mMaxFrameWidth;
225 int mMinFrameHeight, mMaxFrameHeight;
226 int mMinFrameRate, mMaxFrameRate;
227 };
228
229 struct AudioEncoderCap {
230 // Ugly constructor
231 AudioEncoderCap(audio_encoder codec,
232 int minBitRate, int maxBitRate,
233 int minSampleRate, int maxSampleRate,
234 int minChannels, int maxChannels)
235 : mCodec(codec),
236 mMinBitRate(minBitRate), mMaxBitRate(maxBitRate),
237 mMinSampleRate(minSampleRate), mMaxSampleRate(maxSampleRate),
238 mMinChannels(minChannels), mMaxChannels(maxChannels) {}
239
240 ~AudioEncoderCap() {}
241
242 audio_encoder mCodec;
243 int mMinBitRate, mMaxBitRate;
244 int mMinSampleRate, mMaxSampleRate;
245 int mMinChannels, mMaxChannels;
246 };
247
248 struct VideoDecoderCap {
249 VideoDecoderCap(video_decoder codec): mCodec(codec) {}
250 ~VideoDecoderCap() {}
251
252 video_decoder mCodec;
253 };
254
255 struct AudioDecoderCap {
256 AudioDecoderCap(audio_decoder codec): mCodec(codec) {}
257 ~AudioDecoderCap() {}
258
259 audio_decoder mCodec;
260 };
261
262 struct NameToTagMap {
263 const char* name;
264 int tag;
265 };
266
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800267 struct ImageEncodingQualityLevels {
268 int mCameraId;
269 Vector<int> mLevels;
270 };
271
Nipun Kwatra9d619542010-09-09 16:25:08 -0700272 int getCamcorderProfileIndex(int cameraId, camcorder_quality quality) const;
273
James Dongc3711942010-01-19 17:45:38 -0800274 // Debug
275 static void logVideoCodec(const VideoCodec& codec);
276 static void logAudioCodec(const AudioCodec& codec);
277 static void logVideoEncoderCap(const VideoEncoderCap& cap);
278 static void logAudioEncoderCap(const AudioEncoderCap& cap);
279 static void logVideoDecoderCap(const VideoDecoderCap& cap);
280 static void logAudioDecoderCap(const AudioDecoderCap& cap);
281
282 // If the xml configuration file does exist, use the settings
283 // from the xml
284 static MediaProfiles* createInstanceFromXmlFile(const char *xml);
285 static output_format createEncoderOutputFileFormat(const char **atts);
286 static VideoCodec* createVideoCodec(const char **atts, MediaProfiles *profiles);
287 static AudioCodec* createAudioCodec(const char **atts, MediaProfiles *profiles);
288 static AudioDecoderCap* createAudioDecoderCap(const char **atts);
289 static VideoDecoderCap* createVideoDecoderCap(const char **atts);
290 static VideoEncoderCap* createVideoEncoderCap(const char **atts);
291 static AudioEncoderCap* createAudioEncoderCap(const char **atts);
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800292 static CamcorderProfile* createCamcorderProfile(int cameraId, const char **atts);
293 static int getCameraId(const char **atts);
294
295 ImageEncodingQualityLevels* findImageEncodingQualityLevels(int cameraId) const;
296 void addImageEncodingQualityLevel(int cameraId, const char** atts);
James Dongc3711942010-01-19 17:45:38 -0800297
298 // Customized element tag handler for parsing the xml configuration file.
299 static void startElementHandler(void *userData, const char *name, const char **atts);
300
301 // If the xml configuration file does not exist, use hard-coded values
302 static MediaProfiles* createDefaultInstance();
303 static CamcorderProfile *createDefaultCamcorderLowProfile();
304 static CamcorderProfile *createDefaultCamcorderHighProfile();
Nipun Kwatra4af0dfd2010-09-06 15:59:02 -0700305 static CamcorderProfile *createDefaultCamcorderTimeLapseLowProfile();
306 static CamcorderProfile *createDefaultCamcorderTimeLapseHighProfile();
James Dongc3711942010-01-19 17:45:38 -0800307 static void createDefaultCamcorderProfiles(MediaProfiles *profiles);
308 static void createDefaultVideoEncoders(MediaProfiles *profiles);
309 static void createDefaultAudioEncoders(MediaProfiles *profiles);
310 static void createDefaultVideoDecoders(MediaProfiles *profiles);
311 static void createDefaultAudioDecoders(MediaProfiles *profiles);
312 static void createDefaultEncoderOutputFileFormats(MediaProfiles *profiles);
James Dong9b433f02010-02-23 17:21:44 -0800313 static void createDefaultImageEncodingQualityLevels(MediaProfiles *profiles);
314 static void createDefaultImageDecodingMaxMemory(MediaProfiles *profiles);
James Dongc3711942010-01-19 17:45:38 -0800315 static VideoEncoderCap* createDefaultH263VideoEncoderCap();
316 static VideoEncoderCap* createDefaultM4vVideoEncoderCap();
317 static AudioEncoderCap* createDefaultAmrNBEncoderCap();
318
319 static int findTagForName(const NameToTagMap *map, size_t nMappings, const char *name);
320
321 // Mappings from name (for instance, codec name) to enum value
322 static const NameToTagMap sVideoEncoderNameMap[];
323 static const NameToTagMap sAudioEncoderNameMap[];
324 static const NameToTagMap sFileFormatMap[];
325 static const NameToTagMap sVideoDecoderNameMap[];
326 static const NameToTagMap sAudioDecoderNameMap[];
327 static const NameToTagMap sCamcorderQualityNameMap[];
328
329 static bool sIsInitialized;
330 static MediaProfiles *sInstance;
331 static Mutex sLock;
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800332 int mCurrentCameraId;
James Dongc3711942010-01-19 17:45:38 -0800333
334 Vector<CamcorderProfile*> mCamcorderProfiles;
335 Vector<AudioEncoderCap*> mAudioEncoders;
336 Vector<VideoEncoderCap*> mVideoEncoders;
337 Vector<AudioDecoderCap*> mAudioDecoders;
338 Vector<VideoDecoderCap*> mVideoDecoders;
339 Vector<output_format> mEncoderOutputFileFormats;
Chih-Chung Chang09b90052010-06-22 20:50:55 +0800340 Vector<ImageEncodingQualityLevels *> mImageEncodingQualityLevels;
James Dongc3711942010-01-19 17:45:38 -0800341};
342
343}; // namespace android
344
345#endif // ANDROID_MEDIAPROFILES_H
346