blob: 59093c9234e2a08d1cdc72eb4f68bf0e81eda4a1 [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>
James Dongfe1bafe2010-06-25 17:06:47 -070025#include <media/IMediaRecorderClient.h>
James Dong34bbc222010-01-15 18:13:58 -080026#include <media/IMediaDeathNotifier.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
28namespace android {
29
30class Surface;
31class IMediaRecorder;
32class ICamera;
33
34typedef void (*media_completion_f)(status_t status, void *cookie);
35
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036enum video_source {
37 VIDEO_SOURCE_DEFAULT = 0,
38 VIDEO_SOURCE_CAMERA = 1,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070039
40 VIDEO_SOURCE_LIST_END // must be last - used to validate audio source type
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041};
42
Jianhong Jiang2bcda902009-06-08 08:50:42 -070043//Please update media/java/android/media/MediaRecorder.java if the following is updated.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044enum output_format {
45 OUTPUT_FORMAT_DEFAULT = 0,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070046 OUTPUT_FORMAT_THREE_GPP = 1,
47 OUTPUT_FORMAT_MPEG_4 = 2,
48
49
50 OUTPUT_FORMAT_AUDIO_ONLY_START = 3, // Used in validating the output format. Should be the
51 // at the start of the audio only output formats.
52
53 /* These are audio only file formats */
54 OUTPUT_FORMAT_RAW_AMR = 3, //to be backward compatible
55 OUTPUT_FORMAT_AMR_NB = 3,
56 OUTPUT_FORMAT_AMR_WB = 4,
57 OUTPUT_FORMAT_AAC_ADIF = 5,
58 OUTPUT_FORMAT_AAC_ADTS = 6,
59
Andreas Huber57648e42010-08-04 10:14:30 -070060 /* Stream over a socket, limited to a single stream */
61 OUTPUT_FORMAT_RTP_AVP = 7,
62
Andreas Huber9adf4662010-10-12 14:17:45 -070063 /* H.264/AAC data encapsulated in MPEG2/TS */
64 OUTPUT_FORMAT_MPEG2TS = 8,
65
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
67};
68
69enum audio_encoder {
70 AUDIO_ENCODER_DEFAULT = 0,
71 AUDIO_ENCODER_AMR_NB = 1,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070072 AUDIO_ENCODER_AMR_WB = 2,
73 AUDIO_ENCODER_AAC = 3,
74 AUDIO_ENCODER_AAC_PLUS = 4,
75 AUDIO_ENCODER_EAAC_PLUS = 5,
76
77 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 -080078};
79
80enum video_encoder {
81 VIDEO_ENCODER_DEFAULT = 0,
82 VIDEO_ENCODER_H263 = 1,
83 VIDEO_ENCODER_H264 = 2,
84 VIDEO_ENCODER_MPEG_4_SP = 3,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070085
86 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 -080087};
88
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089/*
James Dong7fc8b4f2011-03-18 11:25:41 -070090 * The state machine of the media_recorder.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 */
92enum media_recorder_states {
James Dong7fc8b4f2011-03-18 11:25:41 -070093 // Error state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 MEDIA_RECORDER_ERROR = 0,
James Dong7fc8b4f2011-03-18 11:25:41 -070095
96 // Recorder was just created.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 MEDIA_RECORDER_IDLE = 1 << 0,
James Dong7fc8b4f2011-03-18 11:25:41 -070098
99 // Recorder has been initialized.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 MEDIA_RECORDER_INITIALIZED = 1 << 1,
James Dong7fc8b4f2011-03-18 11:25:41 -0700101
102 // Configuration of the recorder has been completed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 MEDIA_RECORDER_DATASOURCE_CONFIGURED = 1 << 2,
James Dong7fc8b4f2011-03-18 11:25:41 -0700104
105 // Recorder is ready to start.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 MEDIA_RECORDER_PREPARED = 1 << 3,
James Dong7fc8b4f2011-03-18 11:25:41 -0700107
108 // Recording is in progress.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 MEDIA_RECORDER_RECORDING = 1 << 4,
110};
111
112// The "msg" code passed to the listener in notify.
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700113enum media_recorder_event_type {
James Dong7fc8b4f2011-03-18 11:25:41 -0700114 MEDIA_RECORDER_EVENT_LIST_START = 1,
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700115 MEDIA_RECORDER_EVENT_ERROR = 1,
James Dong7fc8b4f2011-03-18 11:25:41 -0700116 MEDIA_RECORDER_EVENT_INFO = 2,
117 MEDIA_RECORDER_EVENT_LIST_END = 99,
118
119 // Track related event types
120 MEDIA_RECORDER_TRACK_EVENT_LIST_START = 100,
121 MEDIA_RECORDER_TRACK_EVENT_ERROR = 100,
122 MEDIA_RECORDER_TRACK_EVENT_INFO = 101,
123 MEDIA_RECORDER_TRACK_EVENT_LIST_END = 1000,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124};
125
James Dong7fc8b4f2011-03-18 11:25:41 -0700126/*
127 * The (part of) "what" code passed to the listener in notify.
128 * When the error or info type is track specific, the what has
129 * the following layout:
130 * the left-most 16-bit is meant for error or info type.
131 * the right-most 4-bit is meant for track id.
132 * the rest is reserved.
133 *
134 * | track id | reserved | error or info type |
135 * 31 28 16 0
136 *
137 */
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700138enum media_recorder_error_type {
James Dong7fc8b4f2011-03-18 11:25:41 -0700139 MEDIA_RECORDER_ERROR_UNKNOWN = 1,
140
141 // Track related error type
142 MEDIA_RECORDER_TRACK_ERROR_LIST_START = 100,
143 MEDIA_RECORDER_TRACK_ERROR_GENERAL = 100,
144 MEDIA_RECORDER_ERROR_VIDEO_NO_SYNC_FRAME = 200,
145 MEDIA_RECORDER_TRACK_ERROR_LIST_END = 1000,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146};
147
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700148// The codes are distributed as follow:
149// 0xx: Reserved
150// 8xx: General info/warning
Jianhong Jiang2bcda902009-06-08 08:50:42 -0700151//
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700152enum media_recorder_info_type {
153 MEDIA_RECORDER_INFO_UNKNOWN = 1,
James Dong7fc8b4f2011-03-18 11:25:41 -0700154
The Android Open Source Project10592532009-03-18 17:39:46 -0700155 MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800,
James Dong68510e62010-05-14 11:48:00 -0700156 MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801,
James Dong7fc8b4f2011-03-18 11:25:41 -0700157
158 // All track related informtional events start here
159 MEDIA_RECORDER_TRACK_INFO_LIST_START = 1000,
160 MEDIA_RECORDER_TRACK_INFO_COMPLETION_STATUS = 1000,
161 MEDIA_RECORDER_TRACK_INFO_PROGRESS_IN_TIME = 1001,
James Donged742302011-05-06 11:27:59 -0700162 MEDIA_RECORDER_TRACK_INFO_TYPE = 1002,
163 MEDIA_RECORDER_TRACK_INFO_DURATION_MS = 1003,
James Dong3aea0372011-05-06 12:19:04 -0700164
165 // The time to measure the max chunk duration
James Donged742302011-05-06 11:27:59 -0700166 MEDIA_RECORDER_TRACK_INFO_MAX_CHUNK_DUR_MS = 1004,
James Dong3aea0372011-05-06 12:19:04 -0700167
James Donged742302011-05-06 11:27:59 -0700168 MEDIA_RECORDER_TRACK_INFO_ENCODED_FRAMES = 1005,
James Dong3aea0372011-05-06 12:19:04 -0700169
170 // The time to measure how well the audio and video
171 // track data is interleaved.
172 MEDIA_RECORDER_TRACK_INTER_CHUNK_TIME_MS = 1006,
173
174 // The time to measure system response. Note that
175 // the delay does not include the intentional delay
176 // we use to eliminate the recording sound.
177 MEDIA_RECORDER_TRACK_INFO_INITIAL_DELAY_MS = 1007,
178
179 // The time used to compensate for initial A/V sync.
180 MEDIA_RECORDER_TRACK_INFO_START_OFFSET_MS = 1008,
181
James Dong7fc8b4f2011-03-18 11:25:41 -0700182 MEDIA_RECORDER_TRACK_INFO_LIST_END = 2000,
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700183};
184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185// ----------------------------------------------------------------------------
186// ref-counted object for callbacks
187class MediaRecorderListener: virtual public RefBase
188{
189public:
190 virtual void notify(int msg, int ext1, int ext2) = 0;
191};
192
James Dongfe1bafe2010-06-25 17:06:47 -0700193class MediaRecorder : public BnMediaRecorderClient,
James Dong34bbc222010-01-15 18:13:58 -0800194 public virtual IMediaDeathNotifier
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195{
196public:
197 MediaRecorder();
198 ~MediaRecorder();
199
James Dong34bbc222010-01-15 18:13:58 -0800200 void died();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 status_t initCheck();
202 status_t setCamera(const sp<ICamera>& camera);
203 status_t setPreviewSurface(const sp<Surface>& surface);
204 status_t setVideoSource(int vs);
205 status_t setAudioSource(int as);
206 status_t setOutputFormat(int of);
207 status_t setVideoEncoder(int ve);
208 status_t setAudioEncoder(int ae);
209 status_t setOutputFile(const char* path);
210 status_t setOutputFile(int fd, int64_t offset, int64_t length);
Nipun Kwatrab33a5ae2010-08-26 17:20:53 -0700211 status_t setOutputFileAuxiliary(int fd);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 status_t setVideoSize(int width, int height);
213 status_t setVideoFrameRate(int frames_per_second);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700214 status_t setParameters(const String8& params);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 status_t setListener(const sp<MediaRecorderListener>& listener);
216 status_t prepare();
217 status_t getMaxAmplitude(int* max);
218 status_t start();
219 status_t stop();
220 status_t reset();
221 status_t init();
222 status_t close();
223 status_t release();
224 void notify(int msg, int ext1, int ext2);
225
226private:
227 void doCleanUp();
228 status_t doReset();
229
230 sp<IMediaRecorder> mMediaRecorder;
231 sp<MediaRecorderListener> mListener;
232 media_recorder_states mCurrentState;
233 bool mIsAudioSourceSet;
234 bool mIsVideoSourceSet;
235 bool mIsAudioEncoderSet;
236 bool mIsVideoEncoderSet;
237 bool mIsOutputFileSet;
Nipun Kwatrab33a5ae2010-08-26 17:20:53 -0700238 bool mIsAuxiliaryOutputFileSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 Mutex mLock;
240 Mutex mNotifyLock;
241};
242
243}; // namespace android
244
245#endif // ANDROID_MEDIARECORDER_H