mediarecorder.h revision 81573ec97eaf631cc63eedceb928e123dafd593c
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 * The state machine of the media_recorder uses a set of different state names. 98 * The mapping between the media_recorder and the pvauthorengine is shown below: 99 * 100 * mediarecorder pvauthorengine 101 * ---------------------------------------------------------------- 102 * MEDIA_RECORDER_ERROR ERROR 103 * MEDIA_RECORDER_IDLE IDLE 104 * MEDIA_RECORDER_INITIALIZED OPENED 105 * MEDIA_RECORDER_DATASOURCE_CONFIGURED 106 * MEDIA_RECORDER_PREPARED INITIALIZED 107 * MEDIA_RECORDER_RECORDING RECORDING 108 */ 109enum media_recorder_states { 110 MEDIA_RECORDER_ERROR = 0, 111 MEDIA_RECORDER_IDLE = 1 << 0, 112 MEDIA_RECORDER_INITIALIZED = 1 << 1, 113 MEDIA_RECORDER_DATASOURCE_CONFIGURED = 1 << 2, 114 MEDIA_RECORDER_PREPARED = 1 << 3, 115 MEDIA_RECORDER_RECORDING = 1 << 4, 116}; 117 118// The "msg" code passed to the listener in notify. 119enum media_recorder_event_type { 120 MEDIA_RECORDER_EVENT_ERROR = 1, 121 MEDIA_RECORDER_EVENT_INFO = 2 122}; 123 124enum media_recorder_error_type { 125 MEDIA_RECORDER_ERROR_UNKNOWN = 1 126}; 127 128// The codes are distributed as follow: 129// 0xx: Reserved 130// 8xx: General info/warning 131// 132enum media_recorder_info_type { 133 MEDIA_RECORDER_INFO_UNKNOWN = 1, 134 MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800, 135 MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801 136}; 137 138// ---------------------------------------------------------------------------- 139// ref-counted object for callbacks 140class MediaRecorderListener: virtual public RefBase 141{ 142public: 143 virtual void notify(int msg, int ext1, int ext2) = 0; 144}; 145 146class MediaRecorder : public BnMediaPlayerClient 147{ 148public: 149 MediaRecorder(); 150 ~MediaRecorder(); 151 152 status_t initCheck(); 153 status_t setCamera(const sp<ICamera>& camera); 154 status_t setPreviewSurface(const sp<Surface>& surface); 155 status_t setVideoSource(int vs); 156 status_t setAudioSource(int as); 157 status_t setOutputFormat(int of); 158 status_t setVideoEncoder(int ve); 159 status_t setAudioEncoder(int ae); 160 status_t setOutputFile(const char* path); 161 status_t setOutputFile(int fd, int64_t offset, int64_t length); 162 status_t setVideoSize(int width, int height); 163 status_t setVideoFrameRate(int frames_per_second); 164 status_t setParameters(const String8& params); 165 status_t setListener(const sp<MediaRecorderListener>& listener); 166 status_t prepare(); 167 status_t getMaxAmplitude(int* max); 168 status_t start(); 169 status_t stop(); 170 status_t reset(); 171 status_t init(); 172 status_t close(); 173 status_t release(); 174 void notify(int msg, int ext1, int ext2); 175 176private: 177 void doCleanUp(); 178 status_t doReset(); 179 180 sp<IMediaRecorder> mMediaRecorder; 181 sp<MediaRecorderListener> mListener; 182 media_recorder_states mCurrentState; 183 bool mIsAudioSourceSet; 184 bool mIsVideoSourceSet; 185 bool mIsAudioEncoderSet; 186 bool mIsVideoEncoderSet; 187 bool mIsOutputFileSet; 188 Mutex mLock; 189 Mutex mNotifyLock; 190}; 191 192}; // namespace android 193 194#endif // ANDROID_MEDIARECORDER_H 195