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