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