blob: c3e6d65406c68e0c5b96c87b76417a2ea89cecba [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 Zavin24fc2fb2011-04-19 22:30:36 -070025#include <hardware/audio.h>
26
Andreas Huberea6a38c2009-11-16 15:43:38 -080027namespace android {
28
James Dongb00e2462010-04-26 17:48:26 -070029class Camera;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070030class CameraSource;
Nipun Kwatra7553cf72010-09-15 15:08:49 -070031class CameraSourceTimeLapse;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070032class MediaSourceSplitter;
Andreas Huber996dddf2010-01-25 15:30:31 -080033struct MediaSource;
34struct MediaWriter;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070035class MetaData;
James Dong57e7f832010-06-24 19:55:31 -070036struct AudioSource;
James Dong42a18c02010-06-16 17:27:46 -070037class MediaProfiles;
Andreas Huberea6a38c2009-11-16 15:43:38 -080038
39struct StagefrightRecorder : public MediaRecorderBase {
40 StagefrightRecorder();
41 virtual ~StagefrightRecorder();
42
43 virtual status_t init();
Dima Zavin24fc2fb2011-04-19 22:30:36 -070044 virtual status_t setAudioSource(audio_source_t as);
Andreas Huberea6a38c2009-11-16 15:43:38 -080045 virtual status_t setVideoSource(video_source vs);
46 virtual status_t setOutputFormat(output_format of);
47 virtual status_t setAudioEncoder(audio_encoder ae);
48 virtual status_t setVideoEncoder(video_encoder ve);
49 virtual status_t setVideoSize(int width, int height);
50 virtual status_t setVideoFrameRate(int frames_per_second);
51 virtual status_t setCamera(const sp<ICamera>& camera);
Jamie Gennis85cfdd02010-08-10 16:37:53 -070052 virtual status_t setPreviewSurface(const sp<Surface>& surface);
Andreas Huberea6a38c2009-11-16 15:43:38 -080053 virtual status_t setOutputFile(const char *path);
54 virtual status_t setOutputFile(int fd, int64_t offset, int64_t length);
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070055 virtual status_t setOutputFileAuxiliary(int fd);
Andreas Huberea6a38c2009-11-16 15:43:38 -080056 virtual status_t setParameters(const String8& params);
James Dongfe1bafe2010-06-25 17:06:47 -070057 virtual status_t setListener(const sp<IMediaRecorderClient>& listener);
Andreas Huberea6a38c2009-11-16 15:43:38 -080058 virtual status_t prepare();
59 virtual status_t start();
James Dong08c74732010-06-10 12:28:15 -070060 virtual status_t pause();
Andreas Huberea6a38c2009-11-16 15:43:38 -080061 virtual status_t stop();
62 virtual status_t close();
63 virtual status_t reset();
64 virtual status_t getMaxAmplitude(int *max);
James Dong929642e2010-07-08 11:16:11 -070065 virtual status_t dump(int fd, const Vector<String16>& args) const;
Andreas Huberea6a38c2009-11-16 15:43:38 -080066
67private:
James Dong0c128b62010-10-08 11:59:32 -070068 sp<ICamera> mCamera;
Jamie Gennis85cfdd02010-08-10 16:37:53 -070069 sp<Surface> mPreviewSurface;
James Dongfe1bafe2010-06-25 17:06:47 -070070 sp<IMediaRecorderClient> mListener;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -070071 sp<MediaWriter> mWriter, mWriterAux;
James Dongf84bfab2011-03-21 14:29:38 -070072 int mOutputFd, mOutputFdAux;
James Dong57e7f832010-06-24 19:55:31 -070073 sp<AudioSource> mAudioSourceNode;
Andreas Huberea6a38c2009-11-16 15:43:38 -080074
Dima Zavin24fc2fb2011-04-19 22:30:36 -070075 audio_source_t mAudioSource;
Andreas Huberea6a38c2009-11-16 15:43:38 -080076 video_source mVideoSource;
77 output_format mOutputFormat;
78 audio_encoder mAudioEncoder;
79 video_encoder mVideoEncoder;
James Dong6feaa462010-06-20 08:20:54 -070080 bool mUse64BitFileOffset;
James Dongabed93a2010-04-22 17:27:04 -070081 int32_t mVideoWidth, mVideoHeight;
Nipun Kwatra239f2e52010-08-31 15:35:44 -070082 int32_t mAuxVideoWidth, mAuxVideoHeight;
James Dongabed93a2010-04-22 17:27:04 -070083 int32_t mFrameRate;
Nipun Kwatra239f2e52010-08-31 15:35:44 -070084 int32_t mVideoBitRate, mAuxVideoBitRate;
85 int32_t mAudioBitRate;
James Dongabed93a2010-04-22 17:27:04 -070086 int32_t mAudioChannels;
87 int32_t mSampleRate;
James Dong3300e962010-04-21 16:14:15 -070088 int32_t mInterleaveDurationUs;
James Dong52d13f02010-07-02 11:39:06 -070089 int32_t mIFramesIntervalSec;
James Dong09936ed2010-06-24 19:04:27 -070090 int32_t mCameraId;
James Dong81c929a2010-07-01 15:02:14 -070091 int32_t mVideoEncoderProfile;
92 int32_t mVideoEncoderLevel;
James Dong52d13f02010-07-02 11:39:06 -070093 int32_t mMovieTimeScale;
94 int32_t mVideoTimeScale;
95 int32_t mAudioTimeScale;
James Dong2cd841d2010-05-11 11:46:59 -070096 int64_t mMaxFileSizeBytes;
97 int64_t mMaxFileDurationUs;
James Dong09936ed2010-06-24 19:04:27 -070098 int64_t mTrackEveryTimeDurationUs;
James Dongb9d7e012010-11-09 11:15:47 -080099 int32_t mRotationDegrees; // Clockwise
James Dongabed93a2010-04-22 17:27:04 -0700100
Nipun Kwatrad26920a2010-06-30 18:51:31 -0700101 bool mCaptureTimeLapse;
Nipun Kwatrad01371b2010-07-20 21:33:31 -0700102 int64_t mTimeBetweenTimeLapseFrameCaptureUs;
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700103 bool mCaptureAuxVideo;
104 sp<MediaSourceSplitter> mCameraSourceSplitter;
Nipun Kwatra7553cf72010-09-15 15:08:49 -0700105 sp<CameraSourceTimeLapse> mCameraSourceTimeLapse;
Nipun Kwatrad26920a2010-06-30 18:51:31 -0700106
Andreas Huberea6a38c2009-11-16 15:43:38 -0800107 String8 mParams;
Andreas Huberea6a38c2009-11-16 15:43:38 -0800108
James Dong05c2fd52010-11-02 13:20:11 -0700109 bool mIsMetaDataStoredInVideoBuffers;
James Dong42a18c02010-06-16 17:27:46 -0700110 MediaProfiles *mEncoderProfiles;
111
Gloria Wang62e05a62011-02-23 11:47:34 -0800112 bool mStarted;
113
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700114 status_t setupMPEG4Recording(
Nipun Kwatra239f2e52010-08-31 15:35:44 -0700115 bool useSplitCameraSource,
116 int outputFd,
117 int32_t videoWidth, int32_t videoHeight,
118 int32_t videoBitRate,
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700119 int32_t *totalBitRate,
120 sp<MediaWriter> *mediaWriter);
121 void setupMPEG4MetaData(int64_t startTimeUs, int32_t totalBitRate,
122 sp<MetaData> *meta);
Andreas Huber996dddf2010-01-25 15:30:31 -0800123 status_t startMPEG4Recording();
124 status_t startAMRRecording();
James Dong2cd841d2010-05-11 11:46:59 -0700125 status_t startAACRecording();
James Dongf84bfab2011-03-21 14:29:38 -0700126 status_t startRawAudioRecording();
Andreas Huber57648e42010-08-04 10:14:30 -0700127 status_t startRTPRecording();
Andreas Huber9adf4662010-10-12 14:17:45 -0700128 status_t startMPEG2TSRecording();
James Dongabed93a2010-04-22 17:27:04 -0700129 sp<MediaSource> createAudioSource();
James Dong0c128b62010-10-08 11:59:32 -0700130 status_t checkVideoEncoderCapabilities();
James Dong54815a72011-01-12 20:45:16 -0800131 status_t checkAudioEncoderCapabilities();
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700132 status_t setupCameraSource(sp<CameraSource> *cameraSource);
James Dong7b06de62010-06-30 12:41:16 -0700133 status_t setupAudioEncoder(const sp<MediaWriter>& writer);
Nipun Kwatrad7e7a3f2010-08-26 17:05:18 -0700134 status_t setupVideoEncoder(
135 sp<MediaSource> cameraSource,
136 int32_t videoBitRate,
137 sp<MediaSource> *source);
James Dong7b06de62010-06-30 12:41:16 -0700138
139 // Encoding parameter handling utilities
James Dongabed93a2010-04-22 17:27:04 -0700140 status_t setParameter(const String8 &key, const String8 &value);
James Dongabed93a2010-04-22 17:27:04 -0700141 status_t setParamAudioEncodingBitRate(int32_t bitRate);
142 status_t setParamAudioNumberOfChannels(int32_t channles);
143 status_t setParamAudioSamplingRate(int32_t sampleRate);
James Dong52d13f02010-07-02 11:39:06 -0700144 status_t setParamAudioTimeScale(int32_t timeScale);
Nipun Kwatrad01371b2010-07-20 21:33:31 -0700145 status_t setParamTimeLapseEnable(int32_t timeLapseEnable);
146 status_t setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs);
Nipun Kwatra239f2e52010-08-31 15:35:44 -0700147 status_t setParamAuxVideoHeight(int32_t height);
148 status_t setParamAuxVideoWidth(int32_t width);
149 status_t setParamAuxVideoEncodingBitRate(int32_t bitRate);
James Dong09936ed2010-06-24 19:04:27 -0700150 status_t setParamVideoEncodingBitRate(int32_t bitRate);
James Dong52d13f02010-07-02 11:39:06 -0700151 status_t setParamVideoIFramesInterval(int32_t seconds);
James Dong81c929a2010-07-01 15:02:14 -0700152 status_t setParamVideoEncoderProfile(int32_t profile);
153 status_t setParamVideoEncoderLevel(int32_t level);
James Dong09936ed2010-06-24 19:04:27 -0700154 status_t setParamVideoCameraId(int32_t cameraId);
James Dong52d13f02010-07-02 11:39:06 -0700155 status_t setParamVideoTimeScale(int32_t timeScale);
James Dongb9d7e012010-11-09 11:15:47 -0800156 status_t setParamVideoRotation(int32_t degrees);
James Dong09936ed2010-06-24 19:04:27 -0700157 status_t setParamTrackTimeStatus(int64_t timeDurationUs);
James Dong3300e962010-04-21 16:14:15 -0700158 status_t setParamInterleaveDuration(int32_t durationUs);
James Dong6feaa462010-06-20 08:20:54 -0700159 status_t setParam64BitFileOffset(bool use64BitFileOffset);
James Dong7b06de62010-06-30 12:41:16 -0700160 status_t setParamMaxFileDurationUs(int64_t timeUs);
161 status_t setParamMaxFileSizeBytes(int64_t bytes);
James Dong52d13f02010-07-02 11:39:06 -0700162 status_t setParamMovieTimeScale(int32_t timeScale);
James Dong42a18c02010-06-16 17:27:46 -0700163 void clipVideoBitRate();
164 void clipVideoFrameRate();
165 void clipVideoFrameWidth();
166 void clipVideoFrameHeight();
James Dong54815a72011-01-12 20:45:16 -0800167 void clipAudioBitRate();
168 void clipAudioSampleRate();
169 void clipNumberOfAudioChannels();
Andreas Huber996dddf2010-01-25 15:30:31 -0800170
Andreas Huberea6a38c2009-11-16 15:43:38 -0800171 StagefrightRecorder(const StagefrightRecorder &);
172 StagefrightRecorder &operator=(const StagefrightRecorder &);
173};
174
175} // namespace android
176
177#endif // STAGEFRIGHT_RECORDER_H_