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