11d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*
21d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong**
31d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong** Copyright 2010, The Android Open Source Project
41d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong**
51d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong** Licensed under the Apache License, Version 2.0 (the "License");
61d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong** you may not use this file except in compliance with the License.
71d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong** You may obtain a copy of the License at
81d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong**
91d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong**     http://www.apache.org/licenses/LICENSE-2.0
101d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong**
111d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong** Unless required by applicable law or agreed to in writing, software
121d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong** distributed under the License is distributed on an "AS IS" BASIS,
131d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong** See the License for the specific language governing permissions and
151d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong** limitations under the License.
161d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong*/
171d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
181d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
191d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong//#define LOG_NDEBUG 0
201d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong#define LOG_TAG "MediaProfiles"
211d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
221d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong#include <stdlib.h>
231d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong#include <utils/Log.h>
241d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong#include <utils/Vector.h>
251d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong#include <cutils/properties.h>
26242b400fc6e360d9444335a3fab296d96db024d8Elliott Hughes#include <expat.h>
271d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong#include <media/MediaProfiles.h>
28f1d5aa162c02a16b7195a43a9bcea4d592600ac4James Dong#include <media/stagefright/foundation/ADebug.h>
296c6b4d0d2b98a7ceee8b697daaf611f8df3254fbJames Dong#include <OMX_Video.h>
301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
311d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongnamespace android {
321d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
331d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMutex MediaProfiles::sLock;
341d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongbool MediaProfiles::sIsInitialized = false;
351d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles *MediaProfiles::sInstance = NULL;
361d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
371d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongconst MediaProfiles::NameToTagMap MediaProfiles::sVideoEncoderNameMap[] = {
381d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"h263", VIDEO_ENCODER_H263},
391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"h264", VIDEO_ENCODER_H264},
409aa87d4ef502c9700a31fe46dc6e1d6f99cf4e5eWonsik Kim    {"m4v",  VIDEO_ENCODER_MPEG_4_SP},
419aa87d4ef502c9700a31fe46dc6e1d6f99cf4e5eWonsik Kim    {"hevc", VIDEO_ENCODER_HEVC}
421d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
431d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
441d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongconst MediaProfiles::NameToTagMap MediaProfiles::sAudioEncoderNameMap[] = {
45aeb8fd460ed87d032b3fb8bb61e21eb542ce0f5bDave Burke    {"amrnb",  AUDIO_ENCODER_AMR_NB},
46aeb8fd460ed87d032b3fb8bb61e21eb542ce0f5bDave Burke    {"amrwb",  AUDIO_ENCODER_AMR_WB},
47aeb8fd460ed87d032b3fb8bb61e21eb542ce0f5bDave Burke    {"aac",    AUDIO_ENCODER_AAC},
48f60c660f048d5f5e2458cff243c20400d73757a7Dave Burke    {"heaac",  AUDIO_ENCODER_HE_AAC},
49f60c660f048d5f5e2458cff243c20400d73757a7Dave Burke    {"aaceld", AUDIO_ENCODER_AAC_ELD}
501d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
521d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongconst MediaProfiles::NameToTagMap MediaProfiles::sFileFormatMap[] = {
531d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"3gp", OUTPUT_FORMAT_THREE_GPP},
541d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"mp4", OUTPUT_FORMAT_MPEG_4}
551d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
561d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
571d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongconst MediaProfiles::NameToTagMap MediaProfiles::sVideoDecoderNameMap[] = {
581d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"wmv", VIDEO_DECODER_WMV}
591d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
601d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
611d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongconst MediaProfiles::NameToTagMap MediaProfiles::sAudioDecoderNameMap[] = {
621d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"wma", AUDIO_DECODER_WMA}
631d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
641d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
651d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongconst MediaProfiles::NameToTagMap MediaProfiles::sCamcorderQualityNameMap[] = {
66c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"low", CAMCORDER_QUALITY_LOW},
671d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"high", CAMCORDER_QUALITY_HIGH},
68c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"qcif", CAMCORDER_QUALITY_QCIF},
699783ed8f85af3d7c72030098acfed7e1d6638349Nipun Kwatra    {"cif", CAMCORDER_QUALITY_CIF},
70c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"480p", CAMCORDER_QUALITY_480P},
71c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"720p", CAMCORDER_QUALITY_720P},
72c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"1080p", CAMCORDER_QUALITY_1080P},
735f6af1a8e34381ca2ac2527fcefe220a22f49b53Zhijun He    {"2160p", CAMCORDER_QUALITY_2160P},
74669012d77b00a2aacb6fd12837f2870f9ec17865James Dong    {"qvga", CAMCORDER_QUALITY_QVGA},
75c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra
76c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"timelapselow",  CAMCORDER_QUALITY_TIME_LAPSE_LOW},
77c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"timelapsehigh", CAMCORDER_QUALITY_TIME_LAPSE_HIGH},
78c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"timelapseqcif", CAMCORDER_QUALITY_TIME_LAPSE_QCIF},
799783ed8f85af3d7c72030098acfed7e1d6638349Nipun Kwatra    {"timelapsecif", CAMCORDER_QUALITY_TIME_LAPSE_CIF},
80c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"timelapse480p", CAMCORDER_QUALITY_TIME_LAPSE_480P},
81c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"timelapse720p", CAMCORDER_QUALITY_TIME_LAPSE_720P},
82669012d77b00a2aacb6fd12837f2870f9ec17865James Dong    {"timelapse1080p", CAMCORDER_QUALITY_TIME_LAPSE_1080P},
835f6af1a8e34381ca2ac2527fcefe220a22f49b53Zhijun He    {"timelapse2160p", CAMCORDER_QUALITY_TIME_LAPSE_2160P},
84669012d77b00a2aacb6fd12837f2870f9ec17865James Dong    {"timelapseqvga", CAMCORDER_QUALITY_TIME_LAPSE_QVGA},
85e07909715b44cc56df723750af93f0608210f94dZhijun He
86e07909715b44cc56df723750af93f0608210f94dZhijun He    {"highspeedlow",  CAMCORDER_QUALITY_HIGH_SPEED_LOW},
87e07909715b44cc56df723750af93f0608210f94dZhijun He    {"highspeedhigh", CAMCORDER_QUALITY_HIGH_SPEED_HIGH},
88e07909715b44cc56df723750af93f0608210f94dZhijun He    {"highspeed480p", CAMCORDER_QUALITY_HIGH_SPEED_480P},
89e07909715b44cc56df723750af93f0608210f94dZhijun He    {"highspeed720p", CAMCORDER_QUALITY_HIGH_SPEED_720P},
90e07909715b44cc56df723750af93f0608210f94dZhijun He    {"highspeed1080p", CAMCORDER_QUALITY_HIGH_SPEED_1080P},
919520aa609c505cf8a9ee105bd78dc186cfb7770bZhijun He    {"highspeed2160p", CAMCORDER_QUALITY_HIGH_SPEED_2160P},
921d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
931d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9480520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten#if LOG_NDEBUG
9580520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten#define UNUSED __unused
9680520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten#else
9780520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten#define UNUSED
9880520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten#endif
9980520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten
1001d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
10180520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logVideoCodec(const MediaProfiles::VideoCodec& codec UNUSED)
1021d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("video codec:");
1043856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", codec.mCodec);
1053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("bit rate: %d", codec.mBitRate);
1063856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame width: %d", codec.mFrameWidth);
1073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame height: %d", codec.mFrameHeight);
1083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame rate: %d", codec.mFrameRate);
1091d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1101d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1111d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
11280520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logAudioCodec(const MediaProfiles::AudioCodec& codec UNUSED)
1131d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("audio codec:");
1153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", codec.mCodec);
1163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("bit rate: %d", codec.mBitRate);
1173856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("sample rate: %d", codec.mSampleRate);
1183856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("number of channels: %d", codec.mChannels);
1191d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1201d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1211d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
12280520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logVideoEncoderCap(const MediaProfiles::VideoEncoderCap& cap UNUSED)
1231d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("video encoder cap:");
1253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", cap.mCodec);
1263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("bit rate: min = %d and max = %d", cap.mMinBitRate, cap.mMaxBitRate);
1273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame width: min = %d and max = %d", cap.mMinFrameWidth, cap.mMaxFrameWidth);
1283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame height: min = %d and max = %d", cap.mMinFrameHeight, cap.mMaxFrameHeight);
1293856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame rate: min = %d and max = %d", cap.mMinFrameRate, cap.mMaxFrameRate);
1301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1311d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1321d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
13380520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logAudioEncoderCap(const MediaProfiles::AudioEncoderCap& cap UNUSED)
1341d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1353856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("audio encoder cap:");
1363856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", cap.mCodec);
1373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("bit rate: min = %d and max = %d", cap.mMinBitRate, cap.mMaxBitRate);
1383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("sample rate: min = %d and max = %d", cap.mMinSampleRate, cap.mMaxSampleRate);
1393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("number of channels: min = %d and max = %d", cap.mMinChannels, cap.mMaxChannels);
1401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1421d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
14380520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logVideoDecoderCap(const MediaProfiles::VideoDecoderCap& cap UNUSED)
1441d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("video decoder cap:");
1463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", cap.mCodec);
1471d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1481d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1491d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
15080520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logAudioDecoderCap(const MediaProfiles::AudioDecoderCap& cap UNUSED)
1511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("audio codec cap:");
1533856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", cap.mCodec);
1541d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1551d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1561d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ int
157b187de1ada34a9023c05d020a4592686ba761278Glenn KastenMediaProfiles::findTagForName(const MediaProfiles::NameToTagMap *map, size_t nMappings,
158b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten        const char *name)
1591d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1601d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    int tag = -1;
1611d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    for (size_t i = 0; i < nMappings; ++i) {
1621d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        if (!strcmp(map[i].name, name)) {
1631d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            tag = map[i].tag;
1641d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            break;
1651d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        }
1661d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    }
1671d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return tag;
1681d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1691d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1701d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::VideoCodec*
1711d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createVideoCodec(const char **atts, MediaProfiles *profiles)
1721d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1731d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("codec",     atts[0]) &&
1741d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("bitRate",   atts[2]) &&
1751d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("width",     atts[4]) &&
1761d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("height",    atts[6]) &&
1771d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("frameRate", atts[8]));
1781d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1791d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]);
1801d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]);
1811d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
1821d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1831d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoCodec *videoCodec =
1841d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::VideoCodec(static_cast<video_encoder>(codec),
1851d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            atoi(atts[3]), atoi(atts[5]), atoi(atts[7]), atoi(atts[9]));
1861d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logVideoCodec(*videoCodec);
1871d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1881d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    size_t nCamcorderProfiles;
1891d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1);
1901d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mVideoCodec = videoCodec;
1911d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return videoCodec;
1921d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1931d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1941d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::AudioCodec*
1951d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createAudioCodec(const char **atts, MediaProfiles *profiles)
1961d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1971d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("codec",      atts[0]) &&
1981d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("bitRate",    atts[2]) &&
1991d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("sampleRate", atts[4]) &&
2001d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("channels",   atts[6]));
2011d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]);
2021d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]);
2031d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
2041d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2051d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::AudioCodec *audioCodec =
2061d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::AudioCodec(static_cast<audio_encoder>(codec),
2071d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            atoi(atts[3]), atoi(atts[5]), atoi(atts[7]));
2081d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logAudioCodec(*audioCodec);
2091d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2101d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    size_t nCamcorderProfiles;
2111d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1);
2121d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mAudioCodec = audioCodec;
2131d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return audioCodec;
2141d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
2151d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::AudioDecoderCap*
2161d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createAudioDecoderCap(const char **atts)
2171d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
2181d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("name",    atts[0]) &&
2191d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("enabled", atts[2]));
2201d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2211d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sAudioDecoderNameMap)/sizeof(sAudioDecoderNameMap[0]);
2221d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sAudioDecoderNameMap, nMappings, atts[1]);
2231d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
2241d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2251d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::AudioDecoderCap *cap =
2261d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::AudioDecoderCap(static_cast<audio_decoder>(codec));
2271d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logAudioDecoderCap(*cap);
2281d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return cap;
2291d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
2301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2311d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::VideoDecoderCap*
2321d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createVideoDecoderCap(const char **atts)
2331d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
2341d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("name",    atts[0]) &&
2351d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("enabled", atts[2]));
2361d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2371d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sVideoDecoderNameMap)/sizeof(sVideoDecoderNameMap[0]);
2381d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sVideoDecoderNameMap, nMappings, atts[1]);
2391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
2401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoDecoderCap *cap =
2421d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::VideoDecoderCap(static_cast<video_decoder>(codec));
2431d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logVideoDecoderCap(*cap);
2441d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return cap;
2451d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
2461d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2471d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::VideoEncoderCap*
2481d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createVideoEncoderCap(const char **atts)
2491d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
2501d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("name",           atts[0])  &&
2511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("enabled",        atts[2])  &&
2521d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minBitRate",     atts[4])  &&
2531d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxBitRate",     atts[6])  &&
2541d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minFrameWidth",  atts[8])  &&
2551d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxFrameWidth",  atts[10]) &&
2561d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minFrameHeight", atts[12]) &&
2571d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxFrameHeight", atts[14]) &&
2581d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minFrameRate",   atts[16]) &&
2591d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxFrameRate",   atts[18]));
2601d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2611d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]);
2621d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]);
2631d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
2641d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2651d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoEncoderCap *cap =
2661d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::VideoEncoderCap(static_cast<video_encoder>(codec),
2671d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            atoi(atts[5]), atoi(atts[7]), atoi(atts[9]), atoi(atts[11]), atoi(atts[13]),
2681d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            atoi(atts[15]), atoi(atts[17]), atoi(atts[19]));
2691d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logVideoEncoderCap(*cap);
2701d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return cap;
2711d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
2721d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2731d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::AudioEncoderCap*
2741d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createAudioEncoderCap(const char **atts)
2751d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
2761d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("name",          atts[0])  &&
2771d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("enabled",       atts[2])  &&
2781d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minBitRate",    atts[4])  &&
2791d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxBitRate",    atts[6])  &&
2801d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minSampleRate", atts[8])  &&
2811d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxSampleRate", atts[10]) &&
2821d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minChannels",   atts[12]) &&
2831d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxChannels",   atts[14]));
2841d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2851d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]);
2861d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]);
2871d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
2881d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2891d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::AudioEncoderCap *cap =
290b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten        new MediaProfiles::AudioEncoderCap(static_cast<audio_encoder>(codec), atoi(atts[5]),
291b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten            atoi(atts[7]), atoi(atts[9]), atoi(atts[11]), atoi(atts[13]), atoi(atts[15]));
2921d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logAudioEncoderCap(*cap);
2931d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return cap;
2941d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
2951d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2961d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ output_format
2971d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createEncoderOutputFileFormat(const char **atts)
2981d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
2991d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("name", atts[0]));
3001d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3011d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings =sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]);
3021d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int format = findTagForName(sFileFormatMap, nMappings, atts[1]);
3031d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(format != -1);
3041d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3051d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return static_cast<output_format>(format);
3061d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
3071d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3082a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongstatic bool isCameraIdFound(int cameraId, const Vector<int>& cameraIds) {
3092a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    for (int i = 0, n = cameraIds.size(); i < n; ++i) {
3102a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        if (cameraId == cameraIds[i]) {
3112a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            return true;
3122a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
3132a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
3142a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    return false;
3152a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
3162a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
3171d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::CamcorderProfile*
3182a7e0a1eb29306982fd77bdc64d324464a48a2b9James DongMediaProfiles::createCamcorderProfile(int cameraId, const char **atts, Vector<int>& cameraIds)
3191d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
3201d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("quality",    atts[0]) &&
3211d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("fileFormat", atts[2]) &&
3221d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("duration",   atts[4]));
3231d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
324b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten    const size_t nProfileMappings = sizeof(sCamcorderQualityNameMap)/
325b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten            sizeof(sCamcorderQualityNameMap[0]);
3261d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int quality = findTagForName(sCamcorderQualityNameMap, nProfileMappings, atts[1]);
3271d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(quality != -1);
3281d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3291d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nFormatMappings = sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]);
3301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int fileFormat = findTagForName(sFileFormatMap, nFormatMappings, atts[3]);
3311d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(fileFormat != -1);
3321d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3331d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
3343eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    profile->mCameraId = cameraId;
3352a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    if (!isCameraIdFound(cameraId, cameraIds)) {
3362a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        cameraIds.add(cameraId);
3372a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
3381d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mFileFormat = static_cast<output_format>(fileFormat);
3391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mQuality = static_cast<camcorder_quality>(quality);
3401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mDuration = atoi(atts[5]);
3411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return profile;
3421d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
3431d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3443eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung ChangMediaProfiles::ImageEncodingQualityLevels*
3453eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung ChangMediaProfiles::findImageEncodingQualityLevels(int cameraId) const
3463eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang{
3473eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    int n = mImageEncodingQualityLevels.size();
3483eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    for (int i = 0; i < n; i++) {
3493eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        ImageEncodingQualityLevels *levels = mImageEncodingQualityLevels[i];
3503eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        if (levels->mCameraId == cameraId) {
3513eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang            return levels;
3523eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        }
3533eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    }
3543eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    return NULL;
3553eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang}
3563eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang
3573eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Changvoid MediaProfiles::addImageEncodingQualityLevel(int cameraId, const char** atts)
358f5a8385649204213dc19e1a64f4693931e048d85James Dong{
359f5a8385649204213dc19e1a64f4693931e048d85James Dong    CHECK(!strcmp("quality", atts[0]));
3603eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    int quality = atoi(atts[1]);
36190bebef5669a9385c706b042d146a31dca2e5d9bGlenn Kasten    ALOGV("%s: cameraId=%d, quality=%d", __func__, cameraId, quality);
3623eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    ImageEncodingQualityLevels *levels = findImageEncodingQualityLevels(cameraId);
3633eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang
3643eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    if (levels == NULL) {
3653eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        levels = new ImageEncodingQualityLevels();
3663eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        levels->mCameraId = cameraId;
3673eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        mImageEncodingQualityLevels.add(levels);
3683eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    }
3693eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang
3703eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    levels->mLevels.add(quality);
3713eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang}
3723eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang
3733eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang/*static*/ int
3743eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung ChangMediaProfiles::getCameraId(const char** atts)
3753eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang{
3763eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    if (!atts[0]) return 0;  // default cameraId = 0
3773eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    CHECK(!strcmp("cameraId", atts[0]));
378f5a8385649204213dc19e1a64f4693931e048d85James Dong    return atoi(atts[1]);
379f5a8385649204213dc19e1a64f4693931e048d85James Dong}
380f5a8385649204213dc19e1a64f4693931e048d85James Dong
3810f056290cb16763453f18bbef80cde673041dbbcJames Dongvoid MediaProfiles::addStartTimeOffset(int cameraId, const char** atts)
3820f056290cb16763453f18bbef80cde673041dbbcJames Dong{
383b1eb1a0dd38a36dd0c0626d3d57043dbd0042a92Eric Laurent    int offsetTimeMs = 1000;
3840f056290cb16763453f18bbef80cde673041dbbcJames Dong    if (atts[2]) {
3850f056290cb16763453f18bbef80cde673041dbbcJames Dong        CHECK(!strcmp("startOffsetMs", atts[2]));
3860f056290cb16763453f18bbef80cde673041dbbcJames Dong        offsetTimeMs = atoi(atts[3]);
3870f056290cb16763453f18bbef80cde673041dbbcJames Dong    }
3880f056290cb16763453f18bbef80cde673041dbbcJames Dong
3893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("%s: cameraId=%d, offset=%d ms", __func__, cameraId, offsetTimeMs);
3900f056290cb16763453f18bbef80cde673041dbbcJames Dong    mStartTimeOffsets.replaceValueFor(cameraId, offsetTimeMs);
3910f056290cb16763453f18bbef80cde673041dbbcJames Dong}
392cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng
3931d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
3941d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::startElementHandler(void *userData, const char *name, const char **atts)
3951d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
3961d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles *profiles = (MediaProfiles *) userData;
3971d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (strcmp("Video", name) == 0) {
3981d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        createVideoCodec(atts, profiles);
3991d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("Audio", name) == 0) {
4001d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        createAudioCodec(atts, profiles);
4011d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("VideoEncoderCap", name) == 0 &&
4021d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong               strcmp("true", atts[3]) == 0) {
4031d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        profiles->mVideoEncoders.add(createVideoEncoderCap(atts));
4041d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("AudioEncoderCap", name) == 0 &&
4051d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong               strcmp("true", atts[3]) == 0) {
4061d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        profiles->mAudioEncoders.add(createAudioEncoderCap(atts));
4071d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("VideoDecoderCap", name) == 0 &&
4081d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong               strcmp("true", atts[3]) == 0) {
4091d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        profiles->mVideoDecoders.add(createVideoDecoderCap(atts));
4101d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("AudioDecoderCap", name) == 0 &&
4111d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong               strcmp("true", atts[3]) == 0) {
4121d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        profiles->mAudioDecoders.add(createAudioDecoderCap(atts));
4131d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("EncoderOutputFileFormat", name) == 0) {
4141d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        profiles->mEncoderOutputFileFormats.add(createEncoderOutputFileFormat(atts));
4153eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    } else if (strcmp("CamcorderProfiles", name) == 0) {
4163eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        profiles->mCurrentCameraId = getCameraId(atts);
4170f056290cb16763453f18bbef80cde673041dbbcJames Dong        profiles->addStartTimeOffset(profiles->mCurrentCameraId, atts);
4181d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("EncoderProfile", name) == 0) {
4193eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        profiles->mCamcorderProfiles.add(
4202a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            createCamcorderProfile(profiles->mCurrentCameraId, atts, profiles->mCameraIds));
421f5a8385649204213dc19e1a64f4693931e048d85James Dong    } else if (strcmp("ImageEncoding", name) == 0) {
4223eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        profiles->addImageEncodingQualityLevel(profiles->mCurrentCameraId, atts);
4231d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    }
4241d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
4251d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
4262a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongstatic bool isCamcorderProfile(camcorder_quality quality) {
4272a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    return quality >= CAMCORDER_QUALITY_LIST_START &&
4282a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong           quality <= CAMCORDER_QUALITY_LIST_END;
4292a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
4302a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
4312a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongstatic bool isTimelapseProfile(camcorder_quality quality) {
4322a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    return quality >= CAMCORDER_QUALITY_TIME_LAPSE_LIST_START &&
4332a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong           quality <= CAMCORDER_QUALITY_TIME_LAPSE_LIST_END;
4342a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
4352a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
436e07909715b44cc56df723750af93f0608210f94dZhijun Hestatic bool isHighSpeedProfile(camcorder_quality quality) {
437e07909715b44cc56df723750af93f0608210f94dZhijun He    return quality >= CAMCORDER_QUALITY_HIGH_SPEED_LIST_START &&
438e07909715b44cc56df723750af93f0608210f94dZhijun He           quality <= CAMCORDER_QUALITY_HIGH_SPEED_LIST_END;
439e07909715b44cc56df723750af93f0608210f94dZhijun He}
440e07909715b44cc56df723750af93f0608210f94dZhijun He
4412a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongvoid MediaProfiles::initRequiredProfileRefs(const Vector<int>& cameraIds) {
44234fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn    ALOGV("Number of camera ids: %zu", cameraIds.size());
4432a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    CHECK(cameraIds.size() > 0);
4442a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    mRequiredProfileRefs = new RequiredProfiles[cameraIds.size()];
4452a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    for (size_t i = 0, n = cameraIds.size(); i < n; ++i) {
4462a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        mRequiredProfileRefs[i].mCameraId = cameraIds[i];
4472a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        for (size_t j = 0; j < kNumRequiredProfiles; ++j) {
4482a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            mRequiredProfileRefs[i].mRefs[j].mHasRefProfile = false;
4492a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            mRequiredProfileRefs[i].mRefs[j].mRefProfileIndex = -1;
4502a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            if ((j & 1) == 0) {  // low resolution
4512a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                mRequiredProfileRefs[i].mRefs[j].mResolutionProduct = 0x7FFFFFFF;
4522a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            } else {             // high resolution
4532a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                mRequiredProfileRefs[i].mRefs[j].mResolutionProduct = 0;
4542a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
4552a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
4562a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
4572a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
4582a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
4592a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongint MediaProfiles::getRequiredProfileRefIndex(int cameraId) {
4602a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    for (size_t i = 0, n = mCameraIds.size(); i < n; ++i) {
4612a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        if (mCameraIds[i] == cameraId) {
4622a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            return i;
4632a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
4642a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
4652a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    return -1;
4662a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
4672a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
4682a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongvoid MediaProfiles::checkAndAddRequiredProfilesIfNecessary() {
4692a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    if (sIsInitialized) {
4702a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        return;
4712a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
4722a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
4732a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    initRequiredProfileRefs(mCameraIds);
4742a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
4752a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    for (size_t i = 0, n = mCamcorderProfiles.size(); i < n; ++i) {
4762a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        int product = mCamcorderProfiles[i]->mVideoCodec->mFrameWidth *
4772a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                      mCamcorderProfiles[i]->mVideoCodec->mFrameHeight;
4782a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
4792a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        camcorder_quality quality = mCamcorderProfiles[i]->mQuality;
4802a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        int cameraId = mCamcorderProfiles[i]->mCameraId;
4812a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        int index = -1;
4822a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        int refIndex = getRequiredProfileRefIndex(cameraId);
4832a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        CHECK(refIndex != -1);
4842a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        RequiredProfileRefInfo *info;
4852a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        camcorder_quality refQuality;
4862a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
487e07909715b44cc56df723750af93f0608210f94dZhijun He        // Check high and low from either camcorder profile, timelapse profile
488e07909715b44cc56df723750af93f0608210f94dZhijun He        // or high speed profile, but not all of them. Default, check camcorder profile
4892a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        size_t j = 0;
4903c8889e827d95b195fe5ba077a01cb5b6042e534Bernhard Rosenkraenzer        size_t o = 2;
4912a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        if (isTimelapseProfile(quality)) {
4922a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            // Check timelapse profile instead.
4932a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            j = 2;
4943c8889e827d95b195fe5ba077a01cb5b6042e534Bernhard Rosenkraenzer            o = kNumRequiredProfiles;
495e07909715b44cc56df723750af93f0608210f94dZhijun He        } else if (isHighSpeedProfile(quality)) {
496e07909715b44cc56df723750af93f0608210f94dZhijun He            // Skip the check for high speed profile.
497e07909715b44cc56df723750af93f0608210f94dZhijun He            continue;
4982a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        } else {
4992a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            // Must be camcorder profile.
5002a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            CHECK(isCamcorderProfile(quality));
5012a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
5023c8889e827d95b195fe5ba077a01cb5b6042e534Bernhard Rosenkraenzer        for (; j < o; ++j) {
5032a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            info = &(mRequiredProfileRefs[refIndex].mRefs[j]);
5042a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            if ((j % 2 == 0 && product > info->mResolutionProduct) ||  // low
5052a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                (j % 2 != 0 && product < info->mResolutionProduct)) {  // high
5062a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                continue;
5072a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
5082a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            switch (j) {
5092a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                case 0:
5102a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   refQuality = CAMCORDER_QUALITY_LOW;
5112a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   break;
5122a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                case 1:
5132a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   refQuality = CAMCORDER_QUALITY_HIGH;
5142a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   break;
5152a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                case 2:
5162a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   refQuality = CAMCORDER_QUALITY_TIME_LAPSE_LOW;
5172a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   break;
5182a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                case 3:
5192a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   refQuality = CAMCORDER_QUALITY_TIME_LAPSE_HIGH;
5202a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   break;
5212a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                default:
5222a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    CHECK(!"Should never reach here");
5232a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
5242a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5252a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            if (!info->mHasRefProfile) {
5262a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                index = getCamcorderProfileIndex(cameraId, refQuality);
5272a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
5282a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            if (index == -1) {
5292a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                // New high or low quality profile is found.
5302a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                // Update its reference.
5312a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                info->mHasRefProfile = true;
5322a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                info->mRefProfileIndex = i;
5332a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                info->mResolutionProduct = product;
5342a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
5352a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
5362a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
5372a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5382a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    for (size_t cameraId = 0; cameraId < mCameraIds.size(); ++cameraId) {
5392a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        for (size_t j = 0; j < kNumRequiredProfiles; ++j) {
5402a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            int refIndex = getRequiredProfileRefIndex(cameraId);
5412a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            CHECK(refIndex != -1);
5422a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            RequiredProfileRefInfo *info =
5432a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    &mRequiredProfileRefs[refIndex].mRefs[j];
5442a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5452a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            if (info->mHasRefProfile) {
5462a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5472a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                CamcorderProfile *profile =
5482a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    new CamcorderProfile(
5492a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                            *mCamcorderProfiles[info->mRefProfileIndex]);
5502a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5512a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                // Overwrite the quality
5522a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                switch (j % kNumRequiredProfiles) {
5532a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    case 0:
5542a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality = CAMCORDER_QUALITY_LOW;
5552a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        break;
5562a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    case 1:
5572a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality = CAMCORDER_QUALITY_HIGH;
5582a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        break;
5592a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    case 2:
5602a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality = CAMCORDER_QUALITY_TIME_LAPSE_LOW;
5612a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        break;
5622a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    case 3:
5632a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality = CAMCORDER_QUALITY_TIME_LAPSE_HIGH;
5642a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        break;
5652a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    default:
5662a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        CHECK(!"Should never come here");
5672a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                }
5682a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5692a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                int index = getCamcorderProfileIndex(cameraId, profile->mQuality);
5702a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                if (index != -1) {
57134fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn                    ALOGV("Profile quality %d for camera %zu already exists",
5722a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality, cameraId);
5732a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    CHECK(index == refIndex);
5742a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    continue;
5752a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                }
5762a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5772a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                // Insert the new profile
57834fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn                ALOGV("Add a profile: quality %d=>%d for camera %zu",
5792a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        mCamcorderProfiles[info->mRefProfileIndex]->mQuality,
5802a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality, cameraId);
5812a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5822a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                mCamcorderProfiles.add(profile);
5832a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
5842a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
5852a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
5862a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
5872a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5881d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles*
5891d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::getInstance()
5901d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
5913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("getInstance");
5921d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    Mutex::Autolock lock(sLock);
5931d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (!sIsInitialized) {
5941d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        char value[PROPERTY_VALUE_MAX];
5951d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        if (property_get("media.settings.xml", value, NULL) <= 0) {
5961d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            const char *defaultXmlFile = "/etc/media_profiles.xml";
5971d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            FILE *fp = fopen(defaultXmlFile, "r");
5981d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            if (fp == NULL) {
5995ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block                ALOGW("could not find media config xml file");
6001d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong                sInstance = createDefaultInstance();
6011d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            } else {
6021d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong                fclose(fp);  // close the file first.
6031d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong                sInstance = createInstanceFromXmlFile(defaultXmlFile);
6041d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            }
6051d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        } else {
6061d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            sInstance = createInstanceFromXmlFile(value);
6071d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        }
6082a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        CHECK(sInstance != NULL);
6092a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        sInstance->checkAndAddRequiredProfilesIfNecessary();
6102a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        sIsInitialized = true;
6111d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    }
6121d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6131d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return sInstance;
6141d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
6151d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6161d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::VideoEncoderCap*
6171d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultH263VideoEncoderCap()
6181d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
6191d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return new MediaProfiles::VideoEncoderCap(
6201d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        VIDEO_ENCODER_H263, 192000, 420000, 176, 352, 144, 288, 1, 20);
6211d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
6221d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6231d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::VideoEncoderCap*
6241d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultM4vVideoEncoderCap()
6251d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
6261d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return new MediaProfiles::VideoEncoderCap(
6271d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        VIDEO_ENCODER_MPEG_4_SP, 192000, 420000, 176, 352, 144, 288, 1, 20);
6281d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
6291d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6311d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
6321d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultVideoEncoders(MediaProfiles *profiles)
6331d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
6341d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mVideoEncoders.add(createDefaultH263VideoEncoderCap());
6351d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mVideoEncoders.add(createDefaultM4vVideoEncoderCap());
6361d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
6371d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6381d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::CamcorderProfile*
639d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderTimeLapseQcifProfile(camcorder_quality quality)
640c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra{
641c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    MediaProfiles::VideoCodec *videoCodec =
642d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 1000000, 176, 144, 20);
643c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra
644c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
645c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
646c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mCameraId = 0;
647c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
648d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mQuality = quality;
649c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mDuration = 60;
650c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mVideoCodec = videoCodec;
651c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mAudioCodec = audioCodec;
652c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    return profile;
653c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra}
654c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra
655c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra/*static*/ MediaProfiles::CamcorderProfile*
656d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderTimeLapse480pProfile(camcorder_quality quality)
657c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra{
658c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    MediaProfiles::VideoCodec *videoCodec =
659d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 20000000, 720, 480, 20);
660c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra
661c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
662c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
663c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mCameraId = 0;
664c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
665d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mQuality = quality;
666c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mDuration = 60;
667c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mVideoCodec = videoCodec;
668c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mAudioCodec = audioCodec;
669c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    return profile;
670c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra}
671c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra
672d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra/*static*/ void
673d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderTimeLapseLowProfiles(
674d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **lowTimeLapseProfile,
675d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **lowSpecificTimeLapseProfile) {
676b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten    *lowTimeLapseProfile = createDefaultCamcorderTimeLapseQcifProfile(
677b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten            CAMCORDER_QUALITY_TIME_LAPSE_LOW);
678b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten    *lowSpecificTimeLapseProfile = createDefaultCamcorderTimeLapseQcifProfile(
679b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten            CAMCORDER_QUALITY_TIME_LAPSE_QCIF);
680d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra}
681d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
682d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra/*static*/ void
683d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderTimeLapseHighProfiles(
684d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **highTimeLapseProfile,
685d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **highSpecificTimeLapseProfile) {
686b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten    *highTimeLapseProfile = createDefaultCamcorderTimeLapse480pProfile(
687b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten            CAMCORDER_QUALITY_TIME_LAPSE_HIGH);
688b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten    *highSpecificTimeLapseProfile = createDefaultCamcorderTimeLapse480pProfile(
689b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten            CAMCORDER_QUALITY_TIME_LAPSE_480P);
690d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra}
691d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
692c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra/*static*/ MediaProfiles::CamcorderProfile*
693d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderQcifProfile(camcorder_quality quality)
6941d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
6951d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoCodec *videoCodec =
696d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 192000, 176, 144, 20);
6971d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
698d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::AudioCodec *audioCodec =
699d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        new MediaProfiles::AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
700d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
701d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
7023eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    profile->mCameraId = 0;
7031d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
704d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mQuality = quality;
705d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mDuration = 30;
7061d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mVideoCodec = videoCodec;
7071d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mAudioCodec = audioCodec;
7081d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return profile;
7091d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
7101d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
7111d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::CamcorderProfile*
712d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderCifProfile(camcorder_quality quality)
7131d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
7141d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoCodec *videoCodec =
715d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 360000, 352, 288, 20);
7161d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
717d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
718d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
7193eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    profile->mCameraId = 0;
7201d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
721d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mQuality = quality;
722d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mDuration = 60;
7231d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mVideoCodec = videoCodec;
7241d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mAudioCodec = audioCodec;
7251d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return profile;
7261d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
7271d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
7281d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
729d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderLowProfiles(
730d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **lowProfile,
731d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **lowSpecificProfile) {
732d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *lowProfile = createDefaultCamcorderQcifProfile(CAMCORDER_QUALITY_LOW);
733d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *lowSpecificProfile = createDefaultCamcorderQcifProfile(CAMCORDER_QUALITY_QCIF);
734d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra}
735d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
736d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra/*static*/ void
737d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderHighProfiles(
738d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **highProfile,
739d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **highSpecificProfile) {
740d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *highProfile = createDefaultCamcorderCifProfile(CAMCORDER_QUALITY_HIGH);
741d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *highSpecificProfile = createDefaultCamcorderCifProfile(CAMCORDER_QUALITY_CIF);
742d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra}
743d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
744d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra/*static*/ void
7451d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultCamcorderProfiles(MediaProfiles *profiles)
7461d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
747d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    // low camcorder profiles.
748d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::CamcorderProfile *lowProfile, *lowSpecificProfile;
749d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    createDefaultCamcorderLowProfiles(&lowProfile, &lowSpecificProfile);
750d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(lowProfile);
751d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(lowSpecificProfile);
752d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
753d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    // high camcorder profiles.
754d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::CamcorderProfile* highProfile, *highSpecificProfile;
755d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    createDefaultCamcorderHighProfiles(&highProfile, &highSpecificProfile);
756d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(highProfile);
757d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(highSpecificProfile);
758d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
759d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    // low camcorder time lapse profiles.
760d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::CamcorderProfile *lowTimeLapseProfile, *lowSpecificTimeLapseProfile;
761d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    createDefaultCamcorderTimeLapseLowProfiles(&lowTimeLapseProfile, &lowSpecificTimeLapseProfile);
762d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(lowTimeLapseProfile);
763d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(lowSpecificTimeLapseProfile);
764d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
765d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    // high camcorder time lapse profiles.
766d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::CamcorderProfile *highTimeLapseProfile, *highSpecificTimeLapseProfile;
767b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten    createDefaultCamcorderTimeLapseHighProfiles(&highTimeLapseProfile,
768b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten            &highSpecificTimeLapseProfile);
769d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(highTimeLapseProfile);
770d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(highSpecificTimeLapseProfile);
7718031ec79eb657a0ae84325410578ea87f50eeb54James Dong
7728031ec79eb657a0ae84325410578ea87f50eeb54James Dong    // For emulator and other legacy devices which does not have a
7738031ec79eb657a0ae84325410578ea87f50eeb54James Dong    // media_profiles.xml file, We assume that the default camera id
7748031ec79eb657a0ae84325410578ea87f50eeb54James Dong    // is 0 and that is the only camera available.
7758031ec79eb657a0ae84325410578ea87f50eeb54James Dong    profiles->mCameraIds.push(0);
7761d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
7771d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
7781d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
7791d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultAudioEncoders(MediaProfiles *profiles)
7801d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
7811d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mAudioEncoders.add(createDefaultAmrNBEncoderCap());
7821d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
7831d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
7841d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
7851d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultVideoDecoders(MediaProfiles *profiles)
7861d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
7871d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoDecoderCap *cap =
7881d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::VideoDecoderCap(VIDEO_DECODER_WMV);
7891d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
7901d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mVideoDecoders.add(cap);
7911d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
7921d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
7931d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
7941d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultAudioDecoders(MediaProfiles *profiles)
7951d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
7961d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::AudioDecoderCap *cap =
7971d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::AudioDecoderCap(AUDIO_DECODER_WMA);
7981d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
7991d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mAudioDecoders.add(cap);
8001d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8011d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8021d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
8031d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultEncoderOutputFileFormats(MediaProfiles *profiles)
8041d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
8051d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_THREE_GPP);
8061d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_MPEG_4);
8071d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8081d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8091d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::AudioEncoderCap*
8101d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultAmrNBEncoderCap()
8111d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
8121d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return new MediaProfiles::AudioEncoderCap(
8131d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        AUDIO_ENCODER_AMR_NB, 5525, 12200, 8000, 8000, 1, 1);
8141d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8151d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
816f5a8385649204213dc19e1a64f4693931e048d85James Dong/*static*/ void
817f5a8385649204213dc19e1a64f4693931e048d85James DongMediaProfiles::createDefaultImageEncodingQualityLevels(MediaProfiles *profiles)
818f5a8385649204213dc19e1a64f4693931e048d85James Dong{
8193eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    ImageEncodingQualityLevels *levels = new ImageEncodingQualityLevels();
8203eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    levels->mCameraId = 0;
8213eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    levels->mLevels.add(70);
8223eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    levels->mLevels.add(80);
8233eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    levels->mLevels.add(90);
8243eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    profiles->mImageEncodingQualityLevels.add(levels);
825f5a8385649204213dc19e1a64f4693931e048d85James Dong}
826f5a8385649204213dc19e1a64f4693931e048d85James Dong
8271d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles*
8281d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultInstance()
8291d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
8301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles *profiles = new MediaProfiles;
8311d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultCamcorderProfiles(profiles);
8321d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultVideoEncoders(profiles);
8331d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultAudioEncoders(profiles);
8341d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultVideoDecoders(profiles);
8351d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultAudioDecoders(profiles);
8361d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultEncoderOutputFileFormats(profiles);
837f5a8385649204213dc19e1a64f4693931e048d85James Dong    createDefaultImageEncodingQualityLevels(profiles);
8381d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return profiles;
8391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles*
8421d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createInstanceFromXmlFile(const char *xml)
8431d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
8441d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    FILE *fp = NULL;
8451d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK((fp = fopen(xml, "r")));
8461d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8471d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    XML_Parser parser = ::XML_ParserCreate(NULL);
8481d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(parser != NULL);
8491d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8501d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles *profiles = new MediaProfiles();
8511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    ::XML_SetUserData(parser, profiles);
8521d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    ::XML_SetElementHandler(parser, startElementHandler, NULL);
8531d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8541d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    /*
8551d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong      FIXME:
8561d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong      expat is not compiled with -DXML_DTD. We don't have DTD parsing support.
8571d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8581d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong      if (!::XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS)) {
85929357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block          ALOGE("failed to enable DTD support in the xml file");
8601d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          return UNKNOWN_ERROR;
8611d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong      }
8621d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8631d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    */
8641d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8651d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int BUFF_SIZE = 512;
8661d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    for (;;) {
8671d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        void *buff = ::XML_GetBuffer(parser, BUFF_SIZE);
8681d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        if (buff == NULL) {
86929357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block            ALOGE("failed to in call to XML_GetBuffer()");
8701d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            delete profiles;
8711d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            profiles = NULL;
8721d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            goto exit;
8731d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        }
8741d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8751d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        int bytes_read = ::fread(buff, 1, BUFF_SIZE, fp);
8761d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        if (bytes_read < 0) {
87729357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block            ALOGE("failed in call to read");
8781d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            delete profiles;
8791d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            profiles = NULL;
8801d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            goto exit;
8811d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        }
8821d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8831d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        CHECK(::XML_ParseBuffer(parser, bytes_read, bytes_read == 0));
8841d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8851d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        if (bytes_read == 0) break;  // done parsing the xml file
8861d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    }
8871d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8881d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongexit:
8891d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    ::XML_ParserFree(parser);
8901d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    ::fclose(fp);
8911d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return profiles;
8921d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8931d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8941d7491b19516505e0754c66a3c8cd61811c9b6a6James DongVector<output_format> MediaProfiles::getOutputFileFormats() const
8951d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
8961d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return mEncoderOutputFileFormats;  // copy out
8971d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8981d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8991d7491b19516505e0754c66a3c8cd61811c9b6a6James DongVector<video_encoder> MediaProfiles::getVideoEncoders() const
9001d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
9011d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    Vector<video_encoder> encoders;
9021d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    for (size_t i = 0; i < mVideoEncoders.size(); ++i) {
9031d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        encoders.add(mVideoEncoders[i]->mCodec);
9041d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    }
9051d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return encoders;  // copy out
9061d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
9071d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9081d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongint MediaProfiles::getVideoEncoderParamByName(const char *name, video_encoder codec) const
9091d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
9103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("getVideoEncoderParamByName: %s for codec %d", name, codec);
9111d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    int index = -1;
9121d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    for (size_t i = 0, n = mVideoEncoders.size(); i < n; ++i) {
9131d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        if (mVideoEncoders[i]->mCodec == codec) {
9141d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            index = i;
9151d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            break;
9161d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        }
9171d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    }
9181d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (index == -1) {
91929357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block        ALOGE("The given video encoder %d is not found", codec);
9201d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        return -1;
9211d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    }
9221d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9231d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (!strcmp("enc.vid.width.min", name)) return mVideoEncoders[index]->mMinFrameWidth;
9241d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (!strcmp("enc.vid.width.max", name)) return mVideoEncoders[index]->mMaxFrameWidth;
9251d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (!strcmp("enc.vid.height.min", name)) return mVideoEncoders[index]->mMinFrameHeight;
9261d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (!strcmp("enc.vid.height.max", name)) return mVideoEncoders[index]->mMaxFrameHeight;
9271d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (!strcmp("enc.vid.bps.min", name)) return mVideoEncoders[index]->mMinBitRate;
9281d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (!strcmp("enc.vid.bps.max", name)) return mVideoEncoders[index]->mMaxBitRate;
9291d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (!strcmp("enc.vid.fps.min", name)) return mVideoEncoders[index]->mMinFrameRate;
9301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (!strcmp("enc.vid.fps.max", name)) return mVideoEncoders[index]->mMaxFrameRate;
9311d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
93229357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block    ALOGE("The given video encoder param name %s is not found", name);
9331d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return -1;
9341d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
935cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng
9361d7491b19516505e0754c66a3c8cd61811c9b6a6James DongVector<audio_encoder> MediaProfiles::getAudioEncoders() const
9371d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
9381d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    Vector<audio_encoder> encoders;
9391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    for (size_t i = 0; i < mAudioEncoders.size(); ++i) {
9401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        encoders.add(mAudioEncoders[i]->mCodec);
9411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    }
9421d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return encoders;  // copy out
9431d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
9441d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9451d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongint MediaProfiles::getAudioEncoderParamByName(const char *name, audio_encoder codec) const
9461d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
9473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("getAudioEncoderParamByName: %s for codec %d", name, codec);
9481d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    int index = -1;
9491d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    for (size_t i = 0, n = mAudioEncoders.size(); i < n; ++i) {
9501d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        if (mAudioEncoders[i]->mCodec == codec) {
9511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            index = i;
9521d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            break;
9531d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        }
954