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