StagefrightRecorder.h revision 99c2a076b4a46762a22bbb4dfbd51d107e0532d9
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 <utils/String8.h> 23 24namespace android { 25 26class Camera; 27struct MediaSource; 28struct MediaWriter; 29class MediaProfiles; 30 31struct StagefrightRecorder : public MediaRecorderBase { 32 StagefrightRecorder(); 33 virtual ~StagefrightRecorder(); 34 35 virtual status_t init(); 36 virtual status_t setAudioSource(audio_source as); 37 virtual status_t setVideoSource(video_source vs); 38 virtual status_t setOutputFormat(output_format of); 39 virtual status_t setAudioEncoder(audio_encoder ae); 40 virtual status_t setVideoEncoder(video_encoder ve); 41 virtual status_t setVideoSize(int width, int height); 42 virtual status_t setVideoFrameRate(int frames_per_second); 43 virtual status_t setCamera(const sp<ICamera>& camera); 44 virtual status_t setPreviewSurface(const sp<ISurface>& surface); 45 virtual status_t setOutputFile(const char *path); 46 virtual status_t setOutputFile(int fd, int64_t offset, int64_t length); 47 virtual status_t setParameters(const String8& params); 48 virtual status_t setListener(const sp<IMediaPlayerClient>& listener); 49 virtual status_t prepare(); 50 virtual status_t start(); 51 virtual status_t pause(); 52 virtual status_t stop(); 53 virtual status_t close(); 54 virtual status_t reset(); 55 virtual status_t getMaxAmplitude(int *max); 56 57private: 58 enum CameraFlags { 59 FLAGS_SET_CAMERA = 1L << 0, 60 FLAGS_HOT_CAMERA = 1L << 1, 61 }; 62 63 sp<Camera> mCamera; 64 sp<ISurface> mPreviewSurface; 65 sp<IMediaPlayerClient> mListener; 66 sp<MediaWriter> mWriter; 67 68 audio_source mAudioSource; 69 video_source mVideoSource; 70 output_format mOutputFormat; 71 audio_encoder mAudioEncoder; 72 video_encoder mVideoEncoder; 73 int32_t mVideoWidth, mVideoHeight; 74 int32_t mFrameRate; 75 int32_t mVideoBitRate; 76 int32_t mAudioBitRate; 77 int32_t mAudioChannels; 78 int32_t mSampleRate; 79 int32_t mInterleaveDurationUs; 80 int32_t mIFramesInterval; 81 int64_t mMaxFileSizeBytes; 82 int64_t mMaxFileDurationUs; 83 84 String8 mParams; 85 int mOutputFd; 86 int32_t mFlags; 87 88 MediaProfiles *mEncoderProfiles; 89 90 status_t startMPEG4Recording(); 91 status_t startAMRRecording(); 92 status_t startAACRecording(); 93 sp<MediaSource> createAudioSource(); 94 status_t setParameter(const String8 &key, const String8 &value); 95 status_t setParamVideoEncodingBitRate(int32_t bitRate); 96 status_t setParamAudioEncodingBitRate(int32_t bitRate); 97 status_t setParamAudioNumberOfChannels(int32_t channles); 98 status_t setParamAudioSamplingRate(int32_t sampleRate); 99 status_t setParamInterleaveDuration(int32_t durationUs); 100 status_t setParamIFramesInterval(int32_t interval); 101 status_t setParamMaxDurationOrFileSize(int64_t limit, bool limit_is_duration); 102 void clipVideoBitRate(); 103 void clipVideoFrameRate(); 104 void clipVideoFrameWidth(); 105 void clipVideoFrameHeight(); 106 107 StagefrightRecorder(const StagefrightRecorder &); 108 StagefrightRecorder &operator=(const StagefrightRecorder &); 109}; 110 111} // namespace android 112 113#endif // STAGEFRIGHT_RECORDER_H_ 114 115