blob: 2c440c1a0dec8a43058ad98ff7af0f98cf1f7bb4 [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
25namespace android {
26
James Dongb00e2462010-04-26 17:48:26 -070027class Camera;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070028class CameraSource;
Nipun Kwatra7553cf72010-09-15 15:08:49 -070029class CameraSourceTimeLapse;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070030class MediaSourceSplitter;
Andreas Huber996dddf2010-01-25 15:30:31 -080031struct MediaSource;
32struct MediaWriter;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070033class MetaData;
James Dong57e7f832010-06-24 19:55:31 -070034struct AudioSource;
James Dong42a18c02010-06-16 17:27:46 -070035class MediaProfiles;
Andreas Huberea6a38c2009-11-16 15:43:38 -080036
37struct StagefrightRecorder : public MediaRecorderBase {
38 StagefrightRecorder();
39 virtual ~StagefrightRecorder();
40
41 virtual status_t init();
42 virtual status_t setAudioSource(audio_source as);
43 virtual status_t setVideoSource(video_source vs);
44 virtual status_t setOutputFormat(output_format of);
45 virtual status_t setAudioEncoder(audio_encoder ae);
46 virtual status_t setVideoEncoder(video_encoder ve);
47 virtual status_t setVideoSize(int width, int height);
48 virtual status_t setVideoFrameRate(int frames_per_second);
49 virtual status_t setCamera(const sp<ICamera>& camera);
Jamie Gennis85cfdd02010-08-10 16:37:53 -070050 virtual status_t setPreviewSurface(const sp<Surface>& surface);
Andreas Huberea6a38c2009-11-16 15:43:38 -080051 virtual status_t setOutputFile(const char *path);
52 virtual status_t setOutputFile(int fd, int64_t offset, int64_t length);
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070053 virtual status_t setOutputFileAuxiliary(int fd);
Andreas Huberea6a38c2009-11-16 15:43:38 -080054 virtual status_t setParameters(const String8& params);
James Dongfe1bafe2010-06-25 17:06:47 -070055 virtual status_t setListener(const sp<IMediaRecorderClient>& listener);
Andreas Huberea6a38c2009-11-16 15:43:38 -080056 virtual status_t prepare();
57 virtual status_t start();
James Dong08c74732010-06-10 12:28:15 -070058 virtual status_t pause();
Andreas Huberea6a38c2009-11-16 15:43:38 -080059 virtual status_t stop();
60 virtual status_t close();
61 virtual status_t reset();
62 virtual status_t getMaxAmplitude(int *max);
James Dong929642e2010-07-08 11:16:11 -070063 virtual status_t dump(int fd, const Vector<String16>& args) const;
Andreas Huberea6a38c2009-11-16 15:43:38 -080064
65private:
James Dong0c128b62010-10-08 11:59:32 -070066 sp<ICamera> mCamera;
Jamie Gennis85cfdd02010-08-10 16:37:53 -070067 sp<Surface> mPreviewSurface;
James Dongfe1bafe2010-06-25 17:06:47 -070068 sp<IMediaRecorderClient> mListener;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070069 sp<MediaWriter> mWriter, mWriterAux;
James Dong57e7f832010-06-24 19:55:31 -070070 sp<AudioSource> mAudioSourceNode;
Andreas Huberea6a38c2009-11-16 15:43:38 -080071
72 audio_source mAudioSource;
73 video_source mVideoSource;
74 output_format mOutputFormat;
75 audio_encoder mAudioEncoder;
76 video_encoder mVideoEncoder;
James Dong6feaa462010-06-20 08:20:54 -070077 bool mUse64BitFileOffset;
James Dongabed93a2010-04-22 17:27:04 -070078 int32_t mVideoWidth, mVideoHeight;
Nipun Kwatra239f2e52010-08-31 15:35:44 -070079 int32_t mAuxVideoWidth, mAuxVideoHeight;
James Dongabed93a2010-04-22 17:27:04 -070080 int32_t mFrameRate;
Nipun Kwatra239f2e52010-08-31 15:35:44 -070081 int32_t mVideoBitRate, mAuxVideoBitRate;
82 int32_t mAudioBitRate;
James Dongabed93a2010-04-22 17:27:04 -070083 int32_t mAudioChannels;
84 int32_t mSampleRate;
James Dong3300e962010-04-21 16:14:15 -070085 int32_t mInterleaveDurationUs;
James Dong52d13f02010-07-02 11:39:06 -070086 int32_t mIFramesIntervalSec;
James Dong09936ed2010-06-24 19:04:27 -070087 int32_t mCameraId;
James Dong81c929a2010-07-01 15:02:14 -070088 int32_t mVideoEncoderProfile;
89 int32_t mVideoEncoderLevel;
James Dong52d13f02010-07-02 11:39:06 -070090 int32_t mMovieTimeScale;
91 int32_t mVideoTimeScale;
92 int32_t mAudioTimeScale;
James Dong2cd841d2010-05-11 11:46:59 -070093 int64_t mMaxFileSizeBytes;
94 int64_t mMaxFileDurationUs;
James Dong09936ed2010-06-24 19:04:27 -070095 int64_t mTrackEveryTimeDurationUs;
James Dongb9d7e012010-11-09 11:15:47 -080096 int32_t mRotationDegrees; // Clockwise
James Dongabed93a2010-04-22 17:27:04 -070097
Nipun Kwatrad26920a2010-06-30 18:51:31 -070098 bool mCaptureTimeLapse;
Nipun Kwatrad01371b2010-07-20 21:33:31 -070099 int64_t mTimeBetweenTimeLapseFrameCaptureUs;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700100 bool mCaptureAuxVideo;
101 sp<MediaSourceSplitter> mCameraSourceSplitter;
Nipun Kwatra7553cf72010-09-15 15:08:49 -0700102 sp<CameraSourceTimeLapse> mCameraSourceTimeLapse;
Nipun Kwatrad26920a2010-06-30 18:51:31 -0700103
Andreas Huberea6a38c2009-11-16 15:43:38 -0800104 String8 mParams;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700105 int mOutputFd, mOutputFdAux;
Andreas Huberea6a38c2009-11-16 15:43:38 -0800106
James Dong05c2fd52010-11-02 13:20:11 -0700107 bool mIsMetaDataStoredInVideoBuffers;
James Dong42a18c02010-06-16 17:27:46 -0700108 MediaProfiles *mEncoderProfiles;
109
Gloria Wang62e05a62011-02-23 11:47:34 -0800110 bool mStarted;
111
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700112 status_t setupMPEG4Recording(
Nipun Kwatra239f2e52010-08-31 15:35:44 -0700113 bool useSplitCameraSource,
114 int outputFd,
115 int32_t videoWidth, int32_t videoHeight,
116 int32_t videoBitRate,
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700117 int32_t *totalBitRate,
118 sp<MediaWriter> *mediaWriter);
119 void setupMPEG4MetaData(int64_t startTimeUs, int32_t totalBitRate,
120 sp<MetaData> *meta);
Andreas Huber996dddf2010-01-25 15:30:31 -0800121 status_t startMPEG4Recording();
122 status_t startAMRRecording();
James Dong2cd841d2010-05-11 11:46:59 -0700123 status_t startAACRecording();
Andreas Huber57648e42010-08-04 10:14:30 -0700124 status_t startRTPRecording();
Andreas Huber9adf4662010-10-12 14:17:45 -0700125 status_t startMPEG2TSRecording();
James Dongabed93a2010-04-22 17:27:04 -0700126 sp<MediaSource> createAudioSource();
James Dong0c128b62010-10-08 11:59:32 -0700127 status_t checkVideoEncoderCapabilities();
James Dong54815a72011-01-12 20:45:16 -0800128 status_t checkAudioEncoderCapabilities();
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700129 status_t setupCameraSource(sp<CameraSource> *cameraSource);
James Dong7b06de62010-06-30 12:41:16 -0700130 status_t setupAudioEncoder(const sp<MediaWriter>& writer);
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700131 status_t setupVideoEncoder(
132 sp<MediaSource> cameraSource,
133 int32_t videoBitRate,
134 sp<MediaSource> *source);
James Dong7b06de62010-06-30 12:41:16 -0700135
136 // Encoding parameter handling utilities
James Dongabed93a2010-04-22 17:27:04 -0700137 status_t setParameter(const String8 &key, const String8 &value);
James Dongabed93a2010-04-22 17:27:04 -0700138 status_t setParamAudioEncodingBitRate(int32_t bitRate);
139 status_t setParamAudioNumberOfChannels(int32_t channles);
140 status_t setParamAudioSamplingRate(int32_t sampleRate);
James Dong52d13f02010-07-02 11:39:06 -0700141 status_t setParamAudioTimeScale(int32_t timeScale);
Nipun Kwatrad01371b2010-07-20 21:33:31 -0700142 status_t setParamTimeLapseEnable(int32_t timeLapseEnable);
143 status_t setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs);
Nipun Kwatra239f2e52010-08-31 15:35:44 -0700144 status_t setParamAuxVideoHeight(int32_t height);
145 status_t setParamAuxVideoWidth(int32_t width);
146 status_t setParamAuxVideoEncodingBitRate(int32_t bitRate);
James Dong09936ed2010-06-24 19:04:27 -0700147 status_t setParamVideoEncodingBitRate(int32_t bitRate);
James Dong52d13f02010-07-02 11:39:06 -0700148 status_t setParamVideoIFramesInterval(int32_t seconds);
James Dong81c929a2010-07-01 15:02:14 -0700149 status_t setParamVideoEncoderProfile(int32_t profile);
150 status_t setParamVideoEncoderLevel(int32_t level);
James Dong09936ed2010-06-24 19:04:27 -0700151 status_t setParamVideoCameraId(int32_t cameraId);
James Dong52d13f02010-07-02 11:39:06 -0700152 status_t setParamVideoTimeScale(int32_t timeScale);
James Dongb9d7e012010-11-09 11:15:47 -0800153 status_t setParamVideoRotation(int32_t degrees);
James Dong09936ed2010-06-24 19:04:27 -0700154 status_t setParamTrackTimeStatus(int64_t timeDurationUs);
James Dong3300e962010-04-21 16:14:15 -0700155 status_t setParamInterleaveDuration(int32_t durationUs);
James Dong6feaa462010-06-20 08:20:54 -0700156 status_t setParam64BitFileOffset(bool use64BitFileOffset);
James Dong7b06de62010-06-30 12:41:16 -0700157 status_t setParamMaxFileDurationUs(int64_t timeUs);
158 status_t setParamMaxFileSizeBytes(int64_t bytes);
James Dong52d13f02010-07-02 11:39:06 -0700159 status_t setParamMovieTimeScale(int32_t timeScale);
James Dong42a18c02010-06-16 17:27:46 -0700160 void clipVideoBitRate();
161 void clipVideoFrameRate();
162 void clipVideoFrameWidth();
163 void clipVideoFrameHeight();
James Dong54815a72011-01-12 20:45:16 -0800164 void clipAudioBitRate();
165 void clipAudioSampleRate();
166 void clipNumberOfAudioChannels();
Andreas Huber996dddf2010-01-25 15:30:31 -0800167
Andreas Huberea6a38c2009-11-16 15:43:38 -0800168 StagefrightRecorder(const StagefrightRecorder &);
169 StagefrightRecorder &operator=(const StagefrightRecorder &);
170};
171
172} // namespace android
173
174#endif // STAGEFRIGHT_RECORDER_H_