Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2009 The Android Open Source Project |
michael@0 | 3 | * Copyright (C) 2013 Mozilla Foundation |
michael@0 | 4 | * |
michael@0 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 6 | * you may not use this file except in compliance with the License. |
michael@0 | 7 | * You may obtain a copy of the License at |
michael@0 | 8 | * |
michael@0 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 10 | * |
michael@0 | 11 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 14 | * See the License for the specific language governing permissions and |
michael@0 | 15 | * limitations under the License. |
michael@0 | 16 | */ |
michael@0 | 17 | |
michael@0 | 18 | #include "nsDebug.h" |
michael@0 | 19 | #define DOM_CAMERA_LOG_LEVEL 3 |
michael@0 | 20 | #include "CameraCommon.h" |
michael@0 | 21 | #include "GonkCameraSource.h" |
michael@0 | 22 | #include "GonkRecorder.h" |
michael@0 | 23 | |
michael@0 | 24 | #define RE_LOGD(fmt, ...) DOM_CAMERA_LOGA("[%s:%d]" fmt,__FILE__,__LINE__, ## __VA_ARGS__) |
michael@0 | 25 | #define RE_LOGV(fmt, ...) DOM_CAMERA_LOGI("[%s:%d]" fmt,__FILE__,__LINE__, ## __VA_ARGS__) |
michael@0 | 26 | #define RE_LOGI(fmt, ...) DOM_CAMERA_LOGI("[%s:%d]" fmt,__FILE__,__LINE__, ## __VA_ARGS__) |
michael@0 | 27 | #define RE_LOGW(fmt, ...) DOM_CAMERA_LOGW("[%s:%d]" fmt,__FILE__,__LINE__, ## __VA_ARGS__) |
michael@0 | 28 | #define RE_LOGE(fmt, ...) DOM_CAMERA_LOGE("[%s:%d]" fmt,__FILE__,__LINE__, ## __VA_ARGS__) |
michael@0 | 29 | |
michael@0 | 30 | #include <binder/IPCThreadState.h> |
michael@0 | 31 | #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 |
michael@0 | 32 | # include <media/openmax/OMX_Audio.h> |
michael@0 | 33 | #endif |
michael@0 | 34 | #include <media/stagefright/foundation/ADebug.h> |
michael@0 | 35 | #include <media/stagefright/AudioSource.h> |
michael@0 | 36 | #include <media/stagefright/AMRWriter.h> |
michael@0 | 37 | #include <media/stagefright/AACWriter.h> |
michael@0 | 38 | #include <media/stagefright/MPEG2TSWriter.h> |
michael@0 | 39 | #include <media/stagefright/MPEG4Writer.h> |
michael@0 | 40 | #include <media/stagefright/MediaDefs.h> |
michael@0 | 41 | #include <media/stagefright/MetaData.h> |
michael@0 | 42 | #include <media/stagefright/OMXClient.h> |
michael@0 | 43 | #include <media/stagefright/OMXCodec.h> |
michael@0 | 44 | #include <media/MediaProfiles.h> |
michael@0 | 45 | |
michael@0 | 46 | #include <utils/Errors.h> |
michael@0 | 47 | #include <sys/types.h> |
michael@0 | 48 | #include <ctype.h> |
michael@0 | 49 | #include <unistd.h> |
michael@0 | 50 | |
michael@0 | 51 | #include <cutils/properties.h> |
michael@0 | 52 | #include <system/audio.h> |
michael@0 | 53 | |
michael@0 | 54 | #define RES_720P (720 * 1280) |
michael@0 | 55 | namespace android { |
michael@0 | 56 | |
michael@0 | 57 | GonkRecorder::GonkRecorder() |
michael@0 | 58 | : mWriter(NULL), |
michael@0 | 59 | mOutputFd(-1), |
michael@0 | 60 | mAudioSource(AUDIO_SOURCE_CNT), |
michael@0 | 61 | mVideoSource(VIDEO_SOURCE_LIST_END), |
michael@0 | 62 | mStarted(false) { |
michael@0 | 63 | |
michael@0 | 64 | RE_LOGV("Constructor"); |
michael@0 | 65 | reset(); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | GonkRecorder::~GonkRecorder() { |
michael@0 | 69 | RE_LOGV("Destructor"); |
michael@0 | 70 | stop(); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | status_t GonkRecorder::init() { |
michael@0 | 74 | RE_LOGV("init"); |
michael@0 | 75 | return OK; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | status_t GonkRecorder::setAudioSource(audio_source_t as) { |
michael@0 | 79 | RE_LOGV("setAudioSource: %d", as); |
michael@0 | 80 | if (as < AUDIO_SOURCE_DEFAULT || |
michael@0 | 81 | as >= AUDIO_SOURCE_CNT) { |
michael@0 | 82 | RE_LOGE("Invalid audio source: %d", as); |
michael@0 | 83 | return BAD_VALUE; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | if (as == AUDIO_SOURCE_DEFAULT) { |
michael@0 | 87 | mAudioSource = AUDIO_SOURCE_MIC; |
michael@0 | 88 | } else { |
michael@0 | 89 | mAudioSource = as; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | return OK; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | status_t GonkRecorder::setVideoSource(video_source vs) { |
michael@0 | 96 | RE_LOGV("setVideoSource: %d", vs); |
michael@0 | 97 | if (vs < VIDEO_SOURCE_DEFAULT || |
michael@0 | 98 | vs >= VIDEO_SOURCE_LIST_END) { |
michael@0 | 99 | RE_LOGE("Invalid video source: %d", vs); |
michael@0 | 100 | return BAD_VALUE; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | if (vs == VIDEO_SOURCE_DEFAULT) { |
michael@0 | 104 | mVideoSource = VIDEO_SOURCE_CAMERA; |
michael@0 | 105 | } else { |
michael@0 | 106 | mVideoSource = vs; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | return OK; |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | status_t GonkRecorder::setOutputFormat(output_format of) { |
michael@0 | 113 | RE_LOGV("setOutputFormat: %d", of); |
michael@0 | 114 | if (of < OUTPUT_FORMAT_DEFAULT || |
michael@0 | 115 | of >= OUTPUT_FORMAT_LIST_END) { |
michael@0 | 116 | RE_LOGE("Invalid output format: %d", of); |
michael@0 | 117 | return BAD_VALUE; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | if (of == OUTPUT_FORMAT_DEFAULT) { |
michael@0 | 121 | mOutputFormat = OUTPUT_FORMAT_THREE_GPP; |
michael@0 | 122 | } else { |
michael@0 | 123 | mOutputFormat = of; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | return OK; |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | status_t GonkRecorder::setAudioEncoder(audio_encoder ae) { |
michael@0 | 130 | RE_LOGV("setAudioEncoder: %d", ae); |
michael@0 | 131 | if (ae < AUDIO_ENCODER_DEFAULT || |
michael@0 | 132 | ae >= AUDIO_ENCODER_LIST_END) { |
michael@0 | 133 | RE_LOGE("Invalid audio encoder: %d", ae); |
michael@0 | 134 | return BAD_VALUE; |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | if (ae == AUDIO_ENCODER_DEFAULT) { |
michael@0 | 138 | mAudioEncoder = AUDIO_ENCODER_AMR_NB; |
michael@0 | 139 | } else { |
michael@0 | 140 | mAudioEncoder = ae; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | return OK; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | status_t GonkRecorder::setVideoEncoder(video_encoder ve) { |
michael@0 | 147 | RE_LOGV("setVideoEncoder: %d", ve); |
michael@0 | 148 | if (ve < VIDEO_ENCODER_DEFAULT || |
michael@0 | 149 | ve >= VIDEO_ENCODER_LIST_END) { |
michael@0 | 150 | RE_LOGE("Invalid video encoder: %d", ve); |
michael@0 | 151 | return BAD_VALUE; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | if (ve == VIDEO_ENCODER_DEFAULT) { |
michael@0 | 155 | mVideoEncoder = VIDEO_ENCODER_H263; |
michael@0 | 156 | } else { |
michael@0 | 157 | mVideoEncoder = ve; |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | return OK; |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | status_t GonkRecorder::setVideoSize(int width, int height) { |
michael@0 | 164 | RE_LOGV("setVideoSize: %dx%d", width, height); |
michael@0 | 165 | if (width <= 0 || height <= 0) { |
michael@0 | 166 | RE_LOGE("Invalid video size: %dx%d", width, height); |
michael@0 | 167 | return BAD_VALUE; |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | // Additional check on the dimension will be performed later |
michael@0 | 171 | mVideoWidth = width; |
michael@0 | 172 | mVideoHeight = height; |
michael@0 | 173 | |
michael@0 | 174 | return OK; |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | status_t GonkRecorder::setVideoFrameRate(int frames_per_second) { |
michael@0 | 178 | RE_LOGV("setVideoFrameRate: %d", frames_per_second); |
michael@0 | 179 | if ((frames_per_second <= 0 && frames_per_second != -1) || |
michael@0 | 180 | frames_per_second > 120) { |
michael@0 | 181 | RE_LOGE("Invalid video frame rate: %d", frames_per_second); |
michael@0 | 182 | return BAD_VALUE; |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | // Additional check on the frame rate will be performed later |
michael@0 | 186 | mFrameRate = frames_per_second; |
michael@0 | 187 | |
michael@0 | 188 | return OK; |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | status_t GonkRecorder::setOutputFile(const char *path) { |
michael@0 | 192 | RE_LOGE("setOutputFile(const char*) must not be called"); |
michael@0 | 193 | // We don't actually support this at all, as the media_server process |
michael@0 | 194 | // no longer has permissions to create files. |
michael@0 | 195 | |
michael@0 | 196 | return -EPERM; |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | status_t GonkRecorder::setOutputFile(int fd, int64_t offset, int64_t length) { |
michael@0 | 200 | RE_LOGV("setOutputFile: %d, %lld, %lld", fd, offset, length); |
michael@0 | 201 | // These don't make any sense, do they? |
michael@0 | 202 | CHECK_EQ(offset, 0ll); |
michael@0 | 203 | CHECK_EQ(length, 0ll); |
michael@0 | 204 | |
michael@0 | 205 | if (fd < 0) { |
michael@0 | 206 | RE_LOGE("Invalid file descriptor: %d", fd); |
michael@0 | 207 | return -EBADF; |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | if (mOutputFd >= 0) { |
michael@0 | 211 | ::close(mOutputFd); |
michael@0 | 212 | } |
michael@0 | 213 | mOutputFd = dup(fd); |
michael@0 | 214 | |
michael@0 | 215 | return OK; |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | // Attempt to parse an int64 literal optionally surrounded by whitespace, |
michael@0 | 219 | // returns true on success, false otherwise. |
michael@0 | 220 | static bool safe_strtoi64(const char *s, int64_t *val) { |
michael@0 | 221 | char *end; |
michael@0 | 222 | |
michael@0 | 223 | // It is lame, but according to man page, we have to set errno to 0 |
michael@0 | 224 | // before calling strtoll(). |
michael@0 | 225 | errno = 0; |
michael@0 | 226 | *val = strtoll(s, &end, 10); |
michael@0 | 227 | |
michael@0 | 228 | if (end == s || errno == ERANGE) { |
michael@0 | 229 | return false; |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | // Skip trailing whitespace |
michael@0 | 233 | while (isspace(*end)) { |
michael@0 | 234 | ++end; |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | // For a successful return, the string must contain nothing but a valid |
michael@0 | 238 | // int64 literal optionally surrounded by whitespace. |
michael@0 | 239 | |
michael@0 | 240 | return *end == '\0'; |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | // Return true if the value is in [0, 0x007FFFFFFF] |
michael@0 | 244 | static bool safe_strtoi32(const char *s, int32_t *val) { |
michael@0 | 245 | int64_t temp; |
michael@0 | 246 | if (safe_strtoi64(s, &temp)) { |
michael@0 | 247 | if (temp >= 0 && temp <= 0x007FFFFFFF) { |
michael@0 | 248 | *val = static_cast<int32_t>(temp); |
michael@0 | 249 | return true; |
michael@0 | 250 | } |
michael@0 | 251 | } |
michael@0 | 252 | return false; |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | // Trim both leading and trailing whitespace from the given string. |
michael@0 | 256 | static void TrimString(String8 *s) { |
michael@0 | 257 | size_t num_bytes = s->bytes(); |
michael@0 | 258 | const char *data = s->string(); |
michael@0 | 259 | |
michael@0 | 260 | size_t leading_space = 0; |
michael@0 | 261 | while (leading_space < num_bytes && isspace(data[leading_space])) { |
michael@0 | 262 | ++leading_space; |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | size_t i = num_bytes; |
michael@0 | 266 | while (i > leading_space && isspace(data[i - 1])) { |
michael@0 | 267 | --i; |
michael@0 | 268 | } |
michael@0 | 269 | |
michael@0 | 270 | s->setTo(String8(&data[leading_space], i - leading_space)); |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | status_t GonkRecorder::setParamAudioSamplingRate(int32_t sampleRate) { |
michael@0 | 274 | RE_LOGV("setParamAudioSamplingRate: %d", sampleRate); |
michael@0 | 275 | if (sampleRate <= 0) { |
michael@0 | 276 | RE_LOGE("Invalid audio sampling rate: %d", sampleRate); |
michael@0 | 277 | return BAD_VALUE; |
michael@0 | 278 | } |
michael@0 | 279 | |
michael@0 | 280 | // Additional check on the sample rate will be performed later. |
michael@0 | 281 | mSampleRate = sampleRate; |
michael@0 | 282 | return OK; |
michael@0 | 283 | } |
michael@0 | 284 | |
michael@0 | 285 | status_t GonkRecorder::setParamAudioNumberOfChannels(int32_t channels) { |
michael@0 | 286 | RE_LOGV("setParamAudioNumberOfChannels: %d", channels); |
michael@0 | 287 | if (channels <= 0 || channels >= 3) { |
michael@0 | 288 | RE_LOGE("Invalid number of audio channels: %d", channels); |
michael@0 | 289 | return BAD_VALUE; |
michael@0 | 290 | } |
michael@0 | 291 | |
michael@0 | 292 | // Additional check on the number of channels will be performed later. |
michael@0 | 293 | mAudioChannels = channels; |
michael@0 | 294 | return OK; |
michael@0 | 295 | } |
michael@0 | 296 | |
michael@0 | 297 | status_t GonkRecorder::setParamAudioEncodingBitRate(int32_t bitRate) { |
michael@0 | 298 | RE_LOGV("setParamAudioEncodingBitRate: %d", bitRate); |
michael@0 | 299 | if (bitRate <= 0) { |
michael@0 | 300 | RE_LOGE("Invalid audio encoding bit rate: %d", bitRate); |
michael@0 | 301 | return BAD_VALUE; |
michael@0 | 302 | } |
michael@0 | 303 | |
michael@0 | 304 | // The target bit rate may not be exactly the same as the requested. |
michael@0 | 305 | // It depends on many factors, such as rate control, and the bit rate |
michael@0 | 306 | // range that a specific encoder supports. The mismatch between the |
michael@0 | 307 | // the target and requested bit rate will NOT be treated as an error. |
michael@0 | 308 | mAudioBitRate = bitRate; |
michael@0 | 309 | return OK; |
michael@0 | 310 | } |
michael@0 | 311 | |
michael@0 | 312 | status_t GonkRecorder::setParamVideoEncodingBitRate(int32_t bitRate) { |
michael@0 | 313 | RE_LOGV("setParamVideoEncodingBitRate: %d", bitRate); |
michael@0 | 314 | if (bitRate <= 0) { |
michael@0 | 315 | RE_LOGE("Invalid video encoding bit rate: %d", bitRate); |
michael@0 | 316 | return BAD_VALUE; |
michael@0 | 317 | } |
michael@0 | 318 | |
michael@0 | 319 | // The target bit rate may not be exactly the same as the requested. |
michael@0 | 320 | // It depends on many factors, such as rate control, and the bit rate |
michael@0 | 321 | // range that a specific encoder supports. The mismatch between the |
michael@0 | 322 | // the target and requested bit rate will NOT be treated as an error. |
michael@0 | 323 | mVideoBitRate = bitRate; |
michael@0 | 324 | return OK; |
michael@0 | 325 | } |
michael@0 | 326 | |
michael@0 | 327 | // Always rotate clockwise, and only support 0, 90, 180 and 270 for now. |
michael@0 | 328 | status_t GonkRecorder::setParamVideoRotation(int32_t degrees) { |
michael@0 | 329 | RE_LOGV("setParamVideoRotation: %d", degrees); |
michael@0 | 330 | if (degrees < 0 || degrees % 90 != 0) { |
michael@0 | 331 | RE_LOGE("Unsupported video rotation angle: %d", degrees); |
michael@0 | 332 | return BAD_VALUE; |
michael@0 | 333 | } |
michael@0 | 334 | mRotationDegrees = degrees % 360; |
michael@0 | 335 | return OK; |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | status_t GonkRecorder::setParamMaxFileDurationUs(int64_t timeUs) { |
michael@0 | 339 | RE_LOGV("setParamMaxFileDurationUs: %lld us", timeUs); |
michael@0 | 340 | |
michael@0 | 341 | // This is meant for backward compatibility for MediaRecorder.java |
michael@0 | 342 | if (timeUs <= 0) { |
michael@0 | 343 | RE_LOGW("Max file duration is not positive: %lld us. Disabling duration limit.", timeUs); |
michael@0 | 344 | timeUs = 0; // Disable the duration limit for zero or negative values. |
michael@0 | 345 | } else if (timeUs <= 100000LL) { // XXX: 100 milli-seconds |
michael@0 | 346 | RE_LOGE("Max file duration is too short: %lld us", timeUs); |
michael@0 | 347 | return BAD_VALUE; |
michael@0 | 348 | } |
michael@0 | 349 | |
michael@0 | 350 | if (timeUs <= 15 * 1000000LL) { |
michael@0 | 351 | RE_LOGW("Target duration (%lld us) too short to be respected", timeUs); |
michael@0 | 352 | } |
michael@0 | 353 | mMaxFileDurationUs = timeUs; |
michael@0 | 354 | return OK; |
michael@0 | 355 | } |
michael@0 | 356 | |
michael@0 | 357 | status_t GonkRecorder::setParamMaxFileSizeBytes(int64_t bytes) { |
michael@0 | 358 | RE_LOGV("setParamMaxFileSizeBytes: %lld bytes", bytes); |
michael@0 | 359 | |
michael@0 | 360 | // This is meant for backward compatibility for MediaRecorder.java |
michael@0 | 361 | if (bytes <= 0) { |
michael@0 | 362 | RE_LOGW("Max file size is not positive: %lld bytes. " |
michael@0 | 363 | "Disabling file size limit.", bytes); |
michael@0 | 364 | bytes = 0; // Disable the file size limit for zero or negative values. |
michael@0 | 365 | } else if (bytes <= 1024) { // XXX: 1 kB |
michael@0 | 366 | RE_LOGE("Max file size is too small: %lld bytes", bytes); |
michael@0 | 367 | return BAD_VALUE; |
michael@0 | 368 | } |
michael@0 | 369 | |
michael@0 | 370 | if (bytes <= 100 * 1024) { |
michael@0 | 371 | RE_LOGW("Target file size (%lld bytes) is too small to be respected", bytes); |
michael@0 | 372 | } |
michael@0 | 373 | |
michael@0 | 374 | if (bytes >= 0xffffffffLL) { |
michael@0 | 375 | RE_LOGW("Target file size (%lld bytes) too large to be respected, clipping to 4GB", bytes); |
michael@0 | 376 | bytes = 0xffffffffLL; |
michael@0 | 377 | } |
michael@0 | 378 | |
michael@0 | 379 | mMaxFileSizeBytes = bytes; |
michael@0 | 380 | return OK; |
michael@0 | 381 | } |
michael@0 | 382 | |
michael@0 | 383 | status_t GonkRecorder::setParamInterleaveDuration(int32_t durationUs) { |
michael@0 | 384 | RE_LOGV("setParamInterleaveDuration: %d", durationUs); |
michael@0 | 385 | if (durationUs <= 500000) { // 500 ms |
michael@0 | 386 | // If interleave duration is too small, it is very inefficient to do |
michael@0 | 387 | // interleaving since the metadata overhead will count for a significant |
michael@0 | 388 | // portion of the saved contents |
michael@0 | 389 | RE_LOGE("Audio/video interleave duration is too small: %d us", durationUs); |
michael@0 | 390 | return BAD_VALUE; |
michael@0 | 391 | } else if (durationUs >= 10000000) { // 10 seconds |
michael@0 | 392 | // If interleaving duration is too large, it can cause the recording |
michael@0 | 393 | // session to use too much memory since we have to save the output |
michael@0 | 394 | // data before we write them out |
michael@0 | 395 | RE_LOGE("Audio/video interleave duration is too large: %d us", durationUs); |
michael@0 | 396 | return BAD_VALUE; |
michael@0 | 397 | } |
michael@0 | 398 | mInterleaveDurationUs = durationUs; |
michael@0 | 399 | return OK; |
michael@0 | 400 | } |
michael@0 | 401 | |
michael@0 | 402 | // If seconds < 0, only the first frame is I frame, and rest are all P frames |
michael@0 | 403 | // If seconds == 0, all frames are encoded as I frames. No P frames |
michael@0 | 404 | // If seconds > 0, it is the time spacing (seconds) between 2 neighboring I frames |
michael@0 | 405 | status_t GonkRecorder::setParamVideoIFramesInterval(int32_t seconds) { |
michael@0 | 406 | RE_LOGV("setParamVideoIFramesInterval: %d seconds", seconds); |
michael@0 | 407 | mIFramesIntervalSec = seconds; |
michael@0 | 408 | return OK; |
michael@0 | 409 | } |
michael@0 | 410 | |
michael@0 | 411 | status_t GonkRecorder::setParam64BitFileOffset(bool use64Bit) { |
michael@0 | 412 | RE_LOGV("setParam64BitFileOffset: %s", |
michael@0 | 413 | use64Bit? "use 64 bit file offset": "use 32 bit file offset"); |
michael@0 | 414 | mUse64BitFileOffset = use64Bit; |
michael@0 | 415 | return OK; |
michael@0 | 416 | } |
michael@0 | 417 | |
michael@0 | 418 | status_t GonkRecorder::setParamVideoCameraId(int32_t cameraId) { |
michael@0 | 419 | RE_LOGV("setParamVideoCameraId: %d", cameraId); |
michael@0 | 420 | if (cameraId < 0) { |
michael@0 | 421 | return BAD_VALUE; |
michael@0 | 422 | } |
michael@0 | 423 | mCameraId = cameraId; |
michael@0 | 424 | return OK; |
michael@0 | 425 | } |
michael@0 | 426 | |
michael@0 | 427 | status_t GonkRecorder::setParamTrackTimeStatus(int64_t timeDurationUs) { |
michael@0 | 428 | RE_LOGV("setParamTrackTimeStatus: %lld", timeDurationUs); |
michael@0 | 429 | if (timeDurationUs < 20000) { // Infeasible if shorter than 20 ms? |
michael@0 | 430 | RE_LOGE("Tracking time duration too short: %lld us", timeDurationUs); |
michael@0 | 431 | return BAD_VALUE; |
michael@0 | 432 | } |
michael@0 | 433 | mTrackEveryTimeDurationUs = timeDurationUs; |
michael@0 | 434 | return OK; |
michael@0 | 435 | } |
michael@0 | 436 | |
michael@0 | 437 | status_t GonkRecorder::setParamVideoEncoderProfile(int32_t profile) { |
michael@0 | 438 | RE_LOGV("setParamVideoEncoderProfile: %d", profile); |
michael@0 | 439 | |
michael@0 | 440 | // Additional check will be done later when we load the encoder. |
michael@0 | 441 | // For now, we are accepting values defined in OpenMAX IL. |
michael@0 | 442 | mVideoEncoderProfile = profile; |
michael@0 | 443 | return OK; |
michael@0 | 444 | } |
michael@0 | 445 | |
michael@0 | 446 | status_t GonkRecorder::setParamVideoEncoderLevel(int32_t level) { |
michael@0 | 447 | RE_LOGV("setParamVideoEncoderLevel: %d", level); |
michael@0 | 448 | |
michael@0 | 449 | // Additional check will be done later when we load the encoder. |
michael@0 | 450 | // For now, we are accepting values defined in OpenMAX IL. |
michael@0 | 451 | mVideoEncoderLevel = level; |
michael@0 | 452 | return OK; |
michael@0 | 453 | } |
michael@0 | 454 | |
michael@0 | 455 | status_t GonkRecorder::setParamMovieTimeScale(int32_t timeScale) { |
michael@0 | 456 | RE_LOGV("setParamMovieTimeScale: %d", timeScale); |
michael@0 | 457 | |
michael@0 | 458 | // The range is set to be the same as the audio's time scale range |
michael@0 | 459 | // since audio's time scale has a wider range. |
michael@0 | 460 | if (timeScale < 600 || timeScale > 96000) { |
michael@0 | 461 | RE_LOGE("Time scale (%d) for movie is out of range [600, 96000]", timeScale); |
michael@0 | 462 | return BAD_VALUE; |
michael@0 | 463 | } |
michael@0 | 464 | mMovieTimeScale = timeScale; |
michael@0 | 465 | return OK; |
michael@0 | 466 | } |
michael@0 | 467 | |
michael@0 | 468 | status_t GonkRecorder::setParamVideoTimeScale(int32_t timeScale) { |
michael@0 | 469 | RE_LOGV("setParamVideoTimeScale: %d", timeScale); |
michael@0 | 470 | |
michael@0 | 471 | // 60000 is chosen to make sure that each video frame from a 60-fps |
michael@0 | 472 | // video has 1000 ticks. |
michael@0 | 473 | if (timeScale < 600 || timeScale > 60000) { |
michael@0 | 474 | RE_LOGE("Time scale (%d) for video is out of range [600, 60000]", timeScale); |
michael@0 | 475 | return BAD_VALUE; |
michael@0 | 476 | } |
michael@0 | 477 | mVideoTimeScale = timeScale; |
michael@0 | 478 | return OK; |
michael@0 | 479 | } |
michael@0 | 480 | |
michael@0 | 481 | status_t GonkRecorder::setParamAudioTimeScale(int32_t timeScale) { |
michael@0 | 482 | RE_LOGV("setParamAudioTimeScale: %d", timeScale); |
michael@0 | 483 | |
michael@0 | 484 | // 96000 Hz is the highest sampling rate support in AAC. |
michael@0 | 485 | if (timeScale < 600 || timeScale > 96000) { |
michael@0 | 486 | RE_LOGE("Time scale (%d) for audio is out of range [600, 96000]", timeScale); |
michael@0 | 487 | return BAD_VALUE; |
michael@0 | 488 | } |
michael@0 | 489 | mAudioTimeScale = timeScale; |
michael@0 | 490 | return OK; |
michael@0 | 491 | } |
michael@0 | 492 | |
michael@0 | 493 | status_t GonkRecorder::setParamGeoDataLongitude( |
michael@0 | 494 | int64_t longitudex10000) { |
michael@0 | 495 | |
michael@0 | 496 | if (longitudex10000 > 1800000 || longitudex10000 < -1800000) { |
michael@0 | 497 | return BAD_VALUE; |
michael@0 | 498 | } |
michael@0 | 499 | mLongitudex10000 = longitudex10000; |
michael@0 | 500 | return OK; |
michael@0 | 501 | } |
michael@0 | 502 | |
michael@0 | 503 | status_t GonkRecorder::setParamGeoDataLatitude( |
michael@0 | 504 | int64_t latitudex10000) { |
michael@0 | 505 | |
michael@0 | 506 | if (latitudex10000 > 900000 || latitudex10000 < -900000) { |
michael@0 | 507 | return BAD_VALUE; |
michael@0 | 508 | } |
michael@0 | 509 | mLatitudex10000 = latitudex10000; |
michael@0 | 510 | return OK; |
michael@0 | 511 | } |
michael@0 | 512 | |
michael@0 | 513 | status_t GonkRecorder::setParameter( |
michael@0 | 514 | const String8 &key, const String8 &value) { |
michael@0 | 515 | RE_LOGV("setParameter: key (%s) => value (%s)", key.string(), value.string()); |
michael@0 | 516 | if (key == "max-duration") { |
michael@0 | 517 | int64_t max_duration_ms; |
michael@0 | 518 | if (safe_strtoi64(value.string(), &max_duration_ms)) { |
michael@0 | 519 | return setParamMaxFileDurationUs(1000LL * max_duration_ms); |
michael@0 | 520 | } |
michael@0 | 521 | } else if (key == "max-filesize") { |
michael@0 | 522 | int64_t max_filesize_bytes; |
michael@0 | 523 | if (safe_strtoi64(value.string(), &max_filesize_bytes)) { |
michael@0 | 524 | return setParamMaxFileSizeBytes(max_filesize_bytes); |
michael@0 | 525 | } |
michael@0 | 526 | } else if (key == "interleave-duration-us") { |
michael@0 | 527 | int32_t durationUs; |
michael@0 | 528 | if (safe_strtoi32(value.string(), &durationUs)) { |
michael@0 | 529 | return setParamInterleaveDuration(durationUs); |
michael@0 | 530 | } |
michael@0 | 531 | } else if (key == "param-movie-time-scale") { |
michael@0 | 532 | int32_t timeScale; |
michael@0 | 533 | if (safe_strtoi32(value.string(), &timeScale)) { |
michael@0 | 534 | return setParamMovieTimeScale(timeScale); |
michael@0 | 535 | } |
michael@0 | 536 | } else if (key == "param-use-64bit-offset") { |
michael@0 | 537 | int32_t use64BitOffset; |
michael@0 | 538 | if (safe_strtoi32(value.string(), &use64BitOffset)) { |
michael@0 | 539 | return setParam64BitFileOffset(use64BitOffset != 0); |
michael@0 | 540 | } |
michael@0 | 541 | } else if (key == "param-geotag-longitude") { |
michael@0 | 542 | int64_t longitudex10000; |
michael@0 | 543 | if (safe_strtoi64(value.string(), &longitudex10000)) { |
michael@0 | 544 | return setParamGeoDataLongitude(longitudex10000); |
michael@0 | 545 | } |
michael@0 | 546 | } else if (key == "param-geotag-latitude") { |
michael@0 | 547 | int64_t latitudex10000; |
michael@0 | 548 | if (safe_strtoi64(value.string(), &latitudex10000)) { |
michael@0 | 549 | return setParamGeoDataLatitude(latitudex10000); |
michael@0 | 550 | } |
michael@0 | 551 | } else if (key == "param-track-time-status") { |
michael@0 | 552 | int64_t timeDurationUs; |
michael@0 | 553 | if (safe_strtoi64(value.string(), &timeDurationUs)) { |
michael@0 | 554 | return setParamTrackTimeStatus(timeDurationUs); |
michael@0 | 555 | } |
michael@0 | 556 | } else if (key == "audio-param-sampling-rate") { |
michael@0 | 557 | int32_t sampling_rate; |
michael@0 | 558 | if (safe_strtoi32(value.string(), &sampling_rate)) { |
michael@0 | 559 | return setParamAudioSamplingRate(sampling_rate); |
michael@0 | 560 | } |
michael@0 | 561 | } else if (key == "audio-param-number-of-channels") { |
michael@0 | 562 | int32_t number_of_channels; |
michael@0 | 563 | if (safe_strtoi32(value.string(), &number_of_channels)) { |
michael@0 | 564 | return setParamAudioNumberOfChannels(number_of_channels); |
michael@0 | 565 | } |
michael@0 | 566 | } else if (key == "audio-param-encoding-bitrate") { |
michael@0 | 567 | int32_t audio_bitrate; |
michael@0 | 568 | if (safe_strtoi32(value.string(), &audio_bitrate)) { |
michael@0 | 569 | return setParamAudioEncodingBitRate(audio_bitrate); |
michael@0 | 570 | } |
michael@0 | 571 | } else if (key == "audio-param-time-scale") { |
michael@0 | 572 | int32_t timeScale; |
michael@0 | 573 | if (safe_strtoi32(value.string(), &timeScale)) { |
michael@0 | 574 | return setParamAudioTimeScale(timeScale); |
michael@0 | 575 | } |
michael@0 | 576 | } else if (key == "video-param-encoding-bitrate") { |
michael@0 | 577 | int32_t video_bitrate; |
michael@0 | 578 | if (safe_strtoi32(value.string(), &video_bitrate)) { |
michael@0 | 579 | return setParamVideoEncodingBitRate(video_bitrate); |
michael@0 | 580 | } |
michael@0 | 581 | } else if (key == "video-param-rotation-angle-degrees") { |
michael@0 | 582 | int32_t degrees; |
michael@0 | 583 | if (safe_strtoi32(value.string(), °rees)) { |
michael@0 | 584 | return setParamVideoRotation(degrees); |
michael@0 | 585 | } |
michael@0 | 586 | } else if (key == "video-param-i-frames-interval") { |
michael@0 | 587 | int32_t seconds; |
michael@0 | 588 | if (safe_strtoi32(value.string(), &seconds)) { |
michael@0 | 589 | return setParamVideoIFramesInterval(seconds); |
michael@0 | 590 | } |
michael@0 | 591 | } else if (key == "video-param-encoder-profile") { |
michael@0 | 592 | int32_t profile; |
michael@0 | 593 | if (safe_strtoi32(value.string(), &profile)) { |
michael@0 | 594 | return setParamVideoEncoderProfile(profile); |
michael@0 | 595 | } |
michael@0 | 596 | } else if (key == "video-param-encoder-level") { |
michael@0 | 597 | int32_t level; |
michael@0 | 598 | if (safe_strtoi32(value.string(), &level)) { |
michael@0 | 599 | return setParamVideoEncoderLevel(level); |
michael@0 | 600 | } |
michael@0 | 601 | } else if (key == "video-param-camera-id") { |
michael@0 | 602 | int32_t cameraId; |
michael@0 | 603 | if (safe_strtoi32(value.string(), &cameraId)) { |
michael@0 | 604 | return setParamVideoCameraId(cameraId); |
michael@0 | 605 | } |
michael@0 | 606 | } else if (key == "video-param-time-scale") { |
michael@0 | 607 | int32_t timeScale; |
michael@0 | 608 | if (safe_strtoi32(value.string(), &timeScale)) { |
michael@0 | 609 | return setParamVideoTimeScale(timeScale); |
michael@0 | 610 | } |
michael@0 | 611 | } else { |
michael@0 | 612 | RE_LOGE("setParameter: failed to find key %s", key.string()); |
michael@0 | 613 | } |
michael@0 | 614 | return BAD_VALUE; |
michael@0 | 615 | } |
michael@0 | 616 | |
michael@0 | 617 | status_t GonkRecorder::setParameters(const String8 ¶ms) { |
michael@0 | 618 | RE_LOGV("setParameters: %s", params.string()); |
michael@0 | 619 | const char *cparams = params.string(); |
michael@0 | 620 | const char *key_start = cparams; |
michael@0 | 621 | for (;;) { |
michael@0 | 622 | const char *equal_pos = strchr(key_start, '='); |
michael@0 | 623 | if (equal_pos == NULL) { |
michael@0 | 624 | RE_LOGE("Parameters %s miss a value", cparams); |
michael@0 | 625 | return BAD_VALUE; |
michael@0 | 626 | } |
michael@0 | 627 | String8 key(key_start, equal_pos - key_start); |
michael@0 | 628 | TrimString(&key); |
michael@0 | 629 | if (key.length() == 0) { |
michael@0 | 630 | RE_LOGE("Parameters %s contains an empty key", cparams); |
michael@0 | 631 | return BAD_VALUE; |
michael@0 | 632 | } |
michael@0 | 633 | const char *value_start = equal_pos + 1; |
michael@0 | 634 | const char *semicolon_pos = strchr(value_start, ';'); |
michael@0 | 635 | String8 value; |
michael@0 | 636 | if (semicolon_pos == NULL) { |
michael@0 | 637 | value.setTo(value_start); |
michael@0 | 638 | } else { |
michael@0 | 639 | value.setTo(value_start, semicolon_pos - value_start); |
michael@0 | 640 | } |
michael@0 | 641 | if (setParameter(key, value) != OK) { |
michael@0 | 642 | return BAD_VALUE; |
michael@0 | 643 | } |
michael@0 | 644 | if (semicolon_pos == NULL) { |
michael@0 | 645 | break; // Reaches the end |
michael@0 | 646 | } |
michael@0 | 647 | key_start = semicolon_pos + 1; |
michael@0 | 648 | } |
michael@0 | 649 | return OK; |
michael@0 | 650 | } |
michael@0 | 651 | |
michael@0 | 652 | status_t GonkRecorder::setListener(const sp<IMediaRecorderClient> &listener) { |
michael@0 | 653 | mListener = listener; |
michael@0 | 654 | |
michael@0 | 655 | return OK; |
michael@0 | 656 | } |
michael@0 | 657 | |
michael@0 | 658 | status_t GonkRecorder::setClientName(const String16& clientName) { |
michael@0 | 659 | mClientName = clientName; |
michael@0 | 660 | |
michael@0 | 661 | return OK; |
michael@0 | 662 | } |
michael@0 | 663 | |
michael@0 | 664 | status_t GonkRecorder::prepare() { |
michael@0 | 665 | if (mVideoSource != VIDEO_SOURCE_LIST_END && mVideoEncoder != VIDEO_ENCODER_LIST_END && |
michael@0 | 666 | mVideoHeight && mVideoWidth && // Video recording |
michael@0 | 667 | (mVideoHeight * mVideoWidth >= RES_720P)) { |
michael@0 | 668 | // TODO: Above check needs to be updated when mMaxFileDurationUs is set from camera app |
michael@0 | 669 | RE_LOGV("Video is high resolution so setting 64-bit file offsets"); |
michael@0 | 670 | setParam64BitFileOffset(true); |
michael@0 | 671 | } |
michael@0 | 672 | return OK; |
michael@0 | 673 | } |
michael@0 | 674 | |
michael@0 | 675 | status_t GonkRecorder::start() { |
michael@0 | 676 | CHECK_GE(mOutputFd, 0); |
michael@0 | 677 | |
michael@0 | 678 | // Get UID here for permission checking |
michael@0 | 679 | mClientUid = IPCThreadState::self()->getCallingUid(); |
michael@0 | 680 | if (mWriter != NULL) { |
michael@0 | 681 | RE_LOGE("File writer is not avaialble"); |
michael@0 | 682 | return UNKNOWN_ERROR; |
michael@0 | 683 | } |
michael@0 | 684 | |
michael@0 | 685 | status_t status = OK; |
michael@0 | 686 | |
michael@0 | 687 | switch (mOutputFormat) { |
michael@0 | 688 | case OUTPUT_FORMAT_DEFAULT: |
michael@0 | 689 | case OUTPUT_FORMAT_THREE_GPP: |
michael@0 | 690 | case OUTPUT_FORMAT_MPEG_4: |
michael@0 | 691 | status = startMPEG4Recording(); |
michael@0 | 692 | break; |
michael@0 | 693 | |
michael@0 | 694 | case OUTPUT_FORMAT_AMR_NB: |
michael@0 | 695 | case OUTPUT_FORMAT_AMR_WB: |
michael@0 | 696 | status = startAMRRecording(); |
michael@0 | 697 | break; |
michael@0 | 698 | |
michael@0 | 699 | #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 |
michael@0 | 700 | case OUTPUT_FORMAT_AAC_ADIF: |
michael@0 | 701 | case OUTPUT_FORMAT_AAC_ADTS: |
michael@0 | 702 | status = startAACRecording(); |
michael@0 | 703 | break; |
michael@0 | 704 | #endif |
michael@0 | 705 | |
michael@0 | 706 | case OUTPUT_FORMAT_RTP_AVP: |
michael@0 | 707 | status = startRTPRecording(); |
michael@0 | 708 | break; |
michael@0 | 709 | |
michael@0 | 710 | case OUTPUT_FORMAT_MPEG2TS: |
michael@0 | 711 | status = startMPEG2TSRecording(); |
michael@0 | 712 | break; |
michael@0 | 713 | |
michael@0 | 714 | default: |
michael@0 | 715 | RE_LOGE("Unsupported output file format: %d", mOutputFormat); |
michael@0 | 716 | status = UNKNOWN_ERROR; |
michael@0 | 717 | break; |
michael@0 | 718 | } |
michael@0 | 719 | |
michael@0 | 720 | if ((status == OK) && (!mStarted)) { |
michael@0 | 721 | mStarted = true; |
michael@0 | 722 | } |
michael@0 | 723 | |
michael@0 | 724 | return status; |
michael@0 | 725 | } |
michael@0 | 726 | |
michael@0 | 727 | sp<MediaSource> GonkRecorder::createAudioSource() { |
michael@0 | 728 | sp<AudioSource> audioSource = |
michael@0 | 729 | new AudioSource( |
michael@0 | 730 | mAudioSource, |
michael@0 | 731 | mSampleRate, |
michael@0 | 732 | mAudioChannels); |
michael@0 | 733 | |
michael@0 | 734 | status_t err = audioSource->initCheck(); |
michael@0 | 735 | |
michael@0 | 736 | if (err != OK) { |
michael@0 | 737 | RE_LOGE("audio source is not initialized"); |
michael@0 | 738 | return NULL; |
michael@0 | 739 | } |
michael@0 | 740 | |
michael@0 | 741 | sp<MetaData> encMeta = new MetaData; |
michael@0 | 742 | const char *mime; |
michael@0 | 743 | switch (mAudioEncoder) { |
michael@0 | 744 | case AUDIO_ENCODER_AMR_NB: |
michael@0 | 745 | case AUDIO_ENCODER_DEFAULT: |
michael@0 | 746 | mime = MEDIA_MIMETYPE_AUDIO_AMR_NB; |
michael@0 | 747 | break; |
michael@0 | 748 | case AUDIO_ENCODER_AMR_WB: |
michael@0 | 749 | mime = MEDIA_MIMETYPE_AUDIO_AMR_WB; |
michael@0 | 750 | break; |
michael@0 | 751 | #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 |
michael@0 | 752 | case AUDIO_ENCODER_AAC: |
michael@0 | 753 | mime = MEDIA_MIMETYPE_AUDIO_AAC; |
michael@0 | 754 | encMeta->setInt32(kKeyAACProfile, OMX_AUDIO_AACObjectLC); |
michael@0 | 755 | break; |
michael@0 | 756 | case AUDIO_ENCODER_HE_AAC: |
michael@0 | 757 | mime = MEDIA_MIMETYPE_AUDIO_AAC; |
michael@0 | 758 | encMeta->setInt32(kKeyAACProfile, OMX_AUDIO_AACObjectHE); |
michael@0 | 759 | break; |
michael@0 | 760 | case AUDIO_ENCODER_AAC_ELD: |
michael@0 | 761 | mime = MEDIA_MIMETYPE_AUDIO_AAC; |
michael@0 | 762 | encMeta->setInt32(kKeyAACProfile, OMX_AUDIO_AACObjectELD); |
michael@0 | 763 | break; |
michael@0 | 764 | #endif |
michael@0 | 765 | default: |
michael@0 | 766 | RE_LOGE("Unknown audio encoder: %d", mAudioEncoder); |
michael@0 | 767 | return NULL; |
michael@0 | 768 | } |
michael@0 | 769 | encMeta->setCString(kKeyMIMEType, mime); |
michael@0 | 770 | |
michael@0 | 771 | int32_t maxInputSize; |
michael@0 | 772 | CHECK(audioSource->getFormat()->findInt32( |
michael@0 | 773 | kKeyMaxInputSize, &maxInputSize)); |
michael@0 | 774 | |
michael@0 | 775 | encMeta->setInt32(kKeyMaxInputSize, maxInputSize); |
michael@0 | 776 | encMeta->setInt32(kKeyChannelCount, mAudioChannels); |
michael@0 | 777 | encMeta->setInt32(kKeySampleRate, mSampleRate); |
michael@0 | 778 | encMeta->setInt32(kKeyBitRate, mAudioBitRate); |
michael@0 | 779 | if (mAudioTimeScale > 0) { |
michael@0 | 780 | encMeta->setInt32(kKeyTimeScale, mAudioTimeScale); |
michael@0 | 781 | } |
michael@0 | 782 | |
michael@0 | 783 | // OMXClient::connect() always returns OK and abort's fatally if |
michael@0 | 784 | // it can't connect. |
michael@0 | 785 | OMXClient client; |
michael@0 | 786 | // CHECK_EQ causes an abort if the given condition fails. |
michael@0 | 787 | CHECK_EQ(client.connect(), (status_t)OK); |
michael@0 | 788 | sp<MediaSource> audioEncoder = |
michael@0 | 789 | OMXCodec::Create(client.interface(), encMeta, |
michael@0 | 790 | true /* createEncoder */, audioSource); |
michael@0 | 791 | mAudioSourceNode = audioSource; |
michael@0 | 792 | |
michael@0 | 793 | return audioEncoder; |
michael@0 | 794 | } |
michael@0 | 795 | |
michael@0 | 796 | #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 |
michael@0 | 797 | status_t GonkRecorder::startAACRecording() { |
michael@0 | 798 | // FIXME: |
michael@0 | 799 | // Add support for OUTPUT_FORMAT_AAC_ADIF |
michael@0 | 800 | CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_AAC_ADTS); |
michael@0 | 801 | |
michael@0 | 802 | CHECK(mAudioEncoder == AUDIO_ENCODER_AAC || |
michael@0 | 803 | mAudioEncoder == AUDIO_ENCODER_HE_AAC || |
michael@0 | 804 | mAudioEncoder == AUDIO_ENCODER_AAC_ELD); |
michael@0 | 805 | CHECK(mAudioSource != AUDIO_SOURCE_CNT); |
michael@0 | 806 | |
michael@0 | 807 | mWriter = new AACWriter(mOutputFd); |
michael@0 | 808 | status_t status = startRawAudioRecording(); |
michael@0 | 809 | if (status != OK) { |
michael@0 | 810 | mWriter.clear(); |
michael@0 | 811 | mWriter = NULL; |
michael@0 | 812 | } |
michael@0 | 813 | |
michael@0 | 814 | return status; |
michael@0 | 815 | } |
michael@0 | 816 | #endif |
michael@0 | 817 | |
michael@0 | 818 | status_t GonkRecorder::startAMRRecording() { |
michael@0 | 819 | CHECK(mOutputFormat == OUTPUT_FORMAT_AMR_NB || |
michael@0 | 820 | mOutputFormat == OUTPUT_FORMAT_AMR_WB); |
michael@0 | 821 | |
michael@0 | 822 | if (mOutputFormat == OUTPUT_FORMAT_AMR_NB) { |
michael@0 | 823 | if (mAudioEncoder != AUDIO_ENCODER_DEFAULT && |
michael@0 | 824 | mAudioEncoder != AUDIO_ENCODER_AMR_NB) { |
michael@0 | 825 | RE_LOGE("Invalid encoder %d used for AMRNB recording", |
michael@0 | 826 | mAudioEncoder); |
michael@0 | 827 | return BAD_VALUE; |
michael@0 | 828 | } |
michael@0 | 829 | } else { // mOutputFormat must be OUTPUT_FORMAT_AMR_WB |
michael@0 | 830 | if (mAudioEncoder != AUDIO_ENCODER_AMR_WB) { |
michael@0 | 831 | RE_LOGE("Invlaid encoder %d used for AMRWB recording", |
michael@0 | 832 | mAudioEncoder); |
michael@0 | 833 | return BAD_VALUE; |
michael@0 | 834 | } |
michael@0 | 835 | } |
michael@0 | 836 | |
michael@0 | 837 | mWriter = new AMRWriter(mOutputFd); |
michael@0 | 838 | status_t status = startRawAudioRecording(); |
michael@0 | 839 | if (status != OK) { |
michael@0 | 840 | mWriter.clear(); |
michael@0 | 841 | mWriter = NULL; |
michael@0 | 842 | } |
michael@0 | 843 | return status; |
michael@0 | 844 | } |
michael@0 | 845 | |
michael@0 | 846 | status_t GonkRecorder::startRawAudioRecording() { |
michael@0 | 847 | if (mAudioSource >= AUDIO_SOURCE_CNT) { |
michael@0 | 848 | RE_LOGE("Invalid audio source: %d", mAudioSource); |
michael@0 | 849 | return BAD_VALUE; |
michael@0 | 850 | } |
michael@0 | 851 | |
michael@0 | 852 | status_t status = BAD_VALUE; |
michael@0 | 853 | if (OK != (status = checkAudioEncoderCapabilities())) { |
michael@0 | 854 | return status; |
michael@0 | 855 | } |
michael@0 | 856 | |
michael@0 | 857 | sp<MediaSource> audioEncoder = createAudioSource(); |
michael@0 | 858 | if (audioEncoder == NULL) { |
michael@0 | 859 | return UNKNOWN_ERROR; |
michael@0 | 860 | } |
michael@0 | 861 | |
michael@0 | 862 | CHECK(mWriter != 0); |
michael@0 | 863 | mWriter->addSource(audioEncoder); |
michael@0 | 864 | |
michael@0 | 865 | if (mMaxFileDurationUs != 0) { |
michael@0 | 866 | mWriter->setMaxFileDuration(mMaxFileDurationUs); |
michael@0 | 867 | } |
michael@0 | 868 | if (mMaxFileSizeBytes != 0) { |
michael@0 | 869 | mWriter->setMaxFileSize(mMaxFileSizeBytes); |
michael@0 | 870 | } |
michael@0 | 871 | mWriter->setListener(mListener); |
michael@0 | 872 | mWriter->start(); |
michael@0 | 873 | |
michael@0 | 874 | return OK; |
michael@0 | 875 | } |
michael@0 | 876 | |
michael@0 | 877 | status_t GonkRecorder::startRTPRecording() { |
michael@0 | 878 | return INVALID_OPERATION; |
michael@0 | 879 | } |
michael@0 | 880 | |
michael@0 | 881 | status_t GonkRecorder::startMPEG2TSRecording() { |
michael@0 | 882 | CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_MPEG2TS); |
michael@0 | 883 | |
michael@0 | 884 | sp<MediaWriter> writer = new MPEG2TSWriter(mOutputFd); |
michael@0 | 885 | |
michael@0 | 886 | if (mAudioSource != AUDIO_SOURCE_CNT) { |
michael@0 | 887 | #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 |
michael@0 | 888 | if (mAudioEncoder != AUDIO_ENCODER_AAC && |
michael@0 | 889 | mAudioEncoder != AUDIO_ENCODER_HE_AAC && |
michael@0 | 890 | mAudioEncoder != AUDIO_ENCODER_AAC_ELD) { |
michael@0 | 891 | return ERROR_UNSUPPORTED; |
michael@0 | 892 | } |
michael@0 | 893 | #endif |
michael@0 | 894 | status_t err = setupAudioEncoder(writer); |
michael@0 | 895 | |
michael@0 | 896 | if (err != OK) { |
michael@0 | 897 | return err; |
michael@0 | 898 | } |
michael@0 | 899 | } |
michael@0 | 900 | |
michael@0 | 901 | if (mVideoSource < VIDEO_SOURCE_LIST_END) { |
michael@0 | 902 | if (mVideoEncoder != VIDEO_ENCODER_H264) { |
michael@0 | 903 | return ERROR_UNSUPPORTED; |
michael@0 | 904 | } |
michael@0 | 905 | |
michael@0 | 906 | sp<MediaSource> mediaSource; |
michael@0 | 907 | status_t err = setupMediaSource(&mediaSource); |
michael@0 | 908 | if (err != OK) { |
michael@0 | 909 | return err; |
michael@0 | 910 | } |
michael@0 | 911 | |
michael@0 | 912 | sp<MediaSource> encoder; |
michael@0 | 913 | err = setupVideoEncoder(mediaSource, mVideoBitRate, &encoder); |
michael@0 | 914 | |
michael@0 | 915 | if (err != OK) { |
michael@0 | 916 | return err; |
michael@0 | 917 | } |
michael@0 | 918 | |
michael@0 | 919 | writer->addSource(encoder); |
michael@0 | 920 | } |
michael@0 | 921 | |
michael@0 | 922 | if (mMaxFileDurationUs != 0) { |
michael@0 | 923 | writer->setMaxFileDuration(mMaxFileDurationUs); |
michael@0 | 924 | } |
michael@0 | 925 | |
michael@0 | 926 | if (mMaxFileSizeBytes != 0) { |
michael@0 | 927 | writer->setMaxFileSize(mMaxFileSizeBytes); |
michael@0 | 928 | } |
michael@0 | 929 | |
michael@0 | 930 | mWriter = writer; |
michael@0 | 931 | |
michael@0 | 932 | return mWriter->start(); |
michael@0 | 933 | } |
michael@0 | 934 | |
michael@0 | 935 | void GonkRecorder::clipVideoFrameRate() { |
michael@0 | 936 | RE_LOGV("clipVideoFrameRate: encoder %d", mVideoEncoder); |
michael@0 | 937 | int minFrameRate = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 938 | "enc.vid.fps.min", mVideoEncoder); |
michael@0 | 939 | int maxFrameRate = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 940 | "enc.vid.fps.max", mVideoEncoder); |
michael@0 | 941 | if (mFrameRate < minFrameRate && minFrameRate != -1) { |
michael@0 | 942 | RE_LOGW("Intended video encoding frame rate (%d fps) is too small" |
michael@0 | 943 | " and will be set to (%d fps)", mFrameRate, minFrameRate); |
michael@0 | 944 | mFrameRate = minFrameRate; |
michael@0 | 945 | } else if (mFrameRate > maxFrameRate && maxFrameRate != -1) { |
michael@0 | 946 | RE_LOGW("Intended video encoding frame rate (%d fps) is too large" |
michael@0 | 947 | " and will be set to (%d fps)", mFrameRate, maxFrameRate); |
michael@0 | 948 | mFrameRate = maxFrameRate; |
michael@0 | 949 | } |
michael@0 | 950 | } |
michael@0 | 951 | |
michael@0 | 952 | void GonkRecorder::clipVideoBitRate() { |
michael@0 | 953 | RE_LOGV("clipVideoBitRate: encoder %d", mVideoEncoder); |
michael@0 | 954 | int minBitRate = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 955 | "enc.vid.bps.min", mVideoEncoder); |
michael@0 | 956 | int maxBitRate = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 957 | "enc.vid.bps.max", mVideoEncoder); |
michael@0 | 958 | if (mVideoBitRate < minBitRate && minBitRate != -1) { |
michael@0 | 959 | RE_LOGW("Intended video encoding bit rate (%d bps) is too small" |
michael@0 | 960 | " and will be set to (%d bps)", mVideoBitRate, minBitRate); |
michael@0 | 961 | mVideoBitRate = minBitRate; |
michael@0 | 962 | } else if (mVideoBitRate > maxBitRate && maxBitRate != -1) { |
michael@0 | 963 | RE_LOGW("Intended video encoding bit rate (%d bps) is too large" |
michael@0 | 964 | " and will be set to (%d bps)", mVideoBitRate, maxBitRate); |
michael@0 | 965 | mVideoBitRate = maxBitRate; |
michael@0 | 966 | } |
michael@0 | 967 | } |
michael@0 | 968 | |
michael@0 | 969 | void GonkRecorder::clipVideoFrameWidth() { |
michael@0 | 970 | RE_LOGV("clipVideoFrameWidth: encoder %d", mVideoEncoder); |
michael@0 | 971 | int minFrameWidth = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 972 | "enc.vid.width.min", mVideoEncoder); |
michael@0 | 973 | int maxFrameWidth = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 974 | "enc.vid.width.max", mVideoEncoder); |
michael@0 | 975 | if (mVideoWidth < minFrameWidth && minFrameWidth != -1) { |
michael@0 | 976 | RE_LOGW("Intended video encoding frame width (%d) is too small" |
michael@0 | 977 | " and will be set to (%d)", mVideoWidth, minFrameWidth); |
michael@0 | 978 | mVideoWidth = minFrameWidth; |
michael@0 | 979 | } else if (mVideoWidth > maxFrameWidth && maxFrameWidth != -1) { |
michael@0 | 980 | RE_LOGW("Intended video encoding frame width (%d) is too large" |
michael@0 | 981 | " and will be set to (%d)", mVideoWidth, maxFrameWidth); |
michael@0 | 982 | mVideoWidth = maxFrameWidth; |
michael@0 | 983 | } |
michael@0 | 984 | } |
michael@0 | 985 | |
michael@0 | 986 | status_t GonkRecorder::checkVideoEncoderCapabilities() { |
michael@0 | 987 | |
michael@0 | 988 | // Dont clip for time lapse capture as encoder will have enough |
michael@0 | 989 | // time to encode because of slow capture rate of time lapse. |
michael@0 | 990 | clipVideoBitRate(); |
michael@0 | 991 | clipVideoFrameRate(); |
michael@0 | 992 | clipVideoFrameWidth(); |
michael@0 | 993 | clipVideoFrameHeight(); |
michael@0 | 994 | setDefaultProfileIfNecessary(); |
michael@0 | 995 | return OK; |
michael@0 | 996 | } |
michael@0 | 997 | |
michael@0 | 998 | // Set to use AVC baseline profile if the encoding parameters matches |
michael@0 | 999 | // CAMCORDER_QUALITY_LOW profile; this is for the sake of MMS service. |
michael@0 | 1000 | void GonkRecorder::setDefaultProfileIfNecessary() { |
michael@0 | 1001 | RE_LOGV("setDefaultProfileIfNecessary"); |
michael@0 | 1002 | |
michael@0 | 1003 | camcorder_quality quality = CAMCORDER_QUALITY_LOW; |
michael@0 | 1004 | |
michael@0 | 1005 | int64_t durationUs = mEncoderProfiles->getCamcorderProfileParamByName( |
michael@0 | 1006 | "duration", mCameraId, quality) * 1000000LL; |
michael@0 | 1007 | |
michael@0 | 1008 | int fileFormat = mEncoderProfiles->getCamcorderProfileParamByName( |
michael@0 | 1009 | "file.format", mCameraId, quality); |
michael@0 | 1010 | |
michael@0 | 1011 | int videoCodec = mEncoderProfiles->getCamcorderProfileParamByName( |
michael@0 | 1012 | "vid.codec", mCameraId, quality); |
michael@0 | 1013 | |
michael@0 | 1014 | int videoBitRate = mEncoderProfiles->getCamcorderProfileParamByName( |
michael@0 | 1015 | "vid.bps", mCameraId, quality); |
michael@0 | 1016 | |
michael@0 | 1017 | int videoFrameRate = mEncoderProfiles->getCamcorderProfileParamByName( |
michael@0 | 1018 | "vid.fps", mCameraId, quality); |
michael@0 | 1019 | |
michael@0 | 1020 | int videoFrameWidth = mEncoderProfiles->getCamcorderProfileParamByName( |
michael@0 | 1021 | "vid.width", mCameraId, quality); |
michael@0 | 1022 | |
michael@0 | 1023 | int videoFrameHeight = mEncoderProfiles->getCamcorderProfileParamByName( |
michael@0 | 1024 | "vid.height", mCameraId, quality); |
michael@0 | 1025 | |
michael@0 | 1026 | int audioCodec = mEncoderProfiles->getCamcorderProfileParamByName( |
michael@0 | 1027 | "aud.codec", mCameraId, quality); |
michael@0 | 1028 | |
michael@0 | 1029 | int audioBitRate = mEncoderProfiles->getCamcorderProfileParamByName( |
michael@0 | 1030 | "aud.bps", mCameraId, quality); |
michael@0 | 1031 | |
michael@0 | 1032 | int audioSampleRate = mEncoderProfiles->getCamcorderProfileParamByName( |
michael@0 | 1033 | "aud.hz", mCameraId, quality); |
michael@0 | 1034 | |
michael@0 | 1035 | int audioChannels = mEncoderProfiles->getCamcorderProfileParamByName( |
michael@0 | 1036 | "aud.ch", mCameraId, quality); |
michael@0 | 1037 | |
michael@0 | 1038 | if (durationUs == mMaxFileDurationUs && |
michael@0 | 1039 | fileFormat == mOutputFormat && |
michael@0 | 1040 | videoCodec == mVideoEncoder && |
michael@0 | 1041 | videoBitRate == mVideoBitRate && |
michael@0 | 1042 | videoFrameRate == mFrameRate && |
michael@0 | 1043 | videoFrameWidth == mVideoWidth && |
michael@0 | 1044 | videoFrameHeight == mVideoHeight && |
michael@0 | 1045 | audioCodec == mAudioEncoder && |
michael@0 | 1046 | audioBitRate == mAudioBitRate && |
michael@0 | 1047 | audioSampleRate == mSampleRate && |
michael@0 | 1048 | audioChannels == mAudioChannels) { |
michael@0 | 1049 | if (videoCodec == VIDEO_ENCODER_H264) { |
michael@0 | 1050 | RE_LOGI("Force to use AVC baseline profile"); |
michael@0 | 1051 | setParamVideoEncoderProfile(OMX_VIDEO_AVCProfileBaseline); |
michael@0 | 1052 | } |
michael@0 | 1053 | } |
michael@0 | 1054 | } |
michael@0 | 1055 | |
michael@0 | 1056 | status_t GonkRecorder::checkAudioEncoderCapabilities() { |
michael@0 | 1057 | clipAudioBitRate(); |
michael@0 | 1058 | clipAudioSampleRate(); |
michael@0 | 1059 | clipNumberOfAudioChannels(); |
michael@0 | 1060 | return OK; |
michael@0 | 1061 | } |
michael@0 | 1062 | |
michael@0 | 1063 | void GonkRecorder::clipAudioBitRate() { |
michael@0 | 1064 | RE_LOGV("clipAudioBitRate: encoder %d", mAudioEncoder); |
michael@0 | 1065 | |
michael@0 | 1066 | int minAudioBitRate = |
michael@0 | 1067 | mEncoderProfiles->getAudioEncoderParamByName( |
michael@0 | 1068 | "enc.aud.bps.min", mAudioEncoder); |
michael@0 | 1069 | if (minAudioBitRate != -1 && mAudioBitRate < minAudioBitRate) { |
michael@0 | 1070 | RE_LOGW("Intended audio encoding bit rate (%d) is too small" |
michael@0 | 1071 | " and will be set to (%d)", mAudioBitRate, minAudioBitRate); |
michael@0 | 1072 | mAudioBitRate = minAudioBitRate; |
michael@0 | 1073 | } |
michael@0 | 1074 | |
michael@0 | 1075 | int maxAudioBitRate = |
michael@0 | 1076 | mEncoderProfiles->getAudioEncoderParamByName( |
michael@0 | 1077 | "enc.aud.bps.max", mAudioEncoder); |
michael@0 | 1078 | if (maxAudioBitRate != -1 && mAudioBitRate > maxAudioBitRate) { |
michael@0 | 1079 | RE_LOGW("Intended audio encoding bit rate (%d) is too large" |
michael@0 | 1080 | " and will be set to (%d)", mAudioBitRate, maxAudioBitRate); |
michael@0 | 1081 | mAudioBitRate = maxAudioBitRate; |
michael@0 | 1082 | } |
michael@0 | 1083 | } |
michael@0 | 1084 | |
michael@0 | 1085 | void GonkRecorder::clipAudioSampleRate() { |
michael@0 | 1086 | RE_LOGV("clipAudioSampleRate: encoder %d", mAudioEncoder); |
michael@0 | 1087 | |
michael@0 | 1088 | int minSampleRate = |
michael@0 | 1089 | mEncoderProfiles->getAudioEncoderParamByName( |
michael@0 | 1090 | "enc.aud.hz.min", mAudioEncoder); |
michael@0 | 1091 | if (minSampleRate != -1 && mSampleRate < minSampleRate) { |
michael@0 | 1092 | RE_LOGW("Intended audio sample rate (%d) is too small" |
michael@0 | 1093 | " and will be set to (%d)", mSampleRate, minSampleRate); |
michael@0 | 1094 | mSampleRate = minSampleRate; |
michael@0 | 1095 | } |
michael@0 | 1096 | |
michael@0 | 1097 | int maxSampleRate = |
michael@0 | 1098 | mEncoderProfiles->getAudioEncoderParamByName( |
michael@0 | 1099 | "enc.aud.hz.max", mAudioEncoder); |
michael@0 | 1100 | if (maxSampleRate != -1 && mSampleRate > maxSampleRate) { |
michael@0 | 1101 | RE_LOGW("Intended audio sample rate (%d) is too large" |
michael@0 | 1102 | " and will be set to (%d)", mSampleRate, maxSampleRate); |
michael@0 | 1103 | mSampleRate = maxSampleRate; |
michael@0 | 1104 | } |
michael@0 | 1105 | } |
michael@0 | 1106 | |
michael@0 | 1107 | void GonkRecorder::clipNumberOfAudioChannels() { |
michael@0 | 1108 | RE_LOGV("clipNumberOfAudioChannels: encoder %d", mAudioEncoder); |
michael@0 | 1109 | |
michael@0 | 1110 | int minChannels = |
michael@0 | 1111 | mEncoderProfiles->getAudioEncoderParamByName( |
michael@0 | 1112 | "enc.aud.ch.min", mAudioEncoder); |
michael@0 | 1113 | if (minChannels != -1 && mAudioChannels < minChannels) { |
michael@0 | 1114 | RE_LOGW("Intended number of audio channels (%d) is too small" |
michael@0 | 1115 | " and will be set to (%d)", mAudioChannels, minChannels); |
michael@0 | 1116 | mAudioChannels = minChannels; |
michael@0 | 1117 | } |
michael@0 | 1118 | |
michael@0 | 1119 | int maxChannels = |
michael@0 | 1120 | mEncoderProfiles->getAudioEncoderParamByName( |
michael@0 | 1121 | "enc.aud.ch.max", mAudioEncoder); |
michael@0 | 1122 | if (maxChannels != -1 && mAudioChannels > maxChannels) { |
michael@0 | 1123 | RE_LOGW("Intended number of audio channels (%d) is too large" |
michael@0 | 1124 | " and will be set to (%d)", mAudioChannels, maxChannels); |
michael@0 | 1125 | mAudioChannels = maxChannels; |
michael@0 | 1126 | } |
michael@0 | 1127 | } |
michael@0 | 1128 | |
michael@0 | 1129 | void GonkRecorder::clipVideoFrameHeight() { |
michael@0 | 1130 | RE_LOGV("clipVideoFrameHeight: encoder %d", mVideoEncoder); |
michael@0 | 1131 | int minFrameHeight = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 1132 | "enc.vid.height.min", mVideoEncoder); |
michael@0 | 1133 | int maxFrameHeight = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 1134 | "enc.vid.height.max", mVideoEncoder); |
michael@0 | 1135 | if (minFrameHeight != -1 && mVideoHeight < minFrameHeight) { |
michael@0 | 1136 | RE_LOGW("Intended video encoding frame height (%d) is too small" |
michael@0 | 1137 | " and will be set to (%d)", mVideoHeight, minFrameHeight); |
michael@0 | 1138 | mVideoHeight = minFrameHeight; |
michael@0 | 1139 | } else if (maxFrameHeight != -1 && mVideoHeight > maxFrameHeight) { |
michael@0 | 1140 | RE_LOGW("Intended video encoding frame height (%d) is too large" |
michael@0 | 1141 | " and will be set to (%d)", mVideoHeight, maxFrameHeight); |
michael@0 | 1142 | mVideoHeight = maxFrameHeight; |
michael@0 | 1143 | } |
michael@0 | 1144 | } |
michael@0 | 1145 | |
michael@0 | 1146 | // Set up the appropriate MediaSource depending on the chosen option |
michael@0 | 1147 | status_t GonkRecorder::setupMediaSource( |
michael@0 | 1148 | sp<MediaSource> *mediaSource) { |
michael@0 | 1149 | if (mVideoSource == VIDEO_SOURCE_DEFAULT |
michael@0 | 1150 | || mVideoSource == VIDEO_SOURCE_CAMERA) { |
michael@0 | 1151 | sp<GonkCameraSource> cameraSource; |
michael@0 | 1152 | status_t err = setupCameraSource(&cameraSource); |
michael@0 | 1153 | if (err != OK) { |
michael@0 | 1154 | return err; |
michael@0 | 1155 | } |
michael@0 | 1156 | *mediaSource = cameraSource; |
michael@0 | 1157 | } else if (mVideoSource == VIDEO_SOURCE_GRALLOC_BUFFER) { |
michael@0 | 1158 | return BAD_VALUE; |
michael@0 | 1159 | } else { |
michael@0 | 1160 | return INVALID_OPERATION; |
michael@0 | 1161 | } |
michael@0 | 1162 | return OK; |
michael@0 | 1163 | } |
michael@0 | 1164 | |
michael@0 | 1165 | status_t GonkRecorder::setupCameraSource( |
michael@0 | 1166 | sp<GonkCameraSource> *cameraSource) { |
michael@0 | 1167 | status_t err = OK; |
michael@0 | 1168 | if ((err = checkVideoEncoderCapabilities()) != OK) { |
michael@0 | 1169 | return err; |
michael@0 | 1170 | } |
michael@0 | 1171 | Size videoSize; |
michael@0 | 1172 | videoSize.width = mVideoWidth; |
michael@0 | 1173 | videoSize.height = mVideoHeight; |
michael@0 | 1174 | bool useMeta = true; |
michael@0 | 1175 | char value[PROPERTY_VALUE_MAX]; |
michael@0 | 1176 | if (property_get("debug.camcorder.disablemeta", value, NULL) && |
michael@0 | 1177 | atoi(value)) { |
michael@0 | 1178 | useMeta = false; |
michael@0 | 1179 | } |
michael@0 | 1180 | |
michael@0 | 1181 | *cameraSource = GonkCameraSource::Create( |
michael@0 | 1182 | mCameraHw, videoSize, mFrameRate, useMeta); |
michael@0 | 1183 | if (*cameraSource == NULL) { |
michael@0 | 1184 | return UNKNOWN_ERROR; |
michael@0 | 1185 | } |
michael@0 | 1186 | |
michael@0 | 1187 | if ((*cameraSource)->initCheck() != OK) { |
michael@0 | 1188 | (*cameraSource).clear(); |
michael@0 | 1189 | *cameraSource = NULL; |
michael@0 | 1190 | return NO_INIT; |
michael@0 | 1191 | } |
michael@0 | 1192 | |
michael@0 | 1193 | // When frame rate is not set, the actual frame rate will be set to |
michael@0 | 1194 | // the current frame rate being used. |
michael@0 | 1195 | if (mFrameRate == -1) { |
michael@0 | 1196 | int32_t frameRate = 0; |
michael@0 | 1197 | CHECK ((*cameraSource)->getFormat()->findInt32( |
michael@0 | 1198 | kKeyFrameRate, &frameRate)); |
michael@0 | 1199 | RE_LOGI("Frame rate is not explicitly set. Use the current frame " |
michael@0 | 1200 | "rate (%d fps)", frameRate); |
michael@0 | 1201 | mFrameRate = frameRate; |
michael@0 | 1202 | } |
michael@0 | 1203 | |
michael@0 | 1204 | CHECK(mFrameRate != -1); |
michael@0 | 1205 | |
michael@0 | 1206 | mIsMetaDataStoredInVideoBuffers = |
michael@0 | 1207 | (*cameraSource)->isMetaDataStoredInVideoBuffers(); |
michael@0 | 1208 | |
michael@0 | 1209 | return OK; |
michael@0 | 1210 | } |
michael@0 | 1211 | |
michael@0 | 1212 | status_t GonkRecorder::setupVideoEncoder( |
michael@0 | 1213 | sp<MediaSource> cameraSource, |
michael@0 | 1214 | int32_t videoBitRate, |
michael@0 | 1215 | sp<MediaSource> *source) { |
michael@0 | 1216 | source->clear(); |
michael@0 | 1217 | |
michael@0 | 1218 | sp<MetaData> enc_meta = new MetaData; |
michael@0 | 1219 | enc_meta->setInt32(kKeyBitRate, videoBitRate); |
michael@0 | 1220 | enc_meta->setInt32(kKeyFrameRate, mFrameRate); |
michael@0 | 1221 | |
michael@0 | 1222 | switch (mVideoEncoder) { |
michael@0 | 1223 | case VIDEO_ENCODER_H263: |
michael@0 | 1224 | enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_H263); |
michael@0 | 1225 | break; |
michael@0 | 1226 | |
michael@0 | 1227 | case VIDEO_ENCODER_MPEG_4_SP: |
michael@0 | 1228 | enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG4); |
michael@0 | 1229 | break; |
michael@0 | 1230 | |
michael@0 | 1231 | case VIDEO_ENCODER_H264: |
michael@0 | 1232 | enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC); |
michael@0 | 1233 | break; |
michael@0 | 1234 | |
michael@0 | 1235 | default: |
michael@0 | 1236 | CHECK(!"Should not be here, unsupported video encoding."); |
michael@0 | 1237 | break; |
michael@0 | 1238 | } |
michael@0 | 1239 | |
michael@0 | 1240 | sp<MetaData> meta = cameraSource->getFormat(); |
michael@0 | 1241 | |
michael@0 | 1242 | int32_t width, height, stride, sliceHeight, colorFormat; |
michael@0 | 1243 | CHECK(meta->findInt32(kKeyWidth, &width)); |
michael@0 | 1244 | CHECK(meta->findInt32(kKeyHeight, &height)); |
michael@0 | 1245 | CHECK(meta->findInt32(kKeyStride, &stride)); |
michael@0 | 1246 | CHECK(meta->findInt32(kKeySliceHeight, &sliceHeight)); |
michael@0 | 1247 | CHECK(meta->findInt32(kKeyColorFormat, &colorFormat)); |
michael@0 | 1248 | |
michael@0 | 1249 | enc_meta->setInt32(kKeyWidth, width); |
michael@0 | 1250 | enc_meta->setInt32(kKeyHeight, height); |
michael@0 | 1251 | enc_meta->setInt32(kKeyIFramesInterval, mIFramesIntervalSec); |
michael@0 | 1252 | enc_meta->setInt32(kKeyStride, stride); |
michael@0 | 1253 | enc_meta->setInt32(kKeySliceHeight, sliceHeight); |
michael@0 | 1254 | enc_meta->setInt32(kKeyColorFormat, colorFormat); |
michael@0 | 1255 | if (mVideoTimeScale > 0) { |
michael@0 | 1256 | enc_meta->setInt32(kKeyTimeScale, mVideoTimeScale); |
michael@0 | 1257 | } |
michael@0 | 1258 | if (mVideoEncoderProfile != -1) { |
michael@0 | 1259 | enc_meta->setInt32(kKeyVideoProfile, mVideoEncoderProfile); |
michael@0 | 1260 | } |
michael@0 | 1261 | if (mVideoEncoderLevel != -1) { |
michael@0 | 1262 | enc_meta->setInt32(kKeyVideoLevel, mVideoEncoderLevel); |
michael@0 | 1263 | } |
michael@0 | 1264 | |
michael@0 | 1265 | // OMXClient::connect() always returns OK and abort's fatally if |
michael@0 | 1266 | // it can't connect. |
michael@0 | 1267 | OMXClient client; |
michael@0 | 1268 | // CHECK_EQ causes an abort if the given condition fails. |
michael@0 | 1269 | CHECK_EQ(client.connect(), (status_t)OK); |
michael@0 | 1270 | |
michael@0 | 1271 | uint32_t encoder_flags = 0; |
michael@0 | 1272 | if (mIsMetaDataStoredInVideoBuffers) { |
michael@0 | 1273 | #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 |
michael@0 | 1274 | encoder_flags |= OMXCodec::kStoreMetaDataInVideoBuffers; |
michael@0 | 1275 | #else |
michael@0 | 1276 | encoder_flags |= OMXCodec::kHardwareCodecsOnly; |
michael@0 | 1277 | encoder_flags |= OMXCodec::kStoreMetaDataInVideoBuffers; |
michael@0 | 1278 | encoder_flags |= OMXCodec::kOnlySubmitOneInputBufferAtOneTime; |
michael@0 | 1279 | #endif |
michael@0 | 1280 | } |
michael@0 | 1281 | |
michael@0 | 1282 | sp<MediaSource> encoder = OMXCodec::Create( |
michael@0 | 1283 | client.interface(), enc_meta, |
michael@0 | 1284 | true /* createEncoder */, cameraSource, |
michael@0 | 1285 | NULL, encoder_flags); |
michael@0 | 1286 | if (encoder == NULL) { |
michael@0 | 1287 | RE_LOGW("Failed to create the encoder"); |
michael@0 | 1288 | // When the encoder fails to be created, we need |
michael@0 | 1289 | // release the camera source due to the camera's lock |
michael@0 | 1290 | // and unlock mechanism. |
michael@0 | 1291 | cameraSource->stop(); |
michael@0 | 1292 | return UNKNOWN_ERROR; |
michael@0 | 1293 | } |
michael@0 | 1294 | |
michael@0 | 1295 | *source = encoder; |
michael@0 | 1296 | |
michael@0 | 1297 | return OK; |
michael@0 | 1298 | } |
michael@0 | 1299 | |
michael@0 | 1300 | status_t GonkRecorder::setupAudioEncoder(const sp<MediaWriter>& writer) { |
michael@0 | 1301 | status_t status = BAD_VALUE; |
michael@0 | 1302 | if (OK != (status = checkAudioEncoderCapabilities())) { |
michael@0 | 1303 | return status; |
michael@0 | 1304 | } |
michael@0 | 1305 | |
michael@0 | 1306 | switch(mAudioEncoder) { |
michael@0 | 1307 | case AUDIO_ENCODER_AMR_NB: |
michael@0 | 1308 | case AUDIO_ENCODER_AMR_WB: |
michael@0 | 1309 | #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 |
michael@0 | 1310 | case AUDIO_ENCODER_AAC: |
michael@0 | 1311 | case AUDIO_ENCODER_HE_AAC: |
michael@0 | 1312 | case AUDIO_ENCODER_AAC_ELD: |
michael@0 | 1313 | #endif |
michael@0 | 1314 | break; |
michael@0 | 1315 | |
michael@0 | 1316 | default: |
michael@0 | 1317 | RE_LOGE("Unsupported audio encoder: %d", mAudioEncoder); |
michael@0 | 1318 | return UNKNOWN_ERROR; |
michael@0 | 1319 | } |
michael@0 | 1320 | |
michael@0 | 1321 | sp<MediaSource> audioEncoder = createAudioSource(); |
michael@0 | 1322 | if (audioEncoder == NULL) { |
michael@0 | 1323 | return UNKNOWN_ERROR; |
michael@0 | 1324 | } |
michael@0 | 1325 | |
michael@0 | 1326 | writer->addSource(audioEncoder); |
michael@0 | 1327 | return OK; |
michael@0 | 1328 | } |
michael@0 | 1329 | |
michael@0 | 1330 | status_t GonkRecorder::setupMPEG4Recording( |
michael@0 | 1331 | int outputFd, |
michael@0 | 1332 | int32_t videoWidth, int32_t videoHeight, |
michael@0 | 1333 | int32_t videoBitRate, |
michael@0 | 1334 | int32_t *totalBitRate, |
michael@0 | 1335 | sp<MediaWriter> *mediaWriter) { |
michael@0 | 1336 | mediaWriter->clear(); |
michael@0 | 1337 | *totalBitRate = 0; |
michael@0 | 1338 | status_t err = OK; |
michael@0 | 1339 | sp<MediaWriter> writer = new MPEG4Writer(outputFd); |
michael@0 | 1340 | |
michael@0 | 1341 | if (mVideoSource < VIDEO_SOURCE_LIST_END) { |
michael@0 | 1342 | |
michael@0 | 1343 | sp<MediaSource> mediaSource; |
michael@0 | 1344 | err = setupMediaSource(&mediaSource); |
michael@0 | 1345 | if (err != OK) { |
michael@0 | 1346 | return err; |
michael@0 | 1347 | } |
michael@0 | 1348 | |
michael@0 | 1349 | sp<MediaSource> encoder; |
michael@0 | 1350 | err = setupVideoEncoder(mediaSource, videoBitRate, &encoder); |
michael@0 | 1351 | if (err != OK) { |
michael@0 | 1352 | return err; |
michael@0 | 1353 | } |
michael@0 | 1354 | |
michael@0 | 1355 | writer->addSource(encoder); |
michael@0 | 1356 | *totalBitRate += videoBitRate; |
michael@0 | 1357 | } |
michael@0 | 1358 | |
michael@0 | 1359 | // Audio source is added at the end if it exists. |
michael@0 | 1360 | // This help make sure that the "recoding" sound is suppressed for |
michael@0 | 1361 | // camcorder applications in the recorded files. |
michael@0 | 1362 | if (mAudioSource != AUDIO_SOURCE_CNT) { |
michael@0 | 1363 | err = setupAudioEncoder(writer); |
michael@0 | 1364 | if (err != OK) return err; |
michael@0 | 1365 | *totalBitRate += mAudioBitRate; |
michael@0 | 1366 | } |
michael@0 | 1367 | |
michael@0 | 1368 | if (mInterleaveDurationUs > 0) { |
michael@0 | 1369 | reinterpret_cast<MPEG4Writer *>(writer.get())-> |
michael@0 | 1370 | setInterleaveDuration(mInterleaveDurationUs); |
michael@0 | 1371 | } |
michael@0 | 1372 | if (mLongitudex10000 > -3600000 && mLatitudex10000 > -3600000) { |
michael@0 | 1373 | reinterpret_cast<MPEG4Writer *>(writer.get())-> |
michael@0 | 1374 | setGeoData(mLatitudex10000, mLongitudex10000); |
michael@0 | 1375 | } |
michael@0 | 1376 | if (mMaxFileDurationUs != 0) { |
michael@0 | 1377 | writer->setMaxFileDuration(mMaxFileDurationUs); |
michael@0 | 1378 | } |
michael@0 | 1379 | if (mMaxFileSizeBytes != 0) { |
michael@0 | 1380 | writer->setMaxFileSize(mMaxFileSizeBytes); |
michael@0 | 1381 | } |
michael@0 | 1382 | |
michael@0 | 1383 | mStartTimeOffsetMs = mEncoderProfiles->getStartTimeOffsetMs(mCameraId); |
michael@0 | 1384 | if (mStartTimeOffsetMs > 0) { |
michael@0 | 1385 | reinterpret_cast<MPEG4Writer *>(writer.get())-> |
michael@0 | 1386 | setStartTimeOffsetMs(mStartTimeOffsetMs); |
michael@0 | 1387 | } |
michael@0 | 1388 | |
michael@0 | 1389 | writer->setListener(mListener); |
michael@0 | 1390 | *mediaWriter = writer; |
michael@0 | 1391 | return OK; |
michael@0 | 1392 | } |
michael@0 | 1393 | |
michael@0 | 1394 | void GonkRecorder::setupMPEG4MetaData(int64_t startTimeUs, int32_t totalBitRate, |
michael@0 | 1395 | sp<MetaData> *meta) { |
michael@0 | 1396 | (*meta)->setInt64(kKeyTime, startTimeUs); |
michael@0 | 1397 | (*meta)->setInt32(kKeyFileType, mOutputFormat); |
michael@0 | 1398 | (*meta)->setInt32(kKeyBitRate, totalBitRate); |
michael@0 | 1399 | (*meta)->setInt32(kKey64BitFileOffset, mUse64BitFileOffset); |
michael@0 | 1400 | if (mMovieTimeScale > 0) { |
michael@0 | 1401 | (*meta)->setInt32(kKeyTimeScale, mMovieTimeScale); |
michael@0 | 1402 | } |
michael@0 | 1403 | if (mTrackEveryTimeDurationUs > 0) { |
michael@0 | 1404 | (*meta)->setInt64(kKeyTrackTimeStatus, mTrackEveryTimeDurationUs); |
michael@0 | 1405 | } |
michael@0 | 1406 | |
michael@0 | 1407 | char value[PROPERTY_VALUE_MAX]; |
michael@0 | 1408 | if (property_get("debug.camcorder.rotation", value, 0) > 0 && atoi(value) >= 0) { |
michael@0 | 1409 | mRotationDegrees = atoi(value); |
michael@0 | 1410 | RE_LOGI("Setting rotation to %d", mRotationDegrees ); |
michael@0 | 1411 | } |
michael@0 | 1412 | |
michael@0 | 1413 | if (mRotationDegrees != 0) { |
michael@0 | 1414 | (*meta)->setInt32(kKeyRotation, mRotationDegrees); |
michael@0 | 1415 | } |
michael@0 | 1416 | } |
michael@0 | 1417 | |
michael@0 | 1418 | status_t GonkRecorder::startMPEG4Recording() { |
michael@0 | 1419 | int32_t totalBitRate; |
michael@0 | 1420 | status_t err = setupMPEG4Recording( |
michael@0 | 1421 | mOutputFd, mVideoWidth, mVideoHeight, |
michael@0 | 1422 | mVideoBitRate, &totalBitRate, &mWriter); |
michael@0 | 1423 | if (err != OK) { |
michael@0 | 1424 | return err; |
michael@0 | 1425 | } |
michael@0 | 1426 | |
michael@0 | 1427 | //systemTime() doesn't give correct time because |
michael@0 | 1428 | //HAVE_POSIX_CLOCKS is not defined for utils/Timers.cpp |
michael@0 | 1429 | //so, using clock_gettime directly |
michael@0 | 1430 | #include <time.h> |
michael@0 | 1431 | struct timespec t; |
michael@0 | 1432 | clock_gettime(CLOCK_MONOTONIC, &t); |
michael@0 | 1433 | int64_t startTimeUs = int64_t(t.tv_sec)*1000000000LL + t.tv_nsec; |
michael@0 | 1434 | startTimeUs = startTimeUs / 1000; |
michael@0 | 1435 | sp<MetaData> meta = new MetaData; |
michael@0 | 1436 | setupMPEG4MetaData(startTimeUs, totalBitRate, &meta); |
michael@0 | 1437 | |
michael@0 | 1438 | err = mWriter->start(meta.get()); |
michael@0 | 1439 | if (err != OK) { |
michael@0 | 1440 | return err; |
michael@0 | 1441 | } |
michael@0 | 1442 | |
michael@0 | 1443 | return OK; |
michael@0 | 1444 | } |
michael@0 | 1445 | |
michael@0 | 1446 | status_t GonkRecorder::pause() { |
michael@0 | 1447 | RE_LOGV("pause"); |
michael@0 | 1448 | if (mWriter == NULL) { |
michael@0 | 1449 | return UNKNOWN_ERROR; |
michael@0 | 1450 | } |
michael@0 | 1451 | mWriter->pause(); |
michael@0 | 1452 | |
michael@0 | 1453 | if (mStarted) { |
michael@0 | 1454 | mStarted = false; |
michael@0 | 1455 | } |
michael@0 | 1456 | |
michael@0 | 1457 | |
michael@0 | 1458 | return OK; |
michael@0 | 1459 | } |
michael@0 | 1460 | |
michael@0 | 1461 | status_t GonkRecorder::stop() { |
michael@0 | 1462 | RE_LOGV("stop"); |
michael@0 | 1463 | status_t err = OK; |
michael@0 | 1464 | |
michael@0 | 1465 | if (mWriter != NULL) { |
michael@0 | 1466 | err = mWriter->stop(); |
michael@0 | 1467 | mWriter.clear(); |
michael@0 | 1468 | } |
michael@0 | 1469 | |
michael@0 | 1470 | if (mOutputFd >= 0) { |
michael@0 | 1471 | ::close(mOutputFd); |
michael@0 | 1472 | mOutputFd = -1; |
michael@0 | 1473 | } |
michael@0 | 1474 | |
michael@0 | 1475 | if (mStarted) { |
michael@0 | 1476 | mStarted = false; |
michael@0 | 1477 | } |
michael@0 | 1478 | |
michael@0 | 1479 | |
michael@0 | 1480 | return err; |
michael@0 | 1481 | } |
michael@0 | 1482 | |
michael@0 | 1483 | status_t GonkRecorder::close() { |
michael@0 | 1484 | RE_LOGV("close"); |
michael@0 | 1485 | stop(); |
michael@0 | 1486 | |
michael@0 | 1487 | return OK; |
michael@0 | 1488 | } |
michael@0 | 1489 | |
michael@0 | 1490 | status_t GonkRecorder::reset() { |
michael@0 | 1491 | RE_LOGV("reset"); |
michael@0 | 1492 | stop(); |
michael@0 | 1493 | |
michael@0 | 1494 | // No audio or video source by default |
michael@0 | 1495 | mAudioSource = AUDIO_SOURCE_CNT; |
michael@0 | 1496 | mVideoSource = VIDEO_SOURCE_LIST_END; |
michael@0 | 1497 | |
michael@0 | 1498 | // Default parameters |
michael@0 | 1499 | mOutputFormat = OUTPUT_FORMAT_THREE_GPP; |
michael@0 | 1500 | mAudioEncoder = AUDIO_ENCODER_AMR_NB; |
michael@0 | 1501 | mVideoEncoder = VIDEO_ENCODER_H263; |
michael@0 | 1502 | mVideoWidth = 176; |
michael@0 | 1503 | mVideoHeight = 144; |
michael@0 | 1504 | mFrameRate = -1; |
michael@0 | 1505 | mVideoBitRate = 192000; |
michael@0 | 1506 | mSampleRate = 8000; |
michael@0 | 1507 | mAudioChannels = 1; |
michael@0 | 1508 | mAudioBitRate = 12200; |
michael@0 | 1509 | mInterleaveDurationUs = 0; |
michael@0 | 1510 | mIFramesIntervalSec = 1; |
michael@0 | 1511 | mAudioSourceNode = 0; |
michael@0 | 1512 | mUse64BitFileOffset = false; |
michael@0 | 1513 | mMovieTimeScale = -1; |
michael@0 | 1514 | mAudioTimeScale = -1; |
michael@0 | 1515 | mVideoTimeScale = -1; |
michael@0 | 1516 | mCameraId = 0; |
michael@0 | 1517 | mStartTimeOffsetMs = -1; |
michael@0 | 1518 | mVideoEncoderProfile = -1; |
michael@0 | 1519 | mVideoEncoderLevel = -1; |
michael@0 | 1520 | mMaxFileDurationUs = 0; |
michael@0 | 1521 | mMaxFileSizeBytes = 0; |
michael@0 | 1522 | mTrackEveryTimeDurationUs = 0; |
michael@0 | 1523 | mIsMetaDataStoredInVideoBuffers = false; |
michael@0 | 1524 | mEncoderProfiles = MediaProfiles::getInstance(); |
michael@0 | 1525 | mRotationDegrees = 0; |
michael@0 | 1526 | mLatitudex10000 = -3600000; |
michael@0 | 1527 | mLongitudex10000 = -3600000; |
michael@0 | 1528 | |
michael@0 | 1529 | mOutputFd = -1; |
michael@0 | 1530 | mCameraHw.clear(); |
michael@0 | 1531 | //TODO: May need to register a listener eventually |
michael@0 | 1532 | //if someone is interested in recorder events for now |
michael@0 | 1533 | //default to no listener registered |
michael@0 | 1534 | mListener = NULL; |
michael@0 | 1535 | |
michael@0 | 1536 | return OK; |
michael@0 | 1537 | } |
michael@0 | 1538 | |
michael@0 | 1539 | status_t GonkRecorder::getMaxAmplitude(int *max) { |
michael@0 | 1540 | RE_LOGV("getMaxAmplitude"); |
michael@0 | 1541 | |
michael@0 | 1542 | if (max == NULL) { |
michael@0 | 1543 | RE_LOGE("Null pointer argument"); |
michael@0 | 1544 | return BAD_VALUE; |
michael@0 | 1545 | } |
michael@0 | 1546 | |
michael@0 | 1547 | if (mAudioSourceNode != 0) { |
michael@0 | 1548 | *max = mAudioSourceNode->getMaxAmplitude(); |
michael@0 | 1549 | } else { |
michael@0 | 1550 | *max = 0; |
michael@0 | 1551 | } |
michael@0 | 1552 | |
michael@0 | 1553 | return OK; |
michael@0 | 1554 | } |
michael@0 | 1555 | |
michael@0 | 1556 | status_t GonkRecorder::dump( |
michael@0 | 1557 | int fd, const Vector<String16>& args) const { |
michael@0 | 1558 | RE_LOGV("dump"); |
michael@0 | 1559 | const size_t SIZE = 256; |
michael@0 | 1560 | char buffer[SIZE]; |
michael@0 | 1561 | String8 result; |
michael@0 | 1562 | if (mWriter != 0) { |
michael@0 | 1563 | mWriter->dump(fd, args); |
michael@0 | 1564 | } else { |
michael@0 | 1565 | snprintf(buffer, SIZE, " No file writer\n"); |
michael@0 | 1566 | result.append(buffer); |
michael@0 | 1567 | } |
michael@0 | 1568 | snprintf(buffer, SIZE, " Recorder: %p\n", this); |
michael@0 | 1569 | snprintf(buffer, SIZE, " Output file (fd %d):\n", mOutputFd); |
michael@0 | 1570 | result.append(buffer); |
michael@0 | 1571 | snprintf(buffer, SIZE, " File format: %d\n", mOutputFormat); |
michael@0 | 1572 | result.append(buffer); |
michael@0 | 1573 | snprintf(buffer, SIZE, " Max file size (bytes): %lld\n", mMaxFileSizeBytes); |
michael@0 | 1574 | result.append(buffer); |
michael@0 | 1575 | snprintf(buffer, SIZE, " Max file duration (us): %lld\n", mMaxFileDurationUs); |
michael@0 | 1576 | result.append(buffer); |
michael@0 | 1577 | snprintf(buffer, SIZE, " File offset length (bits): %d\n", mUse64BitFileOffset? 64: 32); |
michael@0 | 1578 | result.append(buffer); |
michael@0 | 1579 | snprintf(buffer, SIZE, " Interleave duration (us): %d\n", mInterleaveDurationUs); |
michael@0 | 1580 | result.append(buffer); |
michael@0 | 1581 | snprintf(buffer, SIZE, " Progress notification: %lld us\n", mTrackEveryTimeDurationUs); |
michael@0 | 1582 | result.append(buffer); |
michael@0 | 1583 | snprintf(buffer, SIZE, " Audio\n"); |
michael@0 | 1584 | result.append(buffer); |
michael@0 | 1585 | snprintf(buffer, SIZE, " Source: %d\n", mAudioSource); |
michael@0 | 1586 | result.append(buffer); |
michael@0 | 1587 | snprintf(buffer, SIZE, " Encoder: %d\n", mAudioEncoder); |
michael@0 | 1588 | result.append(buffer); |
michael@0 | 1589 | snprintf(buffer, SIZE, " Bit rate (bps): %d\n", mAudioBitRate); |
michael@0 | 1590 | result.append(buffer); |
michael@0 | 1591 | snprintf(buffer, SIZE, " Sampling rate (hz): %d\n", mSampleRate); |
michael@0 | 1592 | result.append(buffer); |
michael@0 | 1593 | snprintf(buffer, SIZE, " Number of channels: %d\n", mAudioChannels); |
michael@0 | 1594 | result.append(buffer); |
michael@0 | 1595 | snprintf(buffer, SIZE, " Max amplitude: %d\n", mAudioSourceNode == 0? 0: mAudioSourceNode->getMaxAmplitude()); |
michael@0 | 1596 | result.append(buffer); |
michael@0 | 1597 | snprintf(buffer, SIZE, " Video\n"); |
michael@0 | 1598 | result.append(buffer); |
michael@0 | 1599 | snprintf(buffer, SIZE, " Source: %d\n", mVideoSource); |
michael@0 | 1600 | result.append(buffer); |
michael@0 | 1601 | snprintf(buffer, SIZE, " Camera Id: %d\n", mCameraId); |
michael@0 | 1602 | result.append(buffer); |
michael@0 | 1603 | snprintf(buffer, SIZE, " Camera object address: %p\n", mCameraHw.get()); |
michael@0 | 1604 | result.append(buffer); |
michael@0 | 1605 | snprintf(buffer, SIZE, " Start time offset (ms): %d\n", mStartTimeOffsetMs); |
michael@0 | 1606 | result.append(buffer); |
michael@0 | 1607 | snprintf(buffer, SIZE, " Encoder: %d\n", mVideoEncoder); |
michael@0 | 1608 | result.append(buffer); |
michael@0 | 1609 | snprintf(buffer, SIZE, " Encoder profile: %d\n", mVideoEncoderProfile); |
michael@0 | 1610 | result.append(buffer); |
michael@0 | 1611 | snprintf(buffer, SIZE, " Encoder level: %d\n", mVideoEncoderLevel); |
michael@0 | 1612 | result.append(buffer); |
michael@0 | 1613 | snprintf(buffer, SIZE, " I frames interval (s): %d\n", mIFramesIntervalSec); |
michael@0 | 1614 | result.append(buffer); |
michael@0 | 1615 | snprintf(buffer, SIZE, " Frame size (pixels): %dx%d\n", mVideoWidth, mVideoHeight); |
michael@0 | 1616 | result.append(buffer); |
michael@0 | 1617 | snprintf(buffer, SIZE, " Frame rate (fps): %d\n", mFrameRate); |
michael@0 | 1618 | result.append(buffer); |
michael@0 | 1619 | snprintf(buffer, SIZE, " Bit rate (bps): %d\n", mVideoBitRate); |
michael@0 | 1620 | result.append(buffer); |
michael@0 | 1621 | ::write(fd, result.string(), result.size()); |
michael@0 | 1622 | return OK; |
michael@0 | 1623 | } |
michael@0 | 1624 | |
michael@0 | 1625 | status_t GonkRecorder::setCamera(const sp<GonkCameraHardware>& aCameraHw) { |
michael@0 | 1626 | mCameraHw = aCameraHw; |
michael@0 | 1627 | return OK; |
michael@0 | 1628 | } |
michael@0 | 1629 | |
michael@0 | 1630 | } // namespace android |