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