blob: a71054618c14a7b304277cef6eb3bc092b048e76 [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
36/* Do not change these values without updating their counterparts
Jianhong Jiang2bcda902009-06-08 08:50:42 -070037 * in media/java/android/media/MediaRecorder.java!
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038 */
39enum audio_source {
40 AUDIO_SOURCE_DEFAULT = 0,
41 AUDIO_SOURCE_MIC = 1,
Eric Laurent4bc035a2009-05-22 09:18:15 -070042 AUDIO_SOURCE_VOICE_UPLINK = 2,
43 AUDIO_SOURCE_VOICE_DOWNLINK = 3,
44 AUDIO_SOURCE_VOICE_CALL = 4,
Eric Laurentf22a0972009-11-02 05:31:33 -080045 AUDIO_SOURCE_CAMCORDER = 5,
Jean-Michel Trivi6869df32009-11-03 19:43:21 -080046 AUDIO_SOURCE_VOICE_RECOGNITION = 6,
Jean-Michel Trivi820b9e02010-11-08 18:38:14 -080047 AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
48 AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_COMMUNICATION,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070049
50 AUDIO_SOURCE_LIST_END // must be last - used to validate audio source type
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051};
52
53enum video_source {
54 VIDEO_SOURCE_DEFAULT = 0,
55 VIDEO_SOURCE_CAMERA = 1,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070056
57 VIDEO_SOURCE_LIST_END // must be last - used to validate audio source type
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058};
59
Jianhong Jiang2bcda902009-06-08 08:50:42 -070060//Please update media/java/android/media/MediaRecorder.java if the following is updated.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061enum output_format {
62 OUTPUT_FORMAT_DEFAULT = 0,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070063 OUTPUT_FORMAT_THREE_GPP = 1,
64 OUTPUT_FORMAT_MPEG_4 = 2,
65
66
67 OUTPUT_FORMAT_AUDIO_ONLY_START = 3, // Used in validating the output format. Should be the
68 // at the start of the audio only output formats.
69
70 /* These are audio only file formats */
71 OUTPUT_FORMAT_RAW_AMR = 3, //to be backward compatible
72 OUTPUT_FORMAT_AMR_NB = 3,
73 OUTPUT_FORMAT_AMR_WB = 4,
74 OUTPUT_FORMAT_AAC_ADIF = 5,
75 OUTPUT_FORMAT_AAC_ADTS = 6,
76
Andreas Huber57648e42010-08-04 10:14:30 -070077 /* Stream over a socket, limited to a single stream */
78 OUTPUT_FORMAT_RTP_AVP = 7,
79
Andreas Huber9adf4662010-10-12 14:17:45 -070080 /* H.264/AAC data encapsulated in MPEG2/TS */
81 OUTPUT_FORMAT_MPEG2TS = 8,
82
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
84};
85
86enum audio_encoder {
87 AUDIO_ENCODER_DEFAULT = 0,
88 AUDIO_ENCODER_AMR_NB = 1,
Jianhong Jiang2bcda902009-06-08 08:50:42 -070089 AUDIO_ENCODER_AMR_WB = 2,
90 AUDIO_ENCODER_AAC = 3,
91 AUDIO_ENCODER_AAC_PLUS = 4,
92 AUDIO_ENCODER_EAAC_PLUS = 5,
93
94 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 -080095};
96
97enum video_encoder {
98 VIDEO_ENCODER_DEFAULT = 0,
99 VIDEO_ENCODER_H263 = 1,
100 VIDEO_ENCODER_H264 = 2,
101 VIDEO_ENCODER_MPEG_4_SP = 3,
Jianhong Jiang2bcda902009-06-08 08:50:42 -0700102
103 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 -0800104};
105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106/*
107 * The state machine of the media_recorder uses a set of different state names.
108 * The mapping between the media_recorder and the pvauthorengine is shown below:
109 *
110 * mediarecorder pvauthorengine
111 * ----------------------------------------------------------------
112 * MEDIA_RECORDER_ERROR ERROR
113 * MEDIA_RECORDER_IDLE IDLE
114 * MEDIA_RECORDER_INITIALIZED OPENED
115 * MEDIA_RECORDER_DATASOURCE_CONFIGURED
116 * MEDIA_RECORDER_PREPARED INITIALIZED
117 * MEDIA_RECORDER_RECORDING RECORDING
118 */
119enum media_recorder_states {
120 MEDIA_RECORDER_ERROR = 0,
121 MEDIA_RECORDER_IDLE = 1 << 0,
122 MEDIA_RECORDER_INITIALIZED = 1 << 1,
123 MEDIA_RECORDER_DATASOURCE_CONFIGURED = 1 << 2,
124 MEDIA_RECORDER_PREPARED = 1 << 3,
125 MEDIA_RECORDER_RECORDING = 1 << 4,
126};
127
128// The "msg" code passed to the listener in notify.
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700129enum media_recorder_event_type {
130 MEDIA_RECORDER_EVENT_ERROR = 1,
131 MEDIA_RECORDER_EVENT_INFO = 2
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132};
133
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700134enum media_recorder_error_type {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 MEDIA_RECORDER_ERROR_UNKNOWN = 1
136};
137
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700138// The codes are distributed as follow:
139// 0xx: Reserved
140// 8xx: General info/warning
Jianhong Jiang2bcda902009-06-08 08:50:42 -0700141//
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700142enum media_recorder_info_type {
143 MEDIA_RECORDER_INFO_UNKNOWN = 1,
The Android Open Source Project10592532009-03-18 17:39:46 -0700144 MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800,
James Dong68510e62010-05-14 11:48:00 -0700145 MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801,
James Dong09936ed2010-06-24 19:04:27 -0700146 MEDIA_RECORDER_INFO_COMPLETION_STATUS = 802,
147 MEDIA_RECORDER_INFO_PROGRESS_FRAME_STATUS = 803,
148 MEDIA_RECORDER_INFO_PROGRESS_TIME_STATUS = 804,
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700149};
150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151// ----------------------------------------------------------------------------
152// ref-counted object for callbacks
153class MediaRecorderListener: virtual public RefBase
154{
155public:
156 virtual void notify(int msg, int ext1, int ext2) = 0;
157};
158
James Dongfe1bafe2010-06-25 17:06:47 -0700159class MediaRecorder : public BnMediaRecorderClient,
James Dong34bbc222010-01-15 18:13:58 -0800160 public virtual IMediaDeathNotifier
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161{
162public:
163 MediaRecorder();
164 ~MediaRecorder();
165
James Dong34bbc222010-01-15 18:13:58 -0800166 void died();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 status_t initCheck();
168 status_t setCamera(const sp<ICamera>& camera);
169 status_t setPreviewSurface(const sp<Surface>& surface);
170 status_t setVideoSource(int vs);
171 status_t setAudioSource(int as);
172 status_t setOutputFormat(int of);
173 status_t setVideoEncoder(int ve);
174 status_t setAudioEncoder(int ae);
175 status_t setOutputFile(const char* path);
176 status_t setOutputFile(int fd, int64_t offset, int64_t length);
Nipun Kwatrab33a5ae2010-08-26 17:20:53 -0700177 status_t setOutputFileAuxiliary(int fd);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 status_t setVideoSize(int width, int height);
179 status_t setVideoFrameRate(int frames_per_second);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700180 status_t setParameters(const String8& params);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 status_t setListener(const sp<MediaRecorderListener>& listener);
182 status_t prepare();
183 status_t getMaxAmplitude(int* max);
184 status_t start();
185 status_t stop();
186 status_t reset();
187 status_t init();
188 status_t close();
189 status_t release();
190 void notify(int msg, int ext1, int ext2);
191
192private:
193 void doCleanUp();
194 status_t doReset();
195
196 sp<IMediaRecorder> mMediaRecorder;
197 sp<MediaRecorderListener> mListener;
198 media_recorder_states mCurrentState;
199 bool mIsAudioSourceSet;
200 bool mIsVideoSourceSet;
201 bool mIsAudioEncoderSet;
202 bool mIsVideoEncoderSet;
203 bool mIsOutputFileSet;
Nipun Kwatrab33a5ae2010-08-26 17:20:53 -0700204 bool mIsAuxiliaryOutputFileSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 Mutex mLock;
206 Mutex mNotifyLock;
207};
208
209}; // namespace android
210
211#endif // ANDROID_MEDIARECORDER_H