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