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