blob: 048bdd560b0b5aa1d61e07e2767b95618433887e [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * Copyright (C) 2008 HTC Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef ANDROID_HARDWARE_CAMERA_H
19#define ANDROID_HARDWARE_CAMERA_H
20
21#include <ui/ICameraClient.h>
22
23namespace android {
24
25/*
26 * A set of bit masks for specifying how the received preview frames are
27 * handled before the previewCallback() call.
28 *
29 * The least significant 3 bits of an "int" value are used for this purpose:
30 *
31 * ..... 0 0 0
32 * ^ ^ ^
33 * | | |---------> determine whether the callback is enabled or not
34 * | |-----------> determine whether the callback is one-shot or not
35 * |-------------> determine whether the frame is copied out or not
36 *
37 * WARNING:
38 * When a frame is sent directly without copying, it is the frame receiver's
39 * responsiblity to make sure that the frame data won't get corrupted by
40 * subsequent preview frames filled by the camera. This flag is recommended
41 * only when copying out data brings significant performance price and the
42 * handling/processing of the received frame data is always faster than
43 * the preview frame rate so that data corruption won't occur.
44 *
45 * For instance,
46 * 1. 0x00 disables the callback. In this case, copy out and one shot bits
47 * are ignored.
48 * 2. 0x01 enables a callback without copying out the received frames. A
49 * typical use case is the Camcorder application to avoid making costly
50 * frame copies.
51 * 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical
52 * use case is the Camera application.
53 * 4. 0x07 is enabling a callback with frame copied out only once. A typical use
54 * case is the Barcode scanner application.
55 */
56#define FRAME_CALLBACK_FLAG_ENABLE_MASK 0x01
57#define FRAME_CALLBACK_FLAG_ONE_SHOT_MASK 0x02
58#define FRAME_CALLBACK_FLAG_COPY_OUT_MASK 0x04
59
60// Typical use cases
61#define FRAME_CALLBACK_FLAG_NOOP 0x00
62#define FRAME_CALLBACK_FLAG_CAMCORDER 0x01
63#define FRAME_CALLBACK_FLAG_CAMERA 0x05
64#define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07
65
Dave Sparks93b94582009-05-07 19:27:32 -070066// msgType in notifyCallback function
67enum {
68 CAMERA_MSG_ERROR,
69 CAMERA_MSG_SHUTTER,
70 CAMERA_MSG_FOCUS,
71 CAMERA_MSG_ZOOM
72};
73
74// msgType in dataCallback function
75enum {
76 CAMERA_MSG_PREVIEW_FRAME,
77 CAMERA_MSG_VIDEO_FRAME,
78 CAMERA_MSG_POSTVIEW_FRAME,
79 CAMERA_MSG_RAW_IMAGE,
80 CAMERA_MSG_COMPRESSED_IMAGE
81};
82
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083class ICameraService;
84class ICamera;
85class Surface;
86class Mutex;
87class String8;
88
89typedef void (*shutter_callback)(void *cookie);
90typedef void (*frame_callback)(const sp<IMemory>& mem, void *cookie);
91typedef void (*autofocus_callback)(bool focused, void *cookie);
92typedef void (*error_callback)(status_t err, void *cookie);
93
94class Camera : public BnCameraClient, public IBinder::DeathRecipient
95{
96public:
97 // construct a camera client from an existing remote
James Dongf1a53142009-04-23 14:07:23 -070098 static sp<Camera> create(const sp<ICamera>& camera);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099 static sp<Camera> connect();
100 ~Camera();
101 void init();
102
103 status_t reconnect();
104 void disconnect();
105 status_t lock();
106 status_t unlock();
107
108 status_t getStatus() { return mStatus; }
109
110 // pass the buffered ISurface to the camera service
111 status_t setPreviewDisplay(const sp<Surface>& surface);
112 status_t setPreviewDisplay(const sp<ISurface>& surface);
113
114 // start preview mode, must call setPreviewDisplay first
115 status_t startPreview();
116
117 // stop preview mode
118 void stopPreview();
119
120 // get preview state
121 bool previewEnabled();
122
123 // start recording mode, must call setPreviewDisplay first
124 status_t startRecording();
125
126 // stop recording mode
127 void stopRecording();
128
129 // get recording state
130 bool recordingEnabled();
131
132 // release a recording frame
133 void releaseRecordingFrame(const sp<IMemory>& mem);
134
135 // autoFocus - status returned from callback
136 status_t autoFocus();
137
138 // take a picture - picture returned from callback
139 status_t takePicture();
140
141 // set preview/capture parameters - key/value pairs
142 status_t setParameters(const String8& params);
143
144 // get preview/capture parameters - key/value pairs
145 String8 getParameters() const;
146
147 void setShutterCallback(shutter_callback cb, void *cookie);
148 void setRawCallback(frame_callback cb, void *cookie);
149 void setJpegCallback(frame_callback cb, void *cookie);
150 void setRecordingCallback(frame_callback cb, void *cookie);
151 void setPreviewCallback(frame_callback cb, void *cookie, int preview_callback_flag = FRAME_CALLBACK_FLAG_NOOP);
152 void setErrorCallback(error_callback cb, void *cookie);
153 void setAutoFocusCallback(autofocus_callback cb, void *cookie);
154
155 // ICameraClient interface
Dave Sparks9b352332009-05-07 12:25:25 -0700156 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
Dave Sparks93b94582009-05-07 19:27:32 -0700157 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800158
159 sp<ICamera> remote();
160
161private:
162 Camera();
163 virtual void binderDied(const wp<IBinder>& who);
164
165 class DeathNotifier: public IBinder::DeathRecipient
166 {
167 public:
168 DeathNotifier() {
169 }
170
171 virtual void binderDied(const wp<IBinder>& who);
172 };
173
174 static sp<DeathNotifier> mDeathNotifier;
175
176 // helper function to obtain camera service handle
177 static const sp<ICameraService>& getCameraService();
178
179 sp<ICamera> mCamera;
180 status_t mStatus;
181
182 shutter_callback mShutterCallback;
183 void *mShutterCallbackCookie;
184 frame_callback mRawCallback;
185 void *mRawCallbackCookie;
186 frame_callback mJpegCallback;
187 void *mJpegCallbackCookie;
188 frame_callback mPreviewCallback;
189 void *mPreviewCallbackCookie;
190 frame_callback mRecordingCallback;
191 void *mRecordingCallbackCookie;
192 error_callback mErrorCallback;
193 void *mErrorCallbackCookie;
194 autofocus_callback mAutoFocusCallback;
195 void *mAutoFocusCallbackCookie;
196
197 friend class DeathNotifier;
198
199 static Mutex mLock;
200 static sp<ICameraService> mCameraService;
201
202};
203
204}; // namespace android
205
206#endif
207