James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2010, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | #define LOG_TAG "MediaProfiles" |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <utils/Log.h> |
| 24 | #include <utils/Vector.h> |
| 25 | #include <cutils/properties.h> |
Elliott Hughes | 242b400 | 2015-07-10 11:09:23 -0700 | [diff] [blame] | 26 | #include <expat.h> |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 27 | #include <media/MediaProfiles.h> |
James Dong | f1d5aa1 | 2012-02-06 23:46:37 -0800 | [diff] [blame] | 28 | #include <media/stagefright/foundation/ADebug.h> |
James Dong | 6c6b4d0 | 2012-03-12 14:37:53 -0700 | [diff] [blame] | 29 | #include <OMX_Video.h> |
Pawin Vongmasa | d7db05b | 2017-05-03 04:19:20 -0700 | [diff] [blame] | 30 | #include <sys/stat.h> |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 31 | |
Pawin Vongmasa | 7f5e10e | 2020-03-07 04:09:55 -0800 | [diff] [blame] | 32 | #include <array> |
| 33 | #include <string> |
| 34 | #include <vector> |
| 35 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 36 | namespace android { |
| 37 | |
Pawin Vongmasa | 7f5e10e | 2020-03-07 04:09:55 -0800 | [diff] [blame] | 38 | namespace /* unnamed */ { |
| 39 | |
| 40 | // Returns a list of possible paths for the media_profiles XML file. |
| 41 | std::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, |
Matthias Springer | 0f44db0 | 2020-08-14 14:32:05 +0900 | [diff] [blame^] | 66 | "system/etc/media_profiles.xml" // System fallback |
Pawin Vongmasa | 7f5e10e | 2020-03-07 04:09:55 -0800 | [diff] [blame] | 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 Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 81 | Mutex MediaProfiles::sLock; |
| 82 | bool MediaProfiles::sIsInitialized = false; |
| 83 | MediaProfiles *MediaProfiles::sInstance = NULL; |
| 84 | |
| 85 | const MediaProfiles::NameToTagMap MediaProfiles::sVideoEncoderNameMap[] = { |
| 86 | {"h263", VIDEO_ENCODER_H263}, |
| 87 | {"h264", VIDEO_ENCODER_H264}, |
Wonsik Kim | 9aa87d4 | 2015-12-07 13:52:02 +0900 | [diff] [blame] | 88 | {"m4v", VIDEO_ENCODER_MPEG_4_SP}, |
| 89 | {"hevc", VIDEO_ENCODER_HEVC} |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | const MediaProfiles::NameToTagMap MediaProfiles::sAudioEncoderNameMap[] = { |
Dave Burke | aeb8fd4 | 2012-04-19 00:14:27 -0700 | [diff] [blame] | 93 | {"amrnb", AUDIO_ENCODER_AMR_NB}, |
| 94 | {"amrwb", AUDIO_ENCODER_AMR_WB}, |
| 95 | {"aac", AUDIO_ENCODER_AAC}, |
Dave Burke | f60c660 | 2012-04-28 21:58:22 -0700 | [diff] [blame] | 96 | {"heaac", AUDIO_ENCODER_HE_AAC}, |
Pawin Vongmasa | 7f5e10e | 2020-03-07 04:09:55 -0800 | [diff] [blame] | 97 | {"aaceld", AUDIO_ENCODER_AAC_ELD}, |
Ray Essick | df27b04 | 2018-11-27 18:55:09 -0800 | [diff] [blame] | 98 | {"opus", AUDIO_ENCODER_OPUS} |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | const MediaProfiles::NameToTagMap MediaProfiles::sFileFormatMap[] = { |
| 102 | {"3gp", OUTPUT_FORMAT_THREE_GPP}, |
| 103 | {"mp4", OUTPUT_FORMAT_MPEG_4} |
| 104 | }; |
| 105 | |
| 106 | const MediaProfiles::NameToTagMap MediaProfiles::sVideoDecoderNameMap[] = { |
| 107 | {"wmv", VIDEO_DECODER_WMV} |
| 108 | }; |
| 109 | |
| 110 | const MediaProfiles::NameToTagMap MediaProfiles::sAudioDecoderNameMap[] = { |
| 111 | {"wma", AUDIO_DECODER_WMA} |
| 112 | }; |
| 113 | |
| 114 | const MediaProfiles::NameToTagMap MediaProfiles::sCamcorderQualityNameMap[] = { |
Nipun Kwatra | c0a8478 | 2010-09-06 15:59:02 -0700 | [diff] [blame] | 115 | {"low", CAMCORDER_QUALITY_LOW}, |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 116 | {"high", CAMCORDER_QUALITY_HIGH}, |
Nipun Kwatra | c0a8478 | 2010-09-06 15:59:02 -0700 | [diff] [blame] | 117 | {"qcif", CAMCORDER_QUALITY_QCIF}, |
Nipun Kwatra | 9783ed8 | 2010-09-10 15:45:57 -0700 | [diff] [blame] | 118 | {"cif", CAMCORDER_QUALITY_CIF}, |
Nipun Kwatra | c0a8478 | 2010-09-06 15:59:02 -0700 | [diff] [blame] | 119 | {"480p", CAMCORDER_QUALITY_480P}, |
| 120 | {"720p", CAMCORDER_QUALITY_720P}, |
| 121 | {"1080p", CAMCORDER_QUALITY_1080P}, |
Zhijun He | 5f6af1a | 2014-06-10 08:26:33 -0700 | [diff] [blame] | 122 | {"2160p", CAMCORDER_QUALITY_2160P}, |
James Dong | 669012d | 2011-09-19 16:27:31 -0700 | [diff] [blame] | 123 | {"qvga", CAMCORDER_QUALITY_QVGA}, |
Nipun Kwatra | c0a8478 | 2010-09-06 15:59:02 -0700 | [diff] [blame] | 124 | |
| 125 | {"timelapselow", CAMCORDER_QUALITY_TIME_LAPSE_LOW}, |
| 126 | {"timelapsehigh", CAMCORDER_QUALITY_TIME_LAPSE_HIGH}, |
| 127 | {"timelapseqcif", CAMCORDER_QUALITY_TIME_LAPSE_QCIF}, |
Nipun Kwatra | 9783ed8 | 2010-09-10 15:45:57 -0700 | [diff] [blame] | 128 | {"timelapsecif", CAMCORDER_QUALITY_TIME_LAPSE_CIF}, |
Nipun Kwatra | c0a8478 | 2010-09-06 15:59:02 -0700 | [diff] [blame] | 129 | {"timelapse480p", CAMCORDER_QUALITY_TIME_LAPSE_480P}, |
| 130 | {"timelapse720p", CAMCORDER_QUALITY_TIME_LAPSE_720P}, |
James Dong | 669012d | 2011-09-19 16:27:31 -0700 | [diff] [blame] | 131 | {"timelapse1080p", CAMCORDER_QUALITY_TIME_LAPSE_1080P}, |
Zhijun He | 5f6af1a | 2014-06-10 08:26:33 -0700 | [diff] [blame] | 132 | {"timelapse2160p", CAMCORDER_QUALITY_TIME_LAPSE_2160P}, |
James Dong | 669012d | 2011-09-19 16:27:31 -0700 | [diff] [blame] | 133 | {"timelapseqvga", CAMCORDER_QUALITY_TIME_LAPSE_QVGA}, |
Zhijun He | e079097 | 2014-07-23 15:17:26 -0700 | [diff] [blame] | 134 | |
| 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 He | 9520aa6 | 2014-09-09 16:18:31 -0700 | [diff] [blame] | 140 | {"highspeed2160p", CAMCORDER_QUALITY_HIGH_SPEED_2160P}, |
Praveen Chavan | b5bfa0e | 2019-01-16 15:49:42 -0800 | [diff] [blame] | 141 | |
| 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 Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 154 | }; |
| 155 | |
Glenn Kasten | 8052038 | 2014-01-31 16:49:31 -0800 | [diff] [blame] | 156 | #if LOG_NDEBUG |
| 157 | #define UNUSED __unused |
| 158 | #else |
| 159 | #define UNUSED |
| 160 | #endif |
| 161 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 162 | /*static*/ void |
Glenn Kasten | 8052038 | 2014-01-31 16:49:31 -0800 | [diff] [blame] | 163 | MediaProfiles::logVideoCodec(const MediaProfiles::VideoCodec& codec UNUSED) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 164 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 165 | 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); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /*static*/ void |
Glenn Kasten | 8052038 | 2014-01-31 16:49:31 -0800 | [diff] [blame] | 174 | MediaProfiles::logAudioCodec(const MediaProfiles::AudioCodec& codec UNUSED) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 175 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 176 | ALOGV("audio codec:"); |
| 177 | ALOGV("codec = %d", codec.mCodec); |
| 178 | ALOGV("bit rate: %d", codec.mBitRate); |
| 179 | ALOGV("sample rate: %d", codec.mSampleRate); |
| 180 | ALOGV("number of channels: %d", codec.mChannels); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /*static*/ void |
Glenn Kasten | 8052038 | 2014-01-31 16:49:31 -0800 | [diff] [blame] | 184 | MediaProfiles::logVideoEncoderCap(const MediaProfiles::VideoEncoderCap& cap UNUSED) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 185 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 186 | ALOGV("video encoder cap:"); |
| 187 | ALOGV("codec = %d", cap.mCodec); |
| 188 | ALOGV("bit rate: min = %d and max = %d", cap.mMinBitRate, cap.mMaxBitRate); |
| 189 | ALOGV("frame width: min = %d and max = %d", cap.mMinFrameWidth, cap.mMaxFrameWidth); |
| 190 | ALOGV("frame height: min = %d and max = %d", cap.mMinFrameHeight, cap.mMaxFrameHeight); |
| 191 | ALOGV("frame rate: min = %d and max = %d", cap.mMinFrameRate, cap.mMaxFrameRate); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /*static*/ void |
Glenn Kasten | 8052038 | 2014-01-31 16:49:31 -0800 | [diff] [blame] | 195 | MediaProfiles::logAudioEncoderCap(const MediaProfiles::AudioEncoderCap& cap UNUSED) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 196 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 197 | ALOGV("audio encoder cap:"); |
| 198 | ALOGV("codec = %d", cap.mCodec); |
| 199 | ALOGV("bit rate: min = %d and max = %d", cap.mMinBitRate, cap.mMaxBitRate); |
| 200 | ALOGV("sample rate: min = %d and max = %d", cap.mMinSampleRate, cap.mMaxSampleRate); |
| 201 | ALOGV("number of channels: min = %d and max = %d", cap.mMinChannels, cap.mMaxChannels); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /*static*/ void |
Glenn Kasten | 8052038 | 2014-01-31 16:49:31 -0800 | [diff] [blame] | 205 | MediaProfiles::logVideoDecoderCap(const MediaProfiles::VideoDecoderCap& cap UNUSED) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 206 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 207 | ALOGV("video decoder cap:"); |
| 208 | ALOGV("codec = %d", cap.mCodec); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /*static*/ void |
Glenn Kasten | 8052038 | 2014-01-31 16:49:31 -0800 | [diff] [blame] | 212 | MediaProfiles::logAudioDecoderCap(const MediaProfiles::AudioDecoderCap& cap UNUSED) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 213 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 214 | ALOGV("audio codec cap:"); |
| 215 | ALOGV("codec = %d", cap.mCodec); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /*static*/ int |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 219 | MediaProfiles::findTagForName(const MediaProfiles::NameToTagMap *map, size_t nMappings, |
| 220 | const char *name) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 221 | { |
| 222 | int tag = -1; |
| 223 | for (size_t i = 0; i < nMappings; ++i) { |
| 224 | if (!strcmp(map[i].name, name)) { |
| 225 | tag = map[i].tag; |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | return tag; |
| 230 | } |
| 231 | |
| 232 | /*static*/ MediaProfiles::VideoCodec* |
| 233 | MediaProfiles::createVideoCodec(const char **atts, MediaProfiles *profiles) |
| 234 | { |
| 235 | CHECK(!strcmp("codec", atts[0]) && |
| 236 | !strcmp("bitRate", atts[2]) && |
| 237 | !strcmp("width", atts[4]) && |
| 238 | !strcmp("height", atts[6]) && |
| 239 | !strcmp("frameRate", atts[8])); |
| 240 | |
| 241 | const size_t nMappings = sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]); |
| 242 | const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]); |
| 243 | CHECK(codec != -1); |
| 244 | |
| 245 | MediaProfiles::VideoCodec *videoCodec = |
| 246 | new MediaProfiles::VideoCodec(static_cast<video_encoder>(codec), |
| 247 | atoi(atts[3]), atoi(atts[5]), atoi(atts[7]), atoi(atts[9])); |
| 248 | logVideoCodec(*videoCodec); |
| 249 | |
| 250 | size_t nCamcorderProfiles; |
| 251 | CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1); |
| 252 | profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mVideoCodec = videoCodec; |
| 253 | return videoCodec; |
| 254 | } |
| 255 | |
| 256 | /*static*/ MediaProfiles::AudioCodec* |
| 257 | MediaProfiles::createAudioCodec(const char **atts, MediaProfiles *profiles) |
| 258 | { |
| 259 | CHECK(!strcmp("codec", atts[0]) && |
| 260 | !strcmp("bitRate", atts[2]) && |
| 261 | !strcmp("sampleRate", atts[4]) && |
| 262 | !strcmp("channels", atts[6])); |
| 263 | const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]); |
| 264 | const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]); |
| 265 | CHECK(codec != -1); |
| 266 | |
| 267 | MediaProfiles::AudioCodec *audioCodec = |
| 268 | new MediaProfiles::AudioCodec(static_cast<audio_encoder>(codec), |
| 269 | atoi(atts[3]), atoi(atts[5]), atoi(atts[7])); |
| 270 | logAudioCodec(*audioCodec); |
| 271 | |
| 272 | size_t nCamcorderProfiles; |
| 273 | CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1); |
| 274 | profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mAudioCodec = audioCodec; |
| 275 | return audioCodec; |
| 276 | } |
| 277 | /*static*/ MediaProfiles::AudioDecoderCap* |
| 278 | MediaProfiles::createAudioDecoderCap(const char **atts) |
| 279 | { |
| 280 | CHECK(!strcmp("name", atts[0]) && |
| 281 | !strcmp("enabled", atts[2])); |
| 282 | |
| 283 | const size_t nMappings = sizeof(sAudioDecoderNameMap)/sizeof(sAudioDecoderNameMap[0]); |
| 284 | const int codec = findTagForName(sAudioDecoderNameMap, nMappings, atts[1]); |
| 285 | CHECK(codec != -1); |
| 286 | |
| 287 | MediaProfiles::AudioDecoderCap *cap = |
| 288 | new MediaProfiles::AudioDecoderCap(static_cast<audio_decoder>(codec)); |
| 289 | logAudioDecoderCap(*cap); |
| 290 | return cap; |
| 291 | } |
| 292 | |
| 293 | /*static*/ MediaProfiles::VideoDecoderCap* |
| 294 | MediaProfiles::createVideoDecoderCap(const char **atts) |
| 295 | { |
| 296 | CHECK(!strcmp("name", atts[0]) && |
| 297 | !strcmp("enabled", atts[2])); |
| 298 | |
| 299 | const size_t nMappings = sizeof(sVideoDecoderNameMap)/sizeof(sVideoDecoderNameMap[0]); |
| 300 | const int codec = findTagForName(sVideoDecoderNameMap, nMappings, atts[1]); |
| 301 | CHECK(codec != -1); |
| 302 | |
| 303 | MediaProfiles::VideoDecoderCap *cap = |
| 304 | new MediaProfiles::VideoDecoderCap(static_cast<video_decoder>(codec)); |
| 305 | logVideoDecoderCap(*cap); |
| 306 | return cap; |
| 307 | } |
| 308 | |
| 309 | /*static*/ MediaProfiles::VideoEncoderCap* |
| 310 | MediaProfiles::createVideoEncoderCap(const char **atts) |
| 311 | { |
| 312 | CHECK(!strcmp("name", atts[0]) && |
| 313 | !strcmp("enabled", atts[2]) && |
| 314 | !strcmp("minBitRate", atts[4]) && |
| 315 | !strcmp("maxBitRate", atts[6]) && |
| 316 | !strcmp("minFrameWidth", atts[8]) && |
| 317 | !strcmp("maxFrameWidth", atts[10]) && |
| 318 | !strcmp("minFrameHeight", atts[12]) && |
| 319 | !strcmp("maxFrameHeight", atts[14]) && |
| 320 | !strcmp("minFrameRate", atts[16]) && |
| 321 | !strcmp("maxFrameRate", atts[18])); |
| 322 | |
| 323 | const size_t nMappings = sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]); |
| 324 | const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]); |
| 325 | CHECK(codec != -1); |
| 326 | |
| 327 | MediaProfiles::VideoEncoderCap *cap = |
| 328 | new MediaProfiles::VideoEncoderCap(static_cast<video_encoder>(codec), |
| 329 | atoi(atts[5]), atoi(atts[7]), atoi(atts[9]), atoi(atts[11]), atoi(atts[13]), |
| 330 | atoi(atts[15]), atoi(atts[17]), atoi(atts[19])); |
| 331 | logVideoEncoderCap(*cap); |
| 332 | return cap; |
| 333 | } |
| 334 | |
| 335 | /*static*/ MediaProfiles::AudioEncoderCap* |
| 336 | MediaProfiles::createAudioEncoderCap(const char **atts) |
| 337 | { |
| 338 | CHECK(!strcmp("name", atts[0]) && |
| 339 | !strcmp("enabled", atts[2]) && |
| 340 | !strcmp("minBitRate", atts[4]) && |
| 341 | !strcmp("maxBitRate", atts[6]) && |
| 342 | !strcmp("minSampleRate", atts[8]) && |
| 343 | !strcmp("maxSampleRate", atts[10]) && |
| 344 | !strcmp("minChannels", atts[12]) && |
| 345 | !strcmp("maxChannels", atts[14])); |
| 346 | |
| 347 | const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]); |
| 348 | const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]); |
| 349 | CHECK(codec != -1); |
| 350 | |
| 351 | MediaProfiles::AudioEncoderCap *cap = |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 352 | new MediaProfiles::AudioEncoderCap(static_cast<audio_encoder>(codec), atoi(atts[5]), |
| 353 | atoi(atts[7]), atoi(atts[9]), atoi(atts[11]), atoi(atts[13]), atoi(atts[15])); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 354 | logAudioEncoderCap(*cap); |
| 355 | return cap; |
| 356 | } |
| 357 | |
| 358 | /*static*/ output_format |
| 359 | MediaProfiles::createEncoderOutputFileFormat(const char **atts) |
| 360 | { |
| 361 | CHECK(!strcmp("name", atts[0])); |
| 362 | |
| 363 | const size_t nMappings =sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]); |
| 364 | const int format = findTagForName(sFileFormatMap, nMappings, atts[1]); |
| 365 | CHECK(format != -1); |
| 366 | |
| 367 | return static_cast<output_format>(format); |
| 368 | } |
| 369 | |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 370 | static bool isCameraIdFound(int cameraId, const Vector<int>& cameraIds) { |
| 371 | for (int i = 0, n = cameraIds.size(); i < n; ++i) { |
| 372 | if (cameraId == cameraIds[i]) { |
| 373 | return true; |
| 374 | } |
| 375 | } |
| 376 | return false; |
| 377 | } |
| 378 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 379 | /*static*/ MediaProfiles::CamcorderProfile* |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 380 | MediaProfiles::createCamcorderProfile(int cameraId, const char **atts, Vector<int>& cameraIds) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 381 | { |
| 382 | CHECK(!strcmp("quality", atts[0]) && |
| 383 | !strcmp("fileFormat", atts[2]) && |
| 384 | !strcmp("duration", atts[4])); |
| 385 | |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 386 | const size_t nProfileMappings = sizeof(sCamcorderQualityNameMap)/ |
| 387 | sizeof(sCamcorderQualityNameMap[0]); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 388 | const int quality = findTagForName(sCamcorderQualityNameMap, nProfileMappings, atts[1]); |
| 389 | CHECK(quality != -1); |
| 390 | |
| 391 | const size_t nFormatMappings = sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]); |
| 392 | const int fileFormat = findTagForName(sFileFormatMap, nFormatMappings, atts[3]); |
| 393 | CHECK(fileFormat != -1); |
| 394 | |
| 395 | MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile; |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 396 | profile->mCameraId = cameraId; |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 397 | if (!isCameraIdFound(cameraId, cameraIds)) { |
| 398 | cameraIds.add(cameraId); |
| 399 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 400 | profile->mFileFormat = static_cast<output_format>(fileFormat); |
| 401 | profile->mQuality = static_cast<camcorder_quality>(quality); |
| 402 | profile->mDuration = atoi(atts[5]); |
| 403 | return profile; |
| 404 | } |
| 405 | |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 406 | MediaProfiles::ImageEncodingQualityLevels* |
| 407 | MediaProfiles::findImageEncodingQualityLevels(int cameraId) const |
| 408 | { |
| 409 | int n = mImageEncodingQualityLevels.size(); |
| 410 | for (int i = 0; i < n; i++) { |
| 411 | ImageEncodingQualityLevels *levels = mImageEncodingQualityLevels[i]; |
| 412 | if (levels->mCameraId == cameraId) { |
| 413 | return levels; |
| 414 | } |
| 415 | } |
| 416 | return NULL; |
| 417 | } |
| 418 | |
| 419 | void MediaProfiles::addImageEncodingQualityLevel(int cameraId, const char** atts) |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 420 | { |
| 421 | CHECK(!strcmp("quality", atts[0])); |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 422 | int quality = atoi(atts[1]); |
Glenn Kasten | 90bebef | 2012-01-27 15:24:38 -0800 | [diff] [blame] | 423 | ALOGV("%s: cameraId=%d, quality=%d", __func__, cameraId, quality); |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 424 | ImageEncodingQualityLevels *levels = findImageEncodingQualityLevels(cameraId); |
| 425 | |
| 426 | if (levels == NULL) { |
| 427 | levels = new ImageEncodingQualityLevels(); |
| 428 | levels->mCameraId = cameraId; |
| 429 | mImageEncodingQualityLevels.add(levels); |
| 430 | } |
| 431 | |
| 432 | levels->mLevels.add(quality); |
| 433 | } |
| 434 | |
| 435 | /*static*/ int |
| 436 | MediaProfiles::getCameraId(const char** atts) |
| 437 | { |
| 438 | if (!atts[0]) return 0; // default cameraId = 0 |
| 439 | CHECK(!strcmp("cameraId", atts[0])); |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 440 | return atoi(atts[1]); |
| 441 | } |
| 442 | |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 443 | void MediaProfiles::addStartTimeOffset(int cameraId, const char** atts) |
| 444 | { |
Eric Laurent | b1eb1a0 | 2012-10-22 17:44:24 -0700 | [diff] [blame] | 445 | int offsetTimeMs = 1000; |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 446 | if (atts[2]) { |
| 447 | CHECK(!strcmp("startOffsetMs", atts[2])); |
| 448 | offsetTimeMs = atoi(atts[3]); |
| 449 | } |
| 450 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 451 | ALOGV("%s: cameraId=%d, offset=%d ms", __func__, cameraId, offsetTimeMs); |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 452 | mStartTimeOffsets.replaceValueFor(cameraId, offsetTimeMs); |
| 453 | } |
Hong Teng | cabd5f8 | 2011-07-06 18:33:09 -0700 | [diff] [blame] | 454 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 455 | /*static*/ void |
| 456 | MediaProfiles::startElementHandler(void *userData, const char *name, const char **atts) |
| 457 | { |
| 458 | MediaProfiles *profiles = (MediaProfiles *) userData; |
| 459 | if (strcmp("Video", name) == 0) { |
| 460 | createVideoCodec(atts, profiles); |
| 461 | } else if (strcmp("Audio", name) == 0) { |
| 462 | createAudioCodec(atts, profiles); |
| 463 | } else if (strcmp("VideoEncoderCap", name) == 0 && |
| 464 | strcmp("true", atts[3]) == 0) { |
| 465 | profiles->mVideoEncoders.add(createVideoEncoderCap(atts)); |
| 466 | } else if (strcmp("AudioEncoderCap", name) == 0 && |
| 467 | strcmp("true", atts[3]) == 0) { |
| 468 | profiles->mAudioEncoders.add(createAudioEncoderCap(atts)); |
| 469 | } else if (strcmp("VideoDecoderCap", name) == 0 && |
| 470 | strcmp("true", atts[3]) == 0) { |
| 471 | profiles->mVideoDecoders.add(createVideoDecoderCap(atts)); |
| 472 | } else if (strcmp("AudioDecoderCap", name) == 0 && |
| 473 | strcmp("true", atts[3]) == 0) { |
| 474 | profiles->mAudioDecoders.add(createAudioDecoderCap(atts)); |
| 475 | } else if (strcmp("EncoderOutputFileFormat", name) == 0) { |
| 476 | profiles->mEncoderOutputFileFormats.add(createEncoderOutputFileFormat(atts)); |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 477 | } else if (strcmp("CamcorderProfiles", name) == 0) { |
| 478 | profiles->mCurrentCameraId = getCameraId(atts); |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 479 | profiles->addStartTimeOffset(profiles->mCurrentCameraId, atts); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 480 | } else if (strcmp("EncoderProfile", name) == 0) { |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 481 | profiles->mCamcorderProfiles.add( |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 482 | createCamcorderProfile(profiles->mCurrentCameraId, atts, profiles->mCameraIds)); |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 483 | } else if (strcmp("ImageEncoding", name) == 0) { |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 484 | profiles->addImageEncodingQualityLevel(profiles->mCurrentCameraId, atts); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 488 | static bool isCamcorderProfile(camcorder_quality quality) { |
| 489 | return quality >= CAMCORDER_QUALITY_LIST_START && |
| 490 | quality <= CAMCORDER_QUALITY_LIST_END; |
| 491 | } |
| 492 | |
| 493 | static bool isTimelapseProfile(camcorder_quality quality) { |
| 494 | return quality >= CAMCORDER_QUALITY_TIME_LAPSE_LIST_START && |
| 495 | quality <= CAMCORDER_QUALITY_TIME_LAPSE_LIST_END; |
| 496 | } |
| 497 | |
Zhijun He | e079097 | 2014-07-23 15:17:26 -0700 | [diff] [blame] | 498 | static bool isHighSpeedProfile(camcorder_quality quality) { |
| 499 | return quality >= CAMCORDER_QUALITY_HIGH_SPEED_LIST_START && |
| 500 | quality <= CAMCORDER_QUALITY_HIGH_SPEED_LIST_END; |
| 501 | } |
| 502 | |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 503 | void MediaProfiles::initRequiredProfileRefs(const Vector<int>& cameraIds) { |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 504 | ALOGV("Number of camera ids: %zu", cameraIds.size()); |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 505 | CHECK(cameraIds.size() > 0); |
| 506 | mRequiredProfileRefs = new RequiredProfiles[cameraIds.size()]; |
| 507 | for (size_t i = 0, n = cameraIds.size(); i < n; ++i) { |
| 508 | mRequiredProfileRefs[i].mCameraId = cameraIds[i]; |
| 509 | for (size_t j = 0; j < kNumRequiredProfiles; ++j) { |
| 510 | mRequiredProfileRefs[i].mRefs[j].mHasRefProfile = false; |
| 511 | mRequiredProfileRefs[i].mRefs[j].mRefProfileIndex = -1; |
| 512 | if ((j & 1) == 0) { // low resolution |
| 513 | mRequiredProfileRefs[i].mRefs[j].mResolutionProduct = 0x7FFFFFFF; |
| 514 | } else { // high resolution |
| 515 | mRequiredProfileRefs[i].mRefs[j].mResolutionProduct = 0; |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | int MediaProfiles::getRequiredProfileRefIndex(int cameraId) { |
| 522 | for (size_t i = 0, n = mCameraIds.size(); i < n; ++i) { |
| 523 | if (mCameraIds[i] == cameraId) { |
| 524 | return i; |
| 525 | } |
| 526 | } |
| 527 | return -1; |
| 528 | } |
| 529 | |
| 530 | void MediaProfiles::checkAndAddRequiredProfilesIfNecessary() { |
| 531 | if (sIsInitialized) { |
| 532 | return; |
| 533 | } |
| 534 | |
| 535 | initRequiredProfileRefs(mCameraIds); |
| 536 | |
| 537 | for (size_t i = 0, n = mCamcorderProfiles.size(); i < n; ++i) { |
| 538 | int product = mCamcorderProfiles[i]->mVideoCodec->mFrameWidth * |
| 539 | mCamcorderProfiles[i]->mVideoCodec->mFrameHeight; |
| 540 | |
| 541 | camcorder_quality quality = mCamcorderProfiles[i]->mQuality; |
| 542 | int cameraId = mCamcorderProfiles[i]->mCameraId; |
| 543 | int index = -1; |
| 544 | int refIndex = getRequiredProfileRefIndex(cameraId); |
| 545 | CHECK(refIndex != -1); |
| 546 | RequiredProfileRefInfo *info; |
| 547 | camcorder_quality refQuality; |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 548 | |
Zhijun He | e079097 | 2014-07-23 15:17:26 -0700 | [diff] [blame] | 549 | // Check high and low from either camcorder profile, timelapse profile |
| 550 | // or high speed profile, but not all of them. Default, check camcorder profile |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 551 | size_t j = 0; |
Bernhard Rosenkraenzer | 3c8889e | 2012-03-29 11:38:59 +0200 | [diff] [blame] | 552 | size_t o = 2; |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 553 | if (isTimelapseProfile(quality)) { |
| 554 | // Check timelapse profile instead. |
| 555 | j = 2; |
Bernhard Rosenkraenzer | 3c8889e | 2012-03-29 11:38:59 +0200 | [diff] [blame] | 556 | o = kNumRequiredProfiles; |
Zhijun He | e079097 | 2014-07-23 15:17:26 -0700 | [diff] [blame] | 557 | } else if (isHighSpeedProfile(quality)) { |
| 558 | // Skip the check for high speed profile. |
| 559 | continue; |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 560 | } else { |
| 561 | // Must be camcorder profile. |
| 562 | CHECK(isCamcorderProfile(quality)); |
| 563 | } |
Bernhard Rosenkraenzer | 3c8889e | 2012-03-29 11:38:59 +0200 | [diff] [blame] | 564 | for (; j < o; ++j) { |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 565 | info = &(mRequiredProfileRefs[refIndex].mRefs[j]); |
| 566 | if ((j % 2 == 0 && product > info->mResolutionProduct) || // low |
| 567 | (j % 2 != 0 && product < info->mResolutionProduct)) { // high |
| 568 | continue; |
| 569 | } |
| 570 | switch (j) { |
| 571 | case 0: |
| 572 | refQuality = CAMCORDER_QUALITY_LOW; |
| 573 | break; |
| 574 | case 1: |
| 575 | refQuality = CAMCORDER_QUALITY_HIGH; |
| 576 | break; |
| 577 | case 2: |
| 578 | refQuality = CAMCORDER_QUALITY_TIME_LAPSE_LOW; |
| 579 | break; |
| 580 | case 3: |
| 581 | refQuality = CAMCORDER_QUALITY_TIME_LAPSE_HIGH; |
| 582 | break; |
| 583 | default: |
| 584 | CHECK(!"Should never reach here"); |
| 585 | } |
| 586 | |
| 587 | if (!info->mHasRefProfile) { |
| 588 | index = getCamcorderProfileIndex(cameraId, refQuality); |
| 589 | } |
| 590 | if (index == -1) { |
| 591 | // New high or low quality profile is found. |
| 592 | // Update its reference. |
| 593 | info->mHasRefProfile = true; |
| 594 | info->mRefProfileIndex = i; |
| 595 | info->mResolutionProduct = product; |
| 596 | } |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | for (size_t cameraId = 0; cameraId < mCameraIds.size(); ++cameraId) { |
| 601 | for (size_t j = 0; j < kNumRequiredProfiles; ++j) { |
| 602 | int refIndex = getRequiredProfileRefIndex(cameraId); |
| 603 | CHECK(refIndex != -1); |
| 604 | RequiredProfileRefInfo *info = |
| 605 | &mRequiredProfileRefs[refIndex].mRefs[j]; |
| 606 | |
| 607 | if (info->mHasRefProfile) { |
| 608 | |
George Burgess IV | 215545b | 2018-07-25 10:06:30 -0700 | [diff] [blame] | 609 | std::unique_ptr<CamcorderProfile> profile = |
| 610 | std::make_unique<CamcorderProfile>( |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 611 | *mCamcorderProfiles[info->mRefProfileIndex]); |
| 612 | |
| 613 | // Overwrite the quality |
| 614 | switch (j % kNumRequiredProfiles) { |
| 615 | case 0: |
| 616 | profile->mQuality = CAMCORDER_QUALITY_LOW; |
| 617 | break; |
| 618 | case 1: |
| 619 | profile->mQuality = CAMCORDER_QUALITY_HIGH; |
| 620 | break; |
| 621 | case 2: |
| 622 | profile->mQuality = CAMCORDER_QUALITY_TIME_LAPSE_LOW; |
| 623 | break; |
| 624 | case 3: |
| 625 | profile->mQuality = CAMCORDER_QUALITY_TIME_LAPSE_HIGH; |
| 626 | break; |
| 627 | default: |
| 628 | CHECK(!"Should never come here"); |
| 629 | } |
| 630 | |
| 631 | int index = getCamcorderProfileIndex(cameraId, profile->mQuality); |
| 632 | if (index != -1) { |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 633 | ALOGV("Profile quality %d for camera %zu already exists", |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 634 | profile->mQuality, cameraId); |
| 635 | CHECK(index == refIndex); |
| 636 | continue; |
| 637 | } |
| 638 | |
| 639 | // Insert the new profile |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 640 | ALOGV("Add a profile: quality %d=>%d for camera %zu", |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 641 | mCamcorderProfiles[info->mRefProfileIndex]->mQuality, |
| 642 | profile->mQuality, cameraId); |
| 643 | |
George Burgess IV | 215545b | 2018-07-25 10:06:30 -0700 | [diff] [blame] | 644 | mCamcorderProfiles.add(profile.release()); |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 650 | /*static*/ MediaProfiles* |
| 651 | MediaProfiles::getInstance() |
| 652 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 653 | ALOGV("getInstance"); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 654 | Mutex::Autolock lock(sLock); |
| 655 | if (!sIsInitialized) { |
| 656 | char value[PROPERTY_VALUE_MAX]; |
| 657 | if (property_get("media.settings.xml", value, NULL) <= 0) { |
Pawin Vongmasa | d7db05b | 2017-05-03 04:19:20 -0700 | [diff] [blame] | 658 | const char* xmlFile = nullptr; |
Pawin Vongmasa | 7f5e10e | 2020-03-07 04:09:55 -0800 | [diff] [blame] | 659 | for (auto const& f : getXmlPaths()) { |
Pawin Vongmasa | d7db05b | 2017-05-03 04:19:20 -0700 | [diff] [blame] | 660 | if (checkXmlFile(f)) { |
| 661 | xmlFile = f; |
| 662 | break; |
| 663 | } |
| 664 | } |
| 665 | if (xmlFile == nullptr) { |
| 666 | ALOGW("Could not find a validated xml file. " |
| 667 | "Using the default instance instead."); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 668 | sInstance = createDefaultInstance(); |
| 669 | } else { |
Pawin Vongmasa | d7db05b | 2017-05-03 04:19:20 -0700 | [diff] [blame] | 670 | sInstance = createInstanceFromXmlFile(xmlFile); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 671 | } |
| 672 | } else { |
| 673 | sInstance = createInstanceFromXmlFile(value); |
| 674 | } |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 675 | CHECK(sInstance != NULL); |
| 676 | sInstance->checkAndAddRequiredProfilesIfNecessary(); |
| 677 | sIsInitialized = true; |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | return sInstance; |
| 681 | } |
| 682 | |
| 683 | /*static*/ MediaProfiles::VideoEncoderCap* |
| 684 | MediaProfiles::createDefaultH263VideoEncoderCap() |
| 685 | { |
| 686 | return new MediaProfiles::VideoEncoderCap( |
| 687 | VIDEO_ENCODER_H263, 192000, 420000, 176, 352, 144, 288, 1, 20); |
| 688 | } |
| 689 | |
| 690 | /*static*/ MediaProfiles::VideoEncoderCap* |
| 691 | MediaProfiles::createDefaultM4vVideoEncoderCap() |
| 692 | { |
| 693 | return new MediaProfiles::VideoEncoderCap( |
| 694 | VIDEO_ENCODER_MPEG_4_SP, 192000, 420000, 176, 352, 144, 288, 1, 20); |
| 695 | } |
| 696 | |
| 697 | |
| 698 | /*static*/ void |
| 699 | MediaProfiles::createDefaultVideoEncoders(MediaProfiles *profiles) |
| 700 | { |
| 701 | profiles->mVideoEncoders.add(createDefaultH263VideoEncoderCap()); |
| 702 | profiles->mVideoEncoders.add(createDefaultM4vVideoEncoderCap()); |
| 703 | } |
| 704 | |
| 705 | /*static*/ MediaProfiles::CamcorderProfile* |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 706 | MediaProfiles::createDefaultCamcorderTimeLapseQcifProfile(camcorder_quality quality) |
Nipun Kwatra | c0a8478 | 2010-09-06 15:59:02 -0700 | [diff] [blame] | 707 | { |
| 708 | MediaProfiles::VideoCodec *videoCodec = |
| 709 | new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 1000000, 176, 144, 20); |
| 710 | |
| 711 | AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1); |
| 712 | CamcorderProfile *profile = new MediaProfiles::CamcorderProfile; |
| 713 | profile->mCameraId = 0; |
| 714 | profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP; |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 715 | profile->mQuality = quality; |
Nipun Kwatra | c0a8478 | 2010-09-06 15:59:02 -0700 | [diff] [blame] | 716 | profile->mDuration = 60; |
| 717 | profile->mVideoCodec = videoCodec; |
| 718 | profile->mAudioCodec = audioCodec; |
| 719 | return profile; |
| 720 | } |
| 721 | |
| 722 | /*static*/ MediaProfiles::CamcorderProfile* |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 723 | MediaProfiles::createDefaultCamcorderTimeLapse480pProfile(camcorder_quality quality) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 724 | { |
| 725 | MediaProfiles::VideoCodec *videoCodec = |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 726 | new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 20000000, 720, 480, 20); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 727 | |
| 728 | AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1); |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 729 | CamcorderProfile *profile = new MediaProfiles::CamcorderProfile; |
| 730 | profile->mCameraId = 0; |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 731 | profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP; |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 732 | profile->mQuality = quality; |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 733 | profile->mDuration = 60; |
| 734 | profile->mVideoCodec = videoCodec; |
| 735 | profile->mAudioCodec = audioCodec; |
| 736 | return profile; |
| 737 | } |
| 738 | |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 739 | /*static*/ void |
| 740 | MediaProfiles::createDefaultCamcorderTimeLapseLowProfiles( |
| 741 | MediaProfiles::CamcorderProfile **lowTimeLapseProfile, |
| 742 | MediaProfiles::CamcorderProfile **lowSpecificTimeLapseProfile) { |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 743 | *lowTimeLapseProfile = createDefaultCamcorderTimeLapseQcifProfile( |
| 744 | CAMCORDER_QUALITY_TIME_LAPSE_LOW); |
| 745 | *lowSpecificTimeLapseProfile = createDefaultCamcorderTimeLapseQcifProfile( |
| 746 | CAMCORDER_QUALITY_TIME_LAPSE_QCIF); |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /*static*/ void |
| 750 | MediaProfiles::createDefaultCamcorderTimeLapseHighProfiles( |
| 751 | MediaProfiles::CamcorderProfile **highTimeLapseProfile, |
| 752 | MediaProfiles::CamcorderProfile **highSpecificTimeLapseProfile) { |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 753 | *highTimeLapseProfile = createDefaultCamcorderTimeLapse480pProfile( |
| 754 | CAMCORDER_QUALITY_TIME_LAPSE_HIGH); |
| 755 | *highSpecificTimeLapseProfile = createDefaultCamcorderTimeLapse480pProfile( |
| 756 | CAMCORDER_QUALITY_TIME_LAPSE_480P); |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 757 | } |
| 758 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 759 | /*static*/ MediaProfiles::CamcorderProfile* |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 760 | MediaProfiles::createDefaultCamcorderQcifProfile(camcorder_quality quality) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 761 | { |
| 762 | MediaProfiles::VideoCodec *videoCodec = |
| 763 | new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 192000, 176, 144, 20); |
| 764 | |
| 765 | MediaProfiles::AudioCodec *audioCodec = |
| 766 | new MediaProfiles::AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1); |
| 767 | |
| 768 | MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile; |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 769 | profile->mCameraId = 0; |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 770 | profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP; |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 771 | profile->mQuality = quality; |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 772 | profile->mDuration = 30; |
| 773 | profile->mVideoCodec = videoCodec; |
| 774 | profile->mAudioCodec = audioCodec; |
| 775 | return profile; |
| 776 | } |
| 777 | |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 778 | /*static*/ MediaProfiles::CamcorderProfile* |
| 779 | MediaProfiles::createDefaultCamcorderCifProfile(camcorder_quality quality) |
| 780 | { |
| 781 | MediaProfiles::VideoCodec *videoCodec = |
| 782 | new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 360000, 352, 288, 20); |
| 783 | |
| 784 | AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1); |
| 785 | CamcorderProfile *profile = new MediaProfiles::CamcorderProfile; |
| 786 | profile->mCameraId = 0; |
| 787 | profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP; |
| 788 | profile->mQuality = quality; |
| 789 | profile->mDuration = 60; |
| 790 | profile->mVideoCodec = videoCodec; |
| 791 | profile->mAudioCodec = audioCodec; |
| 792 | return profile; |
| 793 | } |
| 794 | |
| 795 | /*static*/ void |
| 796 | MediaProfiles::createDefaultCamcorderLowProfiles( |
| 797 | MediaProfiles::CamcorderProfile **lowProfile, |
| 798 | MediaProfiles::CamcorderProfile **lowSpecificProfile) { |
| 799 | *lowProfile = createDefaultCamcorderQcifProfile(CAMCORDER_QUALITY_LOW); |
| 800 | *lowSpecificProfile = createDefaultCamcorderQcifProfile(CAMCORDER_QUALITY_QCIF); |
| 801 | } |
| 802 | |
| 803 | /*static*/ void |
| 804 | MediaProfiles::createDefaultCamcorderHighProfiles( |
| 805 | MediaProfiles::CamcorderProfile **highProfile, |
| 806 | MediaProfiles::CamcorderProfile **highSpecificProfile) { |
| 807 | *highProfile = createDefaultCamcorderCifProfile(CAMCORDER_QUALITY_HIGH); |
| 808 | *highSpecificProfile = createDefaultCamcorderCifProfile(CAMCORDER_QUALITY_CIF); |
| 809 | } |
| 810 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 811 | /*static*/ void |
| 812 | MediaProfiles::createDefaultCamcorderProfiles(MediaProfiles *profiles) |
| 813 | { |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 814 | // low camcorder profiles. |
| 815 | MediaProfiles::CamcorderProfile *lowProfile, *lowSpecificProfile; |
| 816 | createDefaultCamcorderLowProfiles(&lowProfile, &lowSpecificProfile); |
| 817 | profiles->mCamcorderProfiles.add(lowProfile); |
| 818 | profiles->mCamcorderProfiles.add(lowSpecificProfile); |
| 819 | |
| 820 | // high camcorder profiles. |
| 821 | MediaProfiles::CamcorderProfile* highProfile, *highSpecificProfile; |
| 822 | createDefaultCamcorderHighProfiles(&highProfile, &highSpecificProfile); |
| 823 | profiles->mCamcorderProfiles.add(highProfile); |
| 824 | profiles->mCamcorderProfiles.add(highSpecificProfile); |
| 825 | |
| 826 | // low camcorder time lapse profiles. |
| 827 | MediaProfiles::CamcorderProfile *lowTimeLapseProfile, *lowSpecificTimeLapseProfile; |
| 828 | createDefaultCamcorderTimeLapseLowProfiles(&lowTimeLapseProfile, &lowSpecificTimeLapseProfile); |
| 829 | profiles->mCamcorderProfiles.add(lowTimeLapseProfile); |
| 830 | profiles->mCamcorderProfiles.add(lowSpecificTimeLapseProfile); |
| 831 | |
| 832 | // high camcorder time lapse profiles. |
| 833 | MediaProfiles::CamcorderProfile *highTimeLapseProfile, *highSpecificTimeLapseProfile; |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 834 | createDefaultCamcorderTimeLapseHighProfiles(&highTimeLapseProfile, |
| 835 | &highSpecificTimeLapseProfile); |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 836 | profiles->mCamcorderProfiles.add(highTimeLapseProfile); |
| 837 | profiles->mCamcorderProfiles.add(highSpecificTimeLapseProfile); |
James Dong | 8031ec7 | 2011-03-16 14:09:50 -0700 | [diff] [blame] | 838 | |
| 839 | // For emulator and other legacy devices which does not have a |
| 840 | // media_profiles.xml file, We assume that the default camera id |
| 841 | // is 0 and that is the only camera available. |
| 842 | profiles->mCameraIds.push(0); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | /*static*/ void |
| 846 | MediaProfiles::createDefaultAudioEncoders(MediaProfiles *profiles) |
| 847 | { |
| 848 | profiles->mAudioEncoders.add(createDefaultAmrNBEncoderCap()); |
| 849 | } |
| 850 | |
| 851 | /*static*/ void |
| 852 | MediaProfiles::createDefaultVideoDecoders(MediaProfiles *profiles) |
| 853 | { |
| 854 | MediaProfiles::VideoDecoderCap *cap = |
| 855 | new MediaProfiles::VideoDecoderCap(VIDEO_DECODER_WMV); |
| 856 | |
| 857 | profiles->mVideoDecoders.add(cap); |
| 858 | } |
| 859 | |
| 860 | /*static*/ void |
| 861 | MediaProfiles::createDefaultAudioDecoders(MediaProfiles *profiles) |
| 862 | { |
| 863 | MediaProfiles::AudioDecoderCap *cap = |
| 864 | new MediaProfiles::AudioDecoderCap(AUDIO_DECODER_WMA); |
| 865 | |
| 866 | profiles->mAudioDecoders.add(cap); |
| 867 | } |
| 868 | |
| 869 | /*static*/ void |
| 870 | MediaProfiles::createDefaultEncoderOutputFileFormats(MediaProfiles *profiles) |
| 871 | { |
| 872 | profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_THREE_GPP); |
| 873 | profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_MPEG_4); |
| 874 | } |
| 875 | |
| 876 | /*static*/ MediaProfiles::AudioEncoderCap* |
| 877 | MediaProfiles::createDefaultAmrNBEncoderCap() |
| 878 | { |
| 879 | return new MediaProfiles::AudioEncoderCap( |
| 880 | AUDIO_ENCODER_AMR_NB, 5525, 12200, 8000, 8000, 1, 1); |
| 881 | } |
| 882 | |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 883 | /*static*/ void |
| 884 | MediaProfiles::createDefaultImageEncodingQualityLevels(MediaProfiles *profiles) |
| 885 | { |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 886 | ImageEncodingQualityLevels *levels = new ImageEncodingQualityLevels(); |
| 887 | levels->mCameraId = 0; |
| 888 | levels->mLevels.add(70); |
| 889 | levels->mLevels.add(80); |
| 890 | levels->mLevels.add(90); |
| 891 | profiles->mImageEncodingQualityLevels.add(levels); |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 892 | } |
| 893 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 894 | /*static*/ MediaProfiles* |
| 895 | MediaProfiles::createDefaultInstance() |
| 896 | { |
| 897 | MediaProfiles *profiles = new MediaProfiles; |
| 898 | createDefaultCamcorderProfiles(profiles); |
| 899 | createDefaultVideoEncoders(profiles); |
| 900 | createDefaultAudioEncoders(profiles); |
| 901 | createDefaultVideoDecoders(profiles); |
| 902 | createDefaultAudioDecoders(profiles); |
| 903 | createDefaultEncoderOutputFileFormats(profiles); |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 904 | createDefaultImageEncodingQualityLevels(profiles); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 905 | return profiles; |
| 906 | } |
| 907 | |
Pawin Vongmasa | d7db05b | 2017-05-03 04:19:20 -0700 | [diff] [blame] | 908 | bool MediaProfiles::checkXmlFile(const char* xmlFile) { |
| 909 | struct stat fStat; |
| 910 | return stat(xmlFile, &fStat) == 0 && S_ISREG(fStat.st_mode); |
| 911 | // TODO: Add validation |
| 912 | } |
| 913 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 914 | /*static*/ MediaProfiles* |
| 915 | MediaProfiles::createInstanceFromXmlFile(const char *xml) |
| 916 | { |
| 917 | FILE *fp = NULL; |
| 918 | CHECK((fp = fopen(xml, "r"))); |
| 919 | |
| 920 | XML_Parser parser = ::XML_ParserCreate(NULL); |
| 921 | CHECK(parser != NULL); |
| 922 | |
| 923 | MediaProfiles *profiles = new MediaProfiles(); |
| 924 | ::XML_SetUserData(parser, profiles); |
| 925 | ::XML_SetElementHandler(parser, startElementHandler, NULL); |
| 926 | |
| 927 | /* |
| 928 | FIXME: |
| 929 | expat is not compiled with -DXML_DTD. We don't have DTD parsing support. |
| 930 | |
| 931 | if (!::XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS)) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 932 | ALOGE("failed to enable DTD support in the xml file"); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 933 | return UNKNOWN_ERROR; |
| 934 | } |
| 935 | |
| 936 | */ |
| 937 | |
| 938 | const int BUFF_SIZE = 512; |
| 939 | for (;;) { |
| 940 | void *buff = ::XML_GetBuffer(parser, BUFF_SIZE); |
| 941 | if (buff == NULL) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 942 | ALOGE("failed to in call to XML_GetBuffer()"); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 943 | delete profiles; |
| 944 | profiles = NULL; |
| 945 | goto exit; |
| 946 | } |
| 947 | |
| 948 | int bytes_read = ::fread(buff, 1, BUFF_SIZE, fp); |
| 949 | if (bytes_read < 0) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 950 | ALOGE("failed in call to read"); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 951 | delete profiles; |
| 952 | profiles = NULL; |
| 953 | goto exit; |
| 954 | } |
| 955 | |
| 956 | CHECK(::XML_ParseBuffer(parser, bytes_read, bytes_read == 0)); |
| 957 | |
| 958 | if (bytes_read == 0) break; // done parsing the xml file |
| 959 | } |
| 960 | |
| 961 | exit: |
| 962 | ::XML_ParserFree(parser); |
| 963 | ::fclose(fp); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 964 | return profiles; |
| 965 | } |
| 966 | |
| 967 | Vector<output_format> MediaProfiles::getOutputFileFormats() const |
| 968 | { |
| 969 | return mEncoderOutputFileFormats; // copy out |
| 970 | } |
| 971 | |
| 972 | Vector<video_encoder> MediaProfiles::getVideoEncoders() const |
| 973 | { |
| 974 | Vector<video_encoder> encoders; |
| 975 | for (size_t i = 0; i < mVideoEncoders.size(); ++i) { |
| 976 | encoders.add(mVideoEncoders[i]->mCodec); |
| 977 | } |
| 978 | return encoders; // copy out |
| 979 | } |
| 980 | |
| 981 | int MediaProfiles::getVideoEncoderParamByName(const char *name, video_encoder codec) const |
| 982 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 983 | ALOGV("getVideoEncoderParamByName: %s for codec %d", name, codec); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 984 | int index = -1; |
| 985 | for (size_t i = 0, n = mVideoEncoders.size(); i < n; ++i) { |
| 986 | if (mVideoEncoders[i]->mCodec == codec) { |
| 987 | index = i; |
| 988 | break; |
| 989 | } |
| 990 | } |
| 991 | if (index == -1) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 992 | ALOGE("The given video encoder %d is not found", codec); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 993 | return -1; |
| 994 | } |
| 995 | |
| 996 | if (!strcmp("enc.vid.width.min", name)) return mVideoEncoders[index]->mMinFrameWidth; |
| 997 | if (!strcmp("enc.vid.width.max", name)) return mVideoEncoders[index]->mMaxFrameWidth; |
| 998 | if (!strcmp("enc.vid.height.min", name)) return mVideoEncoders[index]->mMinFrameHeight; |
| 999 | if (!strcmp("enc.vid.height.max", name)) return mVideoEncoders[index]->mMaxFrameHeight; |
| 1000 | if (!strcmp("enc.vid.bps.min", name)) return mVideoEncoders[index]->mMinBitRate; |
| 1001 | if (!strcmp("enc.vid.bps.max", name)) return mVideoEncoders[index]->mMaxBitRate; |
| 1002 | if (!strcmp("enc.vid.fps.min", name)) return mVideoEncoders[index]->mMinFrameRate; |
| 1003 | if (!strcmp("enc.vid.fps.max", name)) return mVideoEncoders[index]->mMaxFrameRate; |
| 1004 | |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1005 | ALOGE("The given video encoder param name %s is not found", name); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1006 | return -1; |
| 1007 | } |
Hong Teng | cabd5f8 | 2011-07-06 18:33:09 -0700 | [diff] [blame] | 1008 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1009 | Vector<audio_encoder> MediaProfiles::getAudioEncoders() const |
| 1010 | { |
| 1011 | Vector<audio_encoder> encoders; |
| 1012 | for (size_t i = 0; i < mAudioEncoders.size(); ++i) { |
| 1013 | encoders.add(mAudioEncoders[i]->mCodec); |
| 1014 | } |
| 1015 | return encoders; // copy out |
| 1016 | } |
| 1017 | |
| 1018 | int MediaProfiles::getAudioEncoderParamByName(const char *name, audio_encoder codec) const |
| 1019 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1020 | ALOGV("getAudioEncoderParamByName: %s for codec %d", name, codec); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1021 | int index = -1; |
| 1022 | for (size_t i = 0, n = mAudioEncoders.size(); i < n; ++i) { |
| 1023 | if (mAudioEncoders[i]->mCodec == codec) { |
| 1024 | index = i; |
| 1025 | break; |
| 1026 | } |
| 1027 | } |
| 1028 | if (index == -1) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1029 | ALOGE("The given audio encoder %d is not found", codec); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1030 | return -1; |
| 1031 | } |
| 1032 | |
| 1033 | if (!strcmp("enc.aud.ch.min", name)) return mAudioEncoders[index]->mMinChannels; |
| 1034 | if (!strcmp("enc.aud.ch.max", name)) return mAudioEncoders[index]->mMaxChannels; |
| 1035 | if (!strcmp("enc.aud.bps.min", name)) return mAudioEncoders[index]->mMinBitRate; |
| 1036 | if (!strcmp("enc.aud.bps.max", name)) return mAudioEncoders[index]->mMaxBitRate; |
| 1037 | if (!strcmp("enc.aud.hz.min", name)) return mAudioEncoders[index]->mMinSampleRate; |
| 1038 | if (!strcmp("enc.aud.hz.max", name)) return mAudioEncoders[index]->mMaxSampleRate; |
| 1039 | |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1040 | ALOGE("The given audio encoder param name %s is not found", name); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1041 | return -1; |
| 1042 | } |
| 1043 | |
| 1044 | Vector<video_decoder> MediaProfiles::getVideoDecoders() const |
| 1045 | { |
| 1046 | Vector<video_decoder> decoders; |
| 1047 | for (size_t i = 0; i < mVideoDecoders.size(); ++i) { |
| 1048 | decoders.add(mVideoDecoders[i]->mCodec); |
| 1049 | } |
| 1050 | return decoders; // copy out |
| 1051 | } |
| 1052 | |
| 1053 | Vector<audio_decoder> MediaProfiles::getAudioDecoders() const |
| 1054 | { |
| 1055 | Vector<audio_decoder> decoders; |
| 1056 | for (size_t i = 0; i < mAudioDecoders.size(); ++i) { |
| 1057 | decoders.add(mAudioDecoders[i]->mCodec); |
| 1058 | } |
| 1059 | return decoders; // copy out |
| 1060 | } |
| 1061 | |
Nipun Kwatra | 8bb5603 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 1062 | int MediaProfiles::getCamcorderProfileIndex(int cameraId, camcorder_quality quality) const |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1063 | { |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1064 | int index = -1; |
| 1065 | for (size_t i = 0, n = mCamcorderProfiles.size(); i < n; ++i) { |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 1066 | if (mCamcorderProfiles[i]->mCameraId == cameraId && |
| 1067 | mCamcorderProfiles[i]->mQuality == quality) { |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1068 | index = i; |
| 1069 | break; |
| 1070 | } |
| 1071 | } |
Nipun Kwatra | 8bb5603 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 1072 | return index; |
| 1073 | } |
| 1074 | |
| 1075 | int MediaProfiles::getCamcorderProfileParamByName(const char *name, |
| 1076 | int cameraId, |
| 1077 | camcorder_quality quality) const |
| 1078 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1079 | ALOGV("getCamcorderProfileParamByName: %s for camera %d, quality %d", |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1080 | name, cameraId, quality); |
Nipun Kwatra | 8bb5603 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 1081 | |
| 1082 | int index = getCamcorderProfileIndex(cameraId, quality); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1083 | if (index == -1) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1084 | ALOGE("The given camcorder profile camera %d quality %d is not found", |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1085 | cameraId, quality); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1086 | return -1; |
| 1087 | } |
| 1088 | |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 1089 | if (!strcmp("duration", name)) return mCamcorderProfiles[index]->mDuration; |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1090 | if (!strcmp("file.format", name)) return mCamcorderProfiles[index]->mFileFormat; |
| 1091 | if (!strcmp("vid.codec", name)) return mCamcorderProfiles[index]->mVideoCodec->mCodec; |
| 1092 | if (!strcmp("vid.width", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameWidth; |
| 1093 | if (!strcmp("vid.height", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameHeight; |
| 1094 | if (!strcmp("vid.bps", name)) return mCamcorderProfiles[index]->mVideoCodec->mBitRate; |
| 1095 | if (!strcmp("vid.fps", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameRate; |
| 1096 | if (!strcmp("aud.codec", name)) return mCamcorderProfiles[index]->mAudioCodec->mCodec; |
| 1097 | if (!strcmp("aud.bps", name)) return mCamcorderProfiles[index]->mAudioCodec->mBitRate; |
| 1098 | if (!strcmp("aud.ch", name)) return mCamcorderProfiles[index]->mAudioCodec->mChannels; |
| 1099 | if (!strcmp("aud.hz", name)) return mCamcorderProfiles[index]->mAudioCodec->mSampleRate; |
| 1100 | |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1101 | ALOGE("The given camcorder profile param id %d name %s is not found", cameraId, name); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1102 | return -1; |
| 1103 | } |
| 1104 | |
Nipun Kwatra | 8bb5603 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 1105 | bool MediaProfiles::hasCamcorderProfile(int cameraId, camcorder_quality quality) const |
| 1106 | { |
| 1107 | return (getCamcorderProfileIndex(cameraId, quality) != -1); |
| 1108 | } |
| 1109 | |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 1110 | Vector<int> MediaProfiles::getImageEncodingQualityLevels(int cameraId) const |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 1111 | { |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 1112 | Vector<int> result; |
| 1113 | ImageEncodingQualityLevels *levels = findImageEncodingQualityLevels(cameraId); |
| 1114 | if (levels != NULL) { |
| 1115 | result = levels->mLevels; // copy out |
| 1116 | } |
| 1117 | return result; |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 1118 | } |
| 1119 | |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 1120 | int MediaProfiles::getStartTimeOffsetMs(int cameraId) const { |
| 1121 | int offsetTimeMs = -1; |
| 1122 | ssize_t index = mStartTimeOffsets.indexOfKey(cameraId); |
| 1123 | if (index >= 0) { |
| 1124 | offsetTimeMs = mStartTimeOffsets.valueFor(cameraId); |
| 1125 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1126 | ALOGV("offsetTime=%d ms and cameraId=%d", offsetTimeMs, cameraId); |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 1127 | return offsetTimeMs; |
| 1128 | } |
| 1129 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1130 | MediaProfiles::~MediaProfiles() |
| 1131 | { |
| 1132 | CHECK("destructor should never be called" == 0); |
| 1133 | #if 0 |
| 1134 | for (size_t i = 0; i < mAudioEncoders.size(); ++i) { |
| 1135 | delete mAudioEncoders[i]; |
| 1136 | } |
| 1137 | mAudioEncoders.clear(); |
| 1138 | |
| 1139 | for (size_t i = 0; i < mVideoEncoders.size(); ++i) { |
| 1140 | delete mVideoEncoders[i]; |
| 1141 | } |
| 1142 | mVideoEncoders.clear(); |
| 1143 | |
| 1144 | for (size_t i = 0; i < mVideoDecoders.size(); ++i) { |
| 1145 | delete mVideoDecoders[i]; |
| 1146 | } |
| 1147 | mVideoDecoders.clear(); |
| 1148 | |
| 1149 | for (size_t i = 0; i < mAudioDecoders.size(); ++i) { |
| 1150 | delete mAudioDecoders[i]; |
| 1151 | } |
| 1152 | mAudioDecoders.clear(); |
| 1153 | |
| 1154 | for (size_t i = 0; i < mCamcorderProfiles.size(); ++i) { |
| 1155 | delete mCamcorderProfiles[i]; |
| 1156 | } |
| 1157 | mCamcorderProfiles.clear(); |
| 1158 | #endif |
| 1159 | } |
| 1160 | } // namespace android |