MediaProfiles.cpp revision 1d7491b19516505e0754c66a3c8cd61811c9b6a6
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 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 296/*static*/ void 297MediaProfiles::startElementHandler(void *userData, const char *name, const char **atts) 298{ 299 MediaProfiles *profiles = (MediaProfiles *) userData; 300 if (strcmp("Video", name) == 0) { 301 createVideoCodec(atts, profiles); 302 } else if (strcmp("Audio", name) == 0) { 303 createAudioCodec(atts, profiles); 304 } else if (strcmp("VideoEncoderCap", name) == 0 && 305 strcmp("true", atts[3]) == 0) { 306 profiles->mVideoEncoders.add(createVideoEncoderCap(atts)); 307 } else if (strcmp("AudioEncoderCap", name) == 0 && 308 strcmp("true", atts[3]) == 0) { 309 profiles->mAudioEncoders.add(createAudioEncoderCap(atts)); 310 } else if (strcmp("VideoDecoderCap", name) == 0 && 311 strcmp("true", atts[3]) == 0) { 312 profiles->mVideoDecoders.add(createVideoDecoderCap(atts)); 313 } else if (strcmp("AudioDecoderCap", name) == 0 && 314 strcmp("true", atts[3]) == 0) { 315 profiles->mAudioDecoders.add(createAudioDecoderCap(atts)); 316 } else if (strcmp("EncoderOutputFileFormat", name) == 0) { 317 profiles->mEncoderOutputFileFormats.add(createEncoderOutputFileFormat(atts)); 318 } else if (strcmp("EncoderProfile", name) == 0) { 319 profiles->mCamcorderProfiles.add(createCamcorderProfile(atts)); 320 } 321} 322 323/*static*/ MediaProfiles* 324MediaProfiles::getInstance() 325{ 326 LOGV("getInstance"); 327 Mutex::Autolock lock(sLock); 328 if (!sIsInitialized) { 329 char value[PROPERTY_VALUE_MAX]; 330 if (property_get("media.settings.xml", value, NULL) <= 0) { 331 const char *defaultXmlFile = "/etc/media_profiles.xml"; 332 FILE *fp = fopen(defaultXmlFile, "r"); 333 if (fp == NULL) { 334 LOGW("could not find media config xml file"); 335 sInstance = createDefaultInstance(); 336 } else { 337 fclose(fp); // close the file first. 338 sInstance = createInstanceFromXmlFile(defaultXmlFile); 339 } 340 } else { 341 sInstance = createInstanceFromXmlFile(value); 342 } 343 } 344 345 return sInstance; 346} 347 348/*static*/ MediaProfiles::VideoEncoderCap* 349MediaProfiles::createDefaultH263VideoEncoderCap() 350{ 351 return new MediaProfiles::VideoEncoderCap( 352 VIDEO_ENCODER_H263, 192000, 420000, 176, 352, 144, 288, 1, 20); 353} 354 355/*static*/ MediaProfiles::VideoEncoderCap* 356MediaProfiles::createDefaultM4vVideoEncoderCap() 357{ 358 return new MediaProfiles::VideoEncoderCap( 359 VIDEO_ENCODER_MPEG_4_SP, 192000, 420000, 176, 352, 144, 288, 1, 20); 360} 361 362 363/*static*/ void 364MediaProfiles::createDefaultVideoEncoders(MediaProfiles *profiles) 365{ 366 profiles->mVideoEncoders.add(createDefaultH263VideoEncoderCap()); 367 profiles->mVideoEncoders.add(createDefaultM4vVideoEncoderCap()); 368} 369 370/*static*/ MediaProfiles::CamcorderProfile* 371MediaProfiles::createDefaultCamcorderHighProfile() 372{ 373 MediaProfiles::VideoCodec *videoCodec = 374 new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 360000, 352, 288, 20); 375 376 AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1); 377 CamcorderProfile *profile = new CamcorderProfile; 378 profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP; 379 profile->mQuality = CAMCORDER_QUALITY_HIGH; 380 profile->mDuration = 60; 381 profile->mVideoCodec = videoCodec; 382 profile->mAudioCodec = audioCodec; 383 return profile; 384} 385 386/*static*/ MediaProfiles::CamcorderProfile* 387MediaProfiles::createDefaultCamcorderLowProfile() 388{ 389 MediaProfiles::VideoCodec *videoCodec = 390 new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 192000, 176, 144, 20); 391 392 MediaProfiles::AudioCodec *audioCodec = 393 new MediaProfiles::AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1); 394 395 MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile; 396 profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP; 397 profile->mQuality = CAMCORDER_QUALITY_LOW; 398 profile->mDuration = 30; 399 profile->mVideoCodec = videoCodec; 400 profile->mAudioCodec = audioCodec; 401 return profile; 402} 403 404/*static*/ void 405MediaProfiles::createDefaultCamcorderProfiles(MediaProfiles *profiles) 406{ 407 profiles->mCamcorderProfiles.add(createDefaultCamcorderHighProfile()); 408 profiles->mCamcorderProfiles.add(createDefaultCamcorderLowProfile()); 409} 410 411/*static*/ void 412MediaProfiles::createDefaultAudioEncoders(MediaProfiles *profiles) 413{ 414 profiles->mAudioEncoders.add(createDefaultAmrNBEncoderCap()); 415} 416 417/*static*/ void 418MediaProfiles::createDefaultVideoDecoders(MediaProfiles *profiles) 419{ 420 MediaProfiles::VideoDecoderCap *cap = 421 new MediaProfiles::VideoDecoderCap(VIDEO_DECODER_WMV); 422 423 profiles->mVideoDecoders.add(cap); 424} 425 426/*static*/ void 427MediaProfiles::createDefaultAudioDecoders(MediaProfiles *profiles) 428{ 429 MediaProfiles::AudioDecoderCap *cap = 430 new MediaProfiles::AudioDecoderCap(AUDIO_DECODER_WMA); 431 432 profiles->mAudioDecoders.add(cap); 433} 434 435/*static*/ void 436MediaProfiles::createDefaultEncoderOutputFileFormats(MediaProfiles *profiles) 437{ 438 profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_THREE_GPP); 439 profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_MPEG_4); 440} 441 442/*static*/ MediaProfiles::AudioEncoderCap* 443MediaProfiles::createDefaultAmrNBEncoderCap() 444{ 445 return new MediaProfiles::AudioEncoderCap( 446 AUDIO_ENCODER_AMR_NB, 5525, 12200, 8000, 8000, 1, 1); 447} 448 449/*static*/ MediaProfiles* 450MediaProfiles::createDefaultInstance() 451{ 452 MediaProfiles *profiles = new MediaProfiles; 453 createDefaultCamcorderProfiles(profiles); 454 createDefaultVideoEncoders(profiles); 455 createDefaultAudioEncoders(profiles); 456 createDefaultVideoDecoders(profiles); 457 createDefaultAudioDecoders(profiles); 458 createDefaultEncoderOutputFileFormats(profiles); 459 sIsInitialized = true; 460 return profiles; 461} 462 463/*static*/ MediaProfiles* 464MediaProfiles::createInstanceFromXmlFile(const char *xml) 465{ 466 FILE *fp = NULL; 467 CHECK((fp = fopen(xml, "r"))); 468 469 XML_Parser parser = ::XML_ParserCreate(NULL); 470 CHECK(parser != NULL); 471 472 MediaProfiles *profiles = new MediaProfiles(); 473 ::XML_SetUserData(parser, profiles); 474 ::XML_SetElementHandler(parser, startElementHandler, NULL); 475 476 /* 477 FIXME: 478 expat is not compiled with -DXML_DTD. We don't have DTD parsing support. 479 480 if (!::XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS)) { 481 LOGE("failed to enable DTD support in the xml file"); 482 return UNKNOWN_ERROR; 483 } 484 485 */ 486 487 const int BUFF_SIZE = 512; 488 for (;;) { 489 void *buff = ::XML_GetBuffer(parser, BUFF_SIZE); 490 if (buff == NULL) { 491 LOGE("failed to in call to XML_GetBuffer()"); 492 delete profiles; 493 profiles = NULL; 494 goto exit; 495 } 496 497 int bytes_read = ::fread(buff, 1, BUFF_SIZE, fp); 498 if (bytes_read < 0) { 499 LOGE("failed in call to read"); 500 delete profiles; 501 profiles = NULL; 502 goto exit; 503 } 504 505 CHECK(::XML_ParseBuffer(parser, bytes_read, bytes_read == 0)); 506 507 if (bytes_read == 0) break; // done parsing the xml file 508 } 509 510exit: 511 ::XML_ParserFree(parser); 512 ::fclose(fp); 513 if (profiles) { 514 sIsInitialized = true; 515 } 516 return profiles; 517} 518 519Vector<output_format> MediaProfiles::getOutputFileFormats() const 520{ 521 return mEncoderOutputFileFormats; // copy out 522} 523 524Vector<video_encoder> MediaProfiles::getVideoEncoders() const 525{ 526 Vector<video_encoder> encoders; 527 for (size_t i = 0; i < mVideoEncoders.size(); ++i) { 528 encoders.add(mVideoEncoders[i]->mCodec); 529 } 530 return encoders; // copy out 531} 532 533int MediaProfiles::getVideoEncoderParamByName(const char *name, video_encoder codec) const 534{ 535 LOGV("getVideoEncoderParamByName: %s for codec %d", name, codec); 536 int index = -1; 537 for (size_t i = 0, n = mVideoEncoders.size(); i < n; ++i) { 538 if (mVideoEncoders[i]->mCodec == codec) { 539 index = i; 540 break; 541 } 542 } 543 if (index == -1) { 544 LOGE("The given video encoder %d is not found", codec); 545 return -1; 546 } 547 548 if (!strcmp("enc.vid.width.min", name)) return mVideoEncoders[index]->mMinFrameWidth; 549 if (!strcmp("enc.vid.width.max", name)) return mVideoEncoders[index]->mMaxFrameWidth; 550 if (!strcmp("enc.vid.height.min", name)) return mVideoEncoders[index]->mMinFrameHeight; 551 if (!strcmp("enc.vid.height.max", name)) return mVideoEncoders[index]->mMaxFrameHeight; 552 if (!strcmp("enc.vid.bps.min", name)) return mVideoEncoders[index]->mMinBitRate; 553 if (!strcmp("enc.vid.bps.max", name)) return mVideoEncoders[index]->mMaxBitRate; 554 if (!strcmp("enc.vid.fps.min", name)) return mVideoEncoders[index]->mMinFrameRate; 555 if (!strcmp("enc.vid.fps.max", name)) return mVideoEncoders[index]->mMaxFrameRate; 556 557 LOGE("The given video encoder param name %s is not found", name); 558 return -1; 559} 560 561Vector<audio_encoder> MediaProfiles::getAudioEncoders() const 562{ 563 Vector<audio_encoder> encoders; 564 for (size_t i = 0; i < mAudioEncoders.size(); ++i) { 565 encoders.add(mAudioEncoders[i]->mCodec); 566 } 567 return encoders; // copy out 568} 569 570int MediaProfiles::getAudioEncoderParamByName(const char *name, audio_encoder codec) const 571{ 572 LOGV("getAudioEncoderParamByName: %s for codec %d", name, codec); 573 int index = -1; 574 for (size_t i = 0, n = mAudioEncoders.size(); i < n; ++i) { 575 if (mAudioEncoders[i]->mCodec == codec) { 576 index = i; 577 break; 578 } 579 } 580 if (index == -1) { 581 LOGE("The given audio encoder %d is not found", codec); 582 return -1; 583 } 584 585 if (!strcmp("enc.aud.ch.min", name)) return mAudioEncoders[index]->mMinChannels; 586 if (!strcmp("enc.aud.ch.max", name)) return mAudioEncoders[index]->mMaxChannels; 587 if (!strcmp("enc.aud.bps.min", name)) return mAudioEncoders[index]->mMinBitRate; 588 if (!strcmp("enc.aud.bps.max", name)) return mAudioEncoders[index]->mMaxBitRate; 589 if (!strcmp("enc.aud.hz.min", name)) return mAudioEncoders[index]->mMinSampleRate; 590 if (!strcmp("enc.aud.hz.max", name)) return mAudioEncoders[index]->mMaxSampleRate; 591 592 LOGE("The given audio encoder param name %s is not found", name); 593 return -1; 594} 595 596Vector<video_decoder> MediaProfiles::getVideoDecoders() const 597{ 598 Vector<video_decoder> decoders; 599 for (size_t i = 0; i < mVideoDecoders.size(); ++i) { 600 decoders.add(mVideoDecoders[i]->mCodec); 601 } 602 return decoders; // copy out 603} 604 605Vector<audio_decoder> MediaProfiles::getAudioDecoders() const 606{ 607 Vector<audio_decoder> decoders; 608 for (size_t i = 0; i < mAudioDecoders.size(); ++i) { 609 decoders.add(mAudioDecoders[i]->mCodec); 610 } 611 return decoders; // copy out 612} 613 614int MediaProfiles::getCamcorderProfileParamByName(const char *name, camcorder_quality quality) const 615{ 616 LOGV("getCamcorderProfileParamByName: %s for quality %d", name, quality); 617 618 int index = -1; 619 for (size_t i = 0, n = mCamcorderProfiles.size(); i < n; ++i) { 620 if (mCamcorderProfiles[i]->mQuality == quality) { 621 index = i; 622 break; 623 } 624 } 625 if (index == -1) { 626 LOGE("The given camcorder profile quality %d is not found", quality); 627 return -1; 628 } 629 630 if (!strcmp("file.format", name)) return mCamcorderProfiles[index]->mFileFormat; 631 if (!strcmp("vid.codec", name)) return mCamcorderProfiles[index]->mVideoCodec->mCodec; 632 if (!strcmp("vid.width", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameWidth; 633 if (!strcmp("vid.height", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameHeight; 634 if (!strcmp("vid.bps", name)) return mCamcorderProfiles[index]->mVideoCodec->mBitRate; 635 if (!strcmp("vid.fps", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameRate; 636 if (!strcmp("aud.codec", name)) return mCamcorderProfiles[index]->mAudioCodec->mCodec; 637 if (!strcmp("aud.bps", name)) return mCamcorderProfiles[index]->mAudioCodec->mBitRate; 638 if (!strcmp("aud.ch", name)) return mCamcorderProfiles[index]->mAudioCodec->mChannels; 639 if (!strcmp("aud.hz", name)) return mCamcorderProfiles[index]->mAudioCodec->mSampleRate; 640 641 LOGE("The given camcorder profile param name %s is not found", name); 642 return -1; 643} 644 645MediaProfiles::~MediaProfiles() 646{ 647 CHECK("destructor should never be called" == 0); 648#if 0 649 for (size_t i = 0; i < mAudioEncoders.size(); ++i) { 650 delete mAudioEncoders[i]; 651 } 652 mAudioEncoders.clear(); 653 654 for (size_t i = 0; i < mVideoEncoders.size(); ++i) { 655 delete mVideoEncoders[i]; 656 } 657 mVideoEncoders.clear(); 658 659 for (size_t i = 0; i < mVideoDecoders.size(); ++i) { 660 delete mVideoDecoders[i]; 661 } 662 mVideoDecoders.clear(); 663 664 for (size_t i = 0; i < mAudioDecoders.size(); ++i) { 665 delete mAudioDecoders[i]; 666 } 667 mAudioDecoders.clear(); 668 669 for (size_t i = 0; i < mCamcorderProfiles.size(); ++i) { 670 delete mCamcorderProfiles[i]; 671 } 672 mCamcorderProfiles.clear(); 673#endif 674} 675} // namespace android 676