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