StagefrightRecorder.h revision be71aa29a3c86d2e01cd17839d2a72ab09a1bce5
126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian/* 226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * Copyright (C) 2009 The Android Open Source Project 326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * 426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * you may not use this file except in compliance with the License. 626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * You may obtain a copy of the License at 726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * 826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * 1026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * Unless required by applicable law or agreed to in writing, software 1126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 1226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * See the License for the specific language governing permissions and 1426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian * limitations under the License. 1526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian */ 1626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 1726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian#ifndef STAGEFRIGHT_RECORDER_H_ 1826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 1926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian#define STAGEFRIGHT_RECORDER_H_ 2026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 2126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian#include <media/MediaRecorderBase.h> 2226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian#include <camera/CameraParameters.h> 2326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian#include <utils/String8.h> 2426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 2526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian#include <system/audio.h> 2626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 2726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopiannamespace android { 2826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 2926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianclass Camera; 3026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianclass ICameraRecordingProxy; 3126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianclass CameraSource; 3226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianclass CameraSourceTimeLapse; 3326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianstruct MediaSource; 3426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianstruct MediaWriter; 3526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianclass MetaData; 3626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianstruct AudioSource; 3726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianclass MediaProfiles; 3826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianclass IGraphicBufferProducer; 3926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianclass SurfaceMediaSource; 4026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianstruct ALooper; 4126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 4226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianstruct StagefrightRecorder : public MediaRecorderBase { 4326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian StagefrightRecorder(const String16 &opPackageName); 4426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual ~StagefrightRecorder(); 4526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 4626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t init(); 4726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setAudioSource(audio_source_t as); 4826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setVideoSource(video_source vs); 4926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setOutputFormat(output_format of); 5026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setAudioEncoder(audio_encoder ae); 5126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setVideoEncoder(video_encoder ve); 5226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setVideoSize(int width, int height); 5326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setVideoFrameRate(int frames_per_second); 5426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy); 5526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface); 5626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setOutputFile(int fd, int64_t offset, int64_t length); 5726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setParameters(const String8& params); 5826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setListener(const sp<IMediaRecorderClient>& listener); 5926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t setClientName(const String16& clientName); 6026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t prepare(); 6126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t start(); 6226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t pause(); 6326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t stop(); 6426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t close(); 6526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t reset(); 6626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t getMaxAmplitude(int *max); 6726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual status_t dump(int fd, const Vector<String16>& args) const; 6826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian // Querying a SurfaceMediaSourcer 6926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian virtual sp<IGraphicBufferProducer> querySurfaceMediaSource() const; 7026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 7126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopianprivate: 7226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian sp<ICamera> mCamera; 7326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian sp<ICameraRecordingProxy> mCameraProxy; 7426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian sp<IGraphicBufferProducer> mPreviewSurface; 7526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian sp<IMediaRecorderClient> mListener; 7626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian String16 mClientName; 7726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian uid_t mClientUid; 7826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian sp<MediaWriter> mWriter; 7926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int mOutputFd; 8026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian sp<AudioSource> mAudioSourceNode; 8126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 8226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian audio_source_t mAudioSource; 8326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian video_source mVideoSource; 8426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian output_format mOutputFormat; 8526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian audio_encoder mAudioEncoder; 8626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian video_encoder mVideoEncoder; 8726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian bool mUse64BitFileOffset; 8826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mVideoWidth, mVideoHeight; 8926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mFrameRate; 9026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mVideoBitRate; 9126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mAudioBitRate; 9226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mAudioChannels; 9326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mSampleRate; 9426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mInterleaveDurationUs; 9526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mIFramesIntervalSec; 9626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mCameraId; 9726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mVideoEncoderProfile; 9826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mVideoEncoderLevel; 9926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mMovieTimeScale; 10026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mVideoTimeScale; 10126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mAudioTimeScale; 10226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int64_t mMaxFileSizeBytes; 10326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int64_t mMaxFileDurationUs; 10426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int64_t mTrackEveryTimeDurationUs; 10526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mRotationDegrees; // Clockwise 10626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mLatitudex10000; 10726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mLongitudex10000; 10826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mStartTimeOffsetMs; 10926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int32_t mTotalBitRate; 11026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 11126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian bool mCaptureTimeLapse; 11226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian float mCaptureFps; 11326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian int64_t mTimeBetweenTimeLapseFrameCaptureUs; 11426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian sp<CameraSourceTimeLapse> mCameraSourceTimeLapse; 11526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 11626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 11726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian String8 mParams; 11826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 11926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian bool mIsMetaDataStoredInVideoBuffers; 12026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian MediaProfiles *mEncoderProfiles; 12126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 12226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian bool mStarted; 12326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian // Needed when GLFrames are encoded. 12426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian // An <IGraphicBufferProducer> pointer 12526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian // will be sent to the client side using which the 12626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian // frame buffers will be queued and dequeued 12726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian sp<IGraphicBufferProducer> mGraphicBufferProducer; 12826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian sp<ALooper> mLooper; 12926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 13026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian static const int kMaxHighSpeedFps = 1000; 13126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 13226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t prepareInternal(); 13326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setupMPEG4orWEBMRecording(); 13426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian void setupMPEG4orWEBMMetaData(sp<MetaData> *meta); 13526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setupAMRRecording(); 13626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setupAACRecording(); 13726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setupRawAudioRecording(); 13826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setupRTPRecording(); 13926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setupMPEG2TSRecording(); 14026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian sp<MediaSource> createAudioSource(); 14126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t checkVideoEncoderCapabilities( 14226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian bool *supportsCameraSourceMetaDataMode); 14326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t checkAudioEncoderCapabilities(); 14426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian // Generic MediaSource set-up. Returns the appropriate 14526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian // source (CameraSource or SurfaceMediaSource) 14626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian // depending on the videosource type 14726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setupMediaSource(sp<MediaSource> *mediaSource); 14826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setupCameraSource(sp<CameraSource> *cameraSource); 14926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setupAudioEncoder(const sp<MediaWriter>& writer); 15026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setupVideoEncoder(sp<MediaSource> cameraSource, sp<MediaSource> *source); 15126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 15226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian // Encoding parameter handling utilities 15326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParameter(const String8 &key, const String8 &value); 15426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamAudioEncodingBitRate(int32_t bitRate); 15526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamAudioNumberOfChannels(int32_t channles); 15626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamAudioSamplingRate(int32_t sampleRate); 15726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamAudioTimeScale(int32_t timeScale); 15826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamTimeLapseEnable(int32_t timeLapseEnable); 15926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamTimeLapseFps(float fps); 16026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamVideoEncodingBitRate(int32_t bitRate); 16126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamVideoIFramesInterval(int32_t seconds); 16226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamVideoEncoderProfile(int32_t profile); 16326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamVideoEncoderLevel(int32_t level); 16426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamVideoCameraId(int32_t cameraId); 16526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamVideoTimeScale(int32_t timeScale); 16626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamVideoRotation(int32_t degrees); 16726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamTrackTimeStatus(int64_t timeDurationUs); 16826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamInterleaveDuration(int32_t durationUs); 16926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParam64BitFileOffset(bool use64BitFileOffset); 17026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamMaxFileDurationUs(int64_t timeUs); 17126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamMaxFileSizeBytes(int64_t bytes); 17226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamMovieTimeScale(int32_t timeScale); 17326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamGeoDataLongitude(int64_t longitudex10000); 17426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian status_t setParamGeoDataLatitude(int64_t latitudex10000); 17526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian void clipVideoBitRate(); 17626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian void clipVideoFrameRate(); 17726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian void clipVideoFrameWidth(); 17826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian void clipVideoFrameHeight(); 17926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian void clipAudioBitRate(); 18026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian void clipAudioSampleRate(); 18126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian void clipNumberOfAudioChannels(); 18226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian void setDefaultProfileIfNecessary(); 18326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian void setDefaultVideoEncoderIfNecessary(); 18426fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 18526fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 18626fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian StagefrightRecorder(const StagefrightRecorder &); 18726fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian StagefrightRecorder &operator=(const StagefrightRecorder &); 18826fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian}; 18926fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 19026fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian} // namespace android 19126fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian 19226fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian#endif // STAGEFRIGHT_RECORDER_H_ 19326fddcd74252bdda95dd7c3f819353e79c622012Mathias Agopian