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