blob: 57968e39cad59ece02b077720d5a547e384eba9d [file] [log] [blame]
Mathias Agopian3cf61352010-02-09 17:46:37 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
Mathias Agopian3cf61352010-02-09 17:46:37 -08003 *
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 * limitations under the License.
15 */
16
17#ifndef ANDROID_HARDWARE_CAMERA_H
18#define ANDROID_HARDWARE_CAMERA_H
19
20#include <utils/Timers.h>
21#include <camera/ICameraClient.h>
22
23namespace android {
24
25class ISurface;
26
27/*
28 * A set of bit masks for specifying how the received preview frames are
29 * handled before the previewCallback() call.
30 *
31 * The least significant 3 bits of an "int" value are used for this purpose:
32 *
33 * ..... 0 0 0
34 * ^ ^ ^
35 * | | |---------> determine whether the callback is enabled or not
36 * | |-----------> determine whether the callback is one-shot or not
37 * |-------------> determine whether the frame is copied out or not
38 *
39 * WARNING:
40 * When a frame is sent directly without copying, it is the frame receiver's
41 * responsiblity to make sure that the frame data won't get corrupted by
42 * subsequent preview frames filled by the camera. This flag is recommended
43 * only when copying out data brings significant performance price and the
44 * handling/processing of the received frame data is always faster than
45 * the preview frame rate so that data corruption won't occur.
46 *
47 * For instance,
48 * 1. 0x00 disables the callback. In this case, copy out and one shot bits
49 * are ignored.
50 * 2. 0x01 enables a callback without copying out the received frames. A
51 * typical use case is the Camcorder application to avoid making costly
52 * frame copies.
53 * 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical
54 * use case is the Camera application.
55 * 4. 0x07 is enabling a callback with frame copied out only once. A typical use
56 * case is the Barcode scanner application.
57 */
58#define FRAME_CALLBACK_FLAG_ENABLE_MASK 0x01
59#define FRAME_CALLBACK_FLAG_ONE_SHOT_MASK 0x02
60#define FRAME_CALLBACK_FLAG_COPY_OUT_MASK 0x04
61
62// Typical use cases
63#define FRAME_CALLBACK_FLAG_NOOP 0x00
64#define FRAME_CALLBACK_FLAG_CAMCORDER 0x01
65#define FRAME_CALLBACK_FLAG_CAMERA 0x05
66#define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07
67
68// msgType in notifyCallback and dataCallback functions
69enum {
70 CAMERA_MSG_ERROR = 0x001,
71 CAMERA_MSG_SHUTTER = 0x002,
72 CAMERA_MSG_FOCUS = 0x004,
73 CAMERA_MSG_ZOOM = 0x008,
74 CAMERA_MSG_PREVIEW_FRAME = 0x010,
75 CAMERA_MSG_VIDEO_FRAME = 0x020,
76 CAMERA_MSG_POSTVIEW_FRAME = 0x040,
77 CAMERA_MSG_RAW_IMAGE = 0x080,
78 CAMERA_MSG_COMPRESSED_IMAGE = 0x100,
79 CAMERA_MSG_ALL_MSGS = 0x1FF
80};
81
82// cmdType in sendCommand functions
83enum {
84 CAMERA_CMD_START_SMOOTH_ZOOM = 1,
85 CAMERA_CMD_STOP_SMOOTH_ZOOM = 2,
86 CAMERA_CMD_SET_DISPLAY_ORIENTATION = 3,
87};
88
89// camera fatal errors
90enum {
91 CAMERA_ERROR_UKNOWN = 1,
92 CAMERA_ERROR_SERVER_DIED = 100
93};
94
95class ICameraService;
96class ICamera;
97class Surface;
98class Mutex;
99class String8;
100
101// ref-counted object for callbacks
102class CameraListener: virtual public RefBase
103{
104public:
105 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
106 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr) = 0;
107 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
108};
109
110class Camera : public BnCameraClient, public IBinder::DeathRecipient
111{
112public:
113 // construct a camera client from an existing remote
114 static sp<Camera> create(const sp<ICamera>& camera);
115 static sp<Camera> connect();
116 ~Camera();
117 void init();
118
119 status_t reconnect();
120 void disconnect();
121 status_t lock();
122 status_t unlock();
123
124 status_t getStatus() { return mStatus; }
125
126 // pass the buffered ISurface to the camera service
127 status_t setPreviewDisplay(const sp<Surface>& surface);
128 status_t setPreviewDisplay(const sp<ISurface>& surface);
129
130 // start preview mode, must call setPreviewDisplay first
131 status_t startPreview();
132
133 // stop preview mode
134 void stopPreview();
135
136 // get preview state
137 bool previewEnabled();
138
139 // start recording mode, must call setPreviewDisplay first
140 status_t startRecording();
141
142 // stop recording mode
143 void stopRecording();
144
145 // get recording state
146 bool recordingEnabled();
147
148 // release a recording frame
149 void releaseRecordingFrame(const sp<IMemory>& mem);
150
151 // autoFocus - status returned from callback
152 status_t autoFocus();
153
154 // cancel auto focus
155 status_t cancelAutoFocus();
156
157 // take a picture - picture returned from callback
158 status_t takePicture();
159
160 // set preview/capture parameters - key/value pairs
161 status_t setParameters(const String8& params);
162
163 // get preview/capture parameters - key/value pairs
164 String8 getParameters() const;
165
166 // send command to camera driver
167 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
168
169 void setListener(const sp<CameraListener>& listener);
170 void setPreviewCallbackFlags(int preview_callback_flag);
171
172 // ICameraClient interface
173 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
174 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr);
175 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
176
177 sp<ICamera> remote();
178
179private:
180 Camera();
181 Camera(const Camera&);
182 Camera& operator=(const Camera);
183 virtual void binderDied(const wp<IBinder>& who);
184
185 class DeathNotifier: public IBinder::DeathRecipient
186 {
187 public:
188 DeathNotifier() {
189 }
190
191 virtual void binderDied(const wp<IBinder>& who);
192 };
193
194 static sp<DeathNotifier> mDeathNotifier;
195
196 // helper function to obtain camera service handle
197 static const sp<ICameraService>& getCameraService();
198
199 sp<ICamera> mCamera;
200 status_t mStatus;
201
202 sp<CameraListener> mListener;
203
204 friend class DeathNotifier;
205
206 static Mutex mLock;
207 static sp<ICameraService> mCameraService;
208
209};
210
211}; // namespace android
212
213#endif