blob: 8c7392b026f4591c33639294de90545ab6ba9c25 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Agopian3b4062e2009-05-31 19:13:00 -070021#include <utils/Log.h>
22#include <utils/threads.h>
23#include <utils/List.h>
24#include <utils/Errors.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025#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
Jianhong Jiang2bcda902009-06-08 08:50:42 -070036 * in media/java/android/media/MediaRecorder.java!
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 */
38enum audio_source {
39 AUDIO_SOURCE_DEFAULT = 0,
40 AUDIO_SOURCE_MIC = 1,
Eric Laurent4bc035a2009-05-22 09:18:15 -070041 AUDIO_SOURCE_VOICE_UPLINK = 2,
42 AUDIO_SOURCE_VOICE_DOWNLINK = 3,
43 AUDIO_SOURCE_VOICE_CALL = 4,
Eric Laurentf22a0972009-11-02 05:31:33 -080044 AUDIO_SOURCE_CAMCORDER = 5,
Jean-Michel Trivi6869df32009-11-03 19:43:21 -080045 AUDIO_SOURCE_VOICE_RECOGNITION = 6,
46 AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_RECOGNITION,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070047
48 AUDIO_SOURCE_LIST_END // must be last - used to validate audio source type
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049};
50
51enum video_source {
52 VIDEO_SOURCE_DEFAULT = 0,
53 VIDEO_SOURCE_CAMERA = 1,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070054
55 VIDEO_SOURCE_LIST_END // must be last - used to validate audio source type
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056};
57
Jianhong Jiang2bcda902009-06-08 08:50:42 -070058//Please update media/java/android/media/MediaRecorder.java if the following is updated.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059enum output_format {
60 OUTPUT_FORMAT_DEFAULT = 0,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070061 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 Project9066cfe2009-03-03 19:31:44 -080075 OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
76};
77
78enum audio_encoder {
79 AUDIO_ENCODER_DEFAULT = 0,
80 AUDIO_ENCODER_AMR_NB = 1,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070081 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 Project9066cfe2009-03-03 19:31:44 -080087};
88
89enum 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 Jiang2bcda902009-06-08 08:50:42 -070094
95 VIDEO_ENCODER_LIST_END // must be the last - used to validate the video encoder type
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096};
97
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098/*
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 */
111enum 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 Projectba87e3e2009-03-13 13:04:22 -0700121enum media_recorder_event_type {
122 MEDIA_RECORDER_EVENT_ERROR = 1,
123 MEDIA_RECORDER_EVENT_INFO = 2
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124};
125
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700126enum media_recorder_error_type {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 MEDIA_RECORDER_ERROR_UNKNOWN = 1
128};
129
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700130// The codes are distributed as follow:
131// 0xx: Reserved
132// 8xx: General info/warning
Jianhong Jiang2bcda902009-06-08 08:50:42 -0700133//
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700134enum media_recorder_info_type {
135 MEDIA_RECORDER_INFO_UNKNOWN = 1,
The Android Open Source Project10592532009-03-18 17:39:46 -0700136 MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800,
137 MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700138};
139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140// ----------------------------------------------------------------------------
141// ref-counted object for callbacks
142class MediaRecorderListener: virtual public RefBase
143{
144public:
145 virtual void notify(int msg, int ext1, int ext2) = 0;
146};
147
148class MediaRecorder : public BnMediaPlayerClient
149{
150public:
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 Projectba87e3e2009-03-13 13:04:22 -0700166 status_t setParameters(const String8& params);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 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
178private:
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