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