mediarecorder.h revision 2a7d5b3c1a3749db7c4ace34bf1253c44967e843
1/* 2 ** Copyright (C) 2008 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 ** 15 ** limitations under the License. 16 */ 17 18#ifndef ANDROID_MEDIARECORDER_H 19#define ANDROID_MEDIARECORDER_H 20 21#include <utils/Log.h> 22#include <utils/threads.h> 23#include <utils/List.h> 24#include <utils/Errors.h> 25#include <media/IMediaPlayerClient.h> 26 27namespace android { 28 29class Surface; 30class IMediaRecorder; 31class ICamera; 32 33typedef void (*media_completion_f)(status_t status, void *cookie); 34 35/* Do not change these values without updating their counterparts 36 * in media/java/android/media/MediaRecorder.java! 37 */ 38enum audio_source { 39 AUDIO_SOURCE_DEFAULT = 0, 40 AUDIO_SOURCE_MIC = 1, 41 AUDIO_SOURCE_VOICE_UPLINK = 2, 42 AUDIO_SOURCE_VOICE_DOWNLINK = 3, 43 AUDIO_SOURCE_VOICE_CALL = 4, 44 AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_CALL, 45 46 AUDIO_SOURCE_LIST_END // must be last - used to validate audio source type 47}; 48 49enum video_source { 50 VIDEO_SOURCE_DEFAULT = 0, 51 VIDEO_SOURCE_CAMERA = 1, 52 53 VIDEO_SOURCE_LIST_END // must be last - used to validate audio source type 54}; 55 56//Please update media/java/android/media/MediaRecorder.java if the following is updated. 57enum output_format { 58 OUTPUT_FORMAT_DEFAULT = 0, 59 OUTPUT_FORMAT_THREE_GPP = 1, 60 OUTPUT_FORMAT_MPEG_4 = 2, 61 62 63 OUTPUT_FORMAT_AUDIO_ONLY_START = 3, // Used in validating the output format. Should be the 64 // at the start of the audio only output formats. 65 66 /* These are audio only file formats */ 67 OUTPUT_FORMAT_RAW_AMR = 3, //to be backward compatible 68 OUTPUT_FORMAT_AMR_NB = 3, 69 OUTPUT_FORMAT_AMR_WB = 4, 70 OUTPUT_FORMAT_AAC_ADIF = 5, 71 OUTPUT_FORMAT_AAC_ADTS = 6, 72 73 OUTPUT_FORMAT_LIST_END // must be last - used to validate format type 74}; 75 76enum audio_encoder { 77 AUDIO_ENCODER_DEFAULT = 0, 78 AUDIO_ENCODER_AMR_NB = 1, 79 AUDIO_ENCODER_AMR_WB = 2, 80 AUDIO_ENCODER_AAC = 3, 81 AUDIO_ENCODER_AAC_PLUS = 4, 82 AUDIO_ENCODER_EAAC_PLUS = 5, 83 84 AUDIO_ENCODER_LIST_END // must be the last - used to validate the audio encoder type 85}; 86 87enum video_encoder { 88 VIDEO_ENCODER_DEFAULT = 0, 89 VIDEO_ENCODER_H263 = 1, 90 VIDEO_ENCODER_H264 = 2, 91 VIDEO_ENCODER_MPEG_4_SP = 3, 92 93 VIDEO_ENCODER_LIST_END // must be the last - used to validate the video encoder type 94}; 95 96 97// Maximum frames per second is 24 98#define MEDIA_RECORDER_MAX_FRAME_RATE 24 99 100/* 101 * The state machine of the media_recorder uses a set of different state names. 102 * The mapping between the media_recorder and the pvauthorengine is shown below: 103 * 104 * mediarecorder pvauthorengine 105 * ---------------------------------------------------------------- 106 * MEDIA_RECORDER_ERROR ERROR 107 * MEDIA_RECORDER_IDLE IDLE 108 * MEDIA_RECORDER_INITIALIZED OPENED 109 * MEDIA_RECORDER_DATASOURCE_CONFIGURED 110 * MEDIA_RECORDER_PREPARED INITIALIZED 111 * MEDIA_RECORDER_RECORDING RECORDING 112 */ 113enum media_recorder_states { 114 MEDIA_RECORDER_ERROR = 0, 115 MEDIA_RECORDER_IDLE = 1 << 0, 116 MEDIA_RECORDER_INITIALIZED = 1 << 1, 117 MEDIA_RECORDER_DATASOURCE_CONFIGURED = 1 << 2, 118 MEDIA_RECORDER_PREPARED = 1 << 3, 119 MEDIA_RECORDER_RECORDING = 1 << 4, 120}; 121 122// The "msg" code passed to the listener in notify. 123enum media_recorder_event_type { 124 MEDIA_RECORDER_EVENT_ERROR = 1, 125 MEDIA_RECORDER_EVENT_INFO = 2 126}; 127 128enum media_recorder_error_type { 129 MEDIA_RECORDER_ERROR_UNKNOWN = 1 130}; 131 132// The codes are distributed as follow: 133// 0xx: Reserved 134// 8xx: General info/warning 135// 136enum media_recorder_info_type { 137 MEDIA_RECORDER_INFO_UNKNOWN = 1, 138 MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800, 139 MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801 140}; 141 142// ---------------------------------------------------------------------------- 143// ref-counted object for callbacks 144class MediaRecorderListener: virtual public RefBase 145{ 146public: 147 virtual void notify(int msg, int ext1, int ext2) = 0; 148}; 149 150class MediaRecorder : public BnMediaPlayerClient 151{ 152public: 153 MediaRecorder(); 154 ~MediaRecorder(); 155 156 status_t initCheck(); 157 status_t setCamera(const sp<ICamera>& camera); 158 status_t setPreviewSurface(const sp<Surface>& surface); 159 status_t setVideoSource(int vs); 160 status_t setAudioSource(int as); 161 status_t setOutputFormat(int of); 162 status_t setVideoEncoder(int ve); 163 status_t setAudioEncoder(int ae); 164 status_t setOutputFile(const char* path); 165 status_t setOutputFile(int fd, int64_t offset, int64_t length); 166 status_t setVideoSize(int width, int height); 167 status_t setVideoFrameRate(int frames_per_second); 168 status_t setParameters(const String8& params); 169 status_t setListener(const sp<MediaRecorderListener>& listener); 170 status_t prepare(); 171 status_t getMaxAmplitude(int* max); 172 status_t start(); 173 status_t stop(); 174 status_t reset(); 175 status_t init(); 176 status_t close(); 177 status_t release(); 178 void notify(int msg, int ext1, int ext2); 179 180private: 181 void doCleanUp(); 182 status_t doReset(); 183 184 sp<IMediaRecorder> mMediaRecorder; 185 sp<MediaRecorderListener> mListener; 186 media_recorder_states mCurrentState; 187 bool mIsAudioSourceSet; 188 bool mIsVideoSourceSet; 189 bool mIsAudioEncoderSet; 190 bool mIsVideoEncoderSet; 191 bool mIsOutputFileSet; 192 Mutex mLock; 193 Mutex mNotifyLock; 194}; 195 196}; // namespace android 197 198#endif // ANDROID_MEDIARECORDER_H 199