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]); |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 243 | if (codec == -1) { |
| 244 | ALOGE("MediaProfiles::createVideoCodec failed to locate codec %s", atts[1]); |
| 245 | return nullptr; |
| 246 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 247 | |
| 248 | MediaProfiles::VideoCodec *videoCodec = |
| 249 | new MediaProfiles::VideoCodec(static_cast<video_encoder>(codec), |
| 250 | atoi(atts[3]), atoi(atts[5]), atoi(atts[7]), atoi(atts[9])); |
| 251 | logVideoCodec(*videoCodec); |
| 252 | |
| 253 | size_t nCamcorderProfiles; |
| 254 | CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1); |
| 255 | profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mVideoCodec = videoCodec; |
| 256 | return videoCodec; |
| 257 | } |
| 258 | |
| 259 | /*static*/ MediaProfiles::AudioCodec* |
| 260 | MediaProfiles::createAudioCodec(const char **atts, MediaProfiles *profiles) |
| 261 | { |
| 262 | CHECK(!strcmp("codec", atts[0]) && |
| 263 | !strcmp("bitRate", atts[2]) && |
| 264 | !strcmp("sampleRate", atts[4]) && |
| 265 | !strcmp("channels", atts[6])); |
| 266 | const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]); |
| 267 | const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]); |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 268 | if (codec == -1) { |
| 269 | ALOGE("MediaProfiles::createAudioCodec failed to locate codec %s", atts[1]); |
| 270 | return nullptr; |
| 271 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 272 | |
| 273 | MediaProfiles::AudioCodec *audioCodec = |
| 274 | new MediaProfiles::AudioCodec(static_cast<audio_encoder>(codec), |
| 275 | atoi(atts[3]), atoi(atts[5]), atoi(atts[7])); |
| 276 | logAudioCodec(*audioCodec); |
| 277 | |
| 278 | size_t nCamcorderProfiles; |
| 279 | CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1); |
| 280 | profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mAudioCodec = audioCodec; |
| 281 | return audioCodec; |
| 282 | } |
| 283 | /*static*/ MediaProfiles::AudioDecoderCap* |
| 284 | MediaProfiles::createAudioDecoderCap(const char **atts) |
| 285 | { |
| 286 | CHECK(!strcmp("name", atts[0]) && |
| 287 | !strcmp("enabled", atts[2])); |
| 288 | |
| 289 | const size_t nMappings = sizeof(sAudioDecoderNameMap)/sizeof(sAudioDecoderNameMap[0]); |
| 290 | const int codec = findTagForName(sAudioDecoderNameMap, nMappings, atts[1]); |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 291 | if (codec == -1) { |
| 292 | ALOGE("MediaProfiles::createAudioDecoderCap failed to locate codec %s", atts[1]); |
| 293 | return nullptr; |
| 294 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 295 | |
| 296 | MediaProfiles::AudioDecoderCap *cap = |
| 297 | new MediaProfiles::AudioDecoderCap(static_cast<audio_decoder>(codec)); |
| 298 | logAudioDecoderCap(*cap); |
| 299 | return cap; |
| 300 | } |
| 301 | |
| 302 | /*static*/ MediaProfiles::VideoDecoderCap* |
| 303 | MediaProfiles::createVideoDecoderCap(const char **atts) |
| 304 | { |
| 305 | CHECK(!strcmp("name", atts[0]) && |
| 306 | !strcmp("enabled", atts[2])); |
| 307 | |
| 308 | const size_t nMappings = sizeof(sVideoDecoderNameMap)/sizeof(sVideoDecoderNameMap[0]); |
| 309 | const int codec = findTagForName(sVideoDecoderNameMap, nMappings, atts[1]); |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 310 | if (codec == -1) { |
| 311 | ALOGE("MediaProfiles::createVideoDecoderCap failed to locate codec %s", atts[1]); |
| 312 | return nullptr; |
| 313 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 314 | |
| 315 | MediaProfiles::VideoDecoderCap *cap = |
| 316 | new MediaProfiles::VideoDecoderCap(static_cast<video_decoder>(codec)); |
| 317 | logVideoDecoderCap(*cap); |
| 318 | return cap; |
| 319 | } |
| 320 | |
| 321 | /*static*/ MediaProfiles::VideoEncoderCap* |
| 322 | MediaProfiles::createVideoEncoderCap(const char **atts) |
| 323 | { |
| 324 | CHECK(!strcmp("name", atts[0]) && |
| 325 | !strcmp("enabled", atts[2]) && |
| 326 | !strcmp("minBitRate", atts[4]) && |
| 327 | !strcmp("maxBitRate", atts[6]) && |
| 328 | !strcmp("minFrameWidth", atts[8]) && |
| 329 | !strcmp("maxFrameWidth", atts[10]) && |
| 330 | !strcmp("minFrameHeight", atts[12]) && |
| 331 | !strcmp("maxFrameHeight", atts[14]) && |
| 332 | !strcmp("minFrameRate", atts[16]) && |
| 333 | !strcmp("maxFrameRate", atts[18])); |
| 334 | |
| 335 | const size_t nMappings = sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]); |
| 336 | const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]); |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 337 | if (codec == -1) { |
| 338 | ALOGE("MediaProfiles::createVideoEncoderCap failed to locate codec %s", atts[1]); |
| 339 | return nullptr; |
| 340 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 341 | |
| 342 | MediaProfiles::VideoEncoderCap *cap = |
| 343 | new MediaProfiles::VideoEncoderCap(static_cast<video_encoder>(codec), |
| 344 | atoi(atts[5]), atoi(atts[7]), atoi(atts[9]), atoi(atts[11]), atoi(atts[13]), |
| 345 | atoi(atts[15]), atoi(atts[17]), atoi(atts[19])); |
| 346 | logVideoEncoderCap(*cap); |
| 347 | return cap; |
| 348 | } |
| 349 | |
| 350 | /*static*/ MediaProfiles::AudioEncoderCap* |
| 351 | MediaProfiles::createAudioEncoderCap(const char **atts) |
| 352 | { |
| 353 | CHECK(!strcmp("name", atts[0]) && |
| 354 | !strcmp("enabled", atts[2]) && |
| 355 | !strcmp("minBitRate", atts[4]) && |
| 356 | !strcmp("maxBitRate", atts[6]) && |
| 357 | !strcmp("minSampleRate", atts[8]) && |
| 358 | !strcmp("maxSampleRate", atts[10]) && |
| 359 | !strcmp("minChannels", atts[12]) && |
| 360 | !strcmp("maxChannels", atts[14])); |
| 361 | |
| 362 | const size_t nMappings = sizeof(sAudioEncoderNameMap)/sizeof(sAudioEncoderNameMap[0]); |
| 363 | const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]); |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 364 | if (codec == -1) { |
| 365 | ALOGE("MediaProfiles::createAudioEncoderCap failed to locate codec %s", atts[1]); |
| 366 | return nullptr; |
| 367 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 368 | |
| 369 | MediaProfiles::AudioEncoderCap *cap = |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 370 | new MediaProfiles::AudioEncoderCap(static_cast<audio_encoder>(codec), atoi(atts[5]), |
| 371 | 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] | 372 | logAudioEncoderCap(*cap); |
| 373 | return cap; |
| 374 | } |
| 375 | |
| 376 | /*static*/ output_format |
| 377 | MediaProfiles::createEncoderOutputFileFormat(const char **atts) |
| 378 | { |
| 379 | CHECK(!strcmp("name", atts[0])); |
| 380 | |
| 381 | const size_t nMappings =sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]); |
| 382 | const int format = findTagForName(sFileFormatMap, nMappings, atts[1]); |
| 383 | CHECK(format != -1); |
| 384 | |
| 385 | return static_cast<output_format>(format); |
| 386 | } |
| 387 | |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 388 | static bool isCameraIdFound(int cameraId, const Vector<int>& cameraIds) { |
| 389 | for (int i = 0, n = cameraIds.size(); i < n; ++i) { |
| 390 | if (cameraId == cameraIds[i]) { |
| 391 | return true; |
| 392 | } |
| 393 | } |
| 394 | return false; |
| 395 | } |
| 396 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 397 | /*static*/ MediaProfiles::CamcorderProfile* |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 398 | MediaProfiles::createCamcorderProfile(int cameraId, const char **atts, Vector<int>& cameraIds) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 399 | { |
| 400 | CHECK(!strcmp("quality", atts[0]) && |
| 401 | !strcmp("fileFormat", atts[2]) && |
| 402 | !strcmp("duration", atts[4])); |
| 403 | |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 404 | const size_t nProfileMappings = sizeof(sCamcorderQualityNameMap)/ |
| 405 | sizeof(sCamcorderQualityNameMap[0]); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 406 | const int quality = findTagForName(sCamcorderQualityNameMap, nProfileMappings, atts[1]); |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 407 | if (quality == -1) { |
| 408 | ALOGE("MediaProfiles::createCamcorderProfile failed to locate quality %s", atts[1]); |
| 409 | return nullptr; |
| 410 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 411 | |
| 412 | const size_t nFormatMappings = sizeof(sFileFormatMap)/sizeof(sFileFormatMap[0]); |
| 413 | const int fileFormat = findTagForName(sFileFormatMap, nFormatMappings, atts[3]); |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 414 | if (fileFormat == -1) { |
| 415 | ALOGE("MediaProfiles::createCamcorderProfile failed to locate file format %s", atts[1]); |
| 416 | return nullptr; |
| 417 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 418 | |
| 419 | MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile; |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 420 | profile->mCameraId = cameraId; |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 421 | if (!isCameraIdFound(cameraId, cameraIds)) { |
| 422 | cameraIds.add(cameraId); |
| 423 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 424 | profile->mFileFormat = static_cast<output_format>(fileFormat); |
| 425 | profile->mQuality = static_cast<camcorder_quality>(quality); |
| 426 | profile->mDuration = atoi(atts[5]); |
| 427 | return profile; |
| 428 | } |
| 429 | |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 430 | MediaProfiles::ImageEncodingQualityLevels* |
| 431 | MediaProfiles::findImageEncodingQualityLevels(int cameraId) const |
| 432 | { |
| 433 | int n = mImageEncodingQualityLevels.size(); |
| 434 | for (int i = 0; i < n; i++) { |
| 435 | ImageEncodingQualityLevels *levels = mImageEncodingQualityLevels[i]; |
| 436 | if (levels->mCameraId == cameraId) { |
| 437 | return levels; |
| 438 | } |
| 439 | } |
| 440 | return NULL; |
| 441 | } |
| 442 | |
| 443 | void MediaProfiles::addImageEncodingQualityLevel(int cameraId, const char** atts) |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 444 | { |
| 445 | CHECK(!strcmp("quality", atts[0])); |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 446 | int quality = atoi(atts[1]); |
Glenn Kasten | 90bebef | 2012-01-27 15:24:38 -0800 | [diff] [blame] | 447 | ALOGV("%s: cameraId=%d, quality=%d", __func__, cameraId, quality); |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 448 | ImageEncodingQualityLevels *levels = findImageEncodingQualityLevels(cameraId); |
| 449 | |
| 450 | if (levels == NULL) { |
| 451 | levels = new ImageEncodingQualityLevels(); |
| 452 | levels->mCameraId = cameraId; |
| 453 | mImageEncodingQualityLevels.add(levels); |
| 454 | } |
| 455 | |
| 456 | levels->mLevels.add(quality); |
| 457 | } |
| 458 | |
| 459 | /*static*/ int |
| 460 | MediaProfiles::getCameraId(const char** atts) |
| 461 | { |
| 462 | if (!atts[0]) return 0; // default cameraId = 0 |
| 463 | CHECK(!strcmp("cameraId", atts[0])); |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 464 | return atoi(atts[1]); |
| 465 | } |
| 466 | |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 467 | void MediaProfiles::addStartTimeOffset(int cameraId, const char** atts) |
| 468 | { |
Eric Laurent | b1eb1a0 | 2012-10-22 17:44:24 -0700 | [diff] [blame] | 469 | int offsetTimeMs = 1000; |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 470 | if (atts[2]) { |
| 471 | CHECK(!strcmp("startOffsetMs", atts[2])); |
| 472 | offsetTimeMs = atoi(atts[3]); |
| 473 | } |
| 474 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 475 | ALOGV("%s: cameraId=%d, offset=%d ms", __func__, cameraId, offsetTimeMs); |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 476 | mStartTimeOffsets.replaceValueFor(cameraId, offsetTimeMs); |
| 477 | } |
Hong Teng | cabd5f8 | 2011-07-06 18:33:09 -0700 | [diff] [blame] | 478 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 479 | /*static*/ void |
| 480 | MediaProfiles::startElementHandler(void *userData, const char *name, const char **atts) |
| 481 | { |
| 482 | MediaProfiles *profiles = (MediaProfiles *) userData; |
| 483 | if (strcmp("Video", name) == 0) { |
| 484 | createVideoCodec(atts, profiles); |
| 485 | } else if (strcmp("Audio", name) == 0) { |
| 486 | createAudioCodec(atts, profiles); |
| 487 | } else if (strcmp("VideoEncoderCap", name) == 0 && |
| 488 | strcmp("true", atts[3]) == 0) { |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 489 | MediaProfiles::VideoEncoderCap* cap = createVideoEncoderCap(atts); |
| 490 | if (cap != nullptr) { |
| 491 | profiles->mVideoEncoders.add(cap); |
| 492 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 493 | } else if (strcmp("AudioEncoderCap", name) == 0 && |
| 494 | strcmp("true", atts[3]) == 0) { |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 495 | MediaProfiles::AudioEncoderCap* cap = createAudioEncoderCap(atts); |
| 496 | if (cap != nullptr) { |
| 497 | profiles->mAudioEncoders.add(cap); |
| 498 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 499 | } else if (strcmp("VideoDecoderCap", name) == 0 && |
| 500 | strcmp("true", atts[3]) == 0) { |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 501 | MediaProfiles::VideoDecoderCap* cap = createVideoDecoderCap(atts); |
| 502 | if (cap != nullptr) { |
| 503 | profiles->mVideoDecoders.add(cap); |
| 504 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 505 | } else if (strcmp("AudioDecoderCap", name) == 0 && |
| 506 | strcmp("true", atts[3]) == 0) { |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 507 | MediaProfiles::AudioDecoderCap* cap = createAudioDecoderCap(atts); |
| 508 | if (cap != nullptr) { |
| 509 | profiles->mAudioDecoders.add(cap); |
| 510 | } |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 511 | } else if (strcmp("EncoderOutputFileFormat", name) == 0) { |
| 512 | profiles->mEncoderOutputFileFormats.add(createEncoderOutputFileFormat(atts)); |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 513 | } else if (strcmp("CamcorderProfiles", name) == 0) { |
| 514 | profiles->mCurrentCameraId = getCameraId(atts); |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 515 | profiles->addStartTimeOffset(profiles->mCurrentCameraId, atts); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 516 | } else if (strcmp("EncoderProfile", name) == 0) { |
Alex Zhang | 032f7a1 | 2020-04-17 16:08:24 -0700 | [diff] [blame] | 517 | MediaProfiles::CamcorderProfile* profile = createCamcorderProfile( |
| 518 | profiles->mCurrentCameraId, atts, profiles->mCameraIds); |
| 519 | if (profile != nullptr) { |
| 520 | profiles->mCamcorderProfiles.add(profile); |
| 521 | } |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 522 | } else if (strcmp("ImageEncoding", name) == 0) { |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 523 | profiles->addImageEncodingQualityLevel(profiles->mCurrentCameraId, atts); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 527 | static bool isCamcorderProfile(camcorder_quality quality) { |
| 528 | return quality >= CAMCORDER_QUALITY_LIST_START && |
| 529 | quality <= CAMCORDER_QUALITY_LIST_END; |
| 530 | } |
| 531 | |
| 532 | static bool isTimelapseProfile(camcorder_quality quality) { |
| 533 | return quality >= CAMCORDER_QUALITY_TIME_LAPSE_LIST_START && |
| 534 | quality <= CAMCORDER_QUALITY_TIME_LAPSE_LIST_END; |
| 535 | } |
| 536 | |
Zhijun He | e079097 | 2014-07-23 15:17:26 -0700 | [diff] [blame] | 537 | static bool isHighSpeedProfile(camcorder_quality quality) { |
| 538 | return quality >= CAMCORDER_QUALITY_HIGH_SPEED_LIST_START && |
| 539 | quality <= CAMCORDER_QUALITY_HIGH_SPEED_LIST_END; |
| 540 | } |
| 541 | |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 542 | void MediaProfiles::initRequiredProfileRefs(const Vector<int>& cameraIds) { |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 543 | ALOGV("Number of camera ids: %zu", cameraIds.size()); |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 544 | CHECK(cameraIds.size() > 0); |
| 545 | mRequiredProfileRefs = new RequiredProfiles[cameraIds.size()]; |
| 546 | for (size_t i = 0, n = cameraIds.size(); i < n; ++i) { |
| 547 | mRequiredProfileRefs[i].mCameraId = cameraIds[i]; |
| 548 | for (size_t j = 0; j < kNumRequiredProfiles; ++j) { |
| 549 | mRequiredProfileRefs[i].mRefs[j].mHasRefProfile = false; |
| 550 | mRequiredProfileRefs[i].mRefs[j].mRefProfileIndex = -1; |
| 551 | if ((j & 1) == 0) { // low resolution |
| 552 | mRequiredProfileRefs[i].mRefs[j].mResolutionProduct = 0x7FFFFFFF; |
| 553 | } else { // high resolution |
| 554 | mRequiredProfileRefs[i].mRefs[j].mResolutionProduct = 0; |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | int MediaProfiles::getRequiredProfileRefIndex(int cameraId) { |
| 561 | for (size_t i = 0, n = mCameraIds.size(); i < n; ++i) { |
| 562 | if (mCameraIds[i] == cameraId) { |
| 563 | return i; |
| 564 | } |
| 565 | } |
| 566 | return -1; |
| 567 | } |
| 568 | |
| 569 | void MediaProfiles::checkAndAddRequiredProfilesIfNecessary() { |
| 570 | if (sIsInitialized) { |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | initRequiredProfileRefs(mCameraIds); |
| 575 | |
| 576 | for (size_t i = 0, n = mCamcorderProfiles.size(); i < n; ++i) { |
| 577 | int product = mCamcorderProfiles[i]->mVideoCodec->mFrameWidth * |
| 578 | mCamcorderProfiles[i]->mVideoCodec->mFrameHeight; |
| 579 | |
| 580 | camcorder_quality quality = mCamcorderProfiles[i]->mQuality; |
| 581 | int cameraId = mCamcorderProfiles[i]->mCameraId; |
| 582 | int index = -1; |
| 583 | int refIndex = getRequiredProfileRefIndex(cameraId); |
| 584 | CHECK(refIndex != -1); |
| 585 | RequiredProfileRefInfo *info; |
| 586 | camcorder_quality refQuality; |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 587 | |
Zhijun He | e079097 | 2014-07-23 15:17:26 -0700 | [diff] [blame] | 588 | // Check high and low from either camcorder profile, timelapse profile |
| 589 | // 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] | 590 | size_t j = 0; |
Bernhard Rosenkraenzer | 3c8889e | 2012-03-29 11:38:59 +0200 | [diff] [blame] | 591 | size_t o = 2; |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 592 | if (isTimelapseProfile(quality)) { |
| 593 | // Check timelapse profile instead. |
| 594 | j = 2; |
Bernhard Rosenkraenzer | 3c8889e | 2012-03-29 11:38:59 +0200 | [diff] [blame] | 595 | o = kNumRequiredProfiles; |
Zhijun He | e079097 | 2014-07-23 15:17:26 -0700 | [diff] [blame] | 596 | } else if (isHighSpeedProfile(quality)) { |
| 597 | // Skip the check for high speed profile. |
| 598 | continue; |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 599 | } else { |
| 600 | // Must be camcorder profile. |
| 601 | CHECK(isCamcorderProfile(quality)); |
| 602 | } |
Bernhard Rosenkraenzer | 3c8889e | 2012-03-29 11:38:59 +0200 | [diff] [blame] | 603 | for (; j < o; ++j) { |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 604 | info = &(mRequiredProfileRefs[refIndex].mRefs[j]); |
| 605 | if ((j % 2 == 0 && product > info->mResolutionProduct) || // low |
| 606 | (j % 2 != 0 && product < info->mResolutionProduct)) { // high |
| 607 | continue; |
| 608 | } |
| 609 | switch (j) { |
| 610 | case 0: |
| 611 | refQuality = CAMCORDER_QUALITY_LOW; |
| 612 | break; |
| 613 | case 1: |
| 614 | refQuality = CAMCORDER_QUALITY_HIGH; |
| 615 | break; |
| 616 | case 2: |
| 617 | refQuality = CAMCORDER_QUALITY_TIME_LAPSE_LOW; |
| 618 | break; |
| 619 | case 3: |
| 620 | refQuality = CAMCORDER_QUALITY_TIME_LAPSE_HIGH; |
| 621 | break; |
| 622 | default: |
| 623 | CHECK(!"Should never reach here"); |
| 624 | } |
| 625 | |
| 626 | if (!info->mHasRefProfile) { |
| 627 | index = getCamcorderProfileIndex(cameraId, refQuality); |
| 628 | } |
| 629 | if (index == -1) { |
| 630 | // New high or low quality profile is found. |
| 631 | // Update its reference. |
| 632 | info->mHasRefProfile = true; |
| 633 | info->mRefProfileIndex = i; |
| 634 | info->mResolutionProduct = product; |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | for (size_t cameraId = 0; cameraId < mCameraIds.size(); ++cameraId) { |
| 640 | for (size_t j = 0; j < kNumRequiredProfiles; ++j) { |
| 641 | int refIndex = getRequiredProfileRefIndex(cameraId); |
| 642 | CHECK(refIndex != -1); |
| 643 | RequiredProfileRefInfo *info = |
| 644 | &mRequiredProfileRefs[refIndex].mRefs[j]; |
| 645 | |
| 646 | if (info->mHasRefProfile) { |
| 647 | |
George Burgess IV | 215545b | 2018-07-25 10:06:30 -0700 | [diff] [blame] | 648 | std::unique_ptr<CamcorderProfile> profile = |
| 649 | std::make_unique<CamcorderProfile>( |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 650 | *mCamcorderProfiles[info->mRefProfileIndex]); |
| 651 | |
| 652 | // Overwrite the quality |
| 653 | switch (j % kNumRequiredProfiles) { |
| 654 | case 0: |
| 655 | profile->mQuality = CAMCORDER_QUALITY_LOW; |
| 656 | break; |
| 657 | case 1: |
| 658 | profile->mQuality = CAMCORDER_QUALITY_HIGH; |
| 659 | break; |
| 660 | case 2: |
| 661 | profile->mQuality = CAMCORDER_QUALITY_TIME_LAPSE_LOW; |
| 662 | break; |
| 663 | case 3: |
| 664 | profile->mQuality = CAMCORDER_QUALITY_TIME_LAPSE_HIGH; |
| 665 | break; |
| 666 | default: |
| 667 | CHECK(!"Should never come here"); |
| 668 | } |
| 669 | |
| 670 | int index = getCamcorderProfileIndex(cameraId, profile->mQuality); |
| 671 | if (index != -1) { |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 672 | ALOGV("Profile quality %d for camera %zu already exists", |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 673 | profile->mQuality, cameraId); |
| 674 | CHECK(index == refIndex); |
| 675 | continue; |
| 676 | } |
| 677 | |
| 678 | // Insert the new profile |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 679 | ALOGV("Add a profile: quality %d=>%d for camera %zu", |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 680 | mCamcorderProfiles[info->mRefProfileIndex]->mQuality, |
| 681 | profile->mQuality, cameraId); |
| 682 | |
George Burgess IV | 215545b | 2018-07-25 10:06:30 -0700 | [diff] [blame] | 683 | mCamcorderProfiles.add(profile.release()); |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | } |
| 687 | } |
| 688 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 689 | /*static*/ MediaProfiles* |
| 690 | MediaProfiles::getInstance() |
| 691 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 692 | ALOGV("getInstance"); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 693 | Mutex::Autolock lock(sLock); |
| 694 | if (!sIsInitialized) { |
| 695 | char value[PROPERTY_VALUE_MAX]; |
| 696 | if (property_get("media.settings.xml", value, NULL) <= 0) { |
Pawin Vongmasa | d7db05b | 2017-05-03 04:19:20 -0700 | [diff] [blame] | 697 | const char* xmlFile = nullptr; |
Pawin Vongmasa | 7f5e10e | 2020-03-07 04:09:55 -0800 | [diff] [blame] | 698 | for (auto const& f : getXmlPaths()) { |
Pawin Vongmasa | d7db05b | 2017-05-03 04:19:20 -0700 | [diff] [blame] | 699 | if (checkXmlFile(f)) { |
| 700 | xmlFile = f; |
| 701 | break; |
| 702 | } |
| 703 | } |
| 704 | if (xmlFile == nullptr) { |
| 705 | ALOGW("Could not find a validated xml file. " |
| 706 | "Using the default instance instead."); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 707 | sInstance = createDefaultInstance(); |
| 708 | } else { |
Pawin Vongmasa | d7db05b | 2017-05-03 04:19:20 -0700 | [diff] [blame] | 709 | sInstance = createInstanceFromXmlFile(xmlFile); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 710 | } |
| 711 | } else { |
| 712 | sInstance = createInstanceFromXmlFile(value); |
| 713 | } |
James Dong | 2a7e0a1 | 2011-02-28 21:07:39 -0800 | [diff] [blame] | 714 | CHECK(sInstance != NULL); |
| 715 | sInstance->checkAndAddRequiredProfilesIfNecessary(); |
| 716 | sIsInitialized = true; |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | return sInstance; |
| 720 | } |
| 721 | |
| 722 | /*static*/ MediaProfiles::VideoEncoderCap* |
| 723 | MediaProfiles::createDefaultH263VideoEncoderCap() |
| 724 | { |
| 725 | return new MediaProfiles::VideoEncoderCap( |
| 726 | VIDEO_ENCODER_H263, 192000, 420000, 176, 352, 144, 288, 1, 20); |
| 727 | } |
| 728 | |
| 729 | /*static*/ MediaProfiles::VideoEncoderCap* |
| 730 | MediaProfiles::createDefaultM4vVideoEncoderCap() |
| 731 | { |
| 732 | return new MediaProfiles::VideoEncoderCap( |
| 733 | VIDEO_ENCODER_MPEG_4_SP, 192000, 420000, 176, 352, 144, 288, 1, 20); |
| 734 | } |
| 735 | |
| 736 | |
| 737 | /*static*/ void |
| 738 | MediaProfiles::createDefaultVideoEncoders(MediaProfiles *profiles) |
| 739 | { |
| 740 | profiles->mVideoEncoders.add(createDefaultH263VideoEncoderCap()); |
| 741 | profiles->mVideoEncoders.add(createDefaultM4vVideoEncoderCap()); |
| 742 | } |
| 743 | |
| 744 | /*static*/ MediaProfiles::CamcorderProfile* |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 745 | MediaProfiles::createDefaultCamcorderTimeLapseQcifProfile(camcorder_quality quality) |
Nipun Kwatra | c0a8478 | 2010-09-06 15:59:02 -0700 | [diff] [blame] | 746 | { |
| 747 | MediaProfiles::VideoCodec *videoCodec = |
| 748 | new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 1000000, 176, 144, 20); |
| 749 | |
| 750 | AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1); |
| 751 | CamcorderProfile *profile = new MediaProfiles::CamcorderProfile; |
| 752 | profile->mCameraId = 0; |
| 753 | profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP; |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 754 | profile->mQuality = quality; |
Nipun Kwatra | c0a8478 | 2010-09-06 15:59:02 -0700 | [diff] [blame] | 755 | profile->mDuration = 60; |
| 756 | profile->mVideoCodec = videoCodec; |
| 757 | profile->mAudioCodec = audioCodec; |
| 758 | return profile; |
| 759 | } |
| 760 | |
| 761 | /*static*/ MediaProfiles::CamcorderProfile* |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 762 | MediaProfiles::createDefaultCamcorderTimeLapse480pProfile(camcorder_quality quality) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 763 | { |
| 764 | MediaProfiles::VideoCodec *videoCodec = |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 765 | new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 20000000, 720, 480, 20); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 766 | |
| 767 | AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1); |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 768 | CamcorderProfile *profile = new MediaProfiles::CamcorderProfile; |
| 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 = 60; |
| 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*/ void |
| 779 | MediaProfiles::createDefaultCamcorderTimeLapseLowProfiles( |
| 780 | MediaProfiles::CamcorderProfile **lowTimeLapseProfile, |
| 781 | MediaProfiles::CamcorderProfile **lowSpecificTimeLapseProfile) { |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 782 | *lowTimeLapseProfile = createDefaultCamcorderTimeLapseQcifProfile( |
| 783 | CAMCORDER_QUALITY_TIME_LAPSE_LOW); |
| 784 | *lowSpecificTimeLapseProfile = createDefaultCamcorderTimeLapseQcifProfile( |
| 785 | CAMCORDER_QUALITY_TIME_LAPSE_QCIF); |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | /*static*/ void |
| 789 | MediaProfiles::createDefaultCamcorderTimeLapseHighProfiles( |
| 790 | MediaProfiles::CamcorderProfile **highTimeLapseProfile, |
| 791 | MediaProfiles::CamcorderProfile **highSpecificTimeLapseProfile) { |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 792 | *highTimeLapseProfile = createDefaultCamcorderTimeLapse480pProfile( |
| 793 | CAMCORDER_QUALITY_TIME_LAPSE_HIGH); |
| 794 | *highSpecificTimeLapseProfile = createDefaultCamcorderTimeLapse480pProfile( |
| 795 | CAMCORDER_QUALITY_TIME_LAPSE_480P); |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 796 | } |
| 797 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 798 | /*static*/ MediaProfiles::CamcorderProfile* |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 799 | MediaProfiles::createDefaultCamcorderQcifProfile(camcorder_quality quality) |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 800 | { |
| 801 | MediaProfiles::VideoCodec *videoCodec = |
| 802 | new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 192000, 176, 144, 20); |
| 803 | |
| 804 | MediaProfiles::AudioCodec *audioCodec = |
| 805 | new MediaProfiles::AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1); |
| 806 | |
| 807 | MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile; |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 808 | profile->mCameraId = 0; |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 809 | profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP; |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 810 | profile->mQuality = quality; |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 811 | profile->mDuration = 30; |
| 812 | profile->mVideoCodec = videoCodec; |
| 813 | profile->mAudioCodec = audioCodec; |
| 814 | return profile; |
| 815 | } |
| 816 | |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 817 | /*static*/ MediaProfiles::CamcorderProfile* |
| 818 | MediaProfiles::createDefaultCamcorderCifProfile(camcorder_quality quality) |
| 819 | { |
| 820 | MediaProfiles::VideoCodec *videoCodec = |
| 821 | new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 360000, 352, 288, 20); |
| 822 | |
| 823 | AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1); |
| 824 | CamcorderProfile *profile = new MediaProfiles::CamcorderProfile; |
| 825 | profile->mCameraId = 0; |
| 826 | profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP; |
| 827 | profile->mQuality = quality; |
| 828 | profile->mDuration = 60; |
| 829 | profile->mVideoCodec = videoCodec; |
| 830 | profile->mAudioCodec = audioCodec; |
| 831 | return profile; |
| 832 | } |
| 833 | |
| 834 | /*static*/ void |
| 835 | MediaProfiles::createDefaultCamcorderLowProfiles( |
| 836 | MediaProfiles::CamcorderProfile **lowProfile, |
| 837 | MediaProfiles::CamcorderProfile **lowSpecificProfile) { |
| 838 | *lowProfile = createDefaultCamcorderQcifProfile(CAMCORDER_QUALITY_LOW); |
| 839 | *lowSpecificProfile = createDefaultCamcorderQcifProfile(CAMCORDER_QUALITY_QCIF); |
| 840 | } |
| 841 | |
| 842 | /*static*/ void |
| 843 | MediaProfiles::createDefaultCamcorderHighProfiles( |
| 844 | MediaProfiles::CamcorderProfile **highProfile, |
| 845 | MediaProfiles::CamcorderProfile **highSpecificProfile) { |
| 846 | *highProfile = createDefaultCamcorderCifProfile(CAMCORDER_QUALITY_HIGH); |
| 847 | *highSpecificProfile = createDefaultCamcorderCifProfile(CAMCORDER_QUALITY_CIF); |
| 848 | } |
| 849 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 850 | /*static*/ void |
| 851 | MediaProfiles::createDefaultCamcorderProfiles(MediaProfiles *profiles) |
| 852 | { |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 853 | // low camcorder profiles. |
| 854 | MediaProfiles::CamcorderProfile *lowProfile, *lowSpecificProfile; |
| 855 | createDefaultCamcorderLowProfiles(&lowProfile, &lowSpecificProfile); |
| 856 | profiles->mCamcorderProfiles.add(lowProfile); |
| 857 | profiles->mCamcorderProfiles.add(lowSpecificProfile); |
| 858 | |
| 859 | // high camcorder profiles. |
| 860 | MediaProfiles::CamcorderProfile* highProfile, *highSpecificProfile; |
| 861 | createDefaultCamcorderHighProfiles(&highProfile, &highSpecificProfile); |
| 862 | profiles->mCamcorderProfiles.add(highProfile); |
| 863 | profiles->mCamcorderProfiles.add(highSpecificProfile); |
| 864 | |
| 865 | // low camcorder time lapse profiles. |
| 866 | MediaProfiles::CamcorderProfile *lowTimeLapseProfile, *lowSpecificTimeLapseProfile; |
| 867 | createDefaultCamcorderTimeLapseLowProfiles(&lowTimeLapseProfile, &lowSpecificTimeLapseProfile); |
| 868 | profiles->mCamcorderProfiles.add(lowTimeLapseProfile); |
| 869 | profiles->mCamcorderProfiles.add(lowSpecificTimeLapseProfile); |
| 870 | |
| 871 | // high camcorder time lapse profiles. |
| 872 | MediaProfiles::CamcorderProfile *highTimeLapseProfile, *highSpecificTimeLapseProfile; |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 873 | createDefaultCamcorderTimeLapseHighProfiles(&highTimeLapseProfile, |
| 874 | &highSpecificTimeLapseProfile); |
Nipun Kwatra | d5672bc | 2010-09-16 22:25:23 -0700 | [diff] [blame] | 875 | profiles->mCamcorderProfiles.add(highTimeLapseProfile); |
| 876 | profiles->mCamcorderProfiles.add(highSpecificTimeLapseProfile); |
James Dong | 8031ec7 | 2011-03-16 14:09:50 -0700 | [diff] [blame] | 877 | |
| 878 | // For emulator and other legacy devices which does not have a |
| 879 | // media_profiles.xml file, We assume that the default camera id |
| 880 | // is 0 and that is the only camera available. |
| 881 | profiles->mCameraIds.push(0); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | /*static*/ void |
| 885 | MediaProfiles::createDefaultAudioEncoders(MediaProfiles *profiles) |
| 886 | { |
| 887 | profiles->mAudioEncoders.add(createDefaultAmrNBEncoderCap()); |
| 888 | } |
| 889 | |
| 890 | /*static*/ void |
| 891 | MediaProfiles::createDefaultVideoDecoders(MediaProfiles *profiles) |
| 892 | { |
| 893 | MediaProfiles::VideoDecoderCap *cap = |
| 894 | new MediaProfiles::VideoDecoderCap(VIDEO_DECODER_WMV); |
| 895 | |
| 896 | profiles->mVideoDecoders.add(cap); |
| 897 | } |
| 898 | |
| 899 | /*static*/ void |
| 900 | MediaProfiles::createDefaultAudioDecoders(MediaProfiles *profiles) |
| 901 | { |
| 902 | MediaProfiles::AudioDecoderCap *cap = |
| 903 | new MediaProfiles::AudioDecoderCap(AUDIO_DECODER_WMA); |
| 904 | |
| 905 | profiles->mAudioDecoders.add(cap); |
| 906 | } |
| 907 | |
| 908 | /*static*/ void |
| 909 | MediaProfiles::createDefaultEncoderOutputFileFormats(MediaProfiles *profiles) |
| 910 | { |
| 911 | profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_THREE_GPP); |
| 912 | profiles->mEncoderOutputFileFormats.add(OUTPUT_FORMAT_MPEG_4); |
| 913 | } |
| 914 | |
| 915 | /*static*/ MediaProfiles::AudioEncoderCap* |
| 916 | MediaProfiles::createDefaultAmrNBEncoderCap() |
| 917 | { |
| 918 | return new MediaProfiles::AudioEncoderCap( |
| 919 | AUDIO_ENCODER_AMR_NB, 5525, 12200, 8000, 8000, 1, 1); |
| 920 | } |
| 921 | |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 922 | /*static*/ void |
| 923 | MediaProfiles::createDefaultImageEncodingQualityLevels(MediaProfiles *profiles) |
| 924 | { |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 925 | ImageEncodingQualityLevels *levels = new ImageEncodingQualityLevels(); |
| 926 | levels->mCameraId = 0; |
| 927 | levels->mLevels.add(70); |
| 928 | levels->mLevels.add(80); |
| 929 | levels->mLevels.add(90); |
| 930 | profiles->mImageEncodingQualityLevels.add(levels); |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 931 | } |
| 932 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 933 | /*static*/ MediaProfiles* |
| 934 | MediaProfiles::createDefaultInstance() |
| 935 | { |
| 936 | MediaProfiles *profiles = new MediaProfiles; |
| 937 | createDefaultCamcorderProfiles(profiles); |
| 938 | createDefaultVideoEncoders(profiles); |
| 939 | createDefaultAudioEncoders(profiles); |
| 940 | createDefaultVideoDecoders(profiles); |
| 941 | createDefaultAudioDecoders(profiles); |
| 942 | createDefaultEncoderOutputFileFormats(profiles); |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 943 | createDefaultImageEncodingQualityLevels(profiles); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 944 | return profiles; |
| 945 | } |
| 946 | |
Pawin Vongmasa | d7db05b | 2017-05-03 04:19:20 -0700 | [diff] [blame] | 947 | bool MediaProfiles::checkXmlFile(const char* xmlFile) { |
| 948 | struct stat fStat; |
| 949 | return stat(xmlFile, &fStat) == 0 && S_ISREG(fStat.st_mode); |
| 950 | // TODO: Add validation |
| 951 | } |
| 952 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 953 | /*static*/ MediaProfiles* |
| 954 | MediaProfiles::createInstanceFromXmlFile(const char *xml) |
| 955 | { |
| 956 | FILE *fp = NULL; |
| 957 | CHECK((fp = fopen(xml, "r"))); |
| 958 | |
| 959 | XML_Parser parser = ::XML_ParserCreate(NULL); |
| 960 | CHECK(parser != NULL); |
| 961 | |
| 962 | MediaProfiles *profiles = new MediaProfiles(); |
| 963 | ::XML_SetUserData(parser, profiles); |
| 964 | ::XML_SetElementHandler(parser, startElementHandler, NULL); |
| 965 | |
| 966 | /* |
| 967 | FIXME: |
| 968 | expat is not compiled with -DXML_DTD. We don't have DTD parsing support. |
| 969 | |
| 970 | if (!::XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS)) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 971 | ALOGE("failed to enable DTD support in the xml file"); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 972 | return UNKNOWN_ERROR; |
| 973 | } |
| 974 | |
| 975 | */ |
| 976 | |
| 977 | const int BUFF_SIZE = 512; |
| 978 | for (;;) { |
| 979 | void *buff = ::XML_GetBuffer(parser, BUFF_SIZE); |
| 980 | if (buff == NULL) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 981 | ALOGE("failed to in call to XML_GetBuffer()"); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 982 | delete profiles; |
| 983 | profiles = NULL; |
| 984 | goto exit; |
| 985 | } |
| 986 | |
| 987 | int bytes_read = ::fread(buff, 1, BUFF_SIZE, fp); |
| 988 | if (bytes_read < 0) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 989 | ALOGE("failed in call to read"); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 990 | delete profiles; |
| 991 | profiles = NULL; |
| 992 | goto exit; |
| 993 | } |
| 994 | |
| 995 | CHECK(::XML_ParseBuffer(parser, bytes_read, bytes_read == 0)); |
| 996 | |
| 997 | if (bytes_read == 0) break; // done parsing the xml file |
| 998 | } |
| 999 | |
| 1000 | exit: |
| 1001 | ::XML_ParserFree(parser); |
| 1002 | ::fclose(fp); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1003 | return profiles; |
| 1004 | } |
| 1005 | |
| 1006 | Vector<output_format> MediaProfiles::getOutputFileFormats() const |
| 1007 | { |
| 1008 | return mEncoderOutputFileFormats; // copy out |
| 1009 | } |
| 1010 | |
| 1011 | Vector<video_encoder> MediaProfiles::getVideoEncoders() const |
| 1012 | { |
| 1013 | Vector<video_encoder> encoders; |
| 1014 | for (size_t i = 0; i < mVideoEncoders.size(); ++i) { |
| 1015 | encoders.add(mVideoEncoders[i]->mCodec); |
| 1016 | } |
| 1017 | return encoders; // copy out |
| 1018 | } |
| 1019 | |
| 1020 | int MediaProfiles::getVideoEncoderParamByName(const char *name, video_encoder codec) const |
| 1021 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1022 | ALOGV("getVideoEncoderParamByName: %s for codec %d", name, codec); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1023 | int index = -1; |
| 1024 | for (size_t i = 0, n = mVideoEncoders.size(); i < n; ++i) { |
| 1025 | if (mVideoEncoders[i]->mCodec == codec) { |
| 1026 | index = i; |
| 1027 | break; |
| 1028 | } |
| 1029 | } |
| 1030 | if (index == -1) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1031 | ALOGE("The given video encoder %d is not found", codec); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1032 | return -1; |
| 1033 | } |
| 1034 | |
| 1035 | if (!strcmp("enc.vid.width.min", name)) return mVideoEncoders[index]->mMinFrameWidth; |
| 1036 | if (!strcmp("enc.vid.width.max", name)) return mVideoEncoders[index]->mMaxFrameWidth; |
| 1037 | if (!strcmp("enc.vid.height.min", name)) return mVideoEncoders[index]->mMinFrameHeight; |
| 1038 | if (!strcmp("enc.vid.height.max", name)) return mVideoEncoders[index]->mMaxFrameHeight; |
| 1039 | if (!strcmp("enc.vid.bps.min", name)) return mVideoEncoders[index]->mMinBitRate; |
| 1040 | if (!strcmp("enc.vid.bps.max", name)) return mVideoEncoders[index]->mMaxBitRate; |
| 1041 | if (!strcmp("enc.vid.fps.min", name)) return mVideoEncoders[index]->mMinFrameRate; |
| 1042 | if (!strcmp("enc.vid.fps.max", name)) return mVideoEncoders[index]->mMaxFrameRate; |
| 1043 | |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1044 | ALOGE("The given video encoder param name %s is not found", name); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1045 | return -1; |
| 1046 | } |
Hong Teng | cabd5f8 | 2011-07-06 18:33:09 -0700 | [diff] [blame] | 1047 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1048 | Vector<audio_encoder> MediaProfiles::getAudioEncoders() const |
| 1049 | { |
| 1050 | Vector<audio_encoder> encoders; |
| 1051 | for (size_t i = 0; i < mAudioEncoders.size(); ++i) { |
| 1052 | encoders.add(mAudioEncoders[i]->mCodec); |
| 1053 | } |
| 1054 | return encoders; // copy out |
| 1055 | } |
| 1056 | |
| 1057 | int MediaProfiles::getAudioEncoderParamByName(const char *name, audio_encoder codec) const |
| 1058 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1059 | ALOGV("getAudioEncoderParamByName: %s for codec %d", name, codec); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1060 | int index = -1; |
| 1061 | for (size_t i = 0, n = mAudioEncoders.size(); i < n; ++i) { |
| 1062 | if (mAudioEncoders[i]->mCodec == codec) { |
| 1063 | index = i; |
| 1064 | break; |
| 1065 | } |
| 1066 | } |
| 1067 | if (index == -1) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1068 | ALOGE("The given audio encoder %d is not found", codec); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1069 | return -1; |
| 1070 | } |
| 1071 | |
| 1072 | if (!strcmp("enc.aud.ch.min", name)) return mAudioEncoders[index]->mMinChannels; |
| 1073 | if (!strcmp("enc.aud.ch.max", name)) return mAudioEncoders[index]->mMaxChannels; |
| 1074 | if (!strcmp("enc.aud.bps.min", name)) return mAudioEncoders[index]->mMinBitRate; |
| 1075 | if (!strcmp("enc.aud.bps.max", name)) return mAudioEncoders[index]->mMaxBitRate; |
| 1076 | if (!strcmp("enc.aud.hz.min", name)) return mAudioEncoders[index]->mMinSampleRate; |
| 1077 | if (!strcmp("enc.aud.hz.max", name)) return mAudioEncoders[index]->mMaxSampleRate; |
| 1078 | |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1079 | ALOGE("The given audio encoder param name %s is not found", name); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1080 | return -1; |
| 1081 | } |
| 1082 | |
| 1083 | Vector<video_decoder> MediaProfiles::getVideoDecoders() const |
| 1084 | { |
| 1085 | Vector<video_decoder> decoders; |
| 1086 | for (size_t i = 0; i < mVideoDecoders.size(); ++i) { |
| 1087 | decoders.add(mVideoDecoders[i]->mCodec); |
| 1088 | } |
| 1089 | return decoders; // copy out |
| 1090 | } |
| 1091 | |
| 1092 | Vector<audio_decoder> MediaProfiles::getAudioDecoders() const |
| 1093 | { |
| 1094 | Vector<audio_decoder> decoders; |
| 1095 | for (size_t i = 0; i < mAudioDecoders.size(); ++i) { |
| 1096 | decoders.add(mAudioDecoders[i]->mCodec); |
| 1097 | } |
| 1098 | return decoders; // copy out |
| 1099 | } |
| 1100 | |
Nipun Kwatra | 8bb5603 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 1101 | int MediaProfiles::getCamcorderProfileIndex(int cameraId, camcorder_quality quality) const |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1102 | { |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1103 | int index = -1; |
| 1104 | for (size_t i = 0, n = mCamcorderProfiles.size(); i < n; ++i) { |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 1105 | if (mCamcorderProfiles[i]->mCameraId == cameraId && |
| 1106 | mCamcorderProfiles[i]->mQuality == quality) { |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1107 | index = i; |
| 1108 | break; |
| 1109 | } |
| 1110 | } |
Nipun Kwatra | 8bb5603 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 1111 | return index; |
| 1112 | } |
| 1113 | |
| 1114 | int MediaProfiles::getCamcorderProfileParamByName(const char *name, |
| 1115 | int cameraId, |
| 1116 | camcorder_quality quality) const |
| 1117 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1118 | ALOGV("getCamcorderProfileParamByName: %s for camera %d, quality %d", |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1119 | name, cameraId, quality); |
Nipun Kwatra | 8bb5603 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 1120 | |
| 1121 | int index = getCamcorderProfileIndex(cameraId, quality); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1122 | if (index == -1) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1123 | ALOGE("The given camcorder profile camera %d quality %d is not found", |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1124 | cameraId, quality); |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1125 | return -1; |
| 1126 | } |
| 1127 | |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 1128 | if (!strcmp("duration", name)) return mCamcorderProfiles[index]->mDuration; |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1129 | if (!strcmp("file.format", name)) return mCamcorderProfiles[index]->mFileFormat; |
| 1130 | if (!strcmp("vid.codec", name)) return mCamcorderProfiles[index]->mVideoCodec->mCodec; |
| 1131 | if (!strcmp("vid.width", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameWidth; |
| 1132 | if (!strcmp("vid.height", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameHeight; |
| 1133 | if (!strcmp("vid.bps", name)) return mCamcorderProfiles[index]->mVideoCodec->mBitRate; |
| 1134 | if (!strcmp("vid.fps", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameRate; |
| 1135 | if (!strcmp("aud.codec", name)) return mCamcorderProfiles[index]->mAudioCodec->mCodec; |
| 1136 | if (!strcmp("aud.bps", name)) return mCamcorderProfiles[index]->mAudioCodec->mBitRate; |
| 1137 | if (!strcmp("aud.ch", name)) return mCamcorderProfiles[index]->mAudioCodec->mChannels; |
| 1138 | if (!strcmp("aud.hz", name)) return mCamcorderProfiles[index]->mAudioCodec->mSampleRate; |
| 1139 | |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1140 | 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] | 1141 | return -1; |
| 1142 | } |
| 1143 | |
Nipun Kwatra | 8bb5603 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 1144 | bool MediaProfiles::hasCamcorderProfile(int cameraId, camcorder_quality quality) const |
| 1145 | { |
| 1146 | return (getCamcorderProfileIndex(cameraId, quality) != -1); |
| 1147 | } |
| 1148 | |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 1149 | Vector<int> MediaProfiles::getImageEncodingQualityLevels(int cameraId) const |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 1150 | { |
Chih-Chung Chang | 3eaa4e9 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 1151 | Vector<int> result; |
| 1152 | ImageEncodingQualityLevels *levels = findImageEncodingQualityLevels(cameraId); |
| 1153 | if (levels != NULL) { |
| 1154 | result = levels->mLevels; // copy out |
| 1155 | } |
| 1156 | return result; |
James Dong | f5a8385 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 1157 | } |
| 1158 | |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 1159 | int MediaProfiles::getStartTimeOffsetMs(int cameraId) const { |
| 1160 | int offsetTimeMs = -1; |
| 1161 | ssize_t index = mStartTimeOffsets.indexOfKey(cameraId); |
| 1162 | if (index >= 0) { |
| 1163 | offsetTimeMs = mStartTimeOffsets.valueFor(cameraId); |
| 1164 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1165 | ALOGV("offsetTime=%d ms and cameraId=%d", offsetTimeMs, cameraId); |
James Dong | 0f05629 | 2011-05-09 18:49:31 -0700 | [diff] [blame] | 1166 | return offsetTimeMs; |
| 1167 | } |
| 1168 | |
James Dong | 1d7491b | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1169 | MediaProfiles::~MediaProfiles() |
| 1170 | { |
| 1171 | CHECK("destructor should never be called" == 0); |
| 1172 | #if 0 |
| 1173 | for (size_t i = 0; i < mAudioEncoders.size(); ++i) { |
| 1174 | delete mAudioEncoders[i]; |
| 1175 | } |
| 1176 | mAudioEncoders.clear(); |
| 1177 | |
| 1178 | for (size_t i = 0; i < mVideoEncoders.size(); ++i) { |
| 1179 | delete mVideoEncoders[i]; |
| 1180 | } |
| 1181 | mVideoEncoders.clear(); |
| 1182 | |
| 1183 | for (size_t i = 0; i < mVideoDecoders.size(); ++i) { |
| 1184 | delete mVideoDecoders[i]; |
| 1185 | } |
| 1186 | mVideoDecoders.clear(); |
| 1187 | |
| 1188 | for (size_t i = 0; i < mAudioDecoders.size(); ++i) { |
| 1189 | delete mAudioDecoders[i]; |
| 1190 | } |
| 1191 | mAudioDecoders.clear(); |
| 1192 | |
| 1193 | for (size_t i = 0; i < mCamcorderProfiles.size(); ++i) { |
| 1194 | delete mCamcorderProfiles[i]; |
| 1195 | } |
| 1196 | mCamcorderProfiles.clear(); |
| 1197 | #endif |
| 1198 | } |
| 1199 | } // namespace android |