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