blob: 126337395d2a46ea62ea50cfaad8ae68921544a7 [file] [log] [blame]
James Dong1d7491b2010-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
19//#define LOG_NDEBUG 0
20#define LOG_TAG "MediaProfiles"
21
22#include <stdlib.h>
23#include <utils/Log.h>
24#include <utils/Vector.h>
25#include <cutils/properties.h>
26#include <expat.h>
27#include <media/MediaProfiles.h>
28#include <media/stagefright/MediaDebug.h>
29
30namespace android {
31
32Mutex MediaProfiles::sLock;
33bool MediaProfiles::sIsInitialized = false;
34MediaProfiles *MediaProfiles::sInstance = NULL;
35
36const MediaProfiles::NameToTagMap MediaProfiles::sVideoEncoderNameMap[] = {
37 {"h263", VIDEO_ENCODER_H263},
38 {"h264", VIDEO_ENCODER_H264},
39 {"m4v", VIDEO_ENCODER_MPEG_4_SP}
40};
41
42const MediaProfiles::NameToTagMap MediaProfiles::sAudioEncoderNameMap[] = {
43 {"amrnb", AUDIO_ENCODER_AMR_NB},
44 {"amrwb", AUDIO_ENCODER_AMR_WB},
45 {"aac", AUDIO_ENCODER_AAC},
46};
47
48const MediaProfiles::NameToTagMap MediaProfiles::sFileFormatMap[] = {
49 {"3gp", OUTPUT_FORMAT_THREE_GPP},
50 {"mp4", OUTPUT_FORMAT_MPEG_4}
51};
52
53const MediaProfiles::NameToTagMap MediaProfiles::sVideoDecoderNameMap[] = {
54 {"wmv", VIDEO_DECODER_WMV}
55};
56
57const MediaProfiles::NameToTagMap MediaProfiles::sAudioDecoderNameMap[] = {
58 {"wma", AUDIO_DECODER_WMA}
59};
60
61const MediaProfiles::NameToTagMap MediaProfiles::sCamcorderQualityNameMap[] = {
62 {"high", CAMCORDER_QUALITY_HIGH},
63 {"low", CAMCORDER_QUALITY_LOW}
64};
65
66/*static*/ void
67MediaProfiles::logVideoCodec(const MediaProfiles::VideoCodec& codec)
68{
69 LOGV("video codec:");
70 LOGV("codec = %d", codec.mCodec);
71 LOGV("bit rate: %d", codec.mBitRate);
72 LOGV("frame width: %d", codec.mFrameWidth);
73 LOGV("frame height: %d", codec.mFrameHeight);
74 LOGV("frame rate: %d", codec.mFrameRate);
75}
76
77/*static*/ void
78MediaProfiles::logAudioCodec(const MediaProfiles::AudioCodec& codec)
79{
80 LOGV("audio codec:");
81 LOGV("codec = %d", codec.mCodec);
82 LOGV("bit rate: %d", codec.mBitRate);
83 LOGV("sample rate: %d", codec.mSampleRate);
84 LOGV("number of channels: %d", codec.mChannels);
85}
86
87/*static*/ void
88MediaProfiles::logVideoEncoderCap(const MediaProfiles::VideoEncoderCap& cap)
89{
90 LOGV("video encoder cap:");
91 LOGV("codec = %d", cap.mCodec);
92 LOGV("bit rate: min = %d and max = %d", cap.mMinBitRate, cap.mMaxBitRate);
93 LOGV("frame width: min = %d and max = %d", cap.mMinFrameWidth, cap.mMaxFrameWidth);
94 LOGV("frame height: min = %d and max = %d", cap.mMinFrameHeight, cap.mMaxFrameHeight);
95 LOGV("frame rate: min = %d and max = %d", cap.mMinFrameRate, cap.mMaxFrameRate);
96}
97
98/*static*/ void
99MediaProfiles::logAudioEncoderCap(const MediaProfiles::AudioEncoderCap& cap)
100{
101 LOGV("audio encoder cap:");
102 LOGV("codec = %d", cap.mCodec);
103 LOGV("bit rate: min = %d and max = %d", cap.mMinBitRate, cap.mMaxBitRate);
104 LOGV("sample rate: min = %d and max = %d", cap.mMinSampleRate, cap.mMaxSampleRate);
105 LOGV("number of channels: min = %d and max = %d", cap.mMinChannels, cap.mMaxChannels);
106}
107
108/*static*/ void
109MediaProfiles::logVideoDecoderCap(const MediaProfiles::VideoDecoderCap& cap)
110{
111 LOGV("video decoder cap:");
112 LOGV("codec = %d", cap.mCodec);
113}
114
115/*static*/ void
116MediaProfiles::logAudioDecoderCap(const MediaProfiles::AudioDecoderCap& cap)
117{
118 LOGV("audio codec cap:");
119 LOGV("codec = %d", cap.mCodec);
120}
121
122/*static*/ int
123MediaProfiles::findTagForName(const MediaProfiles::NameToTagMap *map, size_t nMappings, const char *name)
124{
125 int tag = -1;
126 for (size_t i = 0; i < nMappings; ++i) {
127 if (!strcmp(map[i].name, name)) {
128 tag = map[i].tag;
129 break;
130 }
131 }
132 return tag;
133}
134
135/*static*/ MediaProfiles::VideoCodec*
136MediaProfiles::createVideoCodec(const char **atts, MediaProfiles *profiles)
137{
138 CHECK(!strcmp("codec", atts[0]) &&
139 !strcmp("bitRate", atts[2]) &&
140 !strcmp("width", atts[4]) &&
141 !strcmp("height", atts[6]) &&
142 !strcmp("frameRate", atts[8]));
143
144 const size_t nMappings = sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]);
145 const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]);
146 CHECK(codec != -1);
147
148 MediaProfiles::VideoCodec *videoCodec =
149 new MediaProfiles::VideoCodec(static_cast<video_encoder>(codec),
150 atoi(atts[3]), atoi(atts[5]), atoi(atts[7]), atoi(atts[9]));
151 logVideoCodec(*videoCodec);
152
153 size_t nCamcorderProfiles;
154 CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1);
155 profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mVideoCodec = videoCodec;
156 return videoCodec;
157}
158
159/*static*/ MediaProfiles::AudioCodec*
160MediaProfiles::createAudioCodec(const char **atts, MediaProfiles *profiles)
161{
162 CHECK(!strcmp("codec", atts[0]) &&
163 !strcmp("bitRate", atts[2]) &&
164 !strcmp("sampleRate", atts[4]) &&
165 !strcmp("channels", atts[6]));
166 const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]);
167 const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]);
168 CHECK(codec != -1);
169
170 MediaProfiles::AudioCodec *audioCodec =
171 new MediaProfiles::AudioCodec(static_cast<audio_encoder>(codec),
172 atoi(atts[3]), atoi(atts[5]), atoi(atts[7]));
173 logAudioCodec(*audioCodec);
174
175 size_t nCamcorderProfiles;
176 CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1);
177 profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mAudioCodec = audioCodec;
178 return audioCodec;
179}
180/*static*/ MediaProfiles::AudioDecoderCap*
181MediaProfiles::createAudioDecoderCap(const char **atts)
182{
183 CHECK(!strcmp("name", atts[0]) &&
184 !strcmp("enabled", atts[2]));
185
186 const size_t nMappings = sizeof(sAudioDecoderNameMap)/sizeof(sAudioDecoderNameMap[0]);
187 const int codec = findTagForName(sAudioDecoderNameMap, nMappings, atts[1]);
188 CHECK(codec != -1);
189
190 MediaProfiles::AudioDecoderCap *cap =
191 new MediaProfiles::AudioDecoderCap(static_cast<audio_decoder>(codec));
192 logAudioDecoderCap(*cap);
193 return cap;
194}
195
196/*static*/ MediaProfiles::VideoDecoderCap*
197MediaProfiles::createVideoDecoderCap(const char **atts)
198{
199 CHECK(!strcmp("name", atts[0]) &&
200 !strcmp("enabled", atts[2]));
201
202 const size_t nMappings = sizeof(sVideoDecoderNameMap)/sizeof(sVideoDecoderNameMap[0]);
203 const int codec = findTagForName(sVideoDecoderNameMap, nMappings, atts[1]);
204 CHECK(codec != -1);
205
206 MediaProfiles::VideoDecoderCap *cap =
207 new MediaProfiles::VideoDecoderCap(static_cast<video_decoder>(codec));
208 logVideoDecoderCap(*cap);
209 return cap;
210}
211
212/*static*/ MediaProfiles::VideoEncoderCap*
213MediaProfiles::createVideoEncoderCap(const char **atts)
214{
215 CHECK(!strcmp("name", atts[0]) &&
216 !strcmp("enabled", atts[2]) &&
217 !strcmp("minBitRate", atts[4]) &&
218 !strcmp("maxBitRate", atts[6]) &&
219 !strcmp("minFrameWidth", atts[8]) &&
220 !strcmp("maxFrameWidth", atts[10]) &&
221 !strcmp("minFrameHeight", atts[12]) &&
222 !strcmp("maxFrameHeight", atts[14]) &&
223 !strcmp("minFrameRate", atts[16]) &&
224 !strcmp("maxFrameRate", atts[18]));
225
226 const size_t nMappings = sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]);
227 const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]);
228 CHECK(codec != -1);
229
230 MediaProfiles::VideoEncoderCap *cap =
231 new MediaProfiles::VideoEncoderCap(static_cast<video_encoder>(codec),
232 atoi(atts[5]), atoi(atts[7]), atoi(atts[9]), atoi(atts[11]), atoi(atts[13]),
233 atoi(atts[15]), atoi(atts[17]), atoi(atts[19]));
234 logVideoEncoderCap(*cap);
235 return cap;
236}
237
238/*static*/ MediaProfiles::AudioEncoderCap*
239MediaProfiles::createAudioEncoderCap(const char **atts)
240{
241 CHECK(!strcmp("name", atts[0]) &&
242 !strcmp("enabled", atts[2]) &&
243 !strcmp("minBitRate", atts[4]) &&
244 !strcmp("maxBitRate", atts[6]) &&
245 !strcmp("minSampleRate", atts[8]) &&
246 !strcmp("maxSampleRate", atts[10]) &&
247 !strcmp("minChannels", atts[12]) &&
248 !strcmp("maxChannels", atts[14]));
249
250 const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]);
251 const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]);
252 CHECK(codec != -1);
253
254 MediaProfiles::AudioEncoderCap *cap =
255 new MediaProfiles::AudioEncoderCap(static_cast<audio_encoder>(codec), atoi(atts[5]), atoi(atts[7]),
256 atoi(atts[9]), atoi(atts[11]), atoi(atts[13]),
257 atoi(atts[15]));
258 logAudioEncoderCap(*cap);
259 return cap;
260}
261
262/*static*/ output_format
263MediaProfiles::createEncoderOutputFileFormat(const char **atts)
264{
265 CHECK(!strcmp("name", atts[0]));
266
267 const size_t nMappings =sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]);
268 const int format = findTagForName(sFileFormatMap, nMappings, atts[1]);
269 CHECK(format != -1);
270
271 return static_cast<output_format>(format);
272}
273
274/*static*/ MediaProfiles::CamcorderProfile*
275MediaProfiles::createCamcorderProfile(const char **atts)
276{
277 CHECK(!strcmp("quality", atts[0]) &&
278 !strcmp("fileFormat", atts[2]) &&
279 !strcmp("duration", atts[4]));
280
281 const size_t nProfileMappings = sizeof(sCamcorderQualityNameMap)/sizeof(sCamcorderQualityNameMap[0]);
282 const int quality = findTagForName(sCamcorderQualityNameMap, nProfileMappings, atts[1]);
283 CHECK(quality != -1);
284
285 const size_t nFormatMappings = sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]);
286 const int fileFormat = findTagForName(sFileFormatMap, nFormatMappings, atts[3]);
287 CHECK(fileFormat != -1);
288
289 MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
290 profile->mFileFormat = static_cast<output_format>(fileFormat);
291 profile->mQuality = static_cast<camcorder_quality>(quality);
292 profile->mDuration = atoi(atts[5]);
293 return profile;
294}
295
James Dongf5a83852010-02-23 17:21:44 -0800296/*static*/ int
297MediaProfiles::getImageEncodingQualityLevel(const char** atts)
298{
299 CHECK(!strcmp("quality", atts[0]));
300 return atoi(atts[1]);
301}
302
James Dong1d7491b2010-01-19 17:45:38 -0800303/*static*/ void
304MediaProfiles::startElementHandler(void *userData, const char *name, const char **atts)
305{
306 MediaProfiles *profiles = (MediaProfiles *) userData;
307 if (strcmp("Video", name) == 0) {
308 createVideoCodec(atts, profiles);
309 } else if (strcmp("Audio", name) == 0) {
310 createAudioCodec(atts, profiles);
311 } else if (strcmp("VideoEncoderCap", name) == 0 &&
312 strcmp("true", atts[3]) == 0) {
313 profiles->mVideoEncoders.add(createVideoEncoderCap(atts));
314 } else if (strcmp("AudioEncoderCap", name) == 0 &&
315 strcmp("true", atts[3]) == 0) {
316 profiles->mAudioEncoders.add(createAudioEncoderCap(atts));
317 } else if (strcmp("VideoDecoderCap", name) == 0 &&
318 strcmp("true", atts[3]) == 0) {
319 profiles->mVideoDecoders.add(createVideoDecoderCap(atts));
320 } else if (strcmp("AudioDecoderCap", name) == 0 &&
321 strcmp("true", atts[3]) == 0) {
322 profiles->mAudioDecoders.add(createAudioDecoderCap(atts));
323 } else if (strcmp("EncoderOutputFileFormat", name) == 0) {
324 profiles->mEncoderOutputFileFormats.add(createEncoderOutputFileFormat(atts));
325 } else if (strcmp("EncoderProfile", name) == 0) {
326 profiles->mCamcorderProfiles.add(createCamcorderProfile(atts));
James Dongf5a83852010-02-23 17:21:44 -0800327 } else if (strcmp("ImageEncoding", name) == 0) {
328 profiles->mImageEncodingQualityLevels.add(getImageEncodingQualityLevel(atts));
James Dong1d7491b2010-01-19 17:45:38 -0800329 }
330}
331
332/*static*/ MediaProfiles*
333MediaProfiles::getInstance()
334{
335 LOGV("getInstance");
336 Mutex::Autolock lock(sLock);
337 if (!sIsInitialized) {
338 char value[PROPERTY_VALUE_MAX];
339 if (property_get("media.settings.xml", value, NULL) <= 0) {
340 const char *defaultXmlFile = "/etc/media_profiles.xml";
341 FILE *fp = fopen(defaultXmlFile, "r");
342 if (fp == NULL) {
343 LOGW("could not find media config xml file");
344 sInstance = createDefaultInstance();
345 } else {
346 fclose(fp); // close the file first.
347 sInstance = createInstanceFromXmlFile(defaultXmlFile);
348 }
349 } else {
350 sInstance = createInstanceFromXmlFile(value);
351 }
352 }
353
354 return sInstance;
355}
356
357/*static*/ MediaProfiles::VideoEncoderCap*
358MediaProfiles::createDefaultH263VideoEncoderCap()
359{
360 return new MediaProfiles::VideoEncoderCap(
361 VIDEO_ENCODER_H263, 192000, 420000, 176, 352, 144, 288, 1, 20);
362}
363
364/*static*/ MediaProfiles::VideoEncoderCap*
365MediaProfiles::createDefaultM4vVideoEncoderCap()
366{
367 return new MediaProfiles::VideoEncoderCap(
368 VIDEO_ENCODER_MPEG_4_SP, 192000, 420000, 176, 352, 144, 288, 1, 20);
369}
370
371
372/*static*/ void
373MediaProfiles::createDefaultVideoEncoders(MediaProfiles *profiles)
374{
375 profiles->mVideoEncoders.add(createDefaultH263VideoEncoderCap());
376 profiles->mVideoEncoders.add(createDefaultM4vVideoEncoderCap());
377}
378
379/*static*/ MediaProfiles::CamcorderProfile*
380MediaProfiles::createDefaultCamcorderHighProfile()
381{
382 MediaProfiles::VideoCodec *videoCodec =
383 new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 360000, 352, 288, 20);
384
385 AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
386 CamcorderProfile *profile = new CamcorderProfile;
387 profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
388 profile->mQuality = CAMCORDER_QUALITY_HIGH;
389 profile->mDuration = 60;
390 profile->mVideoCodec = videoCodec;
391 profile->mAudioCodec = audioCodec;
392 return profile;
393}
394
395/*static*/ MediaProfiles::CamcorderProfile*
396MediaProfiles::createDefaultCamcorderLowProfile()
397{
398 MediaProfiles::VideoCodec *videoCodec =
399 new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 192000, 176, 144, 20);
400
401 MediaProfiles::AudioCodec *audioCodec =
402 new MediaProfiles::AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
403
404 MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
405 profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
406 profile->mQuality = CAMCORDER_QUALITY_LOW;
407 profile->mDuration = 30;
408 profile->mVideoCodec = videoCodec;
409 profile->mAudioCodec = audioCodec;
410 return profile;
411}
412
413/*static*/ void
414MediaProfiles::createDefaultCamcorderProfiles(MediaProfiles *profiles)
415{
416 profiles->mCamcorderProfiles.add(createDefaultCamcorderHighProfile());
417 profiles->mCamcorderProfiles.add(createDefaultCamcorderLowProfile());
418}
419
420/*static*/ void
421MediaProfiles::createDefaultAudioEncoders(MediaProfiles *profiles)
422{
423 profiles->mAudioEncoders.add(createDefaultAmrNBEncoderCap());
424}
425
426/*static*/ void
427MediaProfiles::createDefaultVideoDecoders(MediaProfiles *profiles)
428{
429 MediaProfiles::VideoDecoderCap *cap =
430 new MediaProfiles::VideoDecoderCap(VIDEO_DECODER_WMV);
431
432 profiles->mVideoDecoders.add(cap);
433}
434
435/*static*/ void
436MediaProfiles::createDefaultAudioDecoders(MediaProfiles *profiles)
437{
438 MediaProfiles::AudioDecoderCap *cap =
439 new MediaProfiles::AudioDecoderCap(AUDIO_DECODER_WMA);
440
441 profiles->mAudioDecoders.add(cap);
442}
443
444/*static*/ void
445MediaProfiles::createDefaultEncoderOutputFileFormats(MediaProfiles *profiles)
446{
447 profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_THREE_GPP);
448 profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_MPEG_4);
449}
450
451/*static*/ MediaProfiles::AudioEncoderCap*
452MediaProfiles::createDefaultAmrNBEncoderCap()
453{
454 return new MediaProfiles::AudioEncoderCap(
455 AUDIO_ENCODER_AMR_NB, 5525, 12200, 8000, 8000, 1, 1);
456}
457
James Dongf5a83852010-02-23 17:21:44 -0800458/*static*/ void
459MediaProfiles::createDefaultImageEncodingQualityLevels(MediaProfiles *profiles)
460{
461 profiles->mImageEncodingQualityLevels.add(70);
462 profiles->mImageEncodingQualityLevels.add(80);
463 profiles->mImageEncodingQualityLevels.add(90);
464}
465
James Dong1d7491b2010-01-19 17:45:38 -0800466/*static*/ MediaProfiles*
467MediaProfiles::createDefaultInstance()
468{
469 MediaProfiles *profiles = new MediaProfiles;
470 createDefaultCamcorderProfiles(profiles);
471 createDefaultVideoEncoders(profiles);
472 createDefaultAudioEncoders(profiles);
473 createDefaultVideoDecoders(profiles);
474 createDefaultAudioDecoders(profiles);
475 createDefaultEncoderOutputFileFormats(profiles);
James Dongf5a83852010-02-23 17:21:44 -0800476 createDefaultImageEncodingQualityLevels(profiles);
James Dong1d7491b2010-01-19 17:45:38 -0800477 sIsInitialized = true;
478 return profiles;
479}
480
481/*static*/ MediaProfiles*
482MediaProfiles::createInstanceFromXmlFile(const char *xml)
483{
484 FILE *fp = NULL;
485 CHECK((fp = fopen(xml, "r")));
486
487 XML_Parser parser = ::XML_ParserCreate(NULL);
488 CHECK(parser != NULL);
489
490 MediaProfiles *profiles = new MediaProfiles();
491 ::XML_SetUserData(parser, profiles);
492 ::XML_SetElementHandler(parser, startElementHandler, NULL);
493
494 /*
495 FIXME:
496 expat is not compiled with -DXML_DTD. We don't have DTD parsing support.
497
498 if (!::XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS)) {
499 LOGE("failed to enable DTD support in the xml file");
500 return UNKNOWN_ERROR;
501 }
502
503 */
504
505 const int BUFF_SIZE = 512;
506 for (;;) {
507 void *buff = ::XML_GetBuffer(parser, BUFF_SIZE);
508 if (buff == NULL) {
509 LOGE("failed to in call to XML_GetBuffer()");
510 delete profiles;
511 profiles = NULL;
512 goto exit;
513 }
514
515 int bytes_read = ::fread(buff, 1, BUFF_SIZE, fp);
516 if (bytes_read < 0) {
517 LOGE("failed in call to read");
518 delete profiles;
519 profiles = NULL;
520 goto exit;
521 }
522
523 CHECK(::XML_ParseBuffer(parser, bytes_read, bytes_read == 0));
524
525 if (bytes_read == 0) break; // done parsing the xml file
526 }
527
528exit:
529 ::XML_ParserFree(parser);
530 ::fclose(fp);
531 if (profiles) {
532 sIsInitialized = true;
533 }
534 return profiles;
535}
536
537Vector<output_format> MediaProfiles::getOutputFileFormats() const
538{
539 return mEncoderOutputFileFormats; // copy out
540}
541
542Vector<video_encoder> MediaProfiles::getVideoEncoders() const
543{
544 Vector<video_encoder> encoders;
545 for (size_t i = 0; i < mVideoEncoders.size(); ++i) {
546 encoders.add(mVideoEncoders[i]->mCodec);
547 }
548 return encoders; // copy out
549}
550
551int MediaProfiles::getVideoEncoderParamByName(const char *name, video_encoder codec) const
552{
553 LOGV("getVideoEncoderParamByName: %s for codec %d", name, codec);
554 int index = -1;
555 for (size_t i = 0, n = mVideoEncoders.size(); i < n; ++i) {
556 if (mVideoEncoders[i]->mCodec == codec) {
557 index = i;
558 break;
559 }
560 }
561 if (index == -1) {
562 LOGE("The given video encoder %d is not found", codec);
563 return -1;
564 }
565
566 if (!strcmp("enc.vid.width.min", name)) return mVideoEncoders[index]->mMinFrameWidth;
567 if (!strcmp("enc.vid.width.max", name)) return mVideoEncoders[index]->mMaxFrameWidth;
568 if (!strcmp("enc.vid.height.min", name)) return mVideoEncoders[index]->mMinFrameHeight;
569 if (!strcmp("enc.vid.height.max", name)) return mVideoEncoders[index]->mMaxFrameHeight;
570 if (!strcmp("enc.vid.bps.min", name)) return mVideoEncoders[index]->mMinBitRate;
571 if (!strcmp("enc.vid.bps.max", name)) return mVideoEncoders[index]->mMaxBitRate;
572 if (!strcmp("enc.vid.fps.min", name)) return mVideoEncoders[index]->mMinFrameRate;
573 if (!strcmp("enc.vid.fps.max", name)) return mVideoEncoders[index]->mMaxFrameRate;
574
575 LOGE("The given video encoder param name %s is not found", name);
576 return -1;
577}
578
579Vector<audio_encoder> MediaProfiles::getAudioEncoders() const
580{
581 Vector<audio_encoder> encoders;
582 for (size_t i = 0; i < mAudioEncoders.size(); ++i) {
583 encoders.add(mAudioEncoders[i]->mCodec);
584 }
585 return encoders; // copy out
586}
587
588int MediaProfiles::getAudioEncoderParamByName(const char *name, audio_encoder codec) const
589{
590 LOGV("getAudioEncoderParamByName: %s for codec %d", name, codec);
591 int index = -1;
592 for (size_t i = 0, n = mAudioEncoders.size(); i < n; ++i) {
593 if (mAudioEncoders[i]->mCodec == codec) {
594 index = i;
595 break;
596 }
597 }
598 if (index == -1) {
599 LOGE("The given audio encoder %d is not found", codec);
600 return -1;
601 }
602
603 if (!strcmp("enc.aud.ch.min", name)) return mAudioEncoders[index]->mMinChannels;
604 if (!strcmp("enc.aud.ch.max", name)) return mAudioEncoders[index]->mMaxChannels;
605 if (!strcmp("enc.aud.bps.min", name)) return mAudioEncoders[index]->mMinBitRate;
606 if (!strcmp("enc.aud.bps.max", name)) return mAudioEncoders[index]->mMaxBitRate;
607 if (!strcmp("enc.aud.hz.min", name)) return mAudioEncoders[index]->mMinSampleRate;
608 if (!strcmp("enc.aud.hz.max", name)) return mAudioEncoders[index]->mMaxSampleRate;
609
610 LOGE("The given audio encoder param name %s is not found", name);
611 return -1;
612}
613
614Vector<video_decoder> MediaProfiles::getVideoDecoders() const
615{
616 Vector<video_decoder> decoders;
617 for (size_t i = 0; i < mVideoDecoders.size(); ++i) {
618 decoders.add(mVideoDecoders[i]->mCodec);
619 }
620 return decoders; // copy out
621}
622
623Vector<audio_decoder> MediaProfiles::getAudioDecoders() const
624{
625 Vector<audio_decoder> decoders;
626 for (size_t i = 0; i < mAudioDecoders.size(); ++i) {
627 decoders.add(mAudioDecoders[i]->mCodec);
628 }
629 return decoders; // copy out
630}
631
632int MediaProfiles::getCamcorderProfileParamByName(const char *name, camcorder_quality quality) const
633{
634 LOGV("getCamcorderProfileParamByName: %s for quality %d", name, quality);
635
636 int index = -1;
637 for (size_t i = 0, n = mCamcorderProfiles.size(); i < n; ++i) {
638 if (mCamcorderProfiles[i]->mQuality == quality) {
639 index = i;
640 break;
641 }
642 }
643 if (index == -1) {
644 LOGE("The given camcorder profile quality %d is not found", quality);
645 return -1;
646 }
647
James Dongf5a83852010-02-23 17:21:44 -0800648 if (!strcmp("duration", name)) return mCamcorderProfiles[index]->mDuration;
James Dong1d7491b2010-01-19 17:45:38 -0800649 if (!strcmp("file.format", name)) return mCamcorderProfiles[index]->mFileFormat;
650 if (!strcmp("vid.codec", name)) return mCamcorderProfiles[index]->mVideoCodec->mCodec;
651 if (!strcmp("vid.width", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameWidth;
652 if (!strcmp("vid.height", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameHeight;
653 if (!strcmp("vid.bps", name)) return mCamcorderProfiles[index]->mVideoCodec->mBitRate;
654 if (!strcmp("vid.fps", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameRate;
655 if (!strcmp("aud.codec", name)) return mCamcorderProfiles[index]->mAudioCodec->mCodec;
656 if (!strcmp("aud.bps", name)) return mCamcorderProfiles[index]->mAudioCodec->mBitRate;
657 if (!strcmp("aud.ch", name)) return mCamcorderProfiles[index]->mAudioCodec->mChannels;
658 if (!strcmp("aud.hz", name)) return mCamcorderProfiles[index]->mAudioCodec->mSampleRate;
659
660 LOGE("The given camcorder profile param name %s is not found", name);
661 return -1;
662}
663
James Dongf5a83852010-02-23 17:21:44 -0800664Vector<int> MediaProfiles::getImageEncodingQualityLevels() const
665{
666 return mImageEncodingQualityLevels; // copy out
667}
668
James Dong1d7491b2010-01-19 17:45:38 -0800669MediaProfiles::~MediaProfiles()
670{
671 CHECK("destructor should never be called" == 0);
672#if 0
673 for (size_t i = 0; i < mAudioEncoders.size(); ++i) {
674 delete mAudioEncoders[i];
675 }
676 mAudioEncoders.clear();
677
678 for (size_t i = 0; i < mVideoEncoders.size(); ++i) {
679 delete mVideoEncoders[i];
680 }
681 mVideoEncoders.clear();
682
683 for (size_t i = 0; i < mVideoDecoders.size(); ++i) {
684 delete mVideoDecoders[i];
685 }
686 mVideoDecoders.clear();
687
688 for (size_t i = 0; i < mAudioDecoders.size(); ++i) {
689 delete mAudioDecoders[i];
690 }
691 mAudioDecoders.clear();
692
693 for (size_t i = 0; i < mCamcorderProfiles.size(); ++i) {
694 delete mCamcorderProfiles[i];
695 }
696 mCamcorderProfiles.clear();
697#endif
698}
699} // namespace android