Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 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 | #ifndef STAGEFRIGHT_RECORDER_H_ |
| 18 | |
| 19 | #define STAGEFRIGHT_RECORDER_H_ |
| 20 | |
| 21 | #include <media/MediaRecorderBase.h> |
James Dong | 8a9f8bf | 2010-10-03 22:08:23 -0700 | [diff] [blame] | 22 | #include <camera/CameraParameters.h> |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 23 | #include <utils/String8.h> |
| 24 | |
Dima Zavin | 34bb419 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 25 | #include <system/audio.h> |
Dima Zavin | 24fc2fb | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 26 | |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 27 | namespace android { |
| 28 | |
James Dong | b00e246 | 2010-04-26 17:48:26 -0700 | [diff] [blame] | 29 | class Camera; |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 30 | class ICameraRecordingProxy; |
Nipun Kwatra | d7e7a3f | 2010-08-26 17:05:18 -0700 | [diff] [blame] | 31 | class CameraSource; |
Nipun Kwatra | 7553cf7 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 32 | class CameraSourceTimeLapse; |
Nipun Kwatra | d7e7a3f | 2010-08-26 17:05:18 -0700 | [diff] [blame] | 33 | class MediaSourceSplitter; |
Andreas Huber | 996dddf | 2010-01-25 15:30:31 -0800 | [diff] [blame] | 34 | struct MediaSource; |
| 35 | struct MediaWriter; |
Nipun Kwatra | d7e7a3f | 2010-08-26 17:05:18 -0700 | [diff] [blame] | 36 | class MetaData; |
James Dong | 57e7f83 | 2010-06-24 19:55:31 -0700 | [diff] [blame] | 37 | struct AudioSource; |
James Dong | 42a18c0 | 2010-06-16 17:27:46 -0700 | [diff] [blame] | 38 | class MediaProfiles; |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 39 | |
| 40 | struct StagefrightRecorder : public MediaRecorderBase { |
| 41 | StagefrightRecorder(); |
| 42 | virtual ~StagefrightRecorder(); |
| 43 | |
| 44 | virtual status_t init(); |
Dima Zavin | 24fc2fb | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 45 | virtual status_t setAudioSource(audio_source_t as); |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 46 | 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 Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 52 | virtual status_t setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy); |
Jamie Gennis | 85cfdd0 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 53 | virtual status_t setPreviewSurface(const sp<Surface>& surface); |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 54 | virtual status_t setOutputFile(const char *path); |
| 55 | virtual status_t setOutputFile(int fd, int64_t offset, int64_t length); |
Nipun Kwatra | d7e7a3f | 2010-08-26 17:05:18 -0700 | [diff] [blame] | 56 | virtual status_t setOutputFileAuxiliary(int fd); |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 57 | virtual status_t setParameters(const String8& params); |
James Dong | fe1bafe | 2010-06-25 17:06:47 -0700 | [diff] [blame] | 58 | virtual status_t setListener(const sp<IMediaRecorderClient>& listener); |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 59 | virtual status_t prepare(); |
| 60 | virtual status_t start(); |
James Dong | 08c7473 | 2010-06-10 12:28:15 -0700 | [diff] [blame] | 61 | virtual status_t pause(); |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 62 | virtual status_t stop(); |
| 63 | virtual status_t close(); |
| 64 | virtual status_t reset(); |
| 65 | virtual status_t getMaxAmplitude(int *max); |
James Dong | 929642e | 2010-07-08 11:16:11 -0700 | [diff] [blame] | 66 | virtual status_t dump(int fd, const Vector<String16>& args) const; |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 67 | |
| 68 | private: |
James Dong | 0c128b6 | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 69 | sp<ICamera> mCamera; |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 70 | sp<ICameraRecordingProxy> mCameraProxy; |
Jamie Gennis | 85cfdd0 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 71 | sp<Surface> mPreviewSurface; |
James Dong | fe1bafe | 2010-06-25 17:06:47 -0700 | [diff] [blame] | 72 | sp<IMediaRecorderClient> mListener; |
Nipun Kwatra | d7e7a3f | 2010-08-26 17:05:18 -0700 | [diff] [blame] | 73 | sp<MediaWriter> mWriter, mWriterAux; |
James Dong | f84bfab | 2011-03-21 14:29:38 -0700 | [diff] [blame] | 74 | int mOutputFd, mOutputFdAux; |
James Dong | 57e7f83 | 2010-06-24 19:55:31 -0700 | [diff] [blame] | 75 | sp<AudioSource> mAudioSourceNode; |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 76 | |
Dima Zavin | 24fc2fb | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 77 | audio_source_t mAudioSource; |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 78 | video_source mVideoSource; |
| 79 | output_format mOutputFormat; |
| 80 | audio_encoder mAudioEncoder; |
| 81 | video_encoder mVideoEncoder; |
James Dong | 6feaa46 | 2010-06-20 08:20:54 -0700 | [diff] [blame] | 82 | bool mUse64BitFileOffset; |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 83 | int32_t mVideoWidth, mVideoHeight; |
Nipun Kwatra | 239f2e5 | 2010-08-31 15:35:44 -0700 | [diff] [blame] | 84 | int32_t mAuxVideoWidth, mAuxVideoHeight; |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 85 | int32_t mFrameRate; |
Nipun Kwatra | 239f2e5 | 2010-08-31 15:35:44 -0700 | [diff] [blame] | 86 | int32_t mVideoBitRate, mAuxVideoBitRate; |
| 87 | int32_t mAudioBitRate; |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 88 | int32_t mAudioChannels; |
| 89 | int32_t mSampleRate; |
James Dong | 3300e96 | 2010-04-21 16:14:15 -0700 | [diff] [blame] | 90 | int32_t mInterleaveDurationUs; |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 91 | int32_t mIFramesIntervalSec; |
James Dong | 09936ed | 2010-06-24 19:04:27 -0700 | [diff] [blame] | 92 | int32_t mCameraId; |
James Dong | 81c929a | 2010-07-01 15:02:14 -0700 | [diff] [blame] | 93 | int32_t mVideoEncoderProfile; |
| 94 | int32_t mVideoEncoderLevel; |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 95 | int32_t mMovieTimeScale; |
| 96 | int32_t mVideoTimeScale; |
| 97 | int32_t mAudioTimeScale; |
James Dong | 2cd841d | 2010-05-11 11:46:59 -0700 | [diff] [blame] | 98 | int64_t mMaxFileSizeBytes; |
| 99 | int64_t mMaxFileDurationUs; |
James Dong | 09936ed | 2010-06-24 19:04:27 -0700 | [diff] [blame] | 100 | int64_t mTrackEveryTimeDurationUs; |
James Dong | b9d7e01 | 2010-11-09 11:15:47 -0800 | [diff] [blame] | 101 | int32_t mRotationDegrees; // Clockwise |
James Dong | 987ab48 | 2011-05-11 19:09:25 -0700 | [diff] [blame] | 102 | int32_t mLatitudex10000; |
| 103 | int32_t mLongitudex10000; |
James Dong | 13a3316 | 2011-05-09 16:56:25 -0700 | [diff] [blame] | 104 | int32_t mStartTimeOffsetMs; |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 105 | |
Nipun Kwatra | d26920a | 2010-06-30 18:51:31 -0700 | [diff] [blame] | 106 | bool mCaptureTimeLapse; |
Nipun Kwatra | d01371b | 2010-07-20 21:33:31 -0700 | [diff] [blame] | 107 | int64_t mTimeBetweenTimeLapseFrameCaptureUs; |
Nipun Kwatra | d7e7a3f | 2010-08-26 17:05:18 -0700 | [diff] [blame] | 108 | bool mCaptureAuxVideo; |
| 109 | sp<MediaSourceSplitter> mCameraSourceSplitter; |
Nipun Kwatra | 7553cf7 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 110 | sp<CameraSourceTimeLapse> mCameraSourceTimeLapse; |
Nipun Kwatra | d26920a | 2010-06-30 18:51:31 -0700 | [diff] [blame] | 111 | |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 112 | String8 mParams; |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 113 | |
James Dong | 05c2fd5 | 2010-11-02 13:20:11 -0700 | [diff] [blame] | 114 | bool mIsMetaDataStoredInVideoBuffers; |
James Dong | 42a18c0 | 2010-06-16 17:27:46 -0700 | [diff] [blame] | 115 | MediaProfiles *mEncoderProfiles; |
| 116 | |
Gloria Wang | 62e05a6 | 2011-02-23 11:47:34 -0800 | [diff] [blame] | 117 | bool mStarted; |
| 118 | |
Nipun Kwatra | d7e7a3f | 2010-08-26 17:05:18 -0700 | [diff] [blame] | 119 | status_t setupMPEG4Recording( |
Nipun Kwatra | 239f2e5 | 2010-08-31 15:35:44 -0700 | [diff] [blame] | 120 | bool useSplitCameraSource, |
| 121 | int outputFd, |
| 122 | int32_t videoWidth, int32_t videoHeight, |
| 123 | int32_t videoBitRate, |
Nipun Kwatra | d7e7a3f | 2010-08-26 17:05:18 -0700 | [diff] [blame] | 124 | int32_t *totalBitRate, |
| 125 | sp<MediaWriter> *mediaWriter); |
| 126 | void setupMPEG4MetaData(int64_t startTimeUs, int32_t totalBitRate, |
| 127 | sp<MetaData> *meta); |
Andreas Huber | 996dddf | 2010-01-25 15:30:31 -0800 | [diff] [blame] | 128 | status_t startMPEG4Recording(); |
| 129 | status_t startAMRRecording(); |
James Dong | 2cd841d | 2010-05-11 11:46:59 -0700 | [diff] [blame] | 130 | status_t startAACRecording(); |
James Dong | f84bfab | 2011-03-21 14:29:38 -0700 | [diff] [blame] | 131 | status_t startRawAudioRecording(); |
Andreas Huber | 57648e4 | 2010-08-04 10:14:30 -0700 | [diff] [blame] | 132 | status_t startRTPRecording(); |
Andreas Huber | 9adf466 | 2010-10-12 14:17:45 -0700 | [diff] [blame] | 133 | status_t startMPEG2TSRecording(); |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 134 | sp<MediaSource> createAudioSource(); |
James Dong | 0c128b6 | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 135 | status_t checkVideoEncoderCapabilities(); |
James Dong | 54815a7 | 2011-01-12 20:45:16 -0800 | [diff] [blame] | 136 | status_t checkAudioEncoderCapabilities(); |
Nipun Kwatra | d7e7a3f | 2010-08-26 17:05:18 -0700 | [diff] [blame] | 137 | status_t setupCameraSource(sp<CameraSource> *cameraSource); |
James Dong | 7b06de6 | 2010-06-30 12:41:16 -0700 | [diff] [blame] | 138 | status_t setupAudioEncoder(const sp<MediaWriter>& writer); |
Nipun Kwatra | d7e7a3f | 2010-08-26 17:05:18 -0700 | [diff] [blame] | 139 | status_t setupVideoEncoder( |
| 140 | sp<MediaSource> cameraSource, |
| 141 | int32_t videoBitRate, |
| 142 | sp<MediaSource> *source); |
James Dong | 7b06de6 | 2010-06-30 12:41:16 -0700 | [diff] [blame] | 143 | |
| 144 | // Encoding parameter handling utilities |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 145 | status_t setParameter(const String8 &key, const String8 &value); |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 146 | status_t setParamAudioEncodingBitRate(int32_t bitRate); |
| 147 | status_t setParamAudioNumberOfChannels(int32_t channles); |
| 148 | status_t setParamAudioSamplingRate(int32_t sampleRate); |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 149 | status_t setParamAudioTimeScale(int32_t timeScale); |
Nipun Kwatra | d01371b | 2010-07-20 21:33:31 -0700 | [diff] [blame] | 150 | status_t setParamTimeLapseEnable(int32_t timeLapseEnable); |
| 151 | status_t setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs); |
Nipun Kwatra | 239f2e5 | 2010-08-31 15:35:44 -0700 | [diff] [blame] | 152 | status_t setParamAuxVideoHeight(int32_t height); |
| 153 | status_t setParamAuxVideoWidth(int32_t width); |
| 154 | status_t setParamAuxVideoEncodingBitRate(int32_t bitRate); |
James Dong | 09936ed | 2010-06-24 19:04:27 -0700 | [diff] [blame] | 155 | status_t setParamVideoEncodingBitRate(int32_t bitRate); |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 156 | status_t setParamVideoIFramesInterval(int32_t seconds); |
James Dong | 81c929a | 2010-07-01 15:02:14 -0700 | [diff] [blame] | 157 | status_t setParamVideoEncoderProfile(int32_t profile); |
| 158 | status_t setParamVideoEncoderLevel(int32_t level); |
James Dong | 09936ed | 2010-06-24 19:04:27 -0700 | [diff] [blame] | 159 | status_t setParamVideoCameraId(int32_t cameraId); |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 160 | status_t setParamVideoTimeScale(int32_t timeScale); |
James Dong | b9d7e01 | 2010-11-09 11:15:47 -0800 | [diff] [blame] | 161 | status_t setParamVideoRotation(int32_t degrees); |
James Dong | 09936ed | 2010-06-24 19:04:27 -0700 | [diff] [blame] | 162 | status_t setParamTrackTimeStatus(int64_t timeDurationUs); |
James Dong | 3300e96 | 2010-04-21 16:14:15 -0700 | [diff] [blame] | 163 | status_t setParamInterleaveDuration(int32_t durationUs); |
James Dong | 6feaa46 | 2010-06-20 08:20:54 -0700 | [diff] [blame] | 164 | status_t setParam64BitFileOffset(bool use64BitFileOffset); |
James Dong | 7b06de6 | 2010-06-30 12:41:16 -0700 | [diff] [blame] | 165 | status_t setParamMaxFileDurationUs(int64_t timeUs); |
| 166 | status_t setParamMaxFileSizeBytes(int64_t bytes); |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 167 | status_t setParamMovieTimeScale(int32_t timeScale); |
James Dong | 987ab48 | 2011-05-11 19:09:25 -0700 | [diff] [blame] | 168 | status_t setParamGeoDataLongitude(int32_t longitudex10000); |
| 169 | status_t setParamGeoDataLatitude(int32_t latitudex10000); |
James Dong | 42a18c0 | 2010-06-16 17:27:46 -0700 | [diff] [blame] | 170 | void clipVideoBitRate(); |
| 171 | void clipVideoFrameRate(); |
| 172 | void clipVideoFrameWidth(); |
| 173 | void clipVideoFrameHeight(); |
James Dong | 54815a7 | 2011-01-12 20:45:16 -0800 | [diff] [blame] | 174 | void clipAudioBitRate(); |
| 175 | void clipAudioSampleRate(); |
| 176 | void clipNumberOfAudioChannels(); |
James Dong | be65087 | 2011-07-07 16:41:25 -0700 | [diff] [blame] | 177 | void setDefaultProfileIfNecessary(); |
Andreas Huber | 996dddf | 2010-01-25 15:30:31 -0800 | [diff] [blame] | 178 | |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 179 | StagefrightRecorder(const StagefrightRecorder &); |
| 180 | StagefrightRecorder &operator=(const StagefrightRecorder &); |
| 181 | }; |
| 182 | |
| 183 | } // namespace android |
| 184 | |
| 185 | #endif // STAGEFRIGHT_RECORDER_H_ |