blob: 034b373337dc324fb1f924c046bb8d0df0a86758 [file] [log] [blame]
Andreas Huberea6a38c2009-11-16 15:43:38 -08001/*
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#ifndef STAGEFRIGHT_RECORDER_H_
18
19#define STAGEFRIGHT_RECORDER_H_
20
21#include <media/MediaRecorderBase.h>
James Dong8a9f8bf2010-10-03 22:08:23 -070022#include <camera/CameraParameters.h>
Andreas Huberea6a38c2009-11-16 15:43:38 -080023#include <utils/String8.h>
24
Dima Zavin34bb4192011-05-11 14:15:23 -070025#include <system/audio.h>
Dima Zavin24fc2fb2011-04-19 22:30:36 -070026
Andreas Huberea6a38c2009-11-16 15:43:38 -080027namespace android {
28
James Dongb00e2462010-04-26 17:48:26 -070029class Camera;
Wu-cheng Li42419ce2011-06-01 17:22:24 +080030class ICameraRecordingProxy;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070031class CameraSource;
Nipun Kwatra7553cf72010-09-15 15:08:49 -070032class CameraSourceTimeLapse;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070033class MediaSourceSplitter;
Andreas Huber996dddf2010-01-25 15:30:31 -080034struct MediaSource;
35struct MediaWriter;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070036class MetaData;
James Dong57e7f832010-06-24 19:55:31 -070037struct AudioSource;
James Dong42a18c02010-06-16 17:27:46 -070038class MediaProfiles;
Andreas Huberea6a38c2009-11-16 15:43:38 -080039
40struct StagefrightRecorder : public MediaRecorderBase {
41 StagefrightRecorder();
42 virtual ~StagefrightRecorder();
43
44 virtual status_t init();
Dima Zavin24fc2fb2011-04-19 22:30:36 -070045 virtual status_t setAudioSource(audio_source_t as);
Andreas Huberea6a38c2009-11-16 15:43:38 -080046 virtual status_t setVideoSource(video_source vs);
47 virtual status_t setOutputFormat(output_format of);
48 virtual status_t setAudioEncoder(audio_encoder ae);
49 virtual status_t setVideoEncoder(video_encoder ve);
50 virtual status_t setVideoSize(int width, int height);
51 virtual status_t setVideoFrameRate(int frames_per_second);
Wu-cheng Li42419ce2011-06-01 17:22:24 +080052 virtual status_t setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy);
Jamie Gennis85cfdd02010-08-10 16:37:53 -070053 virtual status_t setPreviewSurface(const sp<Surface>& surface);
Andreas Huberea6a38c2009-11-16 15:43:38 -080054 virtual status_t setOutputFile(const char *path);
55 virtual status_t setOutputFile(int fd, int64_t offset, int64_t length);
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070056 virtual status_t setOutputFileAuxiliary(int fd);
Andreas Huberea6a38c2009-11-16 15:43:38 -080057 virtual status_t setParameters(const String8& params);
James Dongfe1bafe2010-06-25 17:06:47 -070058 virtual status_t setListener(const sp<IMediaRecorderClient>& listener);
Andreas Huberea6a38c2009-11-16 15:43:38 -080059 virtual status_t prepare();
60 virtual status_t start();
James Dong08c74732010-06-10 12:28:15 -070061 virtual status_t pause();
Andreas Huberea6a38c2009-11-16 15:43:38 -080062 virtual status_t stop();
63 virtual status_t close();
64 virtual status_t reset();
65 virtual status_t getMaxAmplitude(int *max);
James Dong929642e2010-07-08 11:16:11 -070066 virtual status_t dump(int fd, const Vector<String16>& args) const;
Andreas Huberea6a38c2009-11-16 15:43:38 -080067
68private:
James Dong0c128b62010-10-08 11:59:32 -070069 sp<ICamera> mCamera;
Wu-cheng Li42419ce2011-06-01 17:22:24 +080070 sp<ICameraRecordingProxy> mCameraProxy;
Jamie Gennis85cfdd02010-08-10 16:37:53 -070071 sp<Surface> mPreviewSurface;
James Dongfe1bafe2010-06-25 17:06:47 -070072 sp<IMediaRecorderClient> mListener;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070073 sp<MediaWriter> mWriter, mWriterAux;
James Dongf84bfab2011-03-21 14:29:38 -070074 int mOutputFd, mOutputFdAux;
James Dong57e7f832010-06-24 19:55:31 -070075 sp<AudioSource> mAudioSourceNode;
Andreas Huberea6a38c2009-11-16 15:43:38 -080076
Dima Zavin24fc2fb2011-04-19 22:30:36 -070077 audio_source_t mAudioSource;
Andreas Huberea6a38c2009-11-16 15:43:38 -080078 video_source mVideoSource;
79 output_format mOutputFormat;
80 audio_encoder mAudioEncoder;
81 video_encoder mVideoEncoder;
James Dong6feaa462010-06-20 08:20:54 -070082 bool mUse64BitFileOffset;
James Dongabed93a2010-04-22 17:27:04 -070083 int32_t mVideoWidth, mVideoHeight;
Nipun Kwatra239f2e52010-08-31 15:35:44 -070084 int32_t mAuxVideoWidth, mAuxVideoHeight;
James Dongabed93a2010-04-22 17:27:04 -070085 int32_t mFrameRate;
Nipun Kwatra239f2e52010-08-31 15:35:44 -070086 int32_t mVideoBitRate, mAuxVideoBitRate;
87 int32_t mAudioBitRate;
James Dongabed93a2010-04-22 17:27:04 -070088 int32_t mAudioChannels;
89 int32_t mSampleRate;
James Dong3300e962010-04-21 16:14:15 -070090 int32_t mInterleaveDurationUs;
James Dong52d13f02010-07-02 11:39:06 -070091 int32_t mIFramesIntervalSec;
James Dong09936ed2010-06-24 19:04:27 -070092 int32_t mCameraId;
James Dong81c929a2010-07-01 15:02:14 -070093 int32_t mVideoEncoderProfile;
94 int32_t mVideoEncoderLevel;
James Dong52d13f02010-07-02 11:39:06 -070095 int32_t mMovieTimeScale;
96 int32_t mVideoTimeScale;
97 int32_t mAudioTimeScale;
James Dong2cd841d2010-05-11 11:46:59 -070098 int64_t mMaxFileSizeBytes;
99 int64_t mMaxFileDurationUs;
James Dong09936ed2010-06-24 19:04:27 -0700100 int64_t mTrackEveryTimeDurationUs;
James Dongb9d7e012010-11-09 11:15:47 -0800101 int32_t mRotationDegrees; // Clockwise
James Dong987ab482011-05-11 19:09:25 -0700102 int32_t mLatitudex10000;
103 int32_t mLongitudex10000;
James Dong13a33162011-05-09 16:56:25 -0700104 int32_t mStartTimeOffsetMs;
James Dongabed93a2010-04-22 17:27:04 -0700105
Nipun Kwatrad26920a2010-06-30 18:51:31 -0700106 bool mCaptureTimeLapse;
Nipun Kwatrad01371b2010-07-20 21:33:31 -0700107 int64_t mTimeBetweenTimeLapseFrameCaptureUs;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700108 bool mCaptureAuxVideo;
109 sp<MediaSourceSplitter> mCameraSourceSplitter;
Nipun Kwatra7553cf72010-09-15 15:08:49 -0700110 sp<CameraSourceTimeLapse> mCameraSourceTimeLapse;
Nipun Kwatrad26920a2010-06-30 18:51:31 -0700111
Andreas Huberea6a38c2009-11-16 15:43:38 -0800112 String8 mParams;
Andreas Huberea6a38c2009-11-16 15:43:38 -0800113
James Dong05c2fd52010-11-02 13:20:11 -0700114 bool mIsMetaDataStoredInVideoBuffers;
James Dong42a18c02010-06-16 17:27:46 -0700115 MediaProfiles *mEncoderProfiles;
116
Gloria Wang62e05a62011-02-23 11:47:34 -0800117 bool mStarted;
118
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700119 status_t setupMPEG4Recording(
Nipun Kwatra239f2e52010-08-31 15:35:44 -0700120 bool useSplitCameraSource,
121 int outputFd,
122 int32_t videoWidth, int32_t videoHeight,
123 int32_t videoBitRate,
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700124 int32_t *totalBitRate,
125 sp<MediaWriter> *mediaWriter);
126 void setupMPEG4MetaData(int64_t startTimeUs, int32_t totalBitRate,
127 sp<MetaData> *meta);
Andreas Huber996dddf2010-01-25 15:30:31 -0800128 status_t startMPEG4Recording();
129 status_t startAMRRecording();
James Dong2cd841d2010-05-11 11:46:59 -0700130 status_t startAACRecording();
James Dongf84bfab2011-03-21 14:29:38 -0700131 status_t startRawAudioRecording();
Andreas Huber57648e42010-08-04 10:14:30 -0700132 status_t startRTPRecording();
Andreas Huber9adf4662010-10-12 14:17:45 -0700133 status_t startMPEG2TSRecording();
James Dongabed93a2010-04-22 17:27:04 -0700134 sp<MediaSource> createAudioSource();
James Dong0c128b62010-10-08 11:59:32 -0700135 status_t checkVideoEncoderCapabilities();
James Dong54815a72011-01-12 20:45:16 -0800136 status_t checkAudioEncoderCapabilities();
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700137 status_t setupCameraSource(sp<CameraSource> *cameraSource);
James Dong7b06de62010-06-30 12:41:16 -0700138 status_t setupAudioEncoder(const sp<MediaWriter>& writer);
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700139 status_t setupVideoEncoder(
140 sp<MediaSource> cameraSource,
141 int32_t videoBitRate,
142 sp<MediaSource> *source);
James Dong7b06de62010-06-30 12:41:16 -0700143
144 // Encoding parameter handling utilities
James Dongabed93a2010-04-22 17:27:04 -0700145 status_t setParameter(const String8 &key, const String8 &value);
James Dongabed93a2010-04-22 17:27:04 -0700146 status_t setParamAudioEncodingBitRate(int32_t bitRate);
147 status_t setParamAudioNumberOfChannels(int32_t channles);
148 status_t setParamAudioSamplingRate(int32_t sampleRate);
James Dong52d13f02010-07-02 11:39:06 -0700149 status_t setParamAudioTimeScale(int32_t timeScale);
Nipun Kwatrad01371b2010-07-20 21:33:31 -0700150 status_t setParamTimeLapseEnable(int32_t timeLapseEnable);
151 status_t setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs);
Nipun Kwatra239f2e52010-08-31 15:35:44 -0700152 status_t setParamAuxVideoHeight(int32_t height);
153 status_t setParamAuxVideoWidth(int32_t width);
154 status_t setParamAuxVideoEncodingBitRate(int32_t bitRate);
James Dong09936ed2010-06-24 19:04:27 -0700155 status_t setParamVideoEncodingBitRate(int32_t bitRate);
James Dong52d13f02010-07-02 11:39:06 -0700156 status_t setParamVideoIFramesInterval(int32_t seconds);
James Dong81c929a2010-07-01 15:02:14 -0700157 status_t setParamVideoEncoderProfile(int32_t profile);
158 status_t setParamVideoEncoderLevel(int32_t level);
James Dong09936ed2010-06-24 19:04:27 -0700159 status_t setParamVideoCameraId(int32_t cameraId);
James Dong52d13f02010-07-02 11:39:06 -0700160 status_t setParamVideoTimeScale(int32_t timeScale);
James Dongb9d7e012010-11-09 11:15:47 -0800161 status_t setParamVideoRotation(int32_t degrees);
James Dong09936ed2010-06-24 19:04:27 -0700162 status_t setParamTrackTimeStatus(int64_t timeDurationUs);
James Dong3300e962010-04-21 16:14:15 -0700163 status_t setParamInterleaveDuration(int32_t durationUs);
James Dong6feaa462010-06-20 08:20:54 -0700164 status_t setParam64BitFileOffset(bool use64BitFileOffset);
James Dong7b06de62010-06-30 12:41:16 -0700165 status_t setParamMaxFileDurationUs(int64_t timeUs);
166 status_t setParamMaxFileSizeBytes(int64_t bytes);
James Dong52d13f02010-07-02 11:39:06 -0700167 status_t setParamMovieTimeScale(int32_t timeScale);
James Dong987ab482011-05-11 19:09:25 -0700168 status_t setParamGeoDataLongitude(int32_t longitudex10000);
169 status_t setParamGeoDataLatitude(int32_t latitudex10000);
James Dong42a18c02010-06-16 17:27:46 -0700170 void clipVideoBitRate();
171 void clipVideoFrameRate();
172 void clipVideoFrameWidth();
173 void clipVideoFrameHeight();
James Dong54815a72011-01-12 20:45:16 -0800174 void clipAudioBitRate();
175 void clipAudioSampleRate();
176 void clipNumberOfAudioChannels();
James Dongbe650872011-07-07 16:41:25 -0700177 void setDefaultProfileIfNecessary();
Andreas Huber996dddf2010-01-25 15:30:31 -0800178
Andreas Huberea6a38c2009-11-16 15:43:38 -0800179 StagefrightRecorder(const StagefrightRecorder &);
180 StagefrightRecorder &operator=(const StagefrightRecorder &);
181};
182
183} // namespace android
184
185#endif // STAGEFRIGHT_RECORDER_H_