StagefrightRecorder.h revision b33f3407bab0970a7f9241680723a1140b177c50
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> 22#include <camera/CameraParameters.h> 23#include <utils/String8.h> 24 25#include <system/audio.h> 26 27namespace android { 28 29class Camera; 30class ICameraRecordingProxy; 31class CameraSource; 32class CameraSourceTimeLapse; 33class MediaSourceSplitter; 34struct MediaSource; 35struct MediaWriter; 36class MetaData; 37struct AudioSource; 38class MediaProfiles; 39class ISurfaceTexture; 40class SurfaceMediaSource; 41 42struct StagefrightRecorder : public MediaRecorderBase { 43 StagefrightRecorder(); 44 virtual ~StagefrightRecorder(); 45 46 virtual status_t init(); 47 virtual status_t setAudioSource(audio_source_t as); 48 virtual status_t setVideoSource(video_source vs); 49 virtual status_t setOutputFormat(output_format of); 50 virtual status_t setAudioEncoder(audio_encoder ae); 51 virtual status_t setVideoEncoder(video_encoder ve); 52 virtual status_t setVideoSize(int width, int height); 53 virtual status_t setVideoFrameRate(int frames_per_second); 54 virtual status_t setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy); 55 virtual status_t setPreviewSurface(const sp<Surface>& surface); 56 virtual status_t setOutputFile(const char *path); 57 virtual status_t setOutputFile(int fd, int64_t offset, int64_t length); 58 virtual status_t setOutputFileAuxiliary(int fd); 59 virtual status_t setParameters(const String8& params); 60 virtual status_t setListener(const sp<IMediaRecorderClient>& listener); 61 virtual status_t prepare(); 62 virtual status_t start(); 63 virtual status_t pause(); 64 virtual status_t stop(); 65 virtual status_t close(); 66 virtual status_t reset(); 67 virtual status_t getMaxAmplitude(int *max); 68 virtual status_t dump(int fd, const Vector<String16>& args) const; 69 // Querying a SurfaceMediaSourcer 70 virtual sp<ISurfaceTexture> querySurfaceMediaSource() const; 71 72private: 73 sp<ICamera> mCamera; 74 sp<ICameraRecordingProxy> mCameraProxy; 75 sp<Surface> mPreviewSurface; 76 sp<IMediaRecorderClient> mListener; 77 sp<MediaWriter> mWriter, mWriterAux; 78 int mOutputFd, mOutputFdAux; 79 sp<AudioSource> mAudioSourceNode; 80 81 audio_source_t mAudioSource; 82 video_source mVideoSource; 83 output_format mOutputFormat; 84 audio_encoder mAudioEncoder; 85 video_encoder mVideoEncoder; 86 bool mUse64BitFileOffset; 87 int32_t mVideoWidth, mVideoHeight; 88 int32_t mAuxVideoWidth, mAuxVideoHeight; 89 int32_t mFrameRate; 90 int32_t mVideoBitRate, mAuxVideoBitRate; 91 int32_t mAudioBitRate; 92 int32_t mAudioChannels; 93 int32_t mSampleRate; 94 int32_t mInterleaveDurationUs; 95 int32_t mIFramesIntervalSec; 96 int32_t mCameraId; 97 int32_t mVideoEncoderProfile; 98 int32_t mVideoEncoderLevel; 99 int32_t mMovieTimeScale; 100 int32_t mVideoTimeScale; 101 int32_t mAudioTimeScale; 102 int64_t mMaxFileSizeBytes; 103 int64_t mMaxFileDurationUs; 104 int64_t mTrackEveryTimeDurationUs; 105 int32_t mRotationDegrees; // Clockwise 106 int32_t mLatitudex10000; 107 int32_t mLongitudex10000; 108 int32_t mStartTimeOffsetMs; 109 110 bool mCaptureTimeLapse; 111 int64_t mTimeBetweenTimeLapseFrameCaptureUs; 112 bool mCaptureAuxVideo; 113 sp<MediaSourceSplitter> mCameraSourceSplitter; 114 sp<CameraSourceTimeLapse> mCameraSourceTimeLapse; 115 116 117 String8 mParams; 118 119 bool mIsMetaDataStoredInVideoBuffers; 120 MediaProfiles *mEncoderProfiles; 121 122 bool mStarted; 123 // Needed when GLFrames are encoded. 124 // An <ISurfaceTexture> pointer 125 // will be sent to the client side using which the 126 // frame buffers will be queued and dequeued 127 sp<SurfaceMediaSource> mSurfaceMediaSource; 128 129 status_t setupMPEG4Recording( 130 bool useSplitCameraSource, 131 int outputFd, 132 int32_t videoWidth, int32_t videoHeight, 133 int32_t videoBitRate, 134 int32_t *totalBitRate, 135 sp<MediaWriter> *mediaWriter); 136 void setupMPEG4MetaData(int64_t startTimeUs, int32_t totalBitRate, 137 sp<MetaData> *meta); 138 status_t startMPEG4Recording(); 139 status_t startAMRRecording(); 140 status_t startAACRecording(); 141 status_t startRawAudioRecording(); 142 status_t startRTPRecording(); 143 status_t startMPEG2TSRecording(); 144 sp<MediaSource> createAudioSource(); 145 status_t checkVideoEncoderCapabilities(); 146 status_t checkAudioEncoderCapabilities(); 147 // Generic MediaSource set-up. Returns the appropriate 148 // source (CameraSource or SurfaceMediaSource) 149 // depending on the videosource type 150 status_t setupMediaSource(sp<MediaSource> *mediaSource); 151 status_t setupCameraSource(sp<CameraSource> *cameraSource); 152 // setup the surfacemediasource for the encoder 153 status_t setupSurfaceMediaSource(); 154 155 status_t setupAudioEncoder(const sp<MediaWriter>& writer); 156 status_t setupVideoEncoder( 157 sp<MediaSource> cameraSource, 158 int32_t videoBitRate, 159 sp<MediaSource> *source); 160 161 // Encoding parameter handling utilities 162 status_t setParameter(const String8 &key, const String8 &value); 163 status_t setParamAudioEncodingBitRate(int32_t bitRate); 164 status_t setParamAudioNumberOfChannels(int32_t channles); 165 status_t setParamAudioSamplingRate(int32_t sampleRate); 166 status_t setParamAudioTimeScale(int32_t timeScale); 167 status_t setParamTimeLapseEnable(int32_t timeLapseEnable); 168 status_t setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs); 169 status_t setParamAuxVideoHeight(int32_t height); 170 status_t setParamAuxVideoWidth(int32_t width); 171 status_t setParamAuxVideoEncodingBitRate(int32_t bitRate); 172 status_t setParamVideoEncodingBitRate(int32_t bitRate); 173 status_t setParamVideoIFramesInterval(int32_t seconds); 174 status_t setParamVideoEncoderProfile(int32_t profile); 175 status_t setParamVideoEncoderLevel(int32_t level); 176 status_t setParamVideoCameraId(int32_t cameraId); 177 status_t setParamVideoTimeScale(int32_t timeScale); 178 status_t setParamVideoRotation(int32_t degrees); 179 status_t setParamTrackTimeStatus(int64_t timeDurationUs); 180 status_t setParamInterleaveDuration(int32_t durationUs); 181 status_t setParam64BitFileOffset(bool use64BitFileOffset); 182 status_t setParamMaxFileDurationUs(int64_t timeUs); 183 status_t setParamMaxFileSizeBytes(int64_t bytes); 184 status_t setParamMovieTimeScale(int32_t timeScale); 185 status_t setParamGeoDataLongitude(int32_t longitudex10000); 186 status_t setParamGeoDataLatitude(int32_t latitudex10000); 187 void clipVideoBitRate(); 188 void clipVideoFrameRate(); 189 void clipVideoFrameWidth(); 190 void clipVideoFrameHeight(); 191 void clipAudioBitRate(); 192 void clipAudioSampleRate(); 193 void clipNumberOfAudioChannels(); 194 void setDefaultProfileIfNecessary(); 195 196 197 StagefrightRecorder(const StagefrightRecorder &); 198 StagefrightRecorder &operator=(const StagefrightRecorder &); 199}; 200 201} // namespace android 202 203#endif // STAGEFRIGHT_RECORDER_H_ 204