mediarecorder.h revision c048cae0367db6fbb4fe1127be5011910713d4ad
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.h>
22#include <media/IMediaPlayerClient.h>
23
24namespace android {
25
26class Surface;
27class IMediaRecorder;
28class ICamera;
29
30typedef void (*media_completion_f)(status_t status, void *cookie);
31
32/* Do not change these values without updating their counterparts
33 * in java/android/android/media/MediaRecorder.java!
34 */
35enum audio_source {
36    AUDIO_SOURCE_DEFAULT = 0,
37    AUDIO_SOURCE_MIC = 1,
38};
39
40enum video_source {
41    VIDEO_SOURCE_DEFAULT = 0,
42    VIDEO_SOURCE_CAMERA = 1,
43};
44
45//Please update java/android/android/media/MediaRecorder.java if the following is updated.
46enum output_format {
47    OUTPUT_FORMAT_DEFAULT = 0,
48    OUTPUT_FORMAT_THREE_GPP,
49    OUTPUT_FORMAT_MPEG_4,
50    OUTPUT_FORMAT_RAW_AMR,
51    OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
52};
53
54enum audio_encoder {
55    AUDIO_ENCODER_DEFAULT = 0,
56    AUDIO_ENCODER_AMR_NB = 1,
57};
58
59enum video_encoder {
60    VIDEO_ENCODER_DEFAULT = 0,
61    VIDEO_ENCODER_H263 = 1,
62    VIDEO_ENCODER_H264 = 2,
63    VIDEO_ENCODER_MPEG_4_SP = 3,
64};
65
66// Maximum frames per second is 24
67#define MEDIA_RECORDER_MAX_FRAME_RATE         24
68
69/*
70 * The state machine of the media_recorder uses a set of different state names.
71 * The mapping between the media_recorder and the pvauthorengine is shown below:
72 *
73 *    mediarecorder                        pvauthorengine
74 * ----------------------------------------------------------------
75 *    MEDIA_RECORDER_ERROR                 ERROR
76 *    MEDIA_RECORDER_IDLE                  IDLE
77 *    MEDIA_RECORDER_INITIALIZED           OPENED
78 *    MEDIA_RECORDER_DATASOURCE_CONFIGURED
79 *    MEDIA_RECORDER_PREPARED              INITIALIZED
80 *    MEDIA_RECORDER_RECORDING             RECORDING
81 */
82enum media_recorder_states {
83    MEDIA_RECORDER_ERROR                 =      0,
84    MEDIA_RECORDER_IDLE                  = 1 << 0,
85    MEDIA_RECORDER_INITIALIZED           = 1 << 1,
86    MEDIA_RECORDER_DATASOURCE_CONFIGURED = 1 << 2,
87    MEDIA_RECORDER_PREPARED              = 1 << 3,
88    MEDIA_RECORDER_RECORDING             = 1 << 4,
89};
90
91// The "msg" code passed to the listener in notify.
92enum media_recorder_event_type {
93    MEDIA_RECORDER_EVENT_ERROR                    = 1,
94    MEDIA_RECORDER_EVENT_INFO                     = 2
95};
96
97enum media_recorder_error_type {
98    MEDIA_RECORDER_ERROR_UNKNOWN                  = 1
99};
100
101// The codes are distributed as follow:
102//   0xx: Reserved
103//   8xx: General info/warning
104//
105enum media_recorder_info_type {
106    MEDIA_RECORDER_INFO_UNKNOWN                   = 1,
107    MEDIA_RECORDER_INFO_MAX_DURATION_REACHED      = 800
108};
109
110// ----------------------------------------------------------------------------
111// ref-counted object for callbacks
112class MediaRecorderListener: virtual public RefBase
113{
114public:
115    virtual void notify(int msg, int ext1, int ext2) = 0;
116};
117
118class MediaRecorder : public BnMediaPlayerClient
119{
120public:
121    MediaRecorder();
122    ~MediaRecorder();
123
124    status_t    initCheck();
125    status_t    setCamera(const sp<ICamera>& camera);
126    status_t    setPreviewSurface(const sp<Surface>& surface);
127    status_t    setVideoSource(int vs);
128    status_t    setAudioSource(int as);
129    status_t    setOutputFormat(int of);
130    status_t    setVideoEncoder(int ve);
131    status_t    setAudioEncoder(int ae);
132    status_t    setOutputFile(const char* path);
133    status_t    setOutputFile(int fd, int64_t offset, int64_t length);
134    status_t    setVideoSize(int width, int height);
135    status_t    setVideoFrameRate(int frames_per_second);
136    status_t    setParameters(const String8& params);
137    status_t    setListener(const sp<MediaRecorderListener>& listener);
138    status_t    prepare();
139    status_t    getMaxAmplitude(int* max);
140    status_t    start();
141    status_t    stop();
142    status_t    reset();
143    status_t    init();
144    status_t    close();
145    status_t    release();
146    void        notify(int msg, int ext1, int ext2);
147
148private:
149    void                    doCleanUp();
150    status_t                doReset();
151
152    sp<IMediaRecorder>          mMediaRecorder;
153    sp<MediaRecorderListener>   mListener;
154    media_recorder_states       mCurrentState;
155    bool                        mIsAudioSourceSet;
156    bool                        mIsVideoSourceSet;
157    bool                        mIsAudioEncoderSet;
158    bool                        mIsVideoEncoderSet;
159    bool                        mIsOutputFileSet;
160    Mutex                       mLock;
161    Mutex                       mNotifyLock;
162};
163
164};  // namespace android
165
166#endif // ANDROID_MEDIARECORDER_H
167