StagefrightRecorder.cpp revision ff5bfcf19da45e6bb0136ef818b7c4bf8fd8db3d
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::setParamAudioTimeScale(int32_t timeScale) {
466    LOGV("setParamAudioTimeScale: %d", timeScale);
467
468    // 96000 Hz is the highest sampling rate support in AAC.
469    if (timeScale < 600 || timeScale > 96000) {
470        LOGE("Time scale (%d) for audio is out of range [600, 96000]", timeScale);
471        return BAD_VALUE;
472    }
473    mAudioTimeScale = timeScale;
474    return OK;
475}
476
477status_t StagefrightRecorder::setParameter(
478        const String8 &key, const String8 &value) {
479    LOGV("setParameter: key (%s) => value (%s)", key.string(), value.string());
480    if (key == "max-duration") {
481        int64_t max_duration_ms;
482        if (safe_strtoi64(value.string(), &max_duration_ms)) {
483            return setParamMaxFileDurationUs(1000LL * max_duration_ms);
484        }
485    } else if (key == "max-filesize") {
486        int64_t max_filesize_bytes;
487        if (safe_strtoi64(value.string(), &max_filesize_bytes)) {
488            return setParamMaxFileSizeBytes(max_filesize_bytes);
489        }
490    } else if (key == "interleave-duration-us") {
491        int32_t durationUs;
492        if (safe_strtoi32(value.string(), &durationUs)) {
493            return setParamInterleaveDuration(durationUs);
494        }
495    } else if (key == "param-movie-time-scale") {
496        int32_t timeScale;
497        if (safe_strtoi32(value.string(), &timeScale)) {
498            return setParamMovieTimeScale(timeScale);
499        }
500    } else if (key == "param-use-64bit-offset") {
501        int32_t use64BitOffset;
502        if (safe_strtoi32(value.string(), &use64BitOffset)) {
503            return setParam64BitFileOffset(use64BitOffset != 0);
504        }
505    } else if (key == "param-track-time-status") {
506        int64_t timeDurationUs;
507        if (safe_strtoi64(value.string(), &timeDurationUs)) {
508            return setParamTrackTimeStatus(timeDurationUs);
509        }
510    } else if (key == "audio-param-sampling-rate") {
511        int32_t sampling_rate;
512        if (safe_strtoi32(value.string(), &sampling_rate)) {
513            return setParamAudioSamplingRate(sampling_rate);
514        }
515    } else if (key == "audio-param-number-of-channels") {
516        int32_t number_of_channels;
517        if (safe_strtoi32(value.string(), &number_of_channels)) {
518            return setParamAudioNumberOfChannels(number_of_channels);
519        }
520    } else if (key == "audio-param-encoding-bitrate") {
521        int32_t audio_bitrate;
522        if (safe_strtoi32(value.string(), &audio_bitrate)) {
523            return setParamAudioEncodingBitRate(audio_bitrate);
524        }
525    } else if (key == "audio-param-time-scale") {
526        int32_t timeScale;
527        if (safe_strtoi32(value.string(), &timeScale)) {
528            return setParamAudioTimeScale(timeScale);
529        }
530    } else if (key == "video-param-encoding-bitrate") {
531        int32_t video_bitrate;
532        if (safe_strtoi32(value.string(), &video_bitrate)) {
533            return setParamVideoEncodingBitRate(video_bitrate);
534        }
535    } else if (key == "video-param-i-frames-interval") {
536        int32_t seconds;
537        if (safe_strtoi32(value.string(), &seconds)) {
538            return setParamVideoIFramesInterval(seconds);
539        }
540    } else if (key == "video-param-encoder-profile") {
541        int32_t profile;
542        if (safe_strtoi32(value.string(), &profile)) {
543            return setParamVideoEncoderProfile(profile);
544        }
545    } else if (key == "video-param-encoder-level") {
546        int32_t level;
547        if (safe_strtoi32(value.string(), &level)) {
548            return setParamVideoEncoderLevel(level);
549        }
550    } else if (key == "video-param-camera-id") {
551        int32_t cameraId;
552        if (safe_strtoi32(value.string(), &cameraId)) {
553            return setParamVideoCameraId(cameraId);
554        }
555    } else if (key == "video-param-time-scale") {
556        int32_t timeScale;
557        if (safe_strtoi32(value.string(), &timeScale)) {
558            return setParamVideoTimeScale(timeScale);
559        }
560    } else {
561        LOGE("setParameter: failed to find key %s", key.string());
562    }
563    return BAD_VALUE;
564}
565
566status_t StagefrightRecorder::setParameters(const String8 &params) {
567    LOGV("setParameters: %s", params.string());
568    const char *cparams = params.string();
569    const char *key_start = cparams;
570    for (;;) {
571        const char *equal_pos = strchr(key_start, '=');
572        if (equal_pos == NULL) {
573            LOGE("Parameters %s miss a value", cparams);
574            return BAD_VALUE;
575        }
576        String8 key(key_start, equal_pos - key_start);
577        TrimString(&key);
578        if (key.length() == 0) {
579            LOGE("Parameters %s contains an empty key", cparams);
580            return BAD_VALUE;
581        }
582        const char *value_start = equal_pos + 1;
583        const char *semicolon_pos = strchr(value_start, ';');
584        String8 value;
585        if (semicolon_pos == NULL) {
586            value.setTo(value_start);
587        } else {
588            value.setTo(value_start, semicolon_pos - value_start);
589        }
590        if (setParameter(key, value) != OK) {
591            return BAD_VALUE;
592        }
593        if (semicolon_pos == NULL) {
594            break;  // Reaches the end
595        }
596        key_start = semicolon_pos + 1;
597    }
598    return OK;
599}
600
601status_t StagefrightRecorder::setListener(const sp<IMediaRecorderClient> &listener) {
602    mListener = listener;
603
604    return OK;
605}
606
607status_t StagefrightRecorder::prepare() {
608    return OK;
609}
610
611status_t StagefrightRecorder::start() {
612    CHECK(mOutputFd >= 0);
613
614    if (mWriter != NULL) {
615        LOGE("File writer is not avaialble");
616        return UNKNOWN_ERROR;
617    }
618
619    switch (mOutputFormat) {
620        case OUTPUT_FORMAT_DEFAULT:
621        case OUTPUT_FORMAT_THREE_GPP:
622        case OUTPUT_FORMAT_MPEG_4:
623            return startMPEG4Recording();
624
625        case OUTPUT_FORMAT_AMR_NB:
626        case OUTPUT_FORMAT_AMR_WB:
627            return startAMRRecording();
628
629        case OUTPUT_FORMAT_AAC_ADIF:
630        case OUTPUT_FORMAT_AAC_ADTS:
631            return startAACRecording();
632
633        case OUTPUT_FORMAT_RTP_AVP:
634            return startRTPRecording();
635
636        case OUTPUT_FORMAT_MPEG2TS:
637            return startMPEG2TSRecording();
638
639        default:
640            LOGE("Unsupported output file format: %d", mOutputFormat);
641            return UNKNOWN_ERROR;
642    }
643}
644
645sp<MediaSource> StagefrightRecorder::createAudioSource() {
646    sp<AudioSource> audioSource =
647        new AudioSource(
648                mAudioSource,
649                mSampleRate,
650                mAudioChannels);
651
652    status_t err = audioSource->initCheck();
653
654    if (err != OK) {
655        LOGE("audio source is not initialized");
656        return NULL;
657    }
658
659    sp<MetaData> encMeta = new MetaData;
660    const char *mime;
661    switch (mAudioEncoder) {
662        case AUDIO_ENCODER_AMR_NB:
663        case AUDIO_ENCODER_DEFAULT:
664            mime = MEDIA_MIMETYPE_AUDIO_AMR_NB;
665            break;
666        case AUDIO_ENCODER_AMR_WB:
667            mime = MEDIA_MIMETYPE_AUDIO_AMR_WB;
668            break;
669        case AUDIO_ENCODER_AAC:
670            mime = MEDIA_MIMETYPE_AUDIO_AAC;
671            break;
672        default:
673            LOGE("Unknown audio encoder: %d", mAudioEncoder);
674            return NULL;
675    }
676    encMeta->setCString(kKeyMIMEType, mime);
677
678    int32_t maxInputSize;
679    CHECK(audioSource->getFormat()->findInt32(
680                kKeyMaxInputSize, &maxInputSize));
681
682    encMeta->setInt32(kKeyMaxInputSize, maxInputSize);
683    encMeta->setInt32(kKeyChannelCount, mAudioChannels);
684    encMeta->setInt32(kKeySampleRate, mSampleRate);
685    encMeta->setInt32(kKeyBitRate, mAudioBitRate);
686    if (mAudioTimeScale > 0) {
687        encMeta->setInt32(kKeyTimeScale, mAudioTimeScale);
688    }
689
690    OMXClient client;
691    CHECK_EQ(client.connect(), OK);
692
693    sp<MediaSource> audioEncoder =
694        OMXCodec::Create(client.interface(), encMeta,
695                         true /* createEncoder */, audioSource);
696    mAudioSourceNode = audioSource;
697
698    return audioEncoder;
699}
700
701status_t StagefrightRecorder::startAACRecording() {
702    CHECK(mOutputFormat == OUTPUT_FORMAT_AAC_ADIF ||
703          mOutputFormat == OUTPUT_FORMAT_AAC_ADTS);
704
705    CHECK(mAudioEncoder == AUDIO_ENCODER_AAC);
706    CHECK(mAudioSource != AUDIO_SOURCE_LIST_END);
707
708    CHECK(0 == "AACWriter is not implemented yet");
709
710    return OK;
711}
712
713status_t StagefrightRecorder::startAMRRecording() {
714    CHECK(mOutputFormat == OUTPUT_FORMAT_AMR_NB ||
715          mOutputFormat == OUTPUT_FORMAT_AMR_WB);
716
717    if (mOutputFormat == OUTPUT_FORMAT_AMR_NB) {
718        if (mAudioEncoder != AUDIO_ENCODER_DEFAULT &&
719            mAudioEncoder != AUDIO_ENCODER_AMR_NB) {
720            LOGE("Invalid encoder %d used for AMRNB recording",
721                    mAudioEncoder);
722            return BAD_VALUE;
723        }
724        if (mSampleRate != 8000) {
725            LOGE("Invalid sampling rate %d used for AMRNB recording",
726                    mSampleRate);
727            return BAD_VALUE;
728        }
729    } else {  // mOutputFormat must be OUTPUT_FORMAT_AMR_WB
730        if (mAudioEncoder != AUDIO_ENCODER_AMR_WB) {
731            LOGE("Invlaid encoder %d used for AMRWB recording",
732                    mAudioEncoder);
733            return BAD_VALUE;
734        }
735        if (mSampleRate != 16000) {
736            LOGE("Invalid sample rate %d used for AMRWB recording",
737                    mSampleRate);
738            return BAD_VALUE;
739        }
740    }
741    if (mAudioChannels != 1) {
742        LOGE("Invalid number of audio channels %d used for amr recording",
743                mAudioChannels);
744        return BAD_VALUE;
745    }
746
747    if (mAudioSource >= AUDIO_SOURCE_LIST_END) {
748        LOGE("Invalid audio source: %d", mAudioSource);
749        return BAD_VALUE;
750    }
751
752    sp<MediaSource> audioEncoder = createAudioSource();
753
754    if (audioEncoder == NULL) {
755        return UNKNOWN_ERROR;
756    }
757
758    mWriter = new AMRWriter(dup(mOutputFd));
759    mWriter->addSource(audioEncoder);
760
761    if (mMaxFileDurationUs != 0) {
762        mWriter->setMaxFileDuration(mMaxFileDurationUs);
763    }
764    if (mMaxFileSizeBytes != 0) {
765        mWriter->setMaxFileSize(mMaxFileSizeBytes);
766    }
767    mWriter->setListener(mListener);
768    mWriter->start();
769
770    return OK;
771}
772
773status_t StagefrightRecorder::startRTPRecording() {
774    CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_RTP_AVP);
775
776    if ((mAudioSource != AUDIO_SOURCE_LIST_END
777                && mVideoSource != VIDEO_SOURCE_LIST_END)
778            || (mAudioSource == AUDIO_SOURCE_LIST_END
779                && mVideoSource == VIDEO_SOURCE_LIST_END)) {
780        // Must have exactly one source.
781        return BAD_VALUE;
782    }
783
784    if (mOutputFd < 0) {
785        return BAD_VALUE;
786    }
787
788    sp<MediaSource> source;
789
790    if (mAudioSource != AUDIO_SOURCE_LIST_END) {
791        source = createAudioSource();
792    } else {
793        status_t err = setupVideoEncoder(&source);
794        if (err != OK) {
795            return err;
796        }
797    }
798
799    mWriter = new ARTPWriter(dup(mOutputFd));
800    mWriter->addSource(source);
801    mWriter->setListener(mListener);
802
803    return mWriter->start();
804}
805
806status_t StagefrightRecorder::startMPEG2TSRecording() {
807    CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_MPEG2TS);
808
809    sp<MediaWriter> writer = new MPEG2TSWriter(dup(mOutputFd));
810
811    if (mAudioSource != AUDIO_SOURCE_LIST_END) {
812        if (mAudioEncoder != AUDIO_ENCODER_AAC) {
813            return ERROR_UNSUPPORTED;
814        }
815
816        status_t err = setupAudioEncoder(writer);
817
818        if (err != OK) {
819            return err;
820        }
821    }
822
823    if (mVideoSource == VIDEO_SOURCE_DEFAULT
824            || mVideoSource == VIDEO_SOURCE_CAMERA) {
825        if (mVideoEncoder != VIDEO_ENCODER_H264) {
826            return ERROR_UNSUPPORTED;
827        }
828
829        sp<MediaSource> encoder;
830        status_t err = setupVideoEncoder(&encoder);
831
832        if (err != OK) {
833            return err;
834        }
835
836        writer->addSource(encoder);
837    }
838
839    if (mMaxFileDurationUs != 0) {
840        writer->setMaxFileDuration(mMaxFileDurationUs);
841    }
842
843    if (mMaxFileSizeBytes != 0) {
844        writer->setMaxFileSize(mMaxFileSizeBytes);
845    }
846
847    mWriter = writer;
848
849    return mWriter->start();
850}
851
852void StagefrightRecorder::clipVideoFrameRate() {
853    LOGV("clipVideoFrameRate: encoder %d", mVideoEncoder);
854    int minFrameRate = mEncoderProfiles->getVideoEncoderParamByName(
855                        "enc.vid.fps.min", mVideoEncoder);
856    int maxFrameRate = mEncoderProfiles->getVideoEncoderParamByName(
857                        "enc.vid.fps.max", mVideoEncoder);
858    if (mFrameRate < minFrameRate) {
859        LOGW("Intended video encoding frame rate (%d fps) is too small"
860             " and will be set to (%d fps)", mFrameRate, minFrameRate);
861        mFrameRate = minFrameRate;
862    } else if (mFrameRate > maxFrameRate) {
863        LOGW("Intended video encoding frame rate (%d fps) is too large"
864             " and will be set to (%d fps)", mFrameRate, maxFrameRate);
865        mFrameRate = maxFrameRate;
866    }
867}
868
869void StagefrightRecorder::clipVideoBitRate() {
870    LOGV("clipVideoBitRate: encoder %d", mVideoEncoder);
871    int minBitRate = mEncoderProfiles->getVideoEncoderParamByName(
872                        "enc.vid.bps.min", mVideoEncoder);
873    int maxBitRate = mEncoderProfiles->getVideoEncoderParamByName(
874                        "enc.vid.bps.max", mVideoEncoder);
875    if (mVideoBitRate < minBitRate) {
876        LOGW("Intended video encoding bit rate (%d bps) is too small"
877             " and will be set to (%d bps)", mVideoBitRate, minBitRate);
878        mVideoBitRate = minBitRate;
879    } else if (mVideoBitRate > maxBitRate) {
880        LOGW("Intended video encoding bit rate (%d bps) is too large"
881             " and will be set to (%d bps)", mVideoBitRate, maxBitRate);
882        mVideoBitRate = maxBitRate;
883    }
884}
885
886void StagefrightRecorder::clipVideoFrameWidth() {
887    LOGV("clipVideoFrameWidth: encoder %d", mVideoEncoder);
888    int minFrameWidth = mEncoderProfiles->getVideoEncoderParamByName(
889                        "enc.vid.width.min", mVideoEncoder);
890    int maxFrameWidth = mEncoderProfiles->getVideoEncoderParamByName(
891                        "enc.vid.width.max", mVideoEncoder);
892    if (mVideoWidth < minFrameWidth) {
893        LOGW("Intended video encoding frame width (%d) is too small"
894             " and will be set to (%d)", mVideoWidth, minFrameWidth);
895        mVideoWidth = minFrameWidth;
896    } else if (mVideoWidth > maxFrameWidth) {
897        LOGW("Intended video encoding frame width (%d) is too large"
898             " and will be set to (%d)", mVideoWidth, maxFrameWidth);
899        mVideoWidth = maxFrameWidth;
900    }
901}
902
903status_t StagefrightRecorder::setupCameraSource() {
904    clipVideoBitRate();
905    clipVideoFrameRate();
906    clipVideoFrameWidth();
907    clipVideoFrameHeight();
908
909    int64_t token = IPCThreadState::self()->clearCallingIdentity();
910    if (mCamera == 0) {
911        mCamera = Camera::connect(mCameraId);
912        if (mCamera == 0) {
913            LOGE("Camera connection could not be established.");
914            return -EBUSY;
915        }
916        mFlags &= ~FLAGS_HOT_CAMERA;
917        mCamera->lock();
918    }
919
920    // Set the actual video recording frame size
921    CameraParameters params(mCamera->getParameters());
922    params.setPreviewSize(mVideoWidth, mVideoHeight);
923    params.setPreviewFrameRate(mFrameRate);
924    String8 s = params.flatten();
925    if (OK != mCamera->setParameters(s)) {
926        LOGE("Could not change settings."
927             " Someone else is using camera %d?", mCameraId);
928        return -EBUSY;
929    }
930    CameraParameters newCameraParams(mCamera->getParameters());
931
932    // Check on video frame size
933    int frameWidth = 0, frameHeight = 0;
934    newCameraParams.getPreviewSize(&frameWidth, &frameHeight);
935    if (frameWidth  < 0 || frameWidth  != mVideoWidth ||
936        frameHeight < 0 || frameHeight != mVideoHeight) {
937        LOGE("Failed to set the video frame size to %dx%d",
938                mVideoWidth, mVideoHeight);
939        IPCThreadState::self()->restoreCallingIdentity(token);
940        return UNKNOWN_ERROR;
941    }
942
943    // Check on video frame rate
944    int frameRate = newCameraParams.getPreviewFrameRate();
945    if (frameRate < 0 || (frameRate - mFrameRate) != 0) {
946        LOGE("Failed to set frame rate to %d fps. The actual "
947             "frame rate is %d", mFrameRate, frameRate);
948    }
949
950    // This CHECK is good, since we just passed the lock/unlock
951    // check earlier by calling mCamera->setParameters().
952    CHECK_EQ(OK, mCamera->setPreviewDisplay(mPreviewSurface));
953    IPCThreadState::self()->restoreCallingIdentity(token);
954    return OK;
955}
956
957void StagefrightRecorder::clipVideoFrameHeight() {
958    LOGV("clipVideoFrameHeight: encoder %d", mVideoEncoder);
959    int minFrameHeight = mEncoderProfiles->getVideoEncoderParamByName(
960                        "enc.vid.height.min", mVideoEncoder);
961    int maxFrameHeight = mEncoderProfiles->getVideoEncoderParamByName(
962                        "enc.vid.height.max", mVideoEncoder);
963    if (mVideoHeight < minFrameHeight) {
964        LOGW("Intended video encoding frame height (%d) is too small"
965             " and will be set to (%d)", mVideoHeight, minFrameHeight);
966        mVideoHeight = minFrameHeight;
967    } else if (mVideoHeight > maxFrameHeight) {
968        LOGW("Intended video encoding frame height (%d) is too large"
969             " and will be set to (%d)", mVideoHeight, maxFrameHeight);
970        mVideoHeight = maxFrameHeight;
971    }
972}
973
974status_t StagefrightRecorder::setupVideoEncoder(sp<MediaSource> *source) {
975    source->clear();
976
977    status_t err = setupCameraSource();
978    if (err != OK) return err;
979
980    sp<CameraSource> cameraSource = CameraSource::CreateFromCamera(mCamera);
981    CHECK(cameraSource != NULL);
982
983    sp<MetaData> enc_meta = new MetaData;
984    enc_meta->setInt32(kKeyBitRate, mVideoBitRate);
985    enc_meta->setInt32(kKeySampleRate, mFrameRate);
986
987    switch (mVideoEncoder) {
988        case VIDEO_ENCODER_H263:
989            enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_H263);
990            break;
991
992        case VIDEO_ENCODER_MPEG_4_SP:
993            enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG4);
994            break;
995
996        case VIDEO_ENCODER_H264:
997            enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
998            break;
999
1000        default:
1001            CHECK(!"Should not be here, unsupported video encoding.");
1002            break;
1003    }
1004
1005    sp<MetaData> meta = cameraSource->getFormat();
1006
1007    int32_t width, height, stride, sliceHeight, colorFormat;
1008    CHECK(meta->findInt32(kKeyWidth, &width));
1009    CHECK(meta->findInt32(kKeyHeight, &height));
1010    CHECK(meta->findInt32(kKeyStride, &stride));
1011    CHECK(meta->findInt32(kKeySliceHeight, &sliceHeight));
1012    CHECK(meta->findInt32(kKeyColorFormat, &colorFormat));
1013
1014    enc_meta->setInt32(kKeyWidth, width);
1015    enc_meta->setInt32(kKeyHeight, height);
1016    enc_meta->setInt32(kKeyIFramesInterval, mIFramesIntervalSec);
1017    enc_meta->setInt32(kKeyStride, stride);
1018    enc_meta->setInt32(kKeySliceHeight, sliceHeight);
1019    enc_meta->setInt32(kKeyColorFormat, colorFormat);
1020    if (mVideoTimeScale > 0) {
1021        enc_meta->setInt32(kKeyTimeScale, mVideoTimeScale);
1022    }
1023    if (mVideoEncoderProfile != -1) {
1024        enc_meta->setInt32(kKeyVideoProfile, mVideoEncoderProfile);
1025    }
1026    if (mVideoEncoderLevel != -1) {
1027        enc_meta->setInt32(kKeyVideoLevel, mVideoEncoderLevel);
1028    }
1029
1030    OMXClient client;
1031    CHECK_EQ(client.connect(), OK);
1032
1033    sp<MediaSource> encoder = OMXCodec::Create(
1034            client.interface(), enc_meta,
1035            true /* createEncoder */, cameraSource);
1036    if (encoder == NULL) {
1037        return UNKNOWN_ERROR;
1038    }
1039
1040    *source = encoder;
1041
1042    return OK;
1043}
1044
1045status_t StagefrightRecorder::setupAudioEncoder(const sp<MediaWriter>& writer) {
1046    sp<MediaSource> audioEncoder;
1047    switch(mAudioEncoder) {
1048        case AUDIO_ENCODER_AMR_NB:
1049        case AUDIO_ENCODER_AMR_WB:
1050        case AUDIO_ENCODER_AAC:
1051            audioEncoder = createAudioSource();
1052            break;
1053        default:
1054            LOGE("Unsupported audio encoder: %d", mAudioEncoder);
1055            return UNKNOWN_ERROR;
1056    }
1057
1058    if (audioEncoder == NULL) {
1059        return UNKNOWN_ERROR;
1060    }
1061
1062    writer->addSource(audioEncoder);
1063    return OK;
1064}
1065
1066status_t StagefrightRecorder::startMPEG4Recording() {
1067    int32_t totalBitRate = 0;
1068    status_t err = OK;
1069    sp<MediaWriter> writer = new MPEG4Writer(dup(mOutputFd));
1070
1071    // Add audio source first if it exists
1072    if (mAudioSource != AUDIO_SOURCE_LIST_END) {
1073        err = setupAudioEncoder(writer);
1074        if (err != OK) return err;
1075        totalBitRate += mAudioBitRate;
1076    }
1077    if (mVideoSource == VIDEO_SOURCE_DEFAULT
1078            || mVideoSource == VIDEO_SOURCE_CAMERA) {
1079        sp<MediaSource> encoder;
1080        err = setupVideoEncoder(&encoder);
1081        if (err != OK) return err;
1082        writer->addSource(encoder);
1083        totalBitRate += mVideoBitRate;
1084    }
1085
1086    if (mInterleaveDurationUs > 0) {
1087        reinterpret_cast<MPEG4Writer *>(writer.get())->
1088            setInterleaveDuration(mInterleaveDurationUs);
1089    }
1090
1091    if (mMaxFileDurationUs != 0) {
1092        writer->setMaxFileDuration(mMaxFileDurationUs);
1093    }
1094    if (mMaxFileSizeBytes != 0) {
1095        writer->setMaxFileSize(mMaxFileSizeBytes);
1096    }
1097    sp<MetaData> meta = new MetaData;
1098    meta->setInt64(kKeyTime, systemTime() / 1000);
1099    meta->setInt32(kKeyFileType, mOutputFormat);
1100    meta->setInt32(kKeyBitRate, totalBitRate);
1101    meta->setInt32(kKey64BitFileOffset, mUse64BitFileOffset);
1102    if (mMovieTimeScale > 0) {
1103        meta->setInt32(kKeyTimeScale, mMovieTimeScale);
1104    }
1105    if (mTrackEveryTimeDurationUs > 0) {
1106        meta->setInt64(kKeyTrackTimeStatus, mTrackEveryTimeDurationUs);
1107    }
1108    writer->setListener(mListener);
1109    mWriter = writer;
1110    return mWriter->start(meta.get());
1111}
1112
1113status_t StagefrightRecorder::pause() {
1114    LOGV("pause");
1115    if (mWriter == NULL) {
1116        return UNKNOWN_ERROR;
1117    }
1118    mWriter->pause();
1119    return OK;
1120}
1121
1122status_t StagefrightRecorder::stop() {
1123    LOGV("stop");
1124    status_t err = OK;
1125    if (mWriter != NULL) {
1126        err = mWriter->stop();
1127        mWriter.clear();
1128    }
1129
1130    if (mCamera != 0) {
1131        LOGV("Disconnect camera");
1132        int64_t token = IPCThreadState::self()->clearCallingIdentity();
1133        if ((mFlags & FLAGS_HOT_CAMERA) == 0) {
1134            LOGV("Camera was cold when we started, stopping preview");
1135            mCamera->stopPreview();
1136        }
1137        mCamera->unlock();
1138        mCamera.clear();
1139        IPCThreadState::self()->restoreCallingIdentity(token);
1140        mFlags = 0;
1141    }
1142
1143    if (mOutputFd >= 0) {
1144        ::close(mOutputFd);
1145        mOutputFd = -1;
1146    }
1147
1148    return err;
1149}
1150
1151status_t StagefrightRecorder::close() {
1152    LOGV("close");
1153    stop();
1154
1155    return OK;
1156}
1157
1158status_t StagefrightRecorder::reset() {
1159    LOGV("reset");
1160    stop();
1161
1162    // No audio or video source by default
1163    mAudioSource = AUDIO_SOURCE_LIST_END;
1164    mVideoSource = VIDEO_SOURCE_LIST_END;
1165
1166    // Default parameters
1167    mOutputFormat  = OUTPUT_FORMAT_THREE_GPP;
1168    mAudioEncoder  = AUDIO_ENCODER_AMR_NB;
1169    mVideoEncoder  = VIDEO_ENCODER_H263;
1170    mVideoWidth    = 176;
1171    mVideoHeight   = 144;
1172    mFrameRate     = 20;
1173    mVideoBitRate  = 192000;
1174    mSampleRate    = 8000;
1175    mAudioChannels = 1;
1176    mAudioBitRate  = 12200;
1177    mInterleaveDurationUs = 0;
1178    mIFramesIntervalSec = 1;
1179    mAudioSourceNode = 0;
1180    mUse64BitFileOffset = false;
1181    mMovieTimeScale  = -1;
1182    mAudioTimeScale  = -1;
1183    mVideoTimeScale  = -1;
1184    mCameraId        = 0;
1185    mVideoEncoderProfile = -1;
1186    mVideoEncoderLevel   = -1;
1187    mMaxFileDurationUs = 0;
1188    mMaxFileSizeBytes = 0;
1189    mTrackEveryTimeDurationUs = 0;
1190    mEncoderProfiles = MediaProfiles::getInstance();
1191
1192    mOutputFd = -1;
1193    mFlags = 0;
1194
1195    return OK;
1196}
1197
1198status_t StagefrightRecorder::getMaxAmplitude(int *max) {
1199    LOGV("getMaxAmplitude");
1200
1201    if (max == NULL) {
1202        LOGE("Null pointer argument");
1203        return BAD_VALUE;
1204    }
1205
1206    if (mAudioSourceNode != 0) {
1207        *max = mAudioSourceNode->getMaxAmplitude();
1208    } else {
1209        *max = 0;
1210    }
1211
1212    return OK;
1213}
1214
1215status_t StagefrightRecorder::dump(
1216        int fd, const Vector<String16>& args) const {
1217    LOGV("dump");
1218    const size_t SIZE = 256;
1219    char buffer[SIZE];
1220    String8 result;
1221    if (mWriter != 0) {
1222        mWriter->dump(fd, args);
1223    } else {
1224        snprintf(buffer, SIZE, "   No file writer\n");
1225        result.append(buffer);
1226    }
1227    snprintf(buffer, SIZE, "   Recorder: %p\n", this);
1228    snprintf(buffer, SIZE, "   Output file (fd %d):\n", mOutputFd);
1229    result.append(buffer);
1230    snprintf(buffer, SIZE, "     File format: %d\n", mOutputFormat);
1231    result.append(buffer);
1232    snprintf(buffer, SIZE, "     Max file size (bytes): %lld\n", mMaxFileSizeBytes);
1233    result.append(buffer);
1234    snprintf(buffer, SIZE, "     Max file duration (us): %lld\n", mMaxFileDurationUs);
1235    result.append(buffer);
1236    snprintf(buffer, SIZE, "     File offset length (bits): %d\n", mUse64BitFileOffset? 64: 32);
1237    result.append(buffer);
1238    snprintf(buffer, SIZE, "     Interleave duration (us): %d\n", mInterleaveDurationUs);
1239    result.append(buffer);
1240    snprintf(buffer, SIZE, "     Progress notification: %lld us\n", mTrackEveryTimeDurationUs);
1241    result.append(buffer);
1242    snprintf(buffer, SIZE, "   Audio\n");
1243    result.append(buffer);
1244    snprintf(buffer, SIZE, "     Source: %d\n", mAudioSource);
1245    result.append(buffer);
1246    snprintf(buffer, SIZE, "     Encoder: %d\n", mAudioEncoder);
1247    result.append(buffer);
1248    snprintf(buffer, SIZE, "     Bit rate (bps): %d\n", mAudioBitRate);
1249    result.append(buffer);
1250    snprintf(buffer, SIZE, "     Sampling rate (hz): %d\n", mSampleRate);
1251    result.append(buffer);
1252    snprintf(buffer, SIZE, "     Number of channels: %d\n", mAudioChannels);
1253    result.append(buffer);
1254    snprintf(buffer, SIZE, "     Max amplitude: %d\n", mAudioSourceNode == 0? 0: mAudioSourceNode->getMaxAmplitude());
1255    result.append(buffer);
1256    snprintf(buffer, SIZE, "   Video\n");
1257    result.append(buffer);
1258    snprintf(buffer, SIZE, "     Source: %d\n", mVideoSource);
1259    result.append(buffer);
1260    snprintf(buffer, SIZE, "     Camera Id: %d\n", mCameraId);
1261    result.append(buffer);
1262    snprintf(buffer, SIZE, "     Camera flags: %d\n", mFlags);
1263    result.append(buffer);
1264    snprintf(buffer, SIZE, "     Encoder: %d\n", mVideoEncoder);
1265    result.append(buffer);
1266    snprintf(buffer, SIZE, "     Encoder profile: %d\n", mVideoEncoderProfile);
1267    result.append(buffer);
1268    snprintf(buffer, SIZE, "     Encoder level: %d\n", mVideoEncoderLevel);
1269    result.append(buffer);
1270    snprintf(buffer, SIZE, "     I frames interval (s): %d\n", mIFramesIntervalSec);
1271    result.append(buffer);
1272    snprintf(buffer, SIZE, "     Frame size (pixels): %dx%d\n", mVideoWidth, mVideoHeight);
1273    result.append(buffer);
1274    snprintf(buffer, SIZE, "     Frame rate (fps): %d\n", mFrameRate);
1275    result.append(buffer);
1276    snprintf(buffer, SIZE, "     Bit rate (bps): %d\n", mVideoBitRate);
1277    result.append(buffer);
1278    ::write(fd, result.string(), result.size());
1279    return OK;
1280}
1281}  // namespace android
1282