StagefrightRecorder.cpp revision 5b6edb79827a910d8e677e35e77bc12fdc7772b9
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 <utils/Log.h> 20 21#include "StagefrightRecorder.h" 22 23#include <binder/IPCThreadState.h> 24#include <media/stagefright/AudioSource.h> 25#include <media/stagefright/AMRWriter.h> 26#include <media/stagefright/CameraSource.h> 27#include <media/stagefright/MPEG2TSWriter.h> 28#include <media/stagefright/MPEG4Writer.h> 29#include <media/stagefright/MediaDebug.h> 30#include <media/stagefright/MediaDefs.h> 31#include <media/stagefright/MetaData.h> 32#include <media/stagefright/OMXClient.h> 33#include <media/stagefright/OMXCodec.h> 34#include <media/MediaProfiles.h> 35#include <camera/ICamera.h> 36#include <camera/Camera.h> 37#include <camera/CameraParameters.h> 38#include <surfaceflinger/ISurface.h> 39#include <utils/Errors.h> 40#include <sys/types.h> 41#include <unistd.h> 42#include <ctype.h> 43 44#include "ARTPWriter.h" 45 46namespace android { 47 48StagefrightRecorder::StagefrightRecorder() 49 : mWriter(NULL), 50 mOutputFd(-1) { 51 52 LOGV("Constructor"); 53 reset(); 54} 55 56StagefrightRecorder::~StagefrightRecorder() { 57 LOGV("Destructor"); 58 stop(); 59} 60 61status_t StagefrightRecorder::init() { 62 LOGV("init"); 63 return OK; 64} 65 66status_t StagefrightRecorder::setAudioSource(audio_source as) { 67 LOGV("setAudioSource: %d", as); 68 if (as < AUDIO_SOURCE_DEFAULT || 69 as >= AUDIO_SOURCE_LIST_END) { 70 LOGE("Invalid audio source: %d", as); 71 return BAD_VALUE; 72 } 73 74 if (as == AUDIO_SOURCE_DEFAULT) { 75 mAudioSource = AUDIO_SOURCE_MIC; 76 } else { 77 mAudioSource = as; 78 } 79 80 return OK; 81} 82 83status_t StagefrightRecorder::setVideoSource(video_source vs) { 84 LOGV("setVideoSource: %d", vs); 85 if (vs < VIDEO_SOURCE_DEFAULT || 86 vs >= VIDEO_SOURCE_LIST_END) { 87 LOGE("Invalid video source: %d", vs); 88 return BAD_VALUE; 89 } 90 91 if (vs == VIDEO_SOURCE_DEFAULT) { 92 mVideoSource = VIDEO_SOURCE_CAMERA; 93 } else { 94 mVideoSource = vs; 95 } 96 97 return OK; 98} 99 100status_t StagefrightRecorder::setOutputFormat(output_format of) { 101 LOGV("setOutputFormat: %d", of); 102 if (of < OUTPUT_FORMAT_DEFAULT || 103 of >= OUTPUT_FORMAT_LIST_END) { 104 LOGE("Invalid output format: %d", of); 105 return BAD_VALUE; 106 } 107 108 if (of == OUTPUT_FORMAT_DEFAULT) { 109 mOutputFormat = OUTPUT_FORMAT_THREE_GPP; 110 } else { 111 mOutputFormat = of; 112 } 113 114 return OK; 115} 116 117status_t StagefrightRecorder::setAudioEncoder(audio_encoder ae) { 118 LOGV("setAudioEncoder: %d", ae); 119 if (ae < AUDIO_ENCODER_DEFAULT || 120 ae >= AUDIO_ENCODER_LIST_END) { 121 LOGE("Invalid audio encoder: %d", ae); 122 return BAD_VALUE; 123 } 124 125 if (ae == AUDIO_ENCODER_DEFAULT) { 126 mAudioEncoder = AUDIO_ENCODER_AMR_NB; 127 } else { 128 mAudioEncoder = ae; 129 } 130 131 return OK; 132} 133 134status_t StagefrightRecorder::setVideoEncoder(video_encoder ve) { 135 LOGV("setVideoEncoder: %d", ve); 136 if (ve < VIDEO_ENCODER_DEFAULT || 137 ve >= VIDEO_ENCODER_LIST_END) { 138 LOGE("Invalid video encoder: %d", ve); 139 return BAD_VALUE; 140 } 141 142 if (ve == VIDEO_ENCODER_DEFAULT) { 143 mVideoEncoder = VIDEO_ENCODER_H263; 144 } else { 145 mVideoEncoder = ve; 146 } 147 148 return OK; 149} 150 151status_t StagefrightRecorder::setVideoSize(int width, int height) { 152 LOGV("setVideoSize: %dx%d", width, height); 153 if (width <= 0 || height <= 0) { 154 LOGE("Invalid video size: %dx%d", width, height); 155 return BAD_VALUE; 156 } 157 158 // Additional check on the dimension will be performed later 159 mVideoWidth = width; 160 mVideoHeight = height; 161 162 return OK; 163} 164 165status_t StagefrightRecorder::setVideoFrameRate(int frames_per_second) { 166 LOGV("setVideoFrameRate: %d", frames_per_second); 167 if (frames_per_second <= 0 || frames_per_second > 30) { 168 LOGE("Invalid video frame rate: %d", frames_per_second); 169 return BAD_VALUE; 170 } 171 172 // Additional check on the frame rate will be performed later 173 mFrameRate = frames_per_second; 174 175 return OK; 176} 177 178status_t StagefrightRecorder::setCamera(const sp<ICamera> &camera) { 179 LOGV("setCamera"); 180 if (camera == 0) { 181 LOGE("camera is NULL"); 182 return BAD_VALUE; 183 } 184 185 int64_t token = IPCThreadState::self()->clearCallingIdentity(); 186 mFlags &= ~FLAGS_HOT_CAMERA; 187 mCamera = Camera::create(camera); 188 if (mCamera == 0) { 189 LOGE("Unable to connect to camera"); 190 IPCThreadState::self()->restoreCallingIdentity(token); 191 return -EBUSY; 192 } 193 194 LOGV("Connected to camera"); 195 if (mCamera->previewEnabled()) { 196 LOGV("camera is hot"); 197 mFlags |= FLAGS_HOT_CAMERA; 198 } 199 IPCThreadState::self()->restoreCallingIdentity(token); 200 201 return OK; 202} 203 204status_t StagefrightRecorder::setPreviewSurface(const sp<ISurface> &surface) { 205 LOGV("setPreviewSurface: %p", surface.get()); 206 mPreviewSurface = surface; 207 208 return OK; 209} 210 211status_t StagefrightRecorder::setOutputFile(const char *path) { 212 LOGE("setOutputFile(const char*) must not be called"); 213 // We don't actually support this at all, as the media_server process 214 // no longer has permissions to create files. 215 216 return -EPERM; 217} 218 219status_t StagefrightRecorder::setOutputFile(int fd, int64_t offset, int64_t length) { 220 LOGV("setOutputFile: %d, %lld, %lld", fd, offset, length); 221 // These don't make any sense, do they? 222 CHECK_EQ(offset, 0); 223 CHECK_EQ(length, 0); 224 225 if (fd < 0) { 226 LOGE("Invalid file descriptor: %d", fd); 227 return -EBADF; 228 } 229 230 if (mOutputFd >= 0) { 231 ::close(mOutputFd); 232 } 233 mOutputFd = dup(fd); 234 235 return OK; 236} 237 238// Attempt to parse an int64 literal optionally surrounded by whitespace, 239// returns true on success, false otherwise. 240static bool safe_strtoi64(const char *s, int64_t *val) { 241 char *end; 242 *val = strtoll(s, &end, 10); 243 244 if (end == s || errno == ERANGE) { 245 return false; 246 } 247 248 // Skip trailing whitespace 249 while (isspace(*end)) { 250 ++end; 251 } 252 253 // For a successful return, the string must contain nothing but a valid 254 // int64 literal optionally surrounded by whitespace. 255 256 return *end == '\0'; 257} 258 259// Return true if the value is in [0, 0x007FFFFFFF] 260static bool safe_strtoi32(const char *s, int32_t *val) { 261 int64_t temp; 262 if (safe_strtoi64(s, &temp)) { 263 if (temp >= 0 && temp <= 0x007FFFFFFF) { 264 *val = static_cast<int32_t>(temp); 265 return true; 266 } 267 } 268 return false; 269} 270 271// Trim both leading and trailing whitespace from the given string. 272static void TrimString(String8 *s) { 273 size_t num_bytes = s->bytes(); 274 const char *data = s->string(); 275 276 size_t leading_space = 0; 277 while (leading_space < num_bytes && isspace(data[leading_space])) { 278 ++leading_space; 279 } 280 281 size_t i = num_bytes; 282 while (i > leading_space && isspace(data[i - 1])) { 283 --i; 284 } 285 286 s->setTo(String8(&data[leading_space], i - leading_space)); 287} 288 289status_t StagefrightRecorder::setParamAudioSamplingRate(int32_t sampleRate) { 290 LOGV("setParamAudioSamplingRate: %d", sampleRate); 291 if (sampleRate <= 0) { 292 LOGE("Invalid audio sampling rate: %d", sampleRate); 293 return BAD_VALUE; 294 } 295 296 // Additional check on the sample rate will be performed later. 297 mSampleRate = sampleRate; 298 return OK; 299} 300 301status_t StagefrightRecorder::setParamAudioNumberOfChannels(int32_t channels) { 302 LOGV("setParamAudioNumberOfChannels: %d", channels); 303 if (channels <= 0 || channels >= 3) { 304 LOGE("Invalid number of audio channels: %d", channels); 305 return BAD_VALUE; 306 } 307 308 // Additional check on the number of channels will be performed later. 309 mAudioChannels = channels; 310 return OK; 311} 312 313status_t StagefrightRecorder::setParamAudioEncodingBitRate(int32_t bitRate) { 314 LOGV("setParamAudioEncodingBitRate: %d", bitRate); 315 if (bitRate <= 0) { 316 LOGE("Invalid audio encoding bit rate: %d", bitRate); 317 return BAD_VALUE; 318 } 319 320 // The target bit rate may not be exactly the same as the requested. 321 // It depends on many factors, such as rate control, and the bit rate 322 // range that a specific encoder supports. The mismatch between the 323 // the target and requested bit rate will NOT be treated as an error. 324 mAudioBitRate = bitRate; 325 return OK; 326} 327 328status_t StagefrightRecorder::setParamVideoEncodingBitRate(int32_t bitRate) { 329 LOGV("setParamVideoEncodingBitRate: %d", bitRate); 330 if (bitRate <= 0) { 331 LOGE("Invalid video encoding bit rate: %d", bitRate); 332 return BAD_VALUE; 333 } 334 335 // The target bit rate may not be exactly the same as the requested. 336 // It depends on many factors, such as rate control, and the bit rate 337 // range that a specific encoder supports. The mismatch between the 338 // the target and requested bit rate will NOT be treated as an error. 339 mVideoBitRate = bitRate; 340 return OK; 341} 342 343status_t StagefrightRecorder::setParamMaxFileDurationUs(int64_t timeUs) { 344 LOGV("setParamMaxFileDurationUs: %lld us", timeUs); 345 if (timeUs <= 0) { 346 LOGW("Max file duration is not positive: %lld us. Disabling duration limit.", timeUs); 347 timeUs = 0; // Disable the duration limit for zero or negative values. 348 } else if (timeUs <= 100000LL) { // XXX: 100 milli-seconds 349 LOGE("Max file duration is too short: %lld us", timeUs); 350 return BAD_VALUE; 351 } 352 353 mMaxFileDurationUs = timeUs; 354 return OK; 355} 356 357status_t StagefrightRecorder::setParamMaxFileSizeBytes(int64_t bytes) { 358 LOGV("setParamMaxFileSizeBytes: %lld bytes", bytes); 359 if (bytes <= 1024) { // XXX: 1 kB 360 LOGE("Max file size is too small: %lld bytes", bytes); 361 return BAD_VALUE; 362 } 363 mMaxFileSizeBytes = bytes; 364 return OK; 365} 366 367status_t StagefrightRecorder::setParamInterleaveDuration(int32_t durationUs) { 368 LOGV("setParamInterleaveDuration: %d", durationUs); 369 if (durationUs <= 500000) { // 500 ms 370 // If interleave duration is too small, it is very inefficient to do 371 // interleaving since the metadata overhead will count for a significant 372 // portion of the saved contents 373 LOGE("Audio/video interleave duration is too small: %d us", durationUs); 374 return BAD_VALUE; 375 } else if (durationUs >= 10000000) { // 10 seconds 376 // If interleaving duration is too large, it can cause the recording 377 // session to use too much memory since we have to save the output 378 // data before we write them out 379 LOGE("Audio/video interleave duration is too large: %d us", durationUs); 380 return BAD_VALUE; 381 } 382 mInterleaveDurationUs = durationUs; 383 return OK; 384} 385 386// If seconds < 0, only the first frame is I frame, and rest are all P frames 387// If seconds == 0, all frames are encoded as I frames. No P frames 388// If seconds > 0, it is the time spacing (seconds) between 2 neighboring I frames 389status_t StagefrightRecorder::setParamVideoIFramesInterval(int32_t seconds) { 390 LOGV("setParamVideoIFramesInterval: %d seconds", seconds); 391 mIFramesIntervalSec = seconds; 392 return OK; 393} 394 395status_t StagefrightRecorder::setParam64BitFileOffset(bool use64Bit) { 396 LOGV("setParam64BitFileOffset: %s", 397 use64Bit? "use 64 bit file offset": "use 32 bit file offset"); 398 mUse64BitFileOffset = use64Bit; 399 return OK; 400} 401 402status_t StagefrightRecorder::setParamVideoCameraId(int32_t cameraId) { 403 LOGV("setParamVideoCameraId: %d", cameraId); 404 if (cameraId < 0) { 405 return BAD_VALUE; 406 } 407 mCameraId = cameraId; 408 return OK; 409} 410 411status_t StagefrightRecorder::setParamTrackTimeStatus(int64_t timeDurationUs) { 412 LOGV("setParamTrackTimeStatus: %lld", timeDurationUs); 413 if (timeDurationUs < 20000) { // Infeasible if shorter than 20 ms? 414 LOGE("Tracking time duration too short: %lld us", timeDurationUs); 415 return BAD_VALUE; 416 } 417 mTrackEveryTimeDurationUs = timeDurationUs; 418 return OK; 419} 420 421status_t StagefrightRecorder::setParamVideoEncoderProfile(int32_t profile) { 422 LOGV("setParamVideoEncoderProfile: %d", profile); 423 424 // Additional check will be done later when we load the encoder. 425 // For now, we are accepting values defined in OpenMAX IL. 426 mVideoEncoderProfile = profile; 427 return OK; 428} 429 430status_t StagefrightRecorder::setParamVideoEncoderLevel(int32_t level) { 431 LOGV("setParamVideoEncoderLevel: %d", level); 432 433 // Additional check will be done later when we load the encoder. 434 // For now, we are accepting values defined in OpenMAX IL. 435 mVideoEncoderLevel = level; 436 return OK; 437} 438 439status_t StagefrightRecorder::setParamMovieTimeScale(int32_t timeScale) { 440 LOGV("setParamMovieTimeScale: %d", timeScale); 441 442 // The range is set to be the same as the audio's time scale range 443 // since audio's time scale has a wider range. 444 if (timeScale < 600 || timeScale > 96000) { 445 LOGE("Time scale (%d) for movie is out of range [600, 96000]", timeScale); 446 return BAD_VALUE; 447 } 448 mMovieTimeScale = timeScale; 449 return OK; 450} 451 452status_t StagefrightRecorder::setParamVideoTimeScale(int32_t timeScale) { 453 LOGV("setParamVideoTimeScale: %d", timeScale); 454 455 // 60000 is chosen to make sure that each video frame from a 60-fps 456 // video has 1000 ticks. 457 if (timeScale < 600 || timeScale > 60000) { 458 LOGE("Time scale (%d) for video is out of range [600, 60000]", timeScale); 459 return BAD_VALUE; 460 } 461 mVideoTimeScale = timeScale; 462 return OK; 463} 464 465status_t StagefrightRecorder::setParamVideoRotation(int32_t degreesClockwise) { 466 LOGV("setParamVideoRotation: %d", degreesClockwise); 467 468 if (degreesClockwise < 0 || degreesClockwise % 90 != 0) { 469 LOGE("Unsupported video rotation angle: %d", degreesClockwise); 470 return BAD_VALUE; 471 } 472 mClockwiseRotationDegrees = degreesClockwise; 473 return OK; 474} 475 476status_t StagefrightRecorder::setParamAudioTimeScale(int32_t timeScale) { 477 LOGV("setParamAudioTimeScale: %d", timeScale); 478 479 // 96000 Hz is the highest sampling rate support in AAC. 480 if (timeScale < 600 || timeScale > 96000) { 481 LOGE("Time scale (%d) for audio is out of range [600, 96000]", timeScale); 482 return BAD_VALUE; 483 } 484 mAudioTimeScale = timeScale; 485 return OK; 486} 487 488status_t StagefrightRecorder::setParameter( 489 const String8 &key, const String8 &value) { 490 LOGV("setParameter: key (%s) => value (%s)", key.string(), value.string()); 491 if (key == "max-duration") { 492 int64_t max_duration_ms; 493 if (safe_strtoi64(value.string(), &max_duration_ms)) { 494 return setParamMaxFileDurationUs(1000LL * max_duration_ms); 495 } 496 } else if (key == "max-filesize") { 497 int64_t max_filesize_bytes; 498 if (safe_strtoi64(value.string(), &max_filesize_bytes)) { 499 return setParamMaxFileSizeBytes(max_filesize_bytes); 500 } 501 } else if (key == "interleave-duration-us") { 502 int32_t durationUs; 503 if (safe_strtoi32(value.string(), &durationUs)) { 504 return setParamInterleaveDuration(durationUs); 505 } 506 } else if (key == "param-movie-time-scale") { 507 int32_t timeScale; 508 if (safe_strtoi32(value.string(), &timeScale)) { 509 return setParamMovieTimeScale(timeScale); 510 } 511 } else if (key == "param-use-64bit-offset") { 512 int32_t use64BitOffset; 513 if (safe_strtoi32(value.string(), &use64BitOffset)) { 514 return setParam64BitFileOffset(use64BitOffset != 0); 515 } 516 } else if (key == "param-track-time-status") { 517 int64_t timeDurationUs; 518 if (safe_strtoi64(value.string(), &timeDurationUs)) { 519 return setParamTrackTimeStatus(timeDurationUs); 520 } 521 } else if (key == "audio-param-sampling-rate") { 522 int32_t sampling_rate; 523 if (safe_strtoi32(value.string(), &sampling_rate)) { 524 return setParamAudioSamplingRate(sampling_rate); 525 } 526 } else if (key == "audio-param-number-of-channels") { 527 int32_t number_of_channels; 528 if (safe_strtoi32(value.string(), &number_of_channels)) { 529 return setParamAudioNumberOfChannels(number_of_channels); 530 } 531 } else if (key == "audio-param-encoding-bitrate") { 532 int32_t audio_bitrate; 533 if (safe_strtoi32(value.string(), &audio_bitrate)) { 534 return setParamAudioEncodingBitRate(audio_bitrate); 535 } 536 } else if (key == "audio-param-time-scale") { 537 int32_t timeScale; 538 if (safe_strtoi32(value.string(), &timeScale)) { 539 return setParamAudioTimeScale(timeScale); 540 } 541 } else if (key == "video-param-encoding-bitrate") { 542 int32_t video_bitrate; 543 if (safe_strtoi32(value.string(), &video_bitrate)) { 544 return setParamVideoEncodingBitRate(video_bitrate); 545 } 546 } else if (key == "video-param-i-frames-interval") { 547 int32_t seconds; 548 if (safe_strtoi32(value.string(), &seconds)) { 549 return setParamVideoIFramesInterval(seconds); 550 } 551 } else if (key == "video-param-encoder-profile") { 552 int32_t profile; 553 if (safe_strtoi32(value.string(), &profile)) { 554 return setParamVideoEncoderProfile(profile); 555 } 556 } else if (key == "video-param-encoder-level") { 557 int32_t level; 558 if (safe_strtoi32(value.string(), &level)) { 559 return setParamVideoEncoderLevel(level); 560 } 561 } else if (key == "video-param-camera-id") { 562 int32_t cameraId; 563 if (safe_strtoi32(value.string(), &cameraId)) { 564 return setParamVideoCameraId(cameraId); 565 } 566 } else if (key == "video-param-time-scale") { 567 int32_t timeScale; 568 if (safe_strtoi32(value.string(), &timeScale)) { 569 return setParamVideoTimeScale(timeScale); 570 } 571 } else if (key == "video-param-clockwise-rotation-degrees") { 572 int32_t degrees; 573 if (safe_strtoi32(value.string(), °rees)) { 574 return setParamVideoRotation(degrees); 575 } 576 } else { 577 LOGE("setParameter: failed to find key %s", key.string()); 578 } 579 return BAD_VALUE; 580} 581 582status_t StagefrightRecorder::setParameters(const String8 ¶ms) { 583 LOGV("setParameters: %s", params.string()); 584 const char *cparams = params.string(); 585 const char *key_start = cparams; 586 for (;;) { 587 const char *equal_pos = strchr(key_start, '='); 588 if (equal_pos == NULL) { 589 LOGE("Parameters %s miss a value", cparams); 590 return BAD_VALUE; 591 } 592 String8 key(key_start, equal_pos - key_start); 593 TrimString(&key); 594 if (key.length() == 0) { 595 LOGE("Parameters %s contains an empty key", cparams); 596 return BAD_VALUE; 597 } 598 const char *value_start = equal_pos + 1; 599 const char *semicolon_pos = strchr(value_start, ';'); 600 String8 value; 601 if (semicolon_pos == NULL) { 602 value.setTo(value_start); 603 } else { 604 value.setTo(value_start, semicolon_pos - value_start); 605 } 606 if (setParameter(key, value) != OK) { 607 return BAD_VALUE; 608 } 609 if (semicolon_pos == NULL) { 610 break; // Reaches the end 611 } 612 key_start = semicolon_pos + 1; 613 } 614 return OK; 615} 616 617status_t StagefrightRecorder::setListener(const sp<IMediaRecorderClient> &listener) { 618 mListener = listener; 619 620 return OK; 621} 622 623status_t StagefrightRecorder::prepare() { 624 return OK; 625} 626 627status_t StagefrightRecorder::start() { 628 CHECK(mOutputFd >= 0); 629 630 if (mWriter != NULL) { 631 LOGE("File writer is not avaialble"); 632 return UNKNOWN_ERROR; 633 } 634 635 switch (mOutputFormat) { 636 case OUTPUT_FORMAT_DEFAULT: 637 case OUTPUT_FORMAT_THREE_GPP: 638 case OUTPUT_FORMAT_MPEG_4: 639 return startMPEG4Recording(); 640 641 case OUTPUT_FORMAT_AMR_NB: 642 case OUTPUT_FORMAT_AMR_WB: 643 return startAMRRecording(); 644 645 case OUTPUT_FORMAT_AAC_ADIF: 646 case OUTPUT_FORMAT_AAC_ADTS: 647 return startAACRecording(); 648 649 case OUTPUT_FORMAT_RTP_AVP: 650 return startRTPRecording(); 651 652 case OUTPUT_FORMAT_MPEG2TS: 653 return startMPEG2TSRecording(); 654 655 default: 656 LOGE("Unsupported output file format: %d", mOutputFormat); 657 return UNKNOWN_ERROR; 658 } 659} 660 661sp<MediaSource> StagefrightRecorder::createAudioSource() { 662 sp<AudioSource> audioSource = 663 new AudioSource( 664 mAudioSource, 665 mSampleRate, 666 mAudioChannels); 667 668 status_t err = audioSource->initCheck(); 669 670 if (err != OK) { 671 LOGE("audio source is not initialized"); 672 return NULL; 673 } 674 675 sp<MetaData> encMeta = new MetaData; 676 const char *mime; 677 switch (mAudioEncoder) { 678 case AUDIO_ENCODER_AMR_NB: 679 case AUDIO_ENCODER_DEFAULT: 680 mime = MEDIA_MIMETYPE_AUDIO_AMR_NB; 681 break; 682 case AUDIO_ENCODER_AMR_WB: 683 mime = MEDIA_MIMETYPE_AUDIO_AMR_WB; 684 break; 685 case AUDIO_ENCODER_AAC: 686 mime = MEDIA_MIMETYPE_AUDIO_AAC; 687 break; 688 default: 689 LOGE("Unknown audio encoder: %d", mAudioEncoder); 690 return NULL; 691 } 692 encMeta->setCString(kKeyMIMEType, mime); 693 694 int32_t maxInputSize; 695 CHECK(audioSource->getFormat()->findInt32( 696 kKeyMaxInputSize, &maxInputSize)); 697 698 encMeta->setInt32(kKeyMaxInputSize, maxInputSize); 699 encMeta->setInt32(kKeyChannelCount, mAudioChannels); 700 encMeta->setInt32(kKeySampleRate, mSampleRate); 701 encMeta->setInt32(kKeyBitRate, mAudioBitRate); 702 if (mAudioTimeScale > 0) { 703 encMeta->setInt32(kKeyTimeScale, mAudioTimeScale); 704 } 705 706 OMXClient client; 707 CHECK_EQ(client.connect(), OK); 708 709 sp<MediaSource> audioEncoder = 710 OMXCodec::Create(client.interface(), encMeta, 711 true /* createEncoder */, audioSource); 712 mAudioSourceNode = audioSource; 713 714 return audioEncoder; 715} 716 717status_t StagefrightRecorder::startAACRecording() { 718 CHECK(mOutputFormat == OUTPUT_FORMAT_AAC_ADIF || 719 mOutputFormat == OUTPUT_FORMAT_AAC_ADTS); 720 721 CHECK(mAudioEncoder == AUDIO_ENCODER_AAC); 722 CHECK(mAudioSource != AUDIO_SOURCE_LIST_END); 723 724 CHECK(0 == "AACWriter is not implemented yet"); 725 726 return OK; 727} 728 729status_t StagefrightRecorder::startAMRRecording() { 730 CHECK(mOutputFormat == OUTPUT_FORMAT_AMR_NB || 731 mOutputFormat == OUTPUT_FORMAT_AMR_WB); 732 733 if (mOutputFormat == OUTPUT_FORMAT_AMR_NB) { 734 if (mAudioEncoder != AUDIO_ENCODER_DEFAULT && 735 mAudioEncoder != AUDIO_ENCODER_AMR_NB) { 736 LOGE("Invalid encoder %d used for AMRNB recording", 737 mAudioEncoder); 738 return BAD_VALUE; 739 } 740 if (mSampleRate != 8000) { 741 LOGE("Invalid sampling rate %d used for AMRNB recording", 742 mSampleRate); 743 return BAD_VALUE; 744 } 745 } else { // mOutputFormat must be OUTPUT_FORMAT_AMR_WB 746 if (mAudioEncoder != AUDIO_ENCODER_AMR_WB) { 747 LOGE("Invlaid encoder %d used for AMRWB recording", 748 mAudioEncoder); 749 return BAD_VALUE; 750 } 751 if (mSampleRate != 16000) { 752 LOGE("Invalid sample rate %d used for AMRWB recording", 753 mSampleRate); 754 return BAD_VALUE; 755 } 756 } 757 if (mAudioChannels != 1) { 758 LOGE("Invalid number of audio channels %d used for amr recording", 759 mAudioChannels); 760 return BAD_VALUE; 761 } 762 763 if (mAudioSource >= AUDIO_SOURCE_LIST_END) { 764 LOGE("Invalid audio source: %d", mAudioSource); 765 return BAD_VALUE; 766 } 767 768 sp<MediaSource> audioEncoder = createAudioSource(); 769 770 if (audioEncoder == NULL) { 771 return UNKNOWN_ERROR; 772 } 773 774 mWriter = new AMRWriter(dup(mOutputFd)); 775 mWriter->addSource(audioEncoder); 776 777 if (mMaxFileDurationUs != 0) { 778 mWriter->setMaxFileDuration(mMaxFileDurationUs); 779 } 780 if (mMaxFileSizeBytes != 0) { 781 mWriter->setMaxFileSize(mMaxFileSizeBytes); 782 } 783 mWriter->setListener(mListener); 784 mWriter->start(); 785 786 return OK; 787} 788 789status_t StagefrightRecorder::startRTPRecording() { 790 CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_RTP_AVP); 791 792 if ((mAudioSource != AUDIO_SOURCE_LIST_END 793 && mVideoSource != VIDEO_SOURCE_LIST_END) 794 || (mAudioSource == AUDIO_SOURCE_LIST_END 795 && mVideoSource == VIDEO_SOURCE_LIST_END)) { 796 // Must have exactly one source. 797 return BAD_VALUE; 798 } 799 800 if (mOutputFd < 0) { 801 return BAD_VALUE; 802 } 803 804 sp<MediaSource> source; 805 806 if (mAudioSource != AUDIO_SOURCE_LIST_END) { 807 source = createAudioSource(); 808 } else { 809 status_t err = setupVideoEncoder(&source); 810 if (err != OK) { 811 return err; 812 } 813 } 814 815 mWriter = new ARTPWriter(dup(mOutputFd)); 816 mWriter->addSource(source); 817 mWriter->setListener(mListener); 818 819 return mWriter->start(); 820} 821 822status_t StagefrightRecorder::startMPEG2TSRecording() { 823 CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_MPEG2TS); 824 825 sp<MediaWriter> writer = new MPEG2TSWriter(dup(mOutputFd)); 826 827 if (mAudioSource != AUDIO_SOURCE_LIST_END) { 828 if (mAudioEncoder != AUDIO_ENCODER_AAC) { 829 return ERROR_UNSUPPORTED; 830 } 831 832 status_t err = setupAudioEncoder(writer); 833 834 if (err != OK) { 835 return err; 836 } 837 } 838 839 if (mVideoSource == VIDEO_SOURCE_DEFAULT 840 || mVideoSource == VIDEO_SOURCE_CAMERA) { 841 if (mVideoEncoder != VIDEO_ENCODER_H264) { 842 return ERROR_UNSUPPORTED; 843 } 844 845 sp<MediaSource> encoder; 846 status_t err = setupVideoEncoder(&encoder); 847 848 if (err != OK) { 849 return err; 850 } 851 852 writer->addSource(encoder); 853 } 854 855 if (mMaxFileDurationUs != 0) { 856 writer->setMaxFileDuration(mMaxFileDurationUs); 857 } 858 859 if (mMaxFileSizeBytes != 0) { 860 writer->setMaxFileSize(mMaxFileSizeBytes); 861 } 862 863 mWriter = writer; 864 865 return mWriter->start(); 866} 867 868void StagefrightRecorder::clipVideoFrameRate() { 869 LOGV("clipVideoFrameRate: encoder %d", mVideoEncoder); 870 int minFrameRate = mEncoderProfiles->getVideoEncoderParamByName( 871 "enc.vid.fps.min", mVideoEncoder); 872 int maxFrameRate = mEncoderProfiles->getVideoEncoderParamByName( 873 "enc.vid.fps.max", mVideoEncoder); 874 if (mFrameRate < minFrameRate) { 875 LOGW("Intended video encoding frame rate (%d fps) is too small" 876 " and will be set to (%d fps)", mFrameRate, minFrameRate); 877 mFrameRate = minFrameRate; 878 } else if (mFrameRate > maxFrameRate) { 879 LOGW("Intended video encoding frame rate (%d fps) is too large" 880 " and will be set to (%d fps)", mFrameRate, maxFrameRate); 881 mFrameRate = maxFrameRate; 882 } 883} 884 885void StagefrightRecorder::clipVideoBitRate() { 886 LOGV("clipVideoBitRate: encoder %d", mVideoEncoder); 887 int minBitRate = mEncoderProfiles->getVideoEncoderParamByName( 888 "enc.vid.bps.min", mVideoEncoder); 889 int maxBitRate = mEncoderProfiles->getVideoEncoderParamByName( 890 "enc.vid.bps.max", mVideoEncoder); 891 if (mVideoBitRate < minBitRate) { 892 LOGW("Intended video encoding bit rate (%d bps) is too small" 893 " and will be set to (%d bps)", mVideoBitRate, minBitRate); 894 mVideoBitRate = minBitRate; 895 } else if (mVideoBitRate > maxBitRate) { 896 LOGW("Intended video encoding bit rate (%d bps) is too large" 897 " and will be set to (%d bps)", mVideoBitRate, maxBitRate); 898 mVideoBitRate = maxBitRate; 899 } 900} 901 902void StagefrightRecorder::clipVideoFrameWidth() { 903 LOGV("clipVideoFrameWidth: encoder %d", mVideoEncoder); 904 int minFrameWidth = mEncoderProfiles->getVideoEncoderParamByName( 905 "enc.vid.width.min", mVideoEncoder); 906 int maxFrameWidth = mEncoderProfiles->getVideoEncoderParamByName( 907 "enc.vid.width.max", mVideoEncoder); 908 if (mVideoWidth < minFrameWidth) { 909 LOGW("Intended video encoding frame width (%d) is too small" 910 " and will be set to (%d)", mVideoWidth, minFrameWidth); 911 mVideoWidth = minFrameWidth; 912 } else if (mVideoWidth > maxFrameWidth) { 913 LOGW("Intended video encoding frame width (%d) is too large" 914 " and will be set to (%d)", mVideoWidth, maxFrameWidth); 915 mVideoWidth = maxFrameWidth; 916 } 917} 918 919status_t StagefrightRecorder::setupCameraSource() { 920 clipVideoBitRate(); 921 clipVideoFrameRate(); 922 clipVideoFrameWidth(); 923 clipVideoFrameHeight(); 924 925 int64_t token = IPCThreadState::self()->clearCallingIdentity(); 926 if (mCamera == 0) { 927 mCamera = Camera::connect(mCameraId); 928 if (mCamera == 0) { 929 LOGE("Camera connection could not be established."); 930 return -EBUSY; 931 } 932 mFlags &= ~FLAGS_HOT_CAMERA; 933 mCamera->lock(); 934 } 935 936 // Set the actual video recording frame size 937 CameraParameters params(mCamera->getParameters()); 938 params.setPreviewSize(mVideoWidth, mVideoHeight); 939 params.setPreviewFrameRate(mFrameRate); 940 { 941 // Optional feature: setting the rotation degrees. 942 char degrees[4]; 943 snprintf(degrees, 4, "%d", mClockwiseRotationDegrees); 944 params.set(CameraParameters::KEY_ROTATION, degrees); 945 } 946 String8 s = params.flatten(); 947 if (OK != mCamera->setParameters(s)) { 948 LOGE("Could not change settings." 949 " Someone else is using camera %d?", mCameraId); 950 return -EBUSY; 951 } 952 CameraParameters newCameraParams(mCamera->getParameters()); 953 954 // Check on video frame size 955 int frameWidth = 0, frameHeight = 0; 956 newCameraParams.getPreviewSize(&frameWidth, &frameHeight); 957 if (frameWidth < 0 || frameWidth != mVideoWidth || 958 frameHeight < 0 || frameHeight != mVideoHeight) { 959 LOGE("Failed to set the video frame size to %dx%d", 960 mVideoWidth, mVideoHeight); 961 IPCThreadState::self()->restoreCallingIdentity(token); 962 return UNKNOWN_ERROR; 963 } 964 965 // Check on video frame rate 966 int frameRate = newCameraParams.getPreviewFrameRate(); 967 if (frameRate < 0 || (frameRate - mFrameRate) != 0) { 968 LOGE("Failed to set frame rate to %d fps. The actual " 969 "frame rate is %d", mFrameRate, frameRate); 970 } 971 972 // This CHECK is good, since we just passed the lock/unlock 973 // check earlier by calling mCamera->setParameters(). 974 CHECK_EQ(OK, mCamera->setPreviewDisplay(mPreviewSurface)); 975 IPCThreadState::self()->restoreCallingIdentity(token); 976 return OK; 977} 978 979void StagefrightRecorder::clipVideoFrameHeight() { 980 LOGV("clipVideoFrameHeight: encoder %d", mVideoEncoder); 981 int minFrameHeight = mEncoderProfiles->getVideoEncoderParamByName( 982 "enc.vid.height.min", mVideoEncoder); 983 int maxFrameHeight = mEncoderProfiles->getVideoEncoderParamByName( 984 "enc.vid.height.max", mVideoEncoder); 985 if (mVideoHeight < minFrameHeight) { 986 LOGW("Intended video encoding frame height (%d) is too small" 987 " and will be set to (%d)", mVideoHeight, minFrameHeight); 988 mVideoHeight = minFrameHeight; 989 } else if (mVideoHeight > maxFrameHeight) { 990 LOGW("Intended video encoding frame height (%d) is too large" 991 " and will be set to (%d)", mVideoHeight, maxFrameHeight); 992 mVideoHeight = maxFrameHeight; 993 } 994} 995 996status_t StagefrightRecorder::setupVideoEncoder(sp<MediaSource> *source) { 997 source->clear(); 998 999 status_t err = setupCameraSource(); 1000 if (err != OK) return err; 1001 1002 sp<CameraSource> cameraSource = CameraSource::CreateFromCamera(mCamera); 1003 CHECK(cameraSource != NULL); 1004 1005 sp<MetaData> enc_meta = new MetaData; 1006 enc_meta->setInt32(kKeyBitRate, mVideoBitRate); 1007 enc_meta->setInt32(kKeySampleRate, mFrameRate); 1008 1009 switch (mVideoEncoder) { 1010 case VIDEO_ENCODER_H263: 1011 enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_H263); 1012 break; 1013 1014 case VIDEO_ENCODER_MPEG_4_SP: 1015 enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG4); 1016 break; 1017 1018 case VIDEO_ENCODER_H264: 1019 enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC); 1020 break; 1021 1022 default: 1023 CHECK(!"Should not be here, unsupported video encoding."); 1024 break; 1025 } 1026 1027 sp<MetaData> meta = cameraSource->getFormat(); 1028 1029 int32_t width, height, stride, sliceHeight, colorFormat; 1030 CHECK(meta->findInt32(kKeyWidth, &width)); 1031 CHECK(meta->findInt32(kKeyHeight, &height)); 1032 CHECK(meta->findInt32(kKeyStride, &stride)); 1033 CHECK(meta->findInt32(kKeySliceHeight, &sliceHeight)); 1034 CHECK(meta->findInt32(kKeyColorFormat, &colorFormat)); 1035 1036 enc_meta->setInt32(kKeyWidth, width); 1037 enc_meta->setInt32(kKeyHeight, height); 1038 enc_meta->setInt32(kKeyIFramesInterval, mIFramesIntervalSec); 1039 enc_meta->setInt32(kKeyStride, stride); 1040 enc_meta->setInt32(kKeySliceHeight, sliceHeight); 1041 enc_meta->setInt32(kKeyColorFormat, colorFormat); 1042 if (mVideoTimeScale > 0) { 1043 enc_meta->setInt32(kKeyTimeScale, mVideoTimeScale); 1044 } 1045 if (mVideoEncoderProfile != -1) { 1046 enc_meta->setInt32(kKeyVideoProfile, mVideoEncoderProfile); 1047 } 1048 if (mVideoEncoderLevel != -1) { 1049 enc_meta->setInt32(kKeyVideoLevel, mVideoEncoderLevel); 1050 } 1051 1052 OMXClient client; 1053 CHECK_EQ(client.connect(), OK); 1054 1055 sp<MediaSource> encoder = OMXCodec::Create( 1056 client.interface(), enc_meta, 1057 true /* createEncoder */, cameraSource); 1058 if (encoder == NULL) { 1059 return UNKNOWN_ERROR; 1060 } 1061 1062 *source = encoder; 1063 1064 return OK; 1065} 1066 1067status_t StagefrightRecorder::setupAudioEncoder(const sp<MediaWriter>& writer) { 1068 sp<MediaSource> audioEncoder; 1069 switch(mAudioEncoder) { 1070 case AUDIO_ENCODER_AMR_NB: 1071 case AUDIO_ENCODER_AMR_WB: 1072 case AUDIO_ENCODER_AAC: 1073 audioEncoder = createAudioSource(); 1074 break; 1075 default: 1076 LOGE("Unsupported audio encoder: %d", mAudioEncoder); 1077 return UNKNOWN_ERROR; 1078 } 1079 1080 if (audioEncoder == NULL) { 1081 return UNKNOWN_ERROR; 1082 } 1083 1084 writer->addSource(audioEncoder); 1085 return OK; 1086} 1087 1088status_t StagefrightRecorder::startMPEG4Recording() { 1089 int32_t totalBitRate = 0; 1090 status_t err = OK; 1091 sp<MediaWriter> writer = new MPEG4Writer(dup(mOutputFd)); 1092 1093 // Add audio source first if it exists 1094 if (mAudioSource != AUDIO_SOURCE_LIST_END) { 1095 err = setupAudioEncoder(writer); 1096 if (err != OK) return err; 1097 totalBitRate += mAudioBitRate; 1098 } 1099 if (mVideoSource == VIDEO_SOURCE_DEFAULT 1100 || mVideoSource == VIDEO_SOURCE_CAMERA) { 1101 sp<MediaSource> encoder; 1102 err = setupVideoEncoder(&encoder); 1103 if (err != OK) return err; 1104 writer->addSource(encoder); 1105 totalBitRate += mVideoBitRate; 1106 } 1107 1108 if (mInterleaveDurationUs > 0) { 1109 reinterpret_cast<MPEG4Writer *>(writer.get())-> 1110 setInterleaveDuration(mInterleaveDurationUs); 1111 } 1112 1113 if (mMaxFileDurationUs != 0) { 1114 writer->setMaxFileDuration(mMaxFileDurationUs); 1115 } 1116 if (mMaxFileSizeBytes != 0) { 1117 writer->setMaxFileSize(mMaxFileSizeBytes); 1118 } 1119 sp<MetaData> meta = new MetaData; 1120 meta->setInt64(kKeyTime, systemTime() / 1000); 1121 meta->setInt32(kKeyFileType, mOutputFormat); 1122 meta->setInt32(kKeyBitRate, totalBitRate); 1123 meta->setInt32(kKey64BitFileOffset, mUse64BitFileOffset); 1124 if (mMovieTimeScale > 0) { 1125 meta->setInt32(kKeyTimeScale, mMovieTimeScale); 1126 } 1127 if (mTrackEveryTimeDurationUs > 0) { 1128 meta->setInt64(kKeyTrackTimeStatus, mTrackEveryTimeDurationUs); 1129 } 1130 writer->setListener(mListener); 1131 mWriter = writer; 1132 return mWriter->start(meta.get()); 1133} 1134 1135status_t StagefrightRecorder::pause() { 1136 LOGV("pause"); 1137 if (mWriter == NULL) { 1138 return UNKNOWN_ERROR; 1139 } 1140 mWriter->pause(); 1141 return OK; 1142} 1143 1144status_t StagefrightRecorder::stop() { 1145 LOGV("stop"); 1146 status_t err = OK; 1147 if (mWriter != NULL) { 1148 err = mWriter->stop(); 1149 mWriter.clear(); 1150 } 1151 1152 if (mCamera != 0) { 1153 LOGV("Disconnect camera"); 1154 int64_t token = IPCThreadState::self()->clearCallingIdentity(); 1155 if ((mFlags & FLAGS_HOT_CAMERA) == 0) { 1156 LOGV("Camera was cold when we started, stopping preview"); 1157 mCamera->stopPreview(); 1158 } 1159 mCamera->unlock(); 1160 mCamera.clear(); 1161 IPCThreadState::self()->restoreCallingIdentity(token); 1162 mFlags = 0; 1163 } 1164 1165 if (mOutputFd >= 0) { 1166 ::close(mOutputFd); 1167 mOutputFd = -1; 1168 } 1169 1170 return err; 1171} 1172 1173status_t StagefrightRecorder::close() { 1174 LOGV("close"); 1175 stop(); 1176 1177 return OK; 1178} 1179 1180status_t StagefrightRecorder::reset() { 1181 LOGV("reset"); 1182 stop(); 1183 1184 // No audio or video source by default 1185 mAudioSource = AUDIO_SOURCE_LIST_END; 1186 mVideoSource = VIDEO_SOURCE_LIST_END; 1187 1188 // Default parameters 1189 mOutputFormat = OUTPUT_FORMAT_THREE_GPP; 1190 mAudioEncoder = AUDIO_ENCODER_AMR_NB; 1191 mVideoEncoder = VIDEO_ENCODER_H263; 1192 mVideoWidth = 176; 1193 mVideoHeight = 144; 1194 mFrameRate = 20; 1195 mVideoBitRate = 192000; 1196 mSampleRate = 8000; 1197 mAudioChannels = 1; 1198 mAudioBitRate = 12200; 1199 mInterleaveDurationUs = 0; 1200 mIFramesIntervalSec = 1; 1201 mAudioSourceNode = 0; 1202 mUse64BitFileOffset = false; 1203 mMovieTimeScale = -1; 1204 mAudioTimeScale = -1; 1205 mVideoTimeScale = -1; 1206 mCameraId = 0; 1207 mVideoEncoderProfile = -1; 1208 mVideoEncoderLevel = -1; 1209 mMaxFileDurationUs = 0; 1210 mMaxFileSizeBytes = 0; 1211 mTrackEveryTimeDurationUs = 0; 1212 mEncoderProfiles = MediaProfiles::getInstance(); 1213 mClockwiseRotationDegrees = 0; 1214 1215 mOutputFd = -1; 1216 mFlags = 0; 1217 1218 return OK; 1219} 1220 1221status_t StagefrightRecorder::getMaxAmplitude(int *max) { 1222 LOGV("getMaxAmplitude"); 1223 1224 if (max == NULL) { 1225 LOGE("Null pointer argument"); 1226 return BAD_VALUE; 1227 } 1228 1229 if (mAudioSourceNode != 0) { 1230 *max = mAudioSourceNode->getMaxAmplitude(); 1231 } else { 1232 *max = 0; 1233 } 1234 1235 return OK; 1236} 1237 1238status_t StagefrightRecorder::dump( 1239 int fd, const Vector<String16>& args) const { 1240 LOGV("dump"); 1241 const size_t SIZE = 256; 1242 char buffer[SIZE]; 1243 String8 result; 1244 if (mWriter != 0) { 1245 mWriter->dump(fd, args); 1246 } else { 1247 snprintf(buffer, SIZE, " No file writer\n"); 1248 result.append(buffer); 1249 } 1250 snprintf(buffer, SIZE, " Recorder: %p\n", this); 1251 snprintf(buffer, SIZE, " Output file (fd %d):\n", mOutputFd); 1252 result.append(buffer); 1253 snprintf(buffer, SIZE, " File format: %d\n", mOutputFormat); 1254 result.append(buffer); 1255 snprintf(buffer, SIZE, " Max file size (bytes): %lld\n", mMaxFileSizeBytes); 1256 result.append(buffer); 1257 snprintf(buffer, SIZE, " Max file duration (us): %lld\n", mMaxFileDurationUs); 1258 result.append(buffer); 1259 snprintf(buffer, SIZE, " File offset length (bits): %d\n", mUse64BitFileOffset? 64: 32); 1260 result.append(buffer); 1261 snprintf(buffer, SIZE, " Interleave duration (us): %d\n", mInterleaveDurationUs); 1262 result.append(buffer); 1263 snprintf(buffer, SIZE, " Progress notification: %lld us\n", mTrackEveryTimeDurationUs); 1264 result.append(buffer); 1265 snprintf(buffer, SIZE, " Audio\n"); 1266 result.append(buffer); 1267 snprintf(buffer, SIZE, " Source: %d\n", mAudioSource); 1268 result.append(buffer); 1269 snprintf(buffer, SIZE, " Encoder: %d\n", mAudioEncoder); 1270 result.append(buffer); 1271 snprintf(buffer, SIZE, " Bit rate (bps): %d\n", mAudioBitRate); 1272 result.append(buffer); 1273 snprintf(buffer, SIZE, " Sampling rate (hz): %d\n", mSampleRate); 1274 result.append(buffer); 1275 snprintf(buffer, SIZE, " Number of channels: %d\n", mAudioChannels); 1276 result.append(buffer); 1277 snprintf(buffer, SIZE, " Max amplitude: %d\n", mAudioSourceNode == 0? 0: mAudioSourceNode->getMaxAmplitude()); 1278 result.append(buffer); 1279 snprintf(buffer, SIZE, " Video\n"); 1280 result.append(buffer); 1281 snprintf(buffer, SIZE, " Source: %d\n", mVideoSource); 1282 result.append(buffer); 1283 snprintf(buffer, SIZE, " Camera Id: %d\n", mCameraId); 1284 result.append(buffer); 1285 snprintf(buffer, SIZE, " Camera flags: %d\n", mFlags); 1286 result.append(buffer); 1287 snprintf(buffer, SIZE, " Rotation (clockwise) degrees: %d\n", mClockwiseRotationDegrees); 1288 result.append(buffer); 1289 snprintf(buffer, SIZE, " Encoder: %d\n", mVideoEncoder); 1290 result.append(buffer); 1291 snprintf(buffer, SIZE, " Encoder profile: %d\n", mVideoEncoderProfile); 1292 result.append(buffer); 1293 snprintf(buffer, SIZE, " Encoder level: %d\n", mVideoEncoderLevel); 1294 result.append(buffer); 1295 snprintf(buffer, SIZE, " I frames interval (s): %d\n", mIFramesIntervalSec); 1296 result.append(buffer); 1297 snprintf(buffer, SIZE, " Frame size (pixels): %dx%d\n", mVideoWidth, mVideoHeight); 1298 result.append(buffer); 1299 snprintf(buffer, SIZE, " Frame rate (fps): %d\n", mFrameRate); 1300 result.append(buffer); 1301 snprintf(buffer, SIZE, " Bit rate (bps): %d\n", mVideoBitRate); 1302 result.append(buffer); 1303 ::write(fd, result.string(), result.size()); 1304 return OK; 1305} 1306} // namespace android 1307