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