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>
26e8057dd8208f0a185109992339a995c518b12780Elliott Hughes#include <libexpat/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},
401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"m4v",  VIDEO_ENCODER_MPEG_4_SP}
411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
421d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
431d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongconst MediaProfiles::NameToTagMap MediaProfiles::sAudioEncoderNameMap[] = {
44aeb8fd460ed87d032b3fb8bb61e21eb542ce0f5bDave Burke    {"amrnb",  AUDIO_ENCODER_AMR_NB},
45aeb8fd460ed87d032b3fb8bb61e21eb542ce0f5bDave Burke    {"amrwb",  AUDIO_ENCODER_AMR_WB},
46aeb8fd460ed87d032b3fb8bb61e21eb542ce0f5bDave Burke    {"aac",    AUDIO_ENCODER_AAC},
47f60c660f048d5f5e2458cff243c20400d73757a7Dave Burke    {"heaac",  AUDIO_ENCODER_HE_AAC},
48f60c660f048d5f5e2458cff243c20400d73757a7Dave Burke    {"aaceld", AUDIO_ENCODER_AAC_ELD}
491d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
501d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongconst MediaProfiles::NameToTagMap MediaProfiles::sFileFormatMap[] = {
521d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"3gp", OUTPUT_FORMAT_THREE_GPP},
531d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"mp4", OUTPUT_FORMAT_MPEG_4}
541d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
551d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
561d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongconst MediaProfiles::NameToTagMap MediaProfiles::sVideoDecoderNameMap[] = {
571d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"wmv", VIDEO_DECODER_WMV}
581d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
591d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
601d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongconst MediaProfiles::NameToTagMap MediaProfiles::sAudioDecoderNameMap[] = {
611d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"wma", AUDIO_DECODER_WMA}
621d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
631d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
641d7491b19516505e0754c66a3c8cd61811c9b6a6James Dongconst MediaProfiles::NameToTagMap MediaProfiles::sCamcorderQualityNameMap[] = {
65c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"low", CAMCORDER_QUALITY_LOW},
661d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    {"high", CAMCORDER_QUALITY_HIGH},
67c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"qcif", CAMCORDER_QUALITY_QCIF},
689783ed8f85af3d7c72030098acfed7e1d6638349Nipun Kwatra    {"cif", CAMCORDER_QUALITY_CIF},
69c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"480p", CAMCORDER_QUALITY_480P},
70c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"720p", CAMCORDER_QUALITY_720P},
71c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"1080p", CAMCORDER_QUALITY_1080P},
725f6af1a8e34381ca2ac2527fcefe220a22f49b53Zhijun He    {"2160p", CAMCORDER_QUALITY_2160P},
73669012d77b00a2aacb6fd12837f2870f9ec17865James Dong    {"qvga", CAMCORDER_QUALITY_QVGA},
74c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra
75c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"timelapselow",  CAMCORDER_QUALITY_TIME_LAPSE_LOW},
76c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"timelapsehigh", CAMCORDER_QUALITY_TIME_LAPSE_HIGH},
77c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"timelapseqcif", CAMCORDER_QUALITY_TIME_LAPSE_QCIF},
789783ed8f85af3d7c72030098acfed7e1d6638349Nipun Kwatra    {"timelapsecif", CAMCORDER_QUALITY_TIME_LAPSE_CIF},
79c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"timelapse480p", CAMCORDER_QUALITY_TIME_LAPSE_480P},
80c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    {"timelapse720p", CAMCORDER_QUALITY_TIME_LAPSE_720P},
81669012d77b00a2aacb6fd12837f2870f9ec17865James Dong    {"timelapse1080p", CAMCORDER_QUALITY_TIME_LAPSE_1080P},
825f6af1a8e34381ca2ac2527fcefe220a22f49b53Zhijun He    {"timelapse2160p", CAMCORDER_QUALITY_TIME_LAPSE_2160P},
83669012d77b00a2aacb6fd12837f2870f9ec17865James Dong    {"timelapseqvga", CAMCORDER_QUALITY_TIME_LAPSE_QVGA},
84e07909715b44cc56df723750af93f0608210f94dZhijun He
85e07909715b44cc56df723750af93f0608210f94dZhijun He    {"highspeedlow",  CAMCORDER_QUALITY_HIGH_SPEED_LOW},
86e07909715b44cc56df723750af93f0608210f94dZhijun He    {"highspeedhigh", CAMCORDER_QUALITY_HIGH_SPEED_HIGH},
87e07909715b44cc56df723750af93f0608210f94dZhijun He    {"highspeed480p", CAMCORDER_QUALITY_HIGH_SPEED_480P},
88e07909715b44cc56df723750af93f0608210f94dZhijun He    {"highspeed720p", CAMCORDER_QUALITY_HIGH_SPEED_720P},
89e07909715b44cc56df723750af93f0608210f94dZhijun He    {"highspeed1080p", CAMCORDER_QUALITY_HIGH_SPEED_1080P},
909520aa609c505cf8a9ee105bd78dc186cfb7770bZhijun He    {"highspeed2160p", CAMCORDER_QUALITY_HIGH_SPEED_2160P},
911d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong};
921d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9380520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten#if LOG_NDEBUG
9480520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten#define UNUSED __unused
9580520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten#else
9680520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten#define UNUSED
9780520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten#endif
9880520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn Kasten
991d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
10080520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logVideoCodec(const MediaProfiles::VideoCodec& codec UNUSED)
1011d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1023856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("video codec:");
1033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", codec.mCodec);
1043856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("bit rate: %d", codec.mBitRate);
1053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame width: %d", codec.mFrameWidth);
1063856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame height: %d", codec.mFrameHeight);
1073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame rate: %d", codec.mFrameRate);
1081d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1091d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1101d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
11180520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logAudioCodec(const MediaProfiles::AudioCodec& codec UNUSED)
1121d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("audio codec:");
1143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", codec.mCodec);
1153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("bit rate: %d", codec.mBitRate);
1163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("sample rate: %d", codec.mSampleRate);
1173856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("number of channels: %d", codec.mChannels);
1181d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1191d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1201d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
12180520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logVideoEncoderCap(const MediaProfiles::VideoEncoderCap& cap UNUSED)
1221d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("video encoder cap:");
1243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", cap.mCodec);
1253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("bit rate: min = %d and max = %d", cap.mMinBitRate, cap.mMaxBitRate);
1263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame width: min = %d and max = %d", cap.mMinFrameWidth, cap.mMaxFrameWidth);
1273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame height: min = %d and max = %d", cap.mMinFrameHeight, cap.mMaxFrameHeight);
1283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("frame rate: min = %d and max = %d", cap.mMinFrameRate, cap.mMaxFrameRate);
1291d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1311d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
13280520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logAudioEncoderCap(const MediaProfiles::AudioEncoderCap& cap UNUSED)
1331d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("audio encoder cap:");
1353856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", cap.mCodec);
1363856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("bit rate: min = %d and max = %d", cap.mMinBitRate, cap.mMaxBitRate);
1373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("sample rate: min = %d and max = %d", cap.mMinSampleRate, cap.mMaxSampleRate);
1383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("number of channels: min = %d and max = %d", cap.mMinChannels, cap.mMaxChannels);
1391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
14280520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logVideoDecoderCap(const MediaProfiles::VideoDecoderCap& cap UNUSED)
1431d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("video decoder cap:");
1453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", cap.mCodec);
1461d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1471d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1481d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
14980520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logAudioDecoderCap(const MediaProfiles::AudioDecoderCap& cap UNUSED)
1501d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1513856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("audio codec cap:");
1523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("codec = %d", cap.mCodec);
1531d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1541d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
155cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng/*static*/ void
15680520381d0bdf3451bd17c9ddef73d3fe71c58c2Glenn KastenMediaProfiles::logVideoEditorCap(const MediaProfiles::VideoEditorCap& cap UNUSED)
157cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng{
1583856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("videoeditor cap:");
1593856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("mMaxInputFrameWidth = %d", cap.mMaxInputFrameWidth);
1603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("mMaxInputFrameHeight = %d", cap.mMaxInputFrameHeight);
1613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("mMaxOutputFrameWidth = %d", cap.mMaxOutputFrameWidth);
1623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("mMaxOutputFrameHeight = %d", cap.mMaxOutputFrameHeight);
163cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng}
164cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng
1651d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ int
1661d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::findTagForName(const MediaProfiles::NameToTagMap *map, size_t nMappings, const char *name)
1671d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1681d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    int tag = -1;
1691d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    for (size_t i = 0; i < nMappings; ++i) {
1701d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        if (!strcmp(map[i].name, name)) {
1711d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            tag = map[i].tag;
1721d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            break;
1731d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        }
1741d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    }
1751d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return tag;
1761d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
1771d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1781d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::VideoCodec*
1791d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createVideoCodec(const char **atts, MediaProfiles *profiles)
1801d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
1811d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("codec",     atts[0]) &&
1821d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("bitRate",   atts[2]) &&
1831d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("width",     atts[4]) &&
1841d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("height",    atts[6]) &&
1851d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("frameRate", atts[8]));
1861d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1871d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]);
1881d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]);
1891d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
1901d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1911d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoCodec *videoCodec =
1921d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::VideoCodec(static_cast<video_encoder>(codec),
1931d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            atoi(atts[3]), atoi(atts[5]), atoi(atts[7]), atoi(atts[9]));
1941d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logVideoCodec(*videoCodec);
1951d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
1961d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    size_t nCamcorderProfiles;
1971d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1);
1981d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mVideoCodec = videoCodec;
1991d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return videoCodec;
2001d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
2011d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2021d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::AudioCodec*
2031d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createAudioCodec(const char **atts, MediaProfiles *profiles)
2041d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
2051d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("codec",      atts[0]) &&
2061d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("bitRate",    atts[2]) &&
2071d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("sampleRate", atts[4]) &&
2081d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("channels",   atts[6]));
2091d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]);
2101d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]);
2111d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
2121d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2131d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::AudioCodec *audioCodec =
2141d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::AudioCodec(static_cast<audio_encoder>(codec),
2151d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            atoi(atts[3]), atoi(atts[5]), atoi(atts[7]));
2161d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logAudioCodec(*audioCodec);
2171d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2181d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    size_t nCamcorderProfiles;
2191d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1);
2201d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mAudioCodec = audioCodec;
2211d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return audioCodec;
2221d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
2231d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::AudioDecoderCap*
2241d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createAudioDecoderCap(const char **atts)
2251d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
2261d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("name",    atts[0]) &&
2271d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("enabled", atts[2]));
2281d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2291d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sAudioDecoderNameMap)/sizeof(sAudioDecoderNameMap[0]);
2301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sAudioDecoderNameMap, nMappings, atts[1]);
2311d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
2321d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2331d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::AudioDecoderCap *cap =
2341d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::AudioDecoderCap(static_cast<audio_decoder>(codec));
2351d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logAudioDecoderCap(*cap);
2361d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return cap;
2371d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
2381d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::VideoDecoderCap*
2401d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createVideoDecoderCap(const char **atts)
2411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
2421d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("name",    atts[0]) &&
2431d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("enabled", atts[2]));
2441d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2451d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sVideoDecoderNameMap)/sizeof(sVideoDecoderNameMap[0]);
2461d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sVideoDecoderNameMap, nMappings, atts[1]);
2471d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
2481d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2491d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoDecoderCap *cap =
2501d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::VideoDecoderCap(static_cast<video_decoder>(codec));
2511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logVideoDecoderCap(*cap);
2521d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return cap;
2531d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
2541d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2551d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::VideoEncoderCap*
2561d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createVideoEncoderCap(const char **atts)
2571d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
2581d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("name",           atts[0])  &&
2591d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("enabled",        atts[2])  &&
2601d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minBitRate",     atts[4])  &&
2611d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxBitRate",     atts[6])  &&
2621d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minFrameWidth",  atts[8])  &&
2631d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxFrameWidth",  atts[10]) &&
2641d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minFrameHeight", atts[12]) &&
2651d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxFrameHeight", atts[14]) &&
2661d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minFrameRate",   atts[16]) &&
2671d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxFrameRate",   atts[18]));
2681d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2691d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]);
2701d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]);
2711d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
2721d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2731d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoEncoderCap *cap =
2741d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::VideoEncoderCap(static_cast<video_encoder>(codec),
2751d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            atoi(atts[5]), atoi(atts[7]), atoi(atts[9]), atoi(atts[11]), atoi(atts[13]),
2761d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            atoi(atts[15]), atoi(atts[17]), atoi(atts[19]));
2771d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logVideoEncoderCap(*cap);
2781d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return cap;
2791d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
2801d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2811d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::AudioEncoderCap*
2821d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createAudioEncoderCap(const char **atts)
2831d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
2841d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("name",          atts[0])  &&
2851d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("enabled",       atts[2])  &&
2861d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minBitRate",    atts[4])  &&
2871d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxBitRate",    atts[6])  &&
2881d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minSampleRate", atts[8])  &&
2891d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxSampleRate", atts[10]) &&
2901d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("minChannels",   atts[12]) &&
2911d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("maxChannels",   atts[14]));
2921d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2931d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]);
2941d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]);
2951d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(codec != -1);
2961d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
2971d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::AudioEncoderCap *cap =
2981d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::AudioEncoderCap(static_cast<audio_encoder>(codec), atoi(atts[5]), atoi(atts[7]),
2991d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            atoi(atts[9]), atoi(atts[11]), atoi(atts[13]),
3001d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            atoi(atts[15]));
3011d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    logAudioEncoderCap(*cap);
3021d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return cap;
3031d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
3041d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3051d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ output_format
3061d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createEncoderOutputFileFormat(const char **atts)
3071d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
3081d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("name", atts[0]));
3091d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3101d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nMappings =sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]);
3111d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int format = findTagForName(sFileFormatMap, nMappings, atts[1]);
3121d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(format != -1);
3131d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3141d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return static_cast<output_format>(format);
3151d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
3161d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3172a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongstatic bool isCameraIdFound(int cameraId, const Vector<int>& cameraIds) {
3182a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    for (int i = 0, n = cameraIds.size(); i < n; ++i) {
3192a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        if (cameraId == cameraIds[i]) {
3202a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            return true;
3212a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
3222a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
3232a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    return false;
3242a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
3252a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
3261d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::CamcorderProfile*
3272a7e0a1eb29306982fd77bdc64d324464a48a2b9James DongMediaProfiles::createCamcorderProfile(int cameraId, const char **atts, Vector<int>& cameraIds)
3281d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
3291d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(!strcmp("quality",    atts[0]) &&
3301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("fileFormat", atts[2]) &&
3311d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          !strcmp("duration",   atts[4]));
3321d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3331d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nProfileMappings = sizeof(sCamcorderQualityNameMap)/sizeof(sCamcorderQualityNameMap[0]);
3341d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int quality = findTagForName(sCamcorderQualityNameMap, nProfileMappings, atts[1]);
3351d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(quality != -1);
3361d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3371d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const size_t nFormatMappings = sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]);
3381d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int fileFormat = findTagForName(sFileFormatMap, nFormatMappings, atts[3]);
3391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(fileFormat != -1);
3401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
3423eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    profile->mCameraId = cameraId;
3432a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    if (!isCameraIdFound(cameraId, cameraIds)) {
3442a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        cameraIds.add(cameraId);
3452a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
3461d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mFileFormat = static_cast<output_format>(fileFormat);
3471d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mQuality = static_cast<camcorder_quality>(quality);
3481d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mDuration = atoi(atts[5]);
3491d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return profile;
3501d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
3511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
3523eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung ChangMediaProfiles::ImageEncodingQualityLevels*
3533eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung ChangMediaProfiles::findImageEncodingQualityLevels(int cameraId) const
3543eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang{
3553eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    int n = mImageEncodingQualityLevels.size();
3563eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    for (int i = 0; i < n; i++) {
3573eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        ImageEncodingQualityLevels *levels = mImageEncodingQualityLevels[i];
3583eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        if (levels->mCameraId == cameraId) {
3593eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang            return levels;
3603eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        }
3613eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    }
3623eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    return NULL;
3633eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang}
3643eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang
3653eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Changvoid MediaProfiles::addImageEncodingQualityLevel(int cameraId, const char** atts)
366f5a8385649204213dc19e1a64f4693931e048d85James Dong{
367f5a8385649204213dc19e1a64f4693931e048d85James Dong    CHECK(!strcmp("quality", atts[0]));
3683eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    int quality = atoi(atts[1]);
36990bebef5669a9385c706b042d146a31dca2e5d9bGlenn Kasten    ALOGV("%s: cameraId=%d, quality=%d", __func__, cameraId, quality);
3703eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    ImageEncodingQualityLevels *levels = findImageEncodingQualityLevels(cameraId);
3713eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang
3723eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    if (levels == NULL) {
3733eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        levels = new ImageEncodingQualityLevels();
3743eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        levels->mCameraId = cameraId;
3753eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        mImageEncodingQualityLevels.add(levels);
3763eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    }
3773eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang
3783eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    levels->mLevels.add(quality);
3793eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang}
3803eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang
3813eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang/*static*/ int
3823eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung ChangMediaProfiles::getCameraId(const char** atts)
3833eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang{
3843eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    if (!atts[0]) return 0;  // default cameraId = 0
3853eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    CHECK(!strcmp("cameraId", atts[0]));
386f5a8385649204213dc19e1a64f4693931e048d85James Dong    return atoi(atts[1]);
387f5a8385649204213dc19e1a64f4693931e048d85James Dong}
388f5a8385649204213dc19e1a64f4693931e048d85James Dong
3890f056290cb16763453f18bbef80cde673041dbbcJames Dongvoid MediaProfiles::addStartTimeOffset(int cameraId, const char** atts)
3900f056290cb16763453f18bbef80cde673041dbbcJames Dong{
391b1eb1a0dd38a36dd0c0626d3d57043dbd0042a92Eric Laurent    int offsetTimeMs = 1000;
3920f056290cb16763453f18bbef80cde673041dbbcJames Dong    if (atts[2]) {
3930f056290cb16763453f18bbef80cde673041dbbcJames Dong        CHECK(!strcmp("startOffsetMs", atts[2]));
3940f056290cb16763453f18bbef80cde673041dbbcJames Dong        offsetTimeMs = atoi(atts[3]);
3950f056290cb16763453f18bbef80cde673041dbbcJames Dong    }
3960f056290cb16763453f18bbef80cde673041dbbcJames Dong
3973856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("%s: cameraId=%d, offset=%d ms", __func__, cameraId, offsetTimeMs);
3980f056290cb16763453f18bbef80cde673041dbbcJames Dong    mStartTimeOffsets.replaceValueFor(cameraId, offsetTimeMs);
3990f056290cb16763453f18bbef80cde673041dbbcJames Dong}
4008f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury/*static*/ MediaProfiles::ExportVideoProfile*
4018f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh ChowduryMediaProfiles::createExportVideoProfile(const char **atts)
4028f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury{
4038f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    CHECK(!strcmp("name", atts[0]) &&
4048f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury          !strcmp("profile", atts[2]) &&
4058f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury          !strcmp("level", atts[4]));
4068f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury
4078f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    const size_t nMappings =
4088f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury        sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]);
4098f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]);
4108f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    CHECK(codec != -1);
4118f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury
4128f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    MediaProfiles::ExportVideoProfile *profile =
4138f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury        new MediaProfiles::ExportVideoProfile(
4148f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury            codec, atoi(atts[3]), atoi(atts[5]));
4150f056290cb16763453f18bbef80cde673041dbbcJames Dong
4168f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    return profile;
4178f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury}
418cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng/*static*/ MediaProfiles::VideoEditorCap*
419cabd5f867ec69c0dfe8333cba46323cb58917402Hong TengMediaProfiles::createVideoEditorCap(const char **atts, MediaProfiles *profiles)
420cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng{
421cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng    CHECK(!strcmp("maxInputFrameWidth", atts[0]) &&
422cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng          !strcmp("maxInputFrameHeight", atts[2])  &&
423cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng          !strcmp("maxOutputFrameWidth", atts[4]) &&
4243a9cefebd2c5d2157aefaed01c54f151dc64a5b3Hong Teng          !strcmp("maxOutputFrameHeight", atts[6]) &&
4253a9cefebd2c5d2157aefaed01c54f151dc64a5b3Hong Teng          !strcmp("maxPrefetchYUVFrames", atts[8]));
426cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng
427cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng    MediaProfiles::VideoEditorCap *pVideoEditorCap =
428cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng        new MediaProfiles::VideoEditorCap(atoi(atts[1]), atoi(atts[3]),
4293a9cefebd2c5d2157aefaed01c54f151dc64a5b3Hong Teng                atoi(atts[5]), atoi(atts[7]), atoi(atts[9]));
430cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng
431cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng    logVideoEditorCap(*pVideoEditorCap);
432cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng    profiles->mVideoEditorCap = pVideoEditorCap;
433cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng
434cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng    return pVideoEditorCap;
435cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng}
436cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng
4371d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
4381d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::startElementHandler(void *userData, const char *name, const char **atts)
4391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
4401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles *profiles = (MediaProfiles *) userData;
4411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (strcmp("Video", name) == 0) {
4421d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        createVideoCodec(atts, profiles);
4431d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("Audio", name) == 0) {
4441d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        createAudioCodec(atts, profiles);
4451d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("VideoEncoderCap", name) == 0 &&
4461d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong               strcmp("true", atts[3]) == 0) {
4471d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        profiles->mVideoEncoders.add(createVideoEncoderCap(atts));
4481d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("AudioEncoderCap", name) == 0 &&
4491d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong               strcmp("true", atts[3]) == 0) {
4501d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        profiles->mAudioEncoders.add(createAudioEncoderCap(atts));
4511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("VideoDecoderCap", name) == 0 &&
4521d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong               strcmp("true", atts[3]) == 0) {
4531d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        profiles->mVideoDecoders.add(createVideoDecoderCap(atts));
4541d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("AudioDecoderCap", name) == 0 &&
4551d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong               strcmp("true", atts[3]) == 0) {
4561d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        profiles->mAudioDecoders.add(createAudioDecoderCap(atts));
4571d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("EncoderOutputFileFormat", name) == 0) {
4581d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        profiles->mEncoderOutputFileFormats.add(createEncoderOutputFileFormat(atts));
4593eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    } else if (strcmp("CamcorderProfiles", name) == 0) {
4603eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        profiles->mCurrentCameraId = getCameraId(atts);
4610f056290cb16763453f18bbef80cde673041dbbcJames Dong        profiles->addStartTimeOffset(profiles->mCurrentCameraId, atts);
4621d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    } else if (strcmp("EncoderProfile", name) == 0) {
4633eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        profiles->mCamcorderProfiles.add(
4642a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            createCamcorderProfile(profiles->mCurrentCameraId, atts, profiles->mCameraIds));
465f5a8385649204213dc19e1a64f4693931e048d85James Dong    } else if (strcmp("ImageEncoding", name) == 0) {
4663eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang        profiles->addImageEncodingQualityLevel(profiles->mCurrentCameraId, atts);
467cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng    } else if (strcmp("VideoEditorCap", name) == 0) {
468cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng        createVideoEditorCap(atts, profiles);
4698f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    } else if (strcmp("ExportVideoProfile", name) == 0) {
4708f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury        profiles->mVideoEditorExportProfiles.add(createExportVideoProfile(atts));
4711d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    }
4721d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
4731d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
4742a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongstatic bool isCamcorderProfile(camcorder_quality quality) {
4752a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    return quality >= CAMCORDER_QUALITY_LIST_START &&
4762a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong           quality <= CAMCORDER_QUALITY_LIST_END;
4772a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
4782a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
4792a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongstatic bool isTimelapseProfile(camcorder_quality quality) {
4802a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    return quality >= CAMCORDER_QUALITY_TIME_LAPSE_LIST_START &&
4812a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong           quality <= CAMCORDER_QUALITY_TIME_LAPSE_LIST_END;
4822a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
4832a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
484e07909715b44cc56df723750af93f0608210f94dZhijun Hestatic bool isHighSpeedProfile(camcorder_quality quality) {
485e07909715b44cc56df723750af93f0608210f94dZhijun He    return quality >= CAMCORDER_QUALITY_HIGH_SPEED_LIST_START &&
486e07909715b44cc56df723750af93f0608210f94dZhijun He           quality <= CAMCORDER_QUALITY_HIGH_SPEED_LIST_END;
487e07909715b44cc56df723750af93f0608210f94dZhijun He}
488e07909715b44cc56df723750af93f0608210f94dZhijun He
4892a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongvoid MediaProfiles::initRequiredProfileRefs(const Vector<int>& cameraIds) {
49034fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn    ALOGV("Number of camera ids: %zu", cameraIds.size());
4912a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    CHECK(cameraIds.size() > 0);
4922a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    mRequiredProfileRefs = new RequiredProfiles[cameraIds.size()];
4932a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    for (size_t i = 0, n = cameraIds.size(); i < n; ++i) {
4942a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        mRequiredProfileRefs[i].mCameraId = cameraIds[i];
4952a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        for (size_t j = 0; j < kNumRequiredProfiles; ++j) {
4962a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            mRequiredProfileRefs[i].mRefs[j].mHasRefProfile = false;
4972a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            mRequiredProfileRefs[i].mRefs[j].mRefProfileIndex = -1;
4982a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            if ((j & 1) == 0) {  // low resolution
4992a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                mRequiredProfileRefs[i].mRefs[j].mResolutionProduct = 0x7FFFFFFF;
5002a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            } else {             // high resolution
5012a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                mRequiredProfileRefs[i].mRefs[j].mResolutionProduct = 0;
5022a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
5032a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
5042a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
5052a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
5062a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5072a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongint MediaProfiles::getRequiredProfileRefIndex(int cameraId) {
5082a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    for (size_t i = 0, n = mCameraIds.size(); i < n; ++i) {
5092a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        if (mCameraIds[i] == cameraId) {
5102a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            return i;
5112a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
5122a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
5132a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    return -1;
5142a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
5152a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5162a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dongvoid MediaProfiles::checkAndAddRequiredProfilesIfNecessary() {
5172a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    if (sIsInitialized) {
5182a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        return;
5192a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
5202a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5212a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    initRequiredProfileRefs(mCameraIds);
5222a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5232a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    for (size_t i = 0, n = mCamcorderProfiles.size(); i < n; ++i) {
5242a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        int product = mCamcorderProfiles[i]->mVideoCodec->mFrameWidth *
5252a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                      mCamcorderProfiles[i]->mVideoCodec->mFrameHeight;
5262a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5272a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        camcorder_quality quality = mCamcorderProfiles[i]->mQuality;
5282a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        int cameraId = mCamcorderProfiles[i]->mCameraId;
5292a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        int index = -1;
5302a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        int refIndex = getRequiredProfileRefIndex(cameraId);
5312a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        CHECK(refIndex != -1);
5322a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        RequiredProfileRefInfo *info;
5332a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        camcorder_quality refQuality;
5342a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        VideoCodec *codec = NULL;
5352a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
536e07909715b44cc56df723750af93f0608210f94dZhijun He        // Check high and low from either camcorder profile, timelapse profile
537e07909715b44cc56df723750af93f0608210f94dZhijun He        // or high speed profile, but not all of them. Default, check camcorder profile
5382a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        size_t j = 0;
5393c8889e827d95b195fe5ba077a01cb5b6042e534Bernhard Rosenkraenzer        size_t o = 2;
5402a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        if (isTimelapseProfile(quality)) {
5412a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            // Check timelapse profile instead.
5422a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            j = 2;
5433c8889e827d95b195fe5ba077a01cb5b6042e534Bernhard Rosenkraenzer            o = kNumRequiredProfiles;
544e07909715b44cc56df723750af93f0608210f94dZhijun He        } else if (isHighSpeedProfile(quality)) {
545e07909715b44cc56df723750af93f0608210f94dZhijun He            // Skip the check for high speed profile.
546e07909715b44cc56df723750af93f0608210f94dZhijun He            continue;
5472a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        } else {
5482a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            // Must be camcorder profile.
5492a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            CHECK(isCamcorderProfile(quality));
5502a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
5513c8889e827d95b195fe5ba077a01cb5b6042e534Bernhard Rosenkraenzer        for (; j < o; ++j) {
5522a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            info = &(mRequiredProfileRefs[refIndex].mRefs[j]);
5532a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            if ((j % 2 == 0 && product > info->mResolutionProduct) ||  // low
5542a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                (j % 2 != 0 && product < info->mResolutionProduct)) {  // high
5552a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                continue;
5562a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
5572a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            switch (j) {
5582a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                case 0:
5592a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   refQuality = CAMCORDER_QUALITY_LOW;
5602a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   break;
5612a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                case 1:
5622a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   refQuality = CAMCORDER_QUALITY_HIGH;
5632a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   break;
5642a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                case 2:
5652a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   refQuality = CAMCORDER_QUALITY_TIME_LAPSE_LOW;
5662a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   break;
5672a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                case 3:
5682a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   refQuality = CAMCORDER_QUALITY_TIME_LAPSE_HIGH;
5692a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                   break;
5702a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                default:
5712a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    CHECK(!"Should never reach here");
5722a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
5732a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5742a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            if (!info->mHasRefProfile) {
5752a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                index = getCamcorderProfileIndex(cameraId, refQuality);
5762a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
5772a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            if (index == -1) {
5782a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                // New high or low quality profile is found.
5792a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                // Update its reference.
5802a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                info->mHasRefProfile = true;
5812a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                info->mRefProfileIndex = i;
5822a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                info->mResolutionProduct = product;
5832a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
5842a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
5852a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
5862a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5872a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    for (size_t cameraId = 0; cameraId < mCameraIds.size(); ++cameraId) {
5882a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        for (size_t j = 0; j < kNumRequiredProfiles; ++j) {
5892a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            int refIndex = getRequiredProfileRefIndex(cameraId);
5902a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            CHECK(refIndex != -1);
5912a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            RequiredProfileRefInfo *info =
5922a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    &mRequiredProfileRefs[refIndex].mRefs[j];
5932a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5942a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            if (info->mHasRefProfile) {
5952a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
5962a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                CamcorderProfile *profile =
5972a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    new CamcorderProfile(
5982a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                            *mCamcorderProfiles[info->mRefProfileIndex]);
5992a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
6002a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                // Overwrite the quality
6012a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                switch (j % kNumRequiredProfiles) {
6022a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    case 0:
6032a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality = CAMCORDER_QUALITY_LOW;
6042a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        break;
6052a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    case 1:
6062a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality = CAMCORDER_QUALITY_HIGH;
6072a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        break;
6082a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    case 2:
6092a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality = CAMCORDER_QUALITY_TIME_LAPSE_LOW;
6102a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        break;
6112a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    case 3:
6122a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality = CAMCORDER_QUALITY_TIME_LAPSE_HIGH;
6132a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        break;
6142a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    default:
6152a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        CHECK(!"Should never come here");
6162a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                }
6172a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
6182a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                int index = getCamcorderProfileIndex(cameraId, profile->mQuality);
6192a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                if (index != -1) {
62034fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn                    ALOGV("Profile quality %d for camera %zu already exists",
6212a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality, cameraId);
6222a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    CHECK(index == refIndex);
6232a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                    continue;
6242a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                }
6252a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
6262a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                // Insert the new profile
62734fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn                ALOGV("Add a profile: quality %d=>%d for camera %zu",
6282a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        mCamcorderProfiles[info->mRefProfileIndex]->mQuality,
6292a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                        profile->mQuality, cameraId);
6302a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
6312a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong                mCamcorderProfiles.add(profile);
6322a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong            }
6332a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        }
6342a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong    }
6352a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong}
6362a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong
6371d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles*
6381d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::getInstance()
6391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
6403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("getInstance");
6411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    Mutex::Autolock lock(sLock);
6421d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    if (!sIsInitialized) {
6431d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        char value[PROPERTY_VALUE_MAX];
6441d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        if (property_get("media.settings.xml", value, NULL) <= 0) {
6451d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            const char *defaultXmlFile = "/etc/media_profiles.xml";
6461d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            FILE *fp = fopen(defaultXmlFile, "r");
6471d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            if (fp == NULL) {
6485ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block                ALOGW("could not find media config xml file");
6491d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong                sInstance = createDefaultInstance();
6501d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            } else {
6511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong                fclose(fp);  // close the file first.
6521d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong                sInstance = createInstanceFromXmlFile(defaultXmlFile);
6531d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            }
6541d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        } else {
6551d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong            sInstance = createInstanceFromXmlFile(value);
6561d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        }
6572a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        CHECK(sInstance != NULL);
6582a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        sInstance->checkAndAddRequiredProfilesIfNecessary();
6592a7e0a1eb29306982fd77bdc64d324464a48a2b9James Dong        sIsInitialized = true;
6601d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    }
6611d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6621d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return sInstance;
6631d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
6641d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6651d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::VideoEncoderCap*
6661d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultH263VideoEncoderCap()
6671d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
6681d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return new MediaProfiles::VideoEncoderCap(
6691d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        VIDEO_ENCODER_H263, 192000, 420000, 176, 352, 144, 288, 1, 20);
6701d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
6711d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6721d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::VideoEncoderCap*
6731d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultM4vVideoEncoderCap()
6741d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
6751d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return new MediaProfiles::VideoEncoderCap(
6761d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        VIDEO_ENCODER_MPEG_4_SP, 192000, 420000, 176, 352, 144, 288, 1, 20);
6771d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
6781d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6791d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6801d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
6811d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultVideoEncoders(MediaProfiles *profiles)
6821d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
6831d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mVideoEncoders.add(createDefaultH263VideoEncoderCap());
6841d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mVideoEncoders.add(createDefaultM4vVideoEncoderCap());
6851d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
6861d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
6871d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::CamcorderProfile*
688d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderTimeLapseQcifProfile(camcorder_quality quality)
689c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra{
690c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    MediaProfiles::VideoCodec *videoCodec =
691d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 1000000, 176, 144, 20);
692c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra
693c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
694c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
695c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mCameraId = 0;
696c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
697d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mQuality = quality;
698c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mDuration = 60;
699c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mVideoCodec = videoCodec;
700c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mAudioCodec = audioCodec;
701c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    return profile;
702c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra}
703c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra
704c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra/*static*/ MediaProfiles::CamcorderProfile*
705d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderTimeLapse480pProfile(camcorder_quality quality)
706c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra{
707c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    MediaProfiles::VideoCodec *videoCodec =
708d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 20000000, 720, 480, 20);
709c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra
710c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
711c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
712c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mCameraId = 0;
713c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
714d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mQuality = quality;
715c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mDuration = 60;
716c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mVideoCodec = videoCodec;
717c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    profile->mAudioCodec = audioCodec;
718c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra    return profile;
719c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra}
720c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra
721d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra/*static*/ void
722d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderTimeLapseLowProfiles(
723d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **lowTimeLapseProfile,
724d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **lowSpecificTimeLapseProfile) {
725d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *lowTimeLapseProfile = createDefaultCamcorderTimeLapseQcifProfile(CAMCORDER_QUALITY_TIME_LAPSE_LOW);
726d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *lowSpecificTimeLapseProfile = createDefaultCamcorderTimeLapseQcifProfile(CAMCORDER_QUALITY_TIME_LAPSE_QCIF);
727d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra}
728d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
729d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra/*static*/ void
730d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderTimeLapseHighProfiles(
731d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **highTimeLapseProfile,
732d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **highSpecificTimeLapseProfile) {
733d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *highTimeLapseProfile = createDefaultCamcorderTimeLapse480pProfile(CAMCORDER_QUALITY_TIME_LAPSE_HIGH);
734d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *highSpecificTimeLapseProfile = createDefaultCamcorderTimeLapse480pProfile(CAMCORDER_QUALITY_TIME_LAPSE_480P);
735d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra}
736d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
737c0a84782589eececdfa7e723e8aa0e572d0d79f5Nipun Kwatra/*static*/ MediaProfiles::CamcorderProfile*
738d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderQcifProfile(camcorder_quality quality)
7391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
7401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoCodec *videoCodec =
741d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 192000, 176, 144, 20);
7421d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
743d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::AudioCodec *audioCodec =
744d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        new MediaProfiles::AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
745d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
746d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
7473eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    profile->mCameraId = 0;
7481d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
749d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mQuality = quality;
750d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mDuration = 30;
7511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mVideoCodec = videoCodec;
7521d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mAudioCodec = audioCodec;
7531d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return profile;
7541d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
7551d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
7561d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::CamcorderProfile*
757d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderCifProfile(camcorder_quality quality)
7581d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
7591d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoCodec *videoCodec =
760d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 360000, 352, 288, 20);
7611d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
762d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
763d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
7643eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    profile->mCameraId = 0;
7651d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
766d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mQuality = quality;
767d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profile->mDuration = 60;
7681d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mVideoCodec = videoCodec;
7691d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profile->mAudioCodec = audioCodec;
7701d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return profile;
7711d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
7721d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
7731d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
774d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderLowProfiles(
775d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **lowProfile,
776d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **lowSpecificProfile) {
777d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *lowProfile = createDefaultCamcorderQcifProfile(CAMCORDER_QUALITY_LOW);
778d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *lowSpecificProfile = createDefaultCamcorderQcifProfile(CAMCORDER_QUALITY_QCIF);
779d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra}
780d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
781d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra/*static*/ void
782d5672bc7162fa49abf9bb5844195887e911aa7ceNipun KwatraMediaProfiles::createDefaultCamcorderHighProfiles(
783d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **highProfile,
784d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra        MediaProfiles::CamcorderProfile **highSpecificProfile) {
785d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *highProfile = createDefaultCamcorderCifProfile(CAMCORDER_QUALITY_HIGH);
786d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    *highSpecificProfile = createDefaultCamcorderCifProfile(CAMCORDER_QUALITY_CIF);
787d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra}
788d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
789d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra/*static*/ void
7901d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultCamcorderProfiles(MediaProfiles *profiles)
7911d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
792d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    // low camcorder profiles.
793d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::CamcorderProfile *lowProfile, *lowSpecificProfile;
794d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    createDefaultCamcorderLowProfiles(&lowProfile, &lowSpecificProfile);
795d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(lowProfile);
796d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(lowSpecificProfile);
797d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
798d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    // high camcorder profiles.
799d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::CamcorderProfile* highProfile, *highSpecificProfile;
800d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    createDefaultCamcorderHighProfiles(&highProfile, &highSpecificProfile);
801d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(highProfile);
802d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(highSpecificProfile);
803d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
804d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    // low camcorder time lapse profiles.
805d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::CamcorderProfile *lowTimeLapseProfile, *lowSpecificTimeLapseProfile;
806d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    createDefaultCamcorderTimeLapseLowProfiles(&lowTimeLapseProfile, &lowSpecificTimeLapseProfile);
807d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(lowTimeLapseProfile);
808d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(lowSpecificTimeLapseProfile);
809d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra
810d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    // high camcorder time lapse profiles.
811d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    MediaProfiles::CamcorderProfile *highTimeLapseProfile, *highSpecificTimeLapseProfile;
812d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    createDefaultCamcorderTimeLapseHighProfiles(&highTimeLapseProfile, &highSpecificTimeLapseProfile);
813d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(highTimeLapseProfile);
814d5672bc7162fa49abf9bb5844195887e911aa7ceNipun Kwatra    profiles->mCamcorderProfiles.add(highSpecificTimeLapseProfile);
8158031ec79eb657a0ae84325410578ea87f50eeb54James Dong
8168031ec79eb657a0ae84325410578ea87f50eeb54James Dong    // For emulator and other legacy devices which does not have a
8178031ec79eb657a0ae84325410578ea87f50eeb54James Dong    // media_profiles.xml file, We assume that the default camera id
8188031ec79eb657a0ae84325410578ea87f50eeb54James Dong    // is 0 and that is the only camera available.
8198031ec79eb657a0ae84325410578ea87f50eeb54James Dong    profiles->mCameraIds.push(0);
8201d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8211d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8221d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
8231d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultAudioEncoders(MediaProfiles *profiles)
8241d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
8251d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mAudioEncoders.add(createDefaultAmrNBEncoderCap());
8261d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8271d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8281d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
8291d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultVideoDecoders(MediaProfiles *profiles)
8301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
8311d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::VideoDecoderCap *cap =
8321d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::VideoDecoderCap(VIDEO_DECODER_WMV);
8331d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8341d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mVideoDecoders.add(cap);
8351d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8361d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8371d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
8381d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultAudioDecoders(MediaProfiles *profiles)
8391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
8401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles::AudioDecoderCap *cap =
8411d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        new MediaProfiles::AudioDecoderCap(AUDIO_DECODER_WMA);
8421d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8431d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mAudioDecoders.add(cap);
8441d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8451d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8461d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ void
8471d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultEncoderOutputFileFormats(MediaProfiles *profiles)
8481d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
8491d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_THREE_GPP);
8501d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_MPEG_4);
8511d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8521d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
8531d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles::AudioEncoderCap*
8541d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultAmrNBEncoderCap()
8551d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
8561d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return new MediaProfiles::AudioEncoderCap(
8571d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        AUDIO_ENCODER_AMR_NB, 5525, 12200, 8000, 8000, 1, 1);
8581d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
8591d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
860f5a8385649204213dc19e1a64f4693931e048d85James Dong/*static*/ void
861f5a8385649204213dc19e1a64f4693931e048d85James DongMediaProfiles::createDefaultImageEncodingQualityLevels(MediaProfiles *profiles)
862f5a8385649204213dc19e1a64f4693931e048d85James Dong{
8633eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    ImageEncodingQualityLevels *levels = new ImageEncodingQualityLevels();
8643eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    levels->mCameraId = 0;
8653eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    levels->mLevels.add(70);
8663eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    levels->mLevels.add(80);
8673eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    levels->mLevels.add(90);
8683eaa4e92dbebb5b27cb89f329f31fac6fb6fe1f0Chih-Chung Chang    profiles->mImageEncodingQualityLevels.add(levels);
869f5a8385649204213dc19e1a64f4693931e048d85James Dong}
870f5a8385649204213dc19e1a64f4693931e048d85James Dong
871cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng/*static*/ void
872cabd5f867ec69c0dfe8333cba46323cb58917402Hong TengMediaProfiles::createDefaultVideoEditorCap(MediaProfiles *profiles)
873cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng{
874cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng    profiles->mVideoEditorCap =
875cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng        new MediaProfiles::VideoEditorCap(
876cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng                VIDEOEDITOR_DEFAULT_MAX_INPUT_FRAME_WIDTH,
877cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng                VIDEOEDITOR_DEFUALT_MAX_INPUT_FRAME_HEIGHT,
878cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng                VIDEOEDITOR_DEFAULT_MAX_OUTPUT_FRAME_WIDTH,
8793a9cefebd2c5d2157aefaed01c54f151dc64a5b3Hong Teng                VIDEOEDITOR_DEFUALT_MAX_OUTPUT_FRAME_HEIGHT,
8803a9cefebd2c5d2157aefaed01c54f151dc64a5b3Hong Teng                VIDEOEDITOR_DEFAULT_MAX_PREFETCH_YUV_FRAMES);
881cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng}
8828f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury/*static*/ void
8838f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh ChowduryMediaProfiles::createDefaultExportVideoProfiles(MediaProfiles *profiles)
8848f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury{
8858f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    // Create default video export profiles
8868f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    profiles->mVideoEditorExportProfiles.add(
8878f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury        new ExportVideoProfile(VIDEO_ENCODER_H263,
8888f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury            OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level10));
8898f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    profiles->mVideoEditorExportProfiles.add(
8908f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury        new ExportVideoProfile(VIDEO_ENCODER_MPEG_4_SP,
8918f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury            OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level1));
8928f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    profiles->mVideoEditorExportProfiles.add(
8938f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury        new ExportVideoProfile(VIDEO_ENCODER_H264,
8948f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury            OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel13));
8958f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury}
896cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng
8971d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles*
8981d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createDefaultInstance()
8991d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
9001d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles *profiles = new MediaProfiles;
9011d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultCamcorderProfiles(profiles);
9021d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultVideoEncoders(profiles);
9031d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultAudioEncoders(profiles);
9041d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultVideoDecoders(profiles);
9051d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultAudioDecoders(profiles);
9061d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    createDefaultEncoderOutputFileFormats(profiles);
907f5a8385649204213dc19e1a64f4693931e048d85James Dong    createDefaultImageEncodingQualityLevels(profiles);
908cabd5f867ec69c0dfe8333cba46323cb58917402Hong Teng    createDefaultVideoEditorCap(profiles);
9098f74b712fbf5c24de8bc799b7129dc802747a6f4Rajneesh Chowdury    createDefaultExportVideoProfiles(profiles);
9101d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    return profiles;
9111d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong}
9121d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9131d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong/*static*/ MediaProfiles*
9141d7491b19516505e0754c66a3c8cd61811c9b6a6James DongMediaProfiles::createInstanceFromXmlFile(const char *xml)
9151d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong{
9161d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    FILE *fp = NULL;
9171d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK((fp = fopen(xml, "r")));
9181d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9191d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    XML_Parser parser = ::XML_ParserCreate(NULL);
9201d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    CHECK(parser != NULL);
9211d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9221d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    MediaProfiles *profiles = new MediaProfiles();
9231d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    ::XML_SetUserData(parser, profiles);
9241d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    ::XML_SetElementHandler(parser, startElementHandler, NULL);
9251d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9261d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    /*
9271d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong      FIXME:
9281d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong      expat is not compiled with -DXML_DTD. We don't have DTD parsing support.
9291d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9301d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong      if (!::XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS)) {
93129357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block          ALOGE("failed to enable DTD support in the xml file");
9321d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong          return UNKNOWN_ERROR;
9331d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong      }
9341d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9351d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    */
9361d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong
9371d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    const int BUFF_SIZE = 512;
9381d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong    for (;;) {
9391d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        void *buff = ::XML_GetBuffer(parser, BUFF_SIZE);
9401d7491b19516505e0754c66a3c8cd61811c9b6a6James Dong        if (buff == NULL) {
941