blob: bd17f4db44cf3a62d8ff27869e1e607cb13d2588 [file] [log] [blame]
James Dong1d7491b2010-01-19 17:45:38 -08001/*
2**
3** Copyright 2010, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18
19//#define LOG_NDEBUG 0
20#define LOG_TAG "MediaProfiles"
21
22#include <stdlib.h>
23#include <utils/Log.h>
24#include <utils/Vector.h>
25#include <cutils/properties.h>
Elliott Hughes242b4002015-07-10 11:09:23 -070026#include <expat.h>
James Dong1d7491b2010-01-19 17:45:38 -080027#include <media/MediaProfiles.h>
James Dongf1d5aa12012-02-06 23:46:37 -080028#include <media/stagefright/foundation/ADebug.h>
James Dong6c6b4d02012-03-12 14:37:53 -070029#include <OMX_Video.h>
Pawin Vongmasad7db05b2017-05-03 04:19:20 -070030#include <sys/stat.h>
James Dong1d7491b2010-01-19 17:45:38 -080031
Pawin Vongmasa7f5e10e2020-03-07 04:09:55 -080032#include <array>
33#include <string>
34#include <vector>
35
James Dong1d7491b2010-01-19 17:45:38 -080036namespace android {
37
Pawin Vongmasa7f5e10e2020-03-07 04:09:55 -080038namespace /* unnamed */ {
39
40// Returns a list of possible paths for the media_profiles XML file.
41std::array<char const*, 5> const& getXmlPaths() {
42 static std::array<std::string const, 5> const paths =
43 []() -> decltype(paths) {
44 // Directories for XML file that will be searched (in this order).
45 constexpr std::array<char const*, 4> searchDirs = {
46 "product/etc/",
47 "odm/etc/",
48 "vendor/etc/",
49 "system/etc/",
50 };
51
52 // The file name may contain a variant if the vendor property
53 // ro.vendor.media_profiles_xml_variant is set.
54 char variant[PROPERTY_VALUE_MAX];
55 property_get("ro.media.xml_variant.profiles",
56 variant,
57 "_V1_0");
58
59 std::string fileName =
60 std::string("media_profiles") + variant + ".xml";
61
62 return { searchDirs[0] + fileName,
63 searchDirs[1] + fileName,
64 searchDirs[2] + fileName,
65 searchDirs[3] + fileName,
66 "system/etc/media_profiles_V1_0.xml" // System fallback
67 };
68 }();
69 static std::array<char const*, 5> const cPaths = {
70 paths[0].data(),
71 paths[1].data(),
72 paths[2].data(),
73 paths[3].data(),
74 paths[4].data()
75 };
76 return cPaths;
77}
78
79} // unnamed namespace
80
James Dong1d7491b2010-01-19 17:45:38 -080081Mutex MediaProfiles::sLock;
82bool MediaProfiles::sIsInitialized = false;
83MediaProfiles *MediaProfiles::sInstance = NULL;
84
85const MediaProfiles::NameToTagMap MediaProfiles::sVideoEncoderNameMap[] = {
86 {"h263", VIDEO_ENCODER_H263},
87 {"h264", VIDEO_ENCODER_H264},
Wonsik Kim9aa87d42015-12-07 13:52:02 +090088 {"m4v", VIDEO_ENCODER_MPEG_4_SP},
89 {"hevc", VIDEO_ENCODER_HEVC}
James Dong1d7491b2010-01-19 17:45:38 -080090};
91
92const MediaProfiles::NameToTagMap MediaProfiles::sAudioEncoderNameMap[] = {
Dave Burkeaeb8fd42012-04-19 00:14:27 -070093 {"amrnb", AUDIO_ENCODER_AMR_NB},
94 {"amrwb", AUDIO_ENCODER_AMR_WB},
95 {"aac", AUDIO_ENCODER_AAC},
Dave Burkef60c6602012-04-28 21:58:22 -070096 {"heaac", AUDIO_ENCODER_HE_AAC},
Pawin Vongmasa7f5e10e2020-03-07 04:09:55 -080097 {"aaceld", AUDIO_ENCODER_AAC_ELD},
Ray Essickdf27b042018-11-27 18:55:09 -080098 {"opus", AUDIO_ENCODER_OPUS}
James Dong1d7491b2010-01-19 17:45:38 -080099};
100
101const MediaProfiles::NameToTagMap MediaProfiles::sFileFormatMap[] = {
102 {"3gp", OUTPUT_FORMAT_THREE_GPP},
103 {"mp4", OUTPUT_FORMAT_MPEG_4}
104};
105
106const MediaProfiles::NameToTagMap MediaProfiles::sVideoDecoderNameMap[] = {
107 {"wmv", VIDEO_DECODER_WMV}
108};
109
110const MediaProfiles::NameToTagMap MediaProfiles::sAudioDecoderNameMap[] = {
111 {"wma", AUDIO_DECODER_WMA}
112};
113
114const MediaProfiles::NameToTagMap MediaProfiles::sCamcorderQualityNameMap[] = {
Nipun Kwatrac0a84782010-09-06 15:59:02 -0700115 {"low", CAMCORDER_QUALITY_LOW},
James Dong1d7491b2010-01-19 17:45:38 -0800116 {"high", CAMCORDER_QUALITY_HIGH},
Nipun Kwatrac0a84782010-09-06 15:59:02 -0700117 {"qcif", CAMCORDER_QUALITY_QCIF},
Nipun Kwatra9783ed82010-09-10 15:45:57 -0700118 {"cif", CAMCORDER_QUALITY_CIF},
Nipun Kwatrac0a84782010-09-06 15:59:02 -0700119 {"480p", CAMCORDER_QUALITY_480P},
120 {"720p", CAMCORDER_QUALITY_720P},
121 {"1080p", CAMCORDER_QUALITY_1080P},
Zhijun He5f6af1a2014-06-10 08:26:33 -0700122 {"2160p", CAMCORDER_QUALITY_2160P},
James Dong669012d2011-09-19 16:27:31 -0700123 {"qvga", CAMCORDER_QUALITY_QVGA},
Nipun Kwatrac0a84782010-09-06 15:59:02 -0700124
125 {"timelapselow", CAMCORDER_QUALITY_TIME_LAPSE_LOW},
126 {"timelapsehigh", CAMCORDER_QUALITY_TIME_LAPSE_HIGH},
127 {"timelapseqcif", CAMCORDER_QUALITY_TIME_LAPSE_QCIF},
Nipun Kwatra9783ed82010-09-10 15:45:57 -0700128 {"timelapsecif", CAMCORDER_QUALITY_TIME_LAPSE_CIF},
Nipun Kwatrac0a84782010-09-06 15:59:02 -0700129 {"timelapse480p", CAMCORDER_QUALITY_TIME_LAPSE_480P},
130 {"timelapse720p", CAMCORDER_QUALITY_TIME_LAPSE_720P},
James Dong669012d2011-09-19 16:27:31 -0700131 {"timelapse1080p", CAMCORDER_QUALITY_TIME_LAPSE_1080P},
Zhijun He5f6af1a2014-06-10 08:26:33 -0700132 {"timelapse2160p", CAMCORDER_QUALITY_TIME_LAPSE_2160P},
James Dong669012d2011-09-19 16:27:31 -0700133 {"timelapseqvga", CAMCORDER_QUALITY_TIME_LAPSE_QVGA},
Zhijun Hee0790972014-07-23 15:17:26 -0700134
135 {"highspeedlow", CAMCORDER_QUALITY_HIGH_SPEED_LOW},
136 {"highspeedhigh", CAMCORDER_QUALITY_HIGH_SPEED_HIGH},
137 {"highspeed480p", CAMCORDER_QUALITY_HIGH_SPEED_480P},
138 {"highspeed720p", CAMCORDER_QUALITY_HIGH_SPEED_720P},
139 {"highspeed1080p", CAMCORDER_QUALITY_HIGH_SPEED_1080P},
Zhijun He9520aa62014-09-09 16:18:31 -0700140 {"highspeed2160p", CAMCORDER_QUALITY_HIGH_SPEED_2160P},
Praveen Chavanb5bfa0e2019-01-16 15:49:42 -0800141
142 // Vendor-specific profiles
143 {"vga", CAMCORDER_QUALITY_VGA},
144 {"4kdci", CAMCORDER_QUALITY_4KDCI},
145 {"timelapsevga", CAMCORDER_QUALITY_TIME_LAPSE_VGA},
146 {"timelapse4kdci", CAMCORDER_QUALITY_TIME_LAPSE_4KDCI},
147 {"highspeedcif", CAMCORDER_QUALITY_HIGH_SPEED_CIF},
148 {"highspeedvga", CAMCORDER_QUALITY_HIGH_SPEED_VGA},
149 {"highspeed4kdci", CAMCORDER_QUALITY_HIGH_SPEED_4KDCI},
150 {"qhd", CAMCORDER_QUALITY_QHD},
151 {"2k", CAMCORDER_QUALITY_2k},
152 {"timelapseqhd", CAMCORDER_QUALITY_TIME_LAPSE_QHD},
153 {"timelapse2k", CAMCORDER_QUALITY_TIME_LAPSE_2k},
James Dong1d7491b2010-01-19 17:45:38 -0800154};
155
Glenn Kasten80520382014-01-31 16:49:31 -0800156#if LOG_NDEBUG
157#define UNUSED __unused
158#else
159#define UNUSED
160#endif
161
James Dong1d7491b2010-01-19 17:45:38 -0800162/*static*/ void
Glenn Kasten80520382014-01-31 16:49:31 -0800163MediaProfiles::logVideoCodec(const MediaProfiles::VideoCodec& codec UNUSED)
James Dong1d7491b2010-01-19 17:45:38 -0800164{
Steve Block3856b092011-10-20 11:56:00 +0100165 ALOGV("video codec:");
166 ALOGV("codec = %d", codec.mCodec);
167 ALOGV("bit rate: %d", codec.mBitRate);
168 ALOGV("frame width: %d", codec.mFrameWidth);
169 ALOGV("frame height: %d", codec.mFrameHeight);
170 ALOGV("frame rate: %d", codec.mFrameRate);
Lajos Molnar28091432021-05-03 20:42:32 -0700171 ALOGV("profile: %d", codec.mProfile);
James Dong1d7491b2010-01-19 17:45:38 -0800172}
173
174/*static*/ void
Glenn Kasten80520382014-01-31 16:49:31 -0800175MediaProfiles::logAudioCodec(const MediaProfiles::AudioCodec& codec UNUSED)
James Dong1d7491b2010-01-19 17:45:38 -0800176{
Steve Block3856b092011-10-20 11:56:00 +0100177 ALOGV("audio codec:");
178 ALOGV("codec = %d", codec.mCodec);
179 ALOGV("bit rate: %d", codec.mBitRate);
180 ALOGV("sample rate: %d", codec.mSampleRate);
181 ALOGV("number of channels: %d", codec.mChannels);
Lajos Molnar28091432021-05-03 20:42:32 -0700182 ALOGV("profile: %d", codec.mProfile);
James Dong1d7491b2010-01-19 17:45:38 -0800183}
184
185/*static*/ void
Glenn Kasten80520382014-01-31 16:49:31 -0800186MediaProfiles::logVideoEncoderCap(const MediaProfiles::VideoEncoderCap& cap UNUSED)
James Dong1d7491b2010-01-19 17:45:38 -0800187{
Steve Block3856b092011-10-20 11:56:00 +0100188 ALOGV("video encoder cap:");
189 ALOGV("codec = %d", cap.mCodec);
190 ALOGV("bit rate: min = %d and max = %d", cap.mMinBitRate, cap.mMaxBitRate);
191 ALOGV("frame width: min = %d and max = %d", cap.mMinFrameWidth, cap.mMaxFrameWidth);
192 ALOGV("frame height: min = %d and max = %d", cap.mMinFrameHeight, cap.mMaxFrameHeight);
193 ALOGV("frame rate: min = %d and max = %d", cap.mMinFrameRate, cap.mMaxFrameRate);
James Dong1d7491b2010-01-19 17:45:38 -0800194}
195
196/*static*/ void
Glenn Kasten80520382014-01-31 16:49:31 -0800197MediaProfiles::logAudioEncoderCap(const MediaProfiles::AudioEncoderCap& cap UNUSED)
James Dong1d7491b2010-01-19 17:45:38 -0800198{
Steve Block3856b092011-10-20 11:56:00 +0100199 ALOGV("audio encoder cap:");
200 ALOGV("codec = %d", cap.mCodec);
201 ALOGV("bit rate: min = %d and max = %d", cap.mMinBitRate, cap.mMaxBitRate);
202 ALOGV("sample rate: min = %d and max = %d", cap.mMinSampleRate, cap.mMaxSampleRate);
203 ALOGV("number of channels: min = %d and max = %d", cap.mMinChannels, cap.mMaxChannels);
James Dong1d7491b2010-01-19 17:45:38 -0800204}
205
206/*static*/ void
Glenn Kasten80520382014-01-31 16:49:31 -0800207MediaProfiles::logVideoDecoderCap(const MediaProfiles::VideoDecoderCap& cap UNUSED)
James Dong1d7491b2010-01-19 17:45:38 -0800208{
Steve Block3856b092011-10-20 11:56:00 +0100209 ALOGV("video decoder cap:");
210 ALOGV("codec = %d", cap.mCodec);
James Dong1d7491b2010-01-19 17:45:38 -0800211}
212
213/*static*/ void
Glenn Kasten80520382014-01-31 16:49:31 -0800214MediaProfiles::logAudioDecoderCap(const MediaProfiles::AudioDecoderCap& cap UNUSED)
James Dong1d7491b2010-01-19 17:45:38 -0800215{
Steve Block3856b092011-10-20 11:56:00 +0100216 ALOGV("audio codec cap:");
217 ALOGV("codec = %d", cap.mCodec);
James Dong1d7491b2010-01-19 17:45:38 -0800218}
219
220/*static*/ int
Glenn Kastenb187de12014-12-30 08:18:15 -0800221MediaProfiles::findTagForName(const MediaProfiles::NameToTagMap *map, size_t nMappings,
222 const char *name)
James Dong1d7491b2010-01-19 17:45:38 -0800223{
224 int tag = -1;
225 for (size_t i = 0; i < nMappings; ++i) {
226 if (!strcmp(map[i].name, name)) {
227 tag = map[i].tag;
228 break;
229 }
230 }
231 return tag;
232}
233
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700234/*static*/ void
Lajos Molnar28091432021-05-03 20:42:32 -0700235MediaProfiles::createVideoCodec(const char **atts, size_t natts, MediaProfiles *profiles)
James Dong1d7491b2010-01-19 17:45:38 -0800236{
Lajos Molnar28091432021-05-03 20:42:32 -0700237 CHECK(natts >= 10 &&
238 !strcmp("codec", atts[0]) &&
James Dong1d7491b2010-01-19 17:45:38 -0800239 !strcmp("bitRate", atts[2]) &&
240 !strcmp("width", atts[4]) &&
241 !strcmp("height", atts[6]) &&
242 !strcmp("frameRate", atts[8]));
243
244 const size_t nMappings = sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]);
245 const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]);
Alex Zhang032f7a12020-04-17 16:08:24 -0700246 if (codec == -1) {
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700247 ALOGE("MediaProfiles::createVideoCodec failed to locate codec %s", atts[1]);
248 return;
Alex Zhang032f7a12020-04-17 16:08:24 -0700249 }
James Dong1d7491b2010-01-19 17:45:38 -0800250
Lajos Molnar28091432021-05-03 20:42:32 -0700251 int profile = -1;
252 if (natts >= 12 && !strcmp("profile", atts[10])) {
253 profile = atoi(atts[11]);
254 }
255
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700256 VideoCodec videoCodec {
257 static_cast<video_encoder>(codec),
Lajos Molnar28091432021-05-03 20:42:32 -0700258 atoi(atts[3]), atoi(atts[5]), atoi(atts[7]), atoi(atts[9]), profile };
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700259 logVideoCodec(videoCodec);
James Dong1d7491b2010-01-19 17:45:38 -0800260
261 size_t nCamcorderProfiles;
262 CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1);
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700263 profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mVideoCodecs.emplace_back(videoCodec);
James Dong1d7491b2010-01-19 17:45:38 -0800264}
265
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700266/*static*/ void
Lajos Molnar28091432021-05-03 20:42:32 -0700267MediaProfiles::createAudioCodec(const char **atts, size_t natts, MediaProfiles *profiles)
James Dong1d7491b2010-01-19 17:45:38 -0800268{
Lajos Molnar28091432021-05-03 20:42:32 -0700269 CHECK(natts >= 8 &&
270 !strcmp("codec", atts[0]) &&
James Dong1d7491b2010-01-19 17:45:38 -0800271 !strcmp("bitRate", atts[2]) &&
272 !strcmp("sampleRate", atts[4]) &&
273 !strcmp("channels", atts[6]));
274 const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]);
275 const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]);
Alex Zhang032f7a12020-04-17 16:08:24 -0700276 if (codec == -1) {
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700277 ALOGE("MediaProfiles::createAudioCodec failed to locate codec %s", atts[1]);
278 return;
Alex Zhang032f7a12020-04-17 16:08:24 -0700279 }
James Dong1d7491b2010-01-19 17:45:38 -0800280
Lajos Molnar28091432021-05-03 20:42:32 -0700281 int profile = -1;
282 if (natts >= 10 && !strcmp("profile", atts[8])) {
283 profile = atoi(atts[9]);
284 }
285
286 AudioCodec audioCodec{
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700287 static_cast<audio_encoder>(codec),
Lajos Molnar28091432021-05-03 20:42:32 -0700288 atoi(atts[3]), atoi(atts[5]), atoi(atts[7]), profile };
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700289 logAudioCodec(audioCodec);
James Dong1d7491b2010-01-19 17:45:38 -0800290
291 size_t nCamcorderProfiles;
292 CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1);
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700293 profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mAudioCodecs.emplace_back(audioCodec);
James Dong1d7491b2010-01-19 17:45:38 -0800294}
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700295
James Dong1d7491b2010-01-19 17:45:38 -0800296/*static*/ MediaProfiles::AudioDecoderCap*
Lajos Molnar28091432021-05-03 20:42:32 -0700297MediaProfiles::createAudioDecoderCap(const char **atts, size_t natts)
James Dong1d7491b2010-01-19 17:45:38 -0800298{
Lajos Molnar28091432021-05-03 20:42:32 -0700299 CHECK(natts >= 4 &&
300 !strcmp("name", atts[0]) &&
James Dong1d7491b2010-01-19 17:45:38 -0800301 !strcmp("enabled", atts[2]));
302
303 const size_t nMappings = sizeof(sAudioDecoderNameMap)/sizeof(sAudioDecoderNameMap[0]);
304 const int codec = findTagForName(sAudioDecoderNameMap, nMappings, atts[1]);
Alex Zhang032f7a12020-04-17 16:08:24 -0700305 if (codec == -1) {
306 ALOGE("MediaProfiles::createAudioDecoderCap failed to locate codec %s", atts[1]);
307 return nullptr;
308 }
James Dong1d7491b2010-01-19 17:45:38 -0800309
310 MediaProfiles::AudioDecoderCap *cap =
311 new MediaProfiles::AudioDecoderCap(static_cast<audio_decoder>(codec));
312 logAudioDecoderCap(*cap);
313 return cap;
314}
315
316/*static*/ MediaProfiles::VideoDecoderCap*
Lajos Molnar28091432021-05-03 20:42:32 -0700317MediaProfiles::createVideoDecoderCap(const char **atts, size_t natts)
James Dong1d7491b2010-01-19 17:45:38 -0800318{
Lajos Molnar28091432021-05-03 20:42:32 -0700319 CHECK(natts >= 4 &&
320 !strcmp("name", atts[0]) &&
James Dong1d7491b2010-01-19 17:45:38 -0800321 !strcmp("enabled", atts[2]));
322
323 const size_t nMappings = sizeof(sVideoDecoderNameMap)/sizeof(sVideoDecoderNameMap[0]);
324 const int codec = findTagForName(sVideoDecoderNameMap, nMappings, atts[1]);
Alex Zhang032f7a12020-04-17 16:08:24 -0700325 if (codec == -1) {
326 ALOGE("MediaProfiles::createVideoDecoderCap failed to locate codec %s", atts[1]);
327 return nullptr;
328 }
James Dong1d7491b2010-01-19 17:45:38 -0800329
330 MediaProfiles::VideoDecoderCap *cap =
331 new MediaProfiles::VideoDecoderCap(static_cast<video_decoder>(codec));
332 logVideoDecoderCap(*cap);
333 return cap;
334}
335
336/*static*/ MediaProfiles::VideoEncoderCap*
Lajos Molnar28091432021-05-03 20:42:32 -0700337MediaProfiles::createVideoEncoderCap(const char **atts, size_t natts)
James Dong1d7491b2010-01-19 17:45:38 -0800338{
Lajos Molnar28091432021-05-03 20:42:32 -0700339 CHECK(natts >= 20 &&
340 !strcmp("name", atts[0]) &&
James Dong1d7491b2010-01-19 17:45:38 -0800341 !strcmp("enabled", atts[2]) &&
342 !strcmp("minBitRate", atts[4]) &&
343 !strcmp("maxBitRate", atts[6]) &&
344 !strcmp("minFrameWidth", atts[8]) &&
345 !strcmp("maxFrameWidth", atts[10]) &&
346 !strcmp("minFrameHeight", atts[12]) &&
347 !strcmp("maxFrameHeight", atts[14]) &&
348 !strcmp("minFrameRate", atts[16]) &&
349 !strcmp("maxFrameRate", atts[18]));
350
351 const size_t nMappings = sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]);
352 const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]);
Alex Zhang032f7a12020-04-17 16:08:24 -0700353 if (codec == -1) {
354 ALOGE("MediaProfiles::createVideoEncoderCap failed to locate codec %s", atts[1]);
355 return nullptr;
356 }
James Dong1d7491b2010-01-19 17:45:38 -0800357
358 MediaProfiles::VideoEncoderCap *cap =
359 new MediaProfiles::VideoEncoderCap(static_cast<video_encoder>(codec),
360 atoi(atts[5]), atoi(atts[7]), atoi(atts[9]), atoi(atts[11]), atoi(atts[13]),
361 atoi(atts[15]), atoi(atts[17]), atoi(atts[19]));
362 logVideoEncoderCap(*cap);
363 return cap;
364}
365
366/*static*/ MediaProfiles::AudioEncoderCap*
Lajos Molnar28091432021-05-03 20:42:32 -0700367MediaProfiles::createAudioEncoderCap(const char **atts, size_t natts)
James Dong1d7491b2010-01-19 17:45:38 -0800368{
Lajos Molnar28091432021-05-03 20:42:32 -0700369 CHECK(natts >= 16 &&
370 !strcmp("name", atts[0]) &&
James Dong1d7491b2010-01-19 17:45:38 -0800371 !strcmp("enabled", atts[2]) &&
372 !strcmp("minBitRate", atts[4]) &&
373 !strcmp("maxBitRate", atts[6]) &&
374 !strcmp("minSampleRate", atts[8]) &&
375 !strcmp("maxSampleRate", atts[10]) &&
376 !strcmp("minChannels", atts[12]) &&
377 !strcmp("maxChannels", atts[14]));
378
379 const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]);
380 const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]);
Alex Zhang032f7a12020-04-17 16:08:24 -0700381 if (codec == -1) {
382 ALOGE("MediaProfiles::createAudioEncoderCap failed to locate codec %s", atts[1]);
383 return nullptr;
384 }
James Dong1d7491b2010-01-19 17:45:38 -0800385
386 MediaProfiles::AudioEncoderCap *cap =
Glenn Kastenb187de12014-12-30 08:18:15 -0800387 new MediaProfiles::AudioEncoderCap(static_cast<audio_encoder>(codec), atoi(atts[5]),
388 atoi(atts[7]), atoi(atts[9]), atoi(atts[11]), atoi(atts[13]), atoi(atts[15]));
James Dong1d7491b2010-01-19 17:45:38 -0800389 logAudioEncoderCap(*cap);
390 return cap;
391}
392
393/*static*/ output_format
Lajos Molnar28091432021-05-03 20:42:32 -0700394MediaProfiles::createEncoderOutputFileFormat(const char **atts, size_t natts)
James Dong1d7491b2010-01-19 17:45:38 -0800395{
Lajos Molnar28091432021-05-03 20:42:32 -0700396 CHECK(natts >= 2 &&
397 !strcmp("name", atts[0]));
James Dong1d7491b2010-01-19 17:45:38 -0800398
399 const size_t nMappings =sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]);
400 const int format = findTagForName(sFileFormatMap, nMappings, atts[1]);
401 CHECK(format != -1);
402
403 return static_cast<output_format>(format);
404}
405
James Dong2a7e0a12011-02-28 21:07:39 -0800406static bool isCameraIdFound(int cameraId, const Vector<int>& cameraIds) {
407 for (int i = 0, n = cameraIds.size(); i < n; ++i) {
408 if (cameraId == cameraIds[i]) {
409 return true;
410 }
411 }
412 return false;
413}
414
James Dong1d7491b2010-01-19 17:45:38 -0800415/*static*/ MediaProfiles::CamcorderProfile*
Lajos Molnar28091432021-05-03 20:42:32 -0700416MediaProfiles::createCamcorderProfile(
417 int cameraId, const char **atts, size_t natts, Vector<int>& cameraIds)
James Dong1d7491b2010-01-19 17:45:38 -0800418{
Lajos Molnar28091432021-05-03 20:42:32 -0700419 CHECK(natts >= 6 &&
420 !strcmp("quality", atts[0]) &&
James Dong1d7491b2010-01-19 17:45:38 -0800421 !strcmp("fileFormat", atts[2]) &&
422 !strcmp("duration", atts[4]));
423
Glenn Kastenb187de12014-12-30 08:18:15 -0800424 const size_t nProfileMappings = sizeof(sCamcorderQualityNameMap)/
425 sizeof(sCamcorderQualityNameMap[0]);
James Dong1d7491b2010-01-19 17:45:38 -0800426 const int quality = findTagForName(sCamcorderQualityNameMap, nProfileMappings, atts[1]);
Alex Zhang032f7a12020-04-17 16:08:24 -0700427 if (quality == -1) {
428 ALOGE("MediaProfiles::createCamcorderProfile failed to locate quality %s", atts[1]);
429 return nullptr;
430 }
James Dong1d7491b2010-01-19 17:45:38 -0800431
432 const size_t nFormatMappings = sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]);
433 const int fileFormat = findTagForName(sFileFormatMap, nFormatMappings, atts[3]);
Alex Zhang032f7a12020-04-17 16:08:24 -0700434 if (fileFormat == -1) {
435 ALOGE("MediaProfiles::createCamcorderProfile failed to locate file format %s", atts[1]);
436 return nullptr;
437 }
James Dong1d7491b2010-01-19 17:45:38 -0800438
439 MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +0800440 profile->mCameraId = cameraId;
James Dong2a7e0a12011-02-28 21:07:39 -0800441 if (!isCameraIdFound(cameraId, cameraIds)) {
442 cameraIds.add(cameraId);
443 }
James Dong1d7491b2010-01-19 17:45:38 -0800444 profile->mFileFormat = static_cast<output_format>(fileFormat);
445 profile->mQuality = static_cast<camcorder_quality>(quality);
446 profile->mDuration = atoi(atts[5]);
447 return profile;
448}
449
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +0800450MediaProfiles::ImageEncodingQualityLevels*
451MediaProfiles::findImageEncodingQualityLevels(int cameraId) const
452{
453 int n = mImageEncodingQualityLevels.size();
454 for (int i = 0; i < n; i++) {
455 ImageEncodingQualityLevels *levels = mImageEncodingQualityLevels[i];
456 if (levels->mCameraId == cameraId) {
457 return levels;
458 }
459 }
460 return NULL;
461}
462
Lajos Molnar28091432021-05-03 20:42:32 -0700463void MediaProfiles::addImageEncodingQualityLevel(int cameraId, const char** atts, size_t natts)
James Dongf5a83852010-02-23 17:21:44 -0800464{
Lajos Molnar28091432021-05-03 20:42:32 -0700465 CHECK(natts >= 2 &&
466 !strcmp("quality", atts[0]));
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +0800467 int quality = atoi(atts[1]);
Glenn Kasten90bebef2012-01-27 15:24:38 -0800468 ALOGV("%s: cameraId=%d, quality=%d", __func__, cameraId, quality);
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +0800469 ImageEncodingQualityLevels *levels = findImageEncodingQualityLevels(cameraId);
470
471 if (levels == NULL) {
472 levels = new ImageEncodingQualityLevels();
473 levels->mCameraId = cameraId;
474 mImageEncodingQualityLevels.add(levels);
475 }
476
477 levels->mLevels.add(quality);
478}
479
480/*static*/ int
Lajos Molnar28091432021-05-03 20:42:32 -0700481MediaProfiles::getCameraId(const char** atts, size_t natts)
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +0800482{
483 if (!atts[0]) return 0; // default cameraId = 0
Lajos Molnar28091432021-05-03 20:42:32 -0700484 CHECK(natts >= 2 &&
485 !strcmp("cameraId", atts[0]));
James Dongf5a83852010-02-23 17:21:44 -0800486 return atoi(atts[1]);
487}
488
Lajos Molnar28091432021-05-03 20:42:32 -0700489void MediaProfiles::addStartTimeOffset(int cameraId, const char** atts, size_t natts)
James Dong0f056292011-05-09 18:49:31 -0700490{
Eric Laurentb1eb1a02012-10-22 17:44:24 -0700491 int offsetTimeMs = 1000;
Lajos Molnar28091432021-05-03 20:42:32 -0700492 if (natts >= 3 && atts[2]) {
493 CHECK(natts >= 4 && !strcmp("startOffsetMs", atts[2]));
James Dong0f056292011-05-09 18:49:31 -0700494 offsetTimeMs = atoi(atts[3]);
495 }
496
Steve Block3856b092011-10-20 11:56:00 +0100497 ALOGV("%s: cameraId=%d, offset=%d ms", __func__, cameraId, offsetTimeMs);
James Dong0f056292011-05-09 18:49:31 -0700498 mStartTimeOffsets.replaceValueFor(cameraId, offsetTimeMs);
499}
Hong Tengcabd5f82011-07-06 18:33:09 -0700500
James Dong1d7491b2010-01-19 17:45:38 -0800501/*static*/ void
502MediaProfiles::startElementHandler(void *userData, const char *name, const char **atts)
503{
Lajos Molnar28091432021-05-03 20:42:32 -0700504 // determine number of attributes
505 size_t natts = 0;
506 while (atts[natts]) {
507 ++natts;
508 }
509
510 MediaProfiles *profiles = (MediaProfiles *)userData;
James Dong1d7491b2010-01-19 17:45:38 -0800511 if (strcmp("Video", name) == 0) {
Lajos Molnar28091432021-05-03 20:42:32 -0700512 createVideoCodec(atts, natts, profiles);
James Dong1d7491b2010-01-19 17:45:38 -0800513 } else if (strcmp("Audio", name) == 0) {
Lajos Molnar28091432021-05-03 20:42:32 -0700514 createAudioCodec(atts, natts, profiles);
James Dong1d7491b2010-01-19 17:45:38 -0800515 } else if (strcmp("VideoEncoderCap", name) == 0 &&
Lajos Molnar28091432021-05-03 20:42:32 -0700516 natts >= 4 &&
James Dong1d7491b2010-01-19 17:45:38 -0800517 strcmp("true", atts[3]) == 0) {
Lajos Molnar28091432021-05-03 20:42:32 -0700518 MediaProfiles::VideoEncoderCap* cap = createVideoEncoderCap(atts, natts);
Alex Zhang032f7a12020-04-17 16:08:24 -0700519 if (cap != nullptr) {
520 profiles->mVideoEncoders.add(cap);
521 }
James Dong1d7491b2010-01-19 17:45:38 -0800522 } else if (strcmp("AudioEncoderCap", name) == 0 &&
Lajos Molnar28091432021-05-03 20:42:32 -0700523 natts >= 4 &&
James Dong1d7491b2010-01-19 17:45:38 -0800524 strcmp("true", atts[3]) == 0) {
Lajos Molnar28091432021-05-03 20:42:32 -0700525 MediaProfiles::AudioEncoderCap* cap = createAudioEncoderCap(atts, natts);
Alex Zhang032f7a12020-04-17 16:08:24 -0700526 if (cap != nullptr) {
527 profiles->mAudioEncoders.add(cap);
528 }
James Dong1d7491b2010-01-19 17:45:38 -0800529 } else if (strcmp("VideoDecoderCap", name) == 0 &&
Lajos Molnar28091432021-05-03 20:42:32 -0700530 natts >= 4 &&
James Dong1d7491b2010-01-19 17:45:38 -0800531 strcmp("true", atts[3]) == 0) {
Lajos Molnar28091432021-05-03 20:42:32 -0700532 MediaProfiles::VideoDecoderCap* cap = createVideoDecoderCap(atts, natts);
Alex Zhang032f7a12020-04-17 16:08:24 -0700533 if (cap != nullptr) {
534 profiles->mVideoDecoders.add(cap);
535 }
James Dong1d7491b2010-01-19 17:45:38 -0800536 } else if (strcmp("AudioDecoderCap", name) == 0 &&
Lajos Molnar28091432021-05-03 20:42:32 -0700537 natts >= 4 &&
James Dong1d7491b2010-01-19 17:45:38 -0800538 strcmp("true", atts[3]) == 0) {
Lajos Molnar28091432021-05-03 20:42:32 -0700539 MediaProfiles::AudioDecoderCap* cap = createAudioDecoderCap(atts, natts);
Alex Zhang032f7a12020-04-17 16:08:24 -0700540 if (cap != nullptr) {
541 profiles->mAudioDecoders.add(cap);
542 }
James Dong1d7491b2010-01-19 17:45:38 -0800543 } else if (strcmp("EncoderOutputFileFormat", name) == 0) {
Lajos Molnar28091432021-05-03 20:42:32 -0700544 profiles->mEncoderOutputFileFormats.add(createEncoderOutputFileFormat(atts, natts));
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +0800545 } else if (strcmp("CamcorderProfiles", name) == 0) {
Lajos Molnar28091432021-05-03 20:42:32 -0700546 profiles->mCurrentCameraId = getCameraId(atts, natts);
547 profiles->addStartTimeOffset(profiles->mCurrentCameraId, atts, natts);
James Dong1d7491b2010-01-19 17:45:38 -0800548 } else if (strcmp("EncoderProfile", name) == 0) {
Alex Zhang032f7a12020-04-17 16:08:24 -0700549 MediaProfiles::CamcorderProfile* profile = createCamcorderProfile(
Lajos Molnar28091432021-05-03 20:42:32 -0700550 profiles->mCurrentCameraId, atts, natts, profiles->mCameraIds);
Alex Zhang032f7a12020-04-17 16:08:24 -0700551 if (profile != nullptr) {
552 profiles->mCamcorderProfiles.add(profile);
553 }
James Dongf5a83852010-02-23 17:21:44 -0800554 } else if (strcmp("ImageEncoding", name) == 0) {
Lajos Molnar28091432021-05-03 20:42:32 -0700555 profiles->addImageEncodingQualityLevel(profiles->mCurrentCameraId, atts, natts);
James Dong1d7491b2010-01-19 17:45:38 -0800556 }
557}
558
James Dong2a7e0a12011-02-28 21:07:39 -0800559static bool isCamcorderProfile(camcorder_quality quality) {
560 return quality >= CAMCORDER_QUALITY_LIST_START &&
561 quality <= CAMCORDER_QUALITY_LIST_END;
562}
563
564static bool isTimelapseProfile(camcorder_quality quality) {
565 return quality >= CAMCORDER_QUALITY_TIME_LAPSE_LIST_START &&
566 quality <= CAMCORDER_QUALITY_TIME_LAPSE_LIST_END;
567}
568
Zhijun Hee0790972014-07-23 15:17:26 -0700569static bool isHighSpeedProfile(camcorder_quality quality) {
570 return quality >= CAMCORDER_QUALITY_HIGH_SPEED_LIST_START &&
571 quality <= CAMCORDER_QUALITY_HIGH_SPEED_LIST_END;
572}
573
James Dong2a7e0a12011-02-28 21:07:39 -0800574void MediaProfiles::initRequiredProfileRefs(const Vector<int>& cameraIds) {
Mark Salyzyn34fb2962014-06-18 16:30:56 -0700575 ALOGV("Number of camera ids: %zu", cameraIds.size());
James Dong2a7e0a12011-02-28 21:07:39 -0800576 CHECK(cameraIds.size() > 0);
577 mRequiredProfileRefs = new RequiredProfiles[cameraIds.size()];
578 for (size_t i = 0, n = cameraIds.size(); i < n; ++i) {
579 mRequiredProfileRefs[i].mCameraId = cameraIds[i];
580 for (size_t j = 0; j < kNumRequiredProfiles; ++j) {
581 mRequiredProfileRefs[i].mRefs[j].mHasRefProfile = false;
582 mRequiredProfileRefs[i].mRefs[j].mRefProfileIndex = -1;
583 if ((j & 1) == 0) { // low resolution
584 mRequiredProfileRefs[i].mRefs[j].mResolutionProduct = 0x7FFFFFFF;
585 } else { // high resolution
586 mRequiredProfileRefs[i].mRefs[j].mResolutionProduct = 0;
587 }
588 }
589 }
590}
591
592int MediaProfiles::getRequiredProfileRefIndex(int cameraId) {
593 for (size_t i = 0, n = mCameraIds.size(); i < n; ++i) {
594 if (mCameraIds[i] == cameraId) {
595 return i;
596 }
597 }
598 return -1;
599}
600
601void MediaProfiles::checkAndAddRequiredProfilesIfNecessary() {
602 if (sIsInitialized) {
603 return;
604 }
605
606 initRequiredProfileRefs(mCameraIds);
607
608 for (size_t i = 0, n = mCamcorderProfiles.size(); i < n; ++i) {
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700609 // ensure at least one video and audio profile is added
Lajos Molnar28091432021-05-03 20:42:32 -0700610 if (mCamcorderProfiles[i]->mVideoCodecs.empty()) {
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700611 mCamcorderProfiles[i]->mVideoCodecs.emplace_back(
612 VIDEO_ENCODER_H263, 192000 /* bitrate */,
613 176 /* width */, 144 /* height */, 20 /* frameRate */);
614 }
Lajos Molnar28091432021-05-03 20:42:32 -0700615 if (mCamcorderProfiles[i]->mAudioCodecs.empty()) {
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700616 mCamcorderProfiles[i]->mAudioCodecs.emplace_back(
617 AUDIO_ENCODER_AMR_NB, 12200 /* bitrate */,
618 8000 /* sampleRate */, 1 /* channels */);
619 }
620
621 int product = mCamcorderProfiles[i]->mVideoCodecs[0].mFrameWidth *
622 mCamcorderProfiles[i]->mVideoCodecs[0].mFrameHeight;
James Dong2a7e0a12011-02-28 21:07:39 -0800623
624 camcorder_quality quality = mCamcorderProfiles[i]->mQuality;
625 int cameraId = mCamcorderProfiles[i]->mCameraId;
626 int index = -1;
627 int refIndex = getRequiredProfileRefIndex(cameraId);
628 CHECK(refIndex != -1);
629 RequiredProfileRefInfo *info;
630 camcorder_quality refQuality;
James Dong2a7e0a12011-02-28 21:07:39 -0800631
Zhijun Hee0790972014-07-23 15:17:26 -0700632 // Check high and low from either camcorder profile, timelapse profile
633 // or high speed profile, but not all of them. Default, check camcorder profile
James Dong2a7e0a12011-02-28 21:07:39 -0800634 size_t j = 0;
Bernhard Rosenkraenzer3c8889e2012-03-29 11:38:59 +0200635 size_t o = 2;
James Dong2a7e0a12011-02-28 21:07:39 -0800636 if (isTimelapseProfile(quality)) {
637 // Check timelapse profile instead.
638 j = 2;
Bernhard Rosenkraenzer3c8889e2012-03-29 11:38:59 +0200639 o = kNumRequiredProfiles;
Zhijun Hee0790972014-07-23 15:17:26 -0700640 } else if (isHighSpeedProfile(quality)) {
641 // Skip the check for high speed profile.
642 continue;
James Dong2a7e0a12011-02-28 21:07:39 -0800643 } else {
644 // Must be camcorder profile.
645 CHECK(isCamcorderProfile(quality));
646 }
Bernhard Rosenkraenzer3c8889e2012-03-29 11:38:59 +0200647 for (; j < o; ++j) {
James Dong2a7e0a12011-02-28 21:07:39 -0800648 info = &(mRequiredProfileRefs[refIndex].mRefs[j]);
649 if ((j % 2 == 0 && product > info->mResolutionProduct) || // low
650 (j % 2 != 0 && product < info->mResolutionProduct)) { // high
651 continue;
652 }
653 switch (j) {
654 case 0:
655 refQuality = CAMCORDER_QUALITY_LOW;
656 break;
657 case 1:
658 refQuality = CAMCORDER_QUALITY_HIGH;
659 break;
660 case 2:
661 refQuality = CAMCORDER_QUALITY_TIME_LAPSE_LOW;
662 break;
663 case 3:
664 refQuality = CAMCORDER_QUALITY_TIME_LAPSE_HIGH;
665 break;
666 default:
667 CHECK(!"Should never reach here");
668 }
669
670 if (!info->mHasRefProfile) {
671 index = getCamcorderProfileIndex(cameraId, refQuality);
672 }
673 if (index == -1) {
674 // New high or low quality profile is found.
675 // Update its reference.
676 info->mHasRefProfile = true;
677 info->mRefProfileIndex = i;
678 info->mResolutionProduct = product;
679 }
680 }
681 }
682
683 for (size_t cameraId = 0; cameraId < mCameraIds.size(); ++cameraId) {
684 for (size_t j = 0; j < kNumRequiredProfiles; ++j) {
685 int refIndex = getRequiredProfileRefIndex(cameraId);
686 CHECK(refIndex != -1);
687 RequiredProfileRefInfo *info =
688 &mRequiredProfileRefs[refIndex].mRefs[j];
689
690 if (info->mHasRefProfile) {
691
George Burgess IV215545b2018-07-25 10:06:30 -0700692 std::unique_ptr<CamcorderProfile> profile =
693 std::make_unique<CamcorderProfile>(
James Dong2a7e0a12011-02-28 21:07:39 -0800694 *mCamcorderProfiles[info->mRefProfileIndex]);
695
696 // Overwrite the quality
697 switch (j % kNumRequiredProfiles) {
698 case 0:
699 profile->mQuality = CAMCORDER_QUALITY_LOW;
700 break;
701 case 1:
702 profile->mQuality = CAMCORDER_QUALITY_HIGH;
703 break;
704 case 2:
705 profile->mQuality = CAMCORDER_QUALITY_TIME_LAPSE_LOW;
706 break;
707 case 3:
708 profile->mQuality = CAMCORDER_QUALITY_TIME_LAPSE_HIGH;
709 break;
710 default:
711 CHECK(!"Should never come here");
712 }
713
714 int index = getCamcorderProfileIndex(cameraId, profile->mQuality);
715 if (index != -1) {
Mark Salyzyn34fb2962014-06-18 16:30:56 -0700716 ALOGV("Profile quality %d for camera %zu already exists",
James Dong2a7e0a12011-02-28 21:07:39 -0800717 profile->mQuality, cameraId);
718 CHECK(index == refIndex);
719 continue;
720 }
721
722 // Insert the new profile
Mark Salyzyn34fb2962014-06-18 16:30:56 -0700723 ALOGV("Add a profile: quality %d=>%d for camera %zu",
James Dong2a7e0a12011-02-28 21:07:39 -0800724 mCamcorderProfiles[info->mRefProfileIndex]->mQuality,
725 profile->mQuality, cameraId);
726
George Burgess IV215545b2018-07-25 10:06:30 -0700727 mCamcorderProfiles.add(profile.release());
James Dong2a7e0a12011-02-28 21:07:39 -0800728 }
729 }
730 }
731}
732
James Dong1d7491b2010-01-19 17:45:38 -0800733/*static*/ MediaProfiles*
734MediaProfiles::getInstance()
735{
Steve Block3856b092011-10-20 11:56:00 +0100736 ALOGV("getInstance");
James Dong1d7491b2010-01-19 17:45:38 -0800737 Mutex::Autolock lock(sLock);
738 if (!sIsInitialized) {
739 char value[PROPERTY_VALUE_MAX];
740 if (property_get("media.settings.xml", value, NULL) <= 0) {
Pawin Vongmasad7db05b2017-05-03 04:19:20 -0700741 const char* xmlFile = nullptr;
Pawin Vongmasa7f5e10e2020-03-07 04:09:55 -0800742 for (auto const& f : getXmlPaths()) {
Pawin Vongmasad7db05b2017-05-03 04:19:20 -0700743 if (checkXmlFile(f)) {
744 xmlFile = f;
745 break;
746 }
747 }
748 if (xmlFile == nullptr) {
749 ALOGW("Could not find a validated xml file. "
750 "Using the default instance instead.");
James Dong1d7491b2010-01-19 17:45:38 -0800751 sInstance = createDefaultInstance();
752 } else {
Pawin Vongmasad7db05b2017-05-03 04:19:20 -0700753 sInstance = createInstanceFromXmlFile(xmlFile);
James Dong1d7491b2010-01-19 17:45:38 -0800754 }
755 } else {
756 sInstance = createInstanceFromXmlFile(value);
757 }
James Dong2a7e0a12011-02-28 21:07:39 -0800758 CHECK(sInstance != NULL);
759 sInstance->checkAndAddRequiredProfilesIfNecessary();
760 sIsInitialized = true;
James Dong1d7491b2010-01-19 17:45:38 -0800761 }
762
763 return sInstance;
764}
765
766/*static*/ MediaProfiles::VideoEncoderCap*
767MediaProfiles::createDefaultH263VideoEncoderCap()
768{
769 return new MediaProfiles::VideoEncoderCap(
770 VIDEO_ENCODER_H263, 192000, 420000, 176, 352, 144, 288, 1, 20);
771}
772
773/*static*/ MediaProfiles::VideoEncoderCap*
774MediaProfiles::createDefaultM4vVideoEncoderCap()
775{
776 return new MediaProfiles::VideoEncoderCap(
777 VIDEO_ENCODER_MPEG_4_SP, 192000, 420000, 176, 352, 144, 288, 1, 20);
778}
779
780
781/*static*/ void
782MediaProfiles::createDefaultVideoEncoders(MediaProfiles *profiles)
783{
784 profiles->mVideoEncoders.add(createDefaultH263VideoEncoderCap());
785 profiles->mVideoEncoders.add(createDefaultM4vVideoEncoderCap());
786}
787
788/*static*/ MediaProfiles::CamcorderProfile*
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700789MediaProfiles::createDefaultCamcorderTimeLapseQcifProfile(camcorder_quality quality)
Nipun Kwatrac0a84782010-09-06 15:59:02 -0700790{
Nipun Kwatrac0a84782010-09-06 15:59:02 -0700791 CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
792 profile->mCameraId = 0;
793 profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700794 profile->mQuality = quality;
Nipun Kwatrac0a84782010-09-06 15:59:02 -0700795 profile->mDuration = 60;
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700796 profile->mVideoCodecs.emplace_back(
797 VIDEO_ENCODER_H263, 1000000 /* bitrate */,
798 176 /* width */, 144 /* height */, 20 /* frameRate */);
799 profile->mAudioCodecs.emplace_back(
800 AUDIO_ENCODER_AMR_NB, 12200 /* bitrate */,
801 8000 /* sampleRate */, 1 /* channels */);
802
Nipun Kwatrac0a84782010-09-06 15:59:02 -0700803 return profile;
804}
805
806/*static*/ MediaProfiles::CamcorderProfile*
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700807MediaProfiles::createDefaultCamcorderTimeLapse480pProfile(camcorder_quality quality)
James Dong1d7491b2010-01-19 17:45:38 -0800808{
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +0800809 CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
810 profile->mCameraId = 0;
James Dong1d7491b2010-01-19 17:45:38 -0800811 profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700812 profile->mQuality = quality;
James Dong1d7491b2010-01-19 17:45:38 -0800813 profile->mDuration = 60;
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700814 profile->mVideoCodecs.emplace_back(
815 VIDEO_ENCODER_H263, 20000000 /* bitrate */,
816 720 /* width */, 480 /* height */, 20 /* frameRate */);
817 profile->mAudioCodecs.emplace_back(
818 AUDIO_ENCODER_AMR_NB, 12200 /* bitrate */,
819 8000 /* sampleRate */, 1 /* channels */);
James Dong1d7491b2010-01-19 17:45:38 -0800820 return profile;
821}
822
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700823/*static*/ void
824MediaProfiles::createDefaultCamcorderTimeLapseLowProfiles(
825 MediaProfiles::CamcorderProfile **lowTimeLapseProfile,
826 MediaProfiles::CamcorderProfile **lowSpecificTimeLapseProfile) {
Glenn Kastenb187de12014-12-30 08:18:15 -0800827 *lowTimeLapseProfile = createDefaultCamcorderTimeLapseQcifProfile(
828 CAMCORDER_QUALITY_TIME_LAPSE_LOW);
829 *lowSpecificTimeLapseProfile = createDefaultCamcorderTimeLapseQcifProfile(
830 CAMCORDER_QUALITY_TIME_LAPSE_QCIF);
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700831}
832
833/*static*/ void
834MediaProfiles::createDefaultCamcorderTimeLapseHighProfiles(
835 MediaProfiles::CamcorderProfile **highTimeLapseProfile,
836 MediaProfiles::CamcorderProfile **highSpecificTimeLapseProfile) {
Glenn Kastenb187de12014-12-30 08:18:15 -0800837 *highTimeLapseProfile = createDefaultCamcorderTimeLapse480pProfile(
838 CAMCORDER_QUALITY_TIME_LAPSE_HIGH);
839 *highSpecificTimeLapseProfile = createDefaultCamcorderTimeLapse480pProfile(
840 CAMCORDER_QUALITY_TIME_LAPSE_480P);
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700841}
842
James Dong1d7491b2010-01-19 17:45:38 -0800843/*static*/ MediaProfiles::CamcorderProfile*
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700844MediaProfiles::createDefaultCamcorderQcifProfile(camcorder_quality quality)
James Dong1d7491b2010-01-19 17:45:38 -0800845{
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700846 CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +0800847 profile->mCameraId = 0;
James Dong1d7491b2010-01-19 17:45:38 -0800848 profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700849 profile->mQuality = quality;
James Dong1d7491b2010-01-19 17:45:38 -0800850 profile->mDuration = 30;
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700851 profile->mVideoCodecs.emplace_back(
852 VIDEO_ENCODER_H263, 192000 /* bitrate */,
853 176 /* width */, 144 /* height */, 20 /* frameRate */);
854 profile->mAudioCodecs.emplace_back(
855 AUDIO_ENCODER_AMR_NB, 12200 /* bitrate */,
856 8000 /* sampleRate */, 1 /* channels */);
James Dong1d7491b2010-01-19 17:45:38 -0800857 return profile;
858}
859
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700860/*static*/ MediaProfiles::CamcorderProfile*
861MediaProfiles::createDefaultCamcorderCifProfile(camcorder_quality quality)
862{
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700863 CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
864 profile->mCameraId = 0;
865 profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
866 profile->mQuality = quality;
867 profile->mDuration = 60;
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -0700868 profile->mVideoCodecs.emplace_back(
869 VIDEO_ENCODER_H263, 360000 /* bitrate */,
870 352 /* width */, 288 /* height */, 20 /* frameRate */);
871 profile->mAudioCodecs.emplace_back(
872 AUDIO_ENCODER_AMR_NB, 12200 /* bitrate */,
873 8000 /* sampleRate */, 1 /* channels */);
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700874 return profile;
875}
876
877/*static*/ void
878MediaProfiles::createDefaultCamcorderLowProfiles(
879 MediaProfiles::CamcorderProfile **lowProfile,
880 MediaProfiles::CamcorderProfile **lowSpecificProfile) {
881 *lowProfile = createDefaultCamcorderQcifProfile(CAMCORDER_QUALITY_LOW);
882 *lowSpecificProfile = createDefaultCamcorderQcifProfile(CAMCORDER_QUALITY_QCIF);
883}
884
885/*static*/ void
886MediaProfiles::createDefaultCamcorderHighProfiles(
887 MediaProfiles::CamcorderProfile **highProfile,
888 MediaProfiles::CamcorderProfile **highSpecificProfile) {
889 *highProfile = createDefaultCamcorderCifProfile(CAMCORDER_QUALITY_HIGH);
890 *highSpecificProfile = createDefaultCamcorderCifProfile(CAMCORDER_QUALITY_CIF);
891}
892
James Dong1d7491b2010-01-19 17:45:38 -0800893/*static*/ void
894MediaProfiles::createDefaultCamcorderProfiles(MediaProfiles *profiles)
895{
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700896 // low camcorder profiles.
897 MediaProfiles::CamcorderProfile *lowProfile, *lowSpecificProfile;
898 createDefaultCamcorderLowProfiles(&lowProfile, &lowSpecificProfile);
899 profiles->mCamcorderProfiles.add(lowProfile);
900 profiles->mCamcorderProfiles.add(lowSpecificProfile);
901
902 // high camcorder profiles.
903 MediaProfiles::CamcorderProfile* highProfile, *highSpecificProfile;
904 createDefaultCamcorderHighProfiles(&highProfile, &highSpecificProfile);
905 profiles->mCamcorderProfiles.add(highProfile);
906 profiles->mCamcorderProfiles.add(highSpecificProfile);
907
908 // low camcorder time lapse profiles.
909 MediaProfiles::CamcorderProfile *lowTimeLapseProfile, *lowSpecificTimeLapseProfile;
910 createDefaultCamcorderTimeLapseLowProfiles(&lowTimeLapseProfile, &lowSpecificTimeLapseProfile);
911 profiles->mCamcorderProfiles.add(lowTimeLapseProfile);
912 profiles->mCamcorderProfiles.add(lowSpecificTimeLapseProfile);
913
914 // high camcorder time lapse profiles.
915 MediaProfiles::CamcorderProfile *highTimeLapseProfile, *highSpecificTimeLapseProfile;
Glenn Kastenb187de12014-12-30 08:18:15 -0800916 createDefaultCamcorderTimeLapseHighProfiles(&highTimeLapseProfile,
917 &highSpecificTimeLapseProfile);
Nipun Kwatrad5672bc2010-09-16 22:25:23 -0700918 profiles->mCamcorderProfiles.add(highTimeLapseProfile);
919 profiles->mCamcorderProfiles.add(highSpecificTimeLapseProfile);
James Dong8031ec72011-03-16 14:09:50 -0700920
921 // For emulator and other legacy devices which does not have a
922 // media_profiles.xml file, We assume that the default camera id
923 // is 0 and that is the only camera available.
924 profiles->mCameraIds.push(0);
James Dong1d7491b2010-01-19 17:45:38 -0800925}
926
927/*static*/ void
928MediaProfiles::createDefaultAudioEncoders(MediaProfiles *profiles)
929{
930 profiles->mAudioEncoders.add(createDefaultAmrNBEncoderCap());
931}
932
933/*static*/ void
934MediaProfiles::createDefaultVideoDecoders(MediaProfiles *profiles)
935{
936 MediaProfiles::VideoDecoderCap *cap =
937 new MediaProfiles::VideoDecoderCap(VIDEO_DECODER_WMV);
938
939 profiles->mVideoDecoders.add(cap);
940}
941
942/*static*/ void
943MediaProfiles::createDefaultAudioDecoders(MediaProfiles *profiles)
944{
945 MediaProfiles::AudioDecoderCap *cap =
946 new MediaProfiles::AudioDecoderCap(AUDIO_DECODER_WMA);
947
948 profiles->mAudioDecoders.add(cap);
949}
950
951/*static*/ void
952MediaProfiles::createDefaultEncoderOutputFileFormats(MediaProfiles *profiles)
953{
954 profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_THREE_GPP);
955 profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_MPEG_4);
956}
957
958/*static*/ MediaProfiles::AudioEncoderCap*
959MediaProfiles::createDefaultAmrNBEncoderCap()
960{
961 return new MediaProfiles::AudioEncoderCap(
962 AUDIO_ENCODER_AMR_NB, 5525, 12200, 8000, 8000, 1, 1);
963}
964
James Dongf5a83852010-02-23 17:21:44 -0800965/*static*/ void
966MediaProfiles::createDefaultImageEncodingQualityLevels(MediaProfiles *profiles)
967{
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +0800968 ImageEncodingQualityLevels *levels = new ImageEncodingQualityLevels();
969 levels->mCameraId = 0;
970 levels->mLevels.add(70);
971 levels->mLevels.add(80);
972 levels->mLevels.add(90);
973 profiles->mImageEncodingQualityLevels.add(levels);
James Dongf5a83852010-02-23 17:21:44 -0800974}
975
James Dong1d7491b2010-01-19 17:45:38 -0800976/*static*/ MediaProfiles*
977MediaProfiles::createDefaultInstance()
978{
979 MediaProfiles *profiles = new MediaProfiles;
980 createDefaultCamcorderProfiles(profiles);
981 createDefaultVideoEncoders(profiles);
982 createDefaultAudioEncoders(profiles);
983 createDefaultVideoDecoders(profiles);
984 createDefaultAudioDecoders(profiles);
985 createDefaultEncoderOutputFileFormats(profiles);
James Dongf5a83852010-02-23 17:21:44 -0800986 createDefaultImageEncodingQualityLevels(profiles);
James Dong1d7491b2010-01-19 17:45:38 -0800987 return profiles;
988}
989
Pawin Vongmasad7db05b2017-05-03 04:19:20 -0700990bool MediaProfiles::checkXmlFile(const char* xmlFile) {
991 struct stat fStat;
992 return stat(xmlFile, &fStat) == 0 && S_ISREG(fStat.st_mode);
993 // TODO: Add validation
994}
995
James Dong1d7491b2010-01-19 17:45:38 -0800996/*static*/ MediaProfiles*
997MediaProfiles::createInstanceFromXmlFile(const char *xml)
998{
999 FILE *fp = NULL;
1000 CHECK((fp = fopen(xml, "r")));
1001
1002 XML_Parser parser = ::XML_ParserCreate(NULL);
1003 CHECK(parser != NULL);
1004
1005 MediaProfiles *profiles = new MediaProfiles();
1006 ::XML_SetUserData(parser, profiles);
1007 ::XML_SetElementHandler(parser, startElementHandler, NULL);
1008
1009 /*
1010 FIXME:
1011 expat is not compiled with -DXML_DTD. We don't have DTD parsing support.
1012
1013 if (!::XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS)) {
Steve Block29357bc2012-01-06 19:20:56 +00001014 ALOGE("failed to enable DTD support in the xml file");
James Dong1d7491b2010-01-19 17:45:38 -08001015 return UNKNOWN_ERROR;
1016 }
1017
1018 */
1019
1020 const int BUFF_SIZE = 512;
1021 for (;;) {
1022 void *buff = ::XML_GetBuffer(parser, BUFF_SIZE);
1023 if (buff == NULL) {
Steve Block29357bc2012-01-06 19:20:56 +00001024 ALOGE("failed to in call to XML_GetBuffer()");
James Dong1d7491b2010-01-19 17:45:38 -08001025 delete profiles;
1026 profiles = NULL;
1027 goto exit;
1028 }
1029
1030 int bytes_read = ::fread(buff, 1, BUFF_SIZE, fp);
1031 if (bytes_read < 0) {
Steve Block29357bc2012-01-06 19:20:56 +00001032 ALOGE("failed in call to read");
James Dong1d7491b2010-01-19 17:45:38 -08001033 delete profiles;
1034 profiles = NULL;
1035 goto exit;
1036 }
1037
1038 CHECK(::XML_ParseBuffer(parser, bytes_read, bytes_read == 0));
1039
1040 if (bytes_read == 0) break; // done parsing the xml file
1041 }
1042
1043exit:
1044 ::XML_ParserFree(parser);
1045 ::fclose(fp);
James Dong1d7491b2010-01-19 17:45:38 -08001046 return profiles;
1047}
1048
1049Vector<output_format> MediaProfiles::getOutputFileFormats() const
1050{
1051 return mEncoderOutputFileFormats; // copy out
1052}
1053
1054Vector<video_encoder> MediaProfiles::getVideoEncoders() const
1055{
1056 Vector<video_encoder> encoders;
1057 for (size_t i = 0; i < mVideoEncoders.size(); ++i) {
1058 encoders.add(mVideoEncoders[i]->mCodec);
1059 }
1060 return encoders; // copy out
1061}
1062
1063int MediaProfiles::getVideoEncoderParamByName(const char *name, video_encoder codec) const
1064{
Steve Block3856b092011-10-20 11:56:00 +01001065 ALOGV("getVideoEncoderParamByName: %s for codec %d", name, codec);
James Dong1d7491b2010-01-19 17:45:38 -08001066 int index = -1;
1067 for (size_t i = 0, n = mVideoEncoders.size(); i < n; ++i) {
1068 if (mVideoEncoders[i]->mCodec == codec) {
1069 index = i;
1070 break;
1071 }
1072 }
1073 if (index == -1) {
Steve Block29357bc2012-01-06 19:20:56 +00001074 ALOGE("The given video encoder %d is not found", codec);
James Dong1d7491b2010-01-19 17:45:38 -08001075 return -1;
1076 }
1077
1078 if (!strcmp("enc.vid.width.min", name)) return mVideoEncoders[index]->mMinFrameWidth;
1079 if (!strcmp("enc.vid.width.max", name)) return mVideoEncoders[index]->mMaxFrameWidth;
1080 if (!strcmp("enc.vid.height.min", name)) return mVideoEncoders[index]->mMinFrameHeight;
1081 if (!strcmp("enc.vid.height.max", name)) return mVideoEncoders[index]->mMaxFrameHeight;
1082 if (!strcmp("enc.vid.bps.min", name)) return mVideoEncoders[index]->mMinBitRate;
1083 if (!strcmp("enc.vid.bps.max", name)) return mVideoEncoders[index]->mMaxBitRate;
1084 if (!strcmp("enc.vid.fps.min", name)) return mVideoEncoders[index]->mMinFrameRate;
1085 if (!strcmp("enc.vid.fps.max", name)) return mVideoEncoders[index]->mMaxFrameRate;
1086
Steve Block29357bc2012-01-06 19:20:56 +00001087 ALOGE("The given video encoder param name %s is not found", name);
James Dong1d7491b2010-01-19 17:45:38 -08001088 return -1;
1089}
Hong Tengcabd5f82011-07-06 18:33:09 -07001090
James Dong1d7491b2010-01-19 17:45:38 -08001091Vector<audio_encoder> MediaProfiles::getAudioEncoders() const
1092{
1093 Vector<audio_encoder> encoders;
1094 for (size_t i = 0; i < mAudioEncoders.size(); ++i) {
1095 encoders.add(mAudioEncoders[i]->mCodec);
1096 }
1097 return encoders; // copy out
1098}
1099
1100int MediaProfiles::getAudioEncoderParamByName(const char *name, audio_encoder codec) const
1101{
Steve Block3856b092011-10-20 11:56:00 +01001102 ALOGV("getAudioEncoderParamByName: %s for codec %d", name, codec);
James Dong1d7491b2010-01-19 17:45:38 -08001103 int index = -1;
1104 for (size_t i = 0, n = mAudioEncoders.size(); i < n; ++i) {
1105 if (mAudioEncoders[i]->mCodec == codec) {
1106 index = i;
1107 break;
1108 }
1109 }
1110 if (index == -1) {
Steve Block29357bc2012-01-06 19:20:56 +00001111 ALOGE("The given audio encoder %d is not found", codec);
James Dong1d7491b2010-01-19 17:45:38 -08001112 return -1;
1113 }
1114
1115 if (!strcmp("enc.aud.ch.min", name)) return mAudioEncoders[index]->mMinChannels;
1116 if (!strcmp("enc.aud.ch.max", name)) return mAudioEncoders[index]->mMaxChannels;
1117 if (!strcmp("enc.aud.bps.min", name)) return mAudioEncoders[index]->mMinBitRate;
1118 if (!strcmp("enc.aud.bps.max", name)) return mAudioEncoders[index]->mMaxBitRate;
1119 if (!strcmp("enc.aud.hz.min", name)) return mAudioEncoders[index]->mMinSampleRate;
1120 if (!strcmp("enc.aud.hz.max", name)) return mAudioEncoders[index]->mMaxSampleRate;
1121
Steve Block29357bc2012-01-06 19:20:56 +00001122 ALOGE("The given audio encoder param name %s is not found", name);
James Dong1d7491b2010-01-19 17:45:38 -08001123 return -1;
1124}
1125
1126Vector<video_decoder> MediaProfiles::getVideoDecoders() const
1127{
1128 Vector<video_decoder> decoders;
1129 for (size_t i = 0; i < mVideoDecoders.size(); ++i) {
1130 decoders.add(mVideoDecoders[i]->mCodec);
1131 }
1132 return decoders; // copy out
1133}
1134
1135Vector<audio_decoder> MediaProfiles::getAudioDecoders() const
1136{
1137 Vector<audio_decoder> decoders;
1138 for (size_t i = 0; i < mAudioDecoders.size(); ++i) {
1139 decoders.add(mAudioDecoders[i]->mCodec);
1140 }
1141 return decoders; // copy out
1142}
1143
Nipun Kwatra8bb56032010-09-09 16:25:08 -07001144int MediaProfiles::getCamcorderProfileIndex(int cameraId, camcorder_quality quality) const
James Dong1d7491b2010-01-19 17:45:38 -08001145{
James Dong1d7491b2010-01-19 17:45:38 -08001146 int index = -1;
1147 for (size_t i = 0, n = mCamcorderProfiles.size(); i < n; ++i) {
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +08001148 if (mCamcorderProfiles[i]->mCameraId == cameraId &&
1149 mCamcorderProfiles[i]->mQuality == quality) {
James Dong1d7491b2010-01-19 17:45:38 -08001150 index = i;
1151 break;
1152 }
1153 }
Nipun Kwatra8bb56032010-09-09 16:25:08 -07001154 return index;
1155}
1156
Lajos Molnard64df6d2021-04-29 23:20:57 -07001157const MediaProfiles::CamcorderProfile *MediaProfiles::getCamcorderProfile(
1158 int cameraId, camcorder_quality quality) const {
1159 int index = getCamcorderProfileIndex(cameraId, quality);
1160 if (index == -1) {
1161 ALOGE("The given camcorder profile camera %d quality %d is not found",
1162 cameraId, quality);
1163 return nullptr;
1164 }
1165
1166 return mCamcorderProfiles[index];
1167}
1168
1169std::vector<const MediaProfiles::AudioCodec *>
1170MediaProfiles::CamcorderProfile::getAudioCodecs() const {
1171 std::vector<const MediaProfiles::AudioCodec *> res;
1172 for (const MediaProfiles::AudioCodec &ac : mAudioCodecs) {
1173 res.push_back(&ac);
1174 }
1175 return res;
1176}
1177
1178std::vector<const MediaProfiles::VideoCodec *>
1179MediaProfiles::CamcorderProfile::getVideoCodecs() const {
1180 std::vector<const MediaProfiles::VideoCodec *> res;
1181 for (const MediaProfiles::VideoCodec &vc : mVideoCodecs) {
1182 res.push_back(&vc);
1183 }
1184 return res;
1185}
1186
Nipun Kwatra8bb56032010-09-09 16:25:08 -07001187int MediaProfiles::getCamcorderProfileParamByName(const char *name,
1188 int cameraId,
1189 camcorder_quality quality) const
1190{
Steve Block3856b092011-10-20 11:56:00 +01001191 ALOGV("getCamcorderProfileParamByName: %s for camera %d, quality %d",
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001192 name, cameraId, quality);
Nipun Kwatra8bb56032010-09-09 16:25:08 -07001193
1194 int index = getCamcorderProfileIndex(cameraId, quality);
James Dong1d7491b2010-01-19 17:45:38 -08001195 if (index == -1) {
Steve Block29357bc2012-01-06 19:20:56 +00001196 ALOGE("The given camcorder profile camera %d quality %d is not found",
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001197 cameraId, quality);
James Dong1d7491b2010-01-19 17:45:38 -08001198 return -1;
1199 }
1200
James Dongf5a83852010-02-23 17:21:44 -08001201 if (!strcmp("duration", name)) return mCamcorderProfiles[index]->mDuration;
James Dong1d7491b2010-01-19 17:45:38 -08001202 if (!strcmp("file.format", name)) return mCamcorderProfiles[index]->mFileFormat;
Lajos Molnarb0aeb8b2021-03-24 10:11:41 -07001203 if (!strcmp("vid.codec", name)) return mCamcorderProfiles[index]->mVideoCodecs[0].mCodec;
1204 if (!strcmp("vid.width", name)) return mCamcorderProfiles[index]->mVideoCodecs[0].mFrameWidth;
1205 if (!strcmp("vid.height", name)) return mCamcorderProfiles[index]->mVideoCodecs[0].mFrameHeight;
1206 if (!strcmp("vid.bps", name)) return mCamcorderProfiles[index]->mVideoCodecs[0].mBitRate;
1207 if (!strcmp("vid.fps", name)) return mCamcorderProfiles[index]->mVideoCodecs[0].mFrameRate;
1208 if (!strcmp("aud.codec", name)) return mCamcorderProfiles[index]->mAudioCodecs[0].mCodec;
1209 if (!strcmp("aud.bps", name)) return mCamcorderProfiles[index]->mAudioCodecs[0].mBitRate;
1210 if (!strcmp("aud.ch", name)) return mCamcorderProfiles[index]->mAudioCodecs[0].mChannels;
1211 if (!strcmp("aud.hz", name)) return mCamcorderProfiles[index]->mAudioCodecs[0].mSampleRate;
James Dong1d7491b2010-01-19 17:45:38 -08001212
Steve Block29357bc2012-01-06 19:20:56 +00001213 ALOGE("The given camcorder profile param id %d name %s is not found", cameraId, name);
James Dong1d7491b2010-01-19 17:45:38 -08001214 return -1;
1215}
1216
Nipun Kwatra8bb56032010-09-09 16:25:08 -07001217bool MediaProfiles::hasCamcorderProfile(int cameraId, camcorder_quality quality) const
1218{
1219 return (getCamcorderProfileIndex(cameraId, quality) != -1);
1220}
1221
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +08001222Vector<int> MediaProfiles::getImageEncodingQualityLevels(int cameraId) const
James Dongf5a83852010-02-23 17:21:44 -08001223{
Chih-Chung Chang3eaa4e92010-06-22 20:50:55 +08001224 Vector<int> result;
1225 ImageEncodingQualityLevels *levels = findImageEncodingQualityLevels(cameraId);
1226 if (levels != NULL) {
1227 result = levels->mLevels; // copy out
1228 }
1229 return result;
James Dongf5a83852010-02-23 17:21:44 -08001230}
1231
James Dong0f056292011-05-09 18:49:31 -07001232int MediaProfiles::getStartTimeOffsetMs(int cameraId) const {
1233 int offsetTimeMs = -1;
1234 ssize_t index = mStartTimeOffsets.indexOfKey(cameraId);
1235 if (index >= 0) {
1236 offsetTimeMs = mStartTimeOffsets.valueFor(cameraId);
1237 }
Steve Block3856b092011-10-20 11:56:00 +01001238 ALOGV("offsetTime=%d ms and cameraId=%d", offsetTimeMs, cameraId);
James Dong0f056292011-05-09 18:49:31 -07001239 return offsetTimeMs;
1240}
1241
James Dong1d7491b2010-01-19 17:45:38 -08001242MediaProfiles::~MediaProfiles()
1243{
1244 CHECK("destructor should never be called" == 0);
1245#if 0
1246 for (size_t i = 0; i < mAudioEncoders.size(); ++i) {
1247 delete mAudioEncoders[i];
1248 }
1249 mAudioEncoders.clear();
1250
1251 for (size_t i = 0; i < mVideoEncoders.size(); ++i) {
1252 delete mVideoEncoders[i];
1253 }
1254 mVideoEncoders.clear();
1255
1256 for (size_t i = 0; i < mVideoDecoders.size(); ++i) {
1257 delete mVideoDecoders[i];
1258 }
1259 mVideoDecoders.clear();
1260
1261 for (size_t i = 0; i < mAudioDecoders.size(); ++i) {
1262 delete mAudioDecoders[i];
1263 }
1264 mAudioDecoders.clear();
1265
1266 for (size_t i = 0; i < mCamcorderProfiles.size(); ++i) {
1267 delete mCamcorderProfiles[i];
1268 }
1269 mCamcorderProfiles.clear();
1270#endif
1271}
1272} // namespace android