blob: 901c7a98f9a1a7a7ab02a18d0bc59ee11cfb171b [file] [log] [blame]
The Android Open Source Project9066cfe2009-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
66class ICameraService;
67class ICamera;
68class Surface;
69class Mutex;
70class String8;
71
72typedef void (*shutter_callback)(void *cookie);
73typedef void (*frame_callback)(const sp<IMemory>& mem, void *cookie);
74typedef void (*autofocus_callback)(bool focused, void *cookie);
75typedef void (*error_callback)(status_t err, void *cookie);
76
77class Camera : public BnCameraClient, public IBinder::DeathRecipient
78{
79public:
80 // construct a camera client from an existing remote
James Dong2adc2db2009-04-23 14:07:23 -070081 static sp<Camera> create(const sp<ICamera>& camera);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 static sp<Camera> connect();
83 ~Camera();
84 void init();
85
86 status_t reconnect();
87 void disconnect();
88 status_t lock();
89 status_t unlock();
90
91 status_t getStatus() { return mStatus; }
92
93 // pass the buffered ISurface to the camera service
94 status_t setPreviewDisplay(const sp<Surface>& surface);
95 status_t setPreviewDisplay(const sp<ISurface>& surface);
96
97 // start preview mode, must call setPreviewDisplay first
98 status_t startPreview();
99
100 // stop preview mode
101 void stopPreview();
102
103 // get preview state
104 bool previewEnabled();
105
106 // start recording mode, must call setPreviewDisplay first
107 status_t startRecording();
108
109 // stop recording mode
110 void stopRecording();
111
112 // get recording state
113 bool recordingEnabled();
114
115 // release a recording frame
116 void releaseRecordingFrame(const sp<IMemory>& mem);
117
118 // autoFocus - status returned from callback
119 status_t autoFocus();
120
121 // take a picture - picture returned from callback
122 status_t takePicture();
123
124 // set preview/capture parameters - key/value pairs
125 status_t setParameters(const String8& params);
126
127 // get preview/capture parameters - key/value pairs
128 String8 getParameters() const;
129
130 void setShutterCallback(shutter_callback cb, void *cookie);
131 void setRawCallback(frame_callback cb, void *cookie);
132 void setJpegCallback(frame_callback cb, void *cookie);
133 void setRecordingCallback(frame_callback cb, void *cookie);
134 void setPreviewCallback(frame_callback cb, void *cookie, int preview_callback_flag = FRAME_CALLBACK_FLAG_NOOP);
135 void setErrorCallback(error_callback cb, void *cookie);
136 void setAutoFocusCallback(autofocus_callback cb, void *cookie);
137
138 // ICameraClient interface
139 virtual void shutterCallback();
140 virtual void rawCallback(const sp<IMemory>& picture);
141 virtual void jpegCallback(const sp<IMemory>& picture);
142 virtual void previewCallback(const sp<IMemory>& frame);
143 virtual void errorCallback(status_t error);
144 virtual void autoFocusCallback(bool focused);
145 virtual void recordingCallback(const sp<IMemory>& frame);
Dave Sparks2a04aef2009-05-07 12:25:25 -0700146 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
147 virtual void dataCallback(int32_t msgType, const sp<IMemory>& frame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148
149 sp<ICamera> remote();
150
151private:
152 Camera();
153 virtual void binderDied(const wp<IBinder>& who);
154
155 class DeathNotifier: public IBinder::DeathRecipient
156 {
157 public:
158 DeathNotifier() {
159 }
160
161 virtual void binderDied(const wp<IBinder>& who);
162 };
163
164 static sp<DeathNotifier> mDeathNotifier;
165
166 // helper function to obtain camera service handle
167 static const sp<ICameraService>& getCameraService();
168
169 sp<ICamera> mCamera;
170 status_t mStatus;
171
172 shutter_callback mShutterCallback;
173 void *mShutterCallbackCookie;
174 frame_callback mRawCallback;
175 void *mRawCallbackCookie;
176 frame_callback mJpegCallback;
177 void *mJpegCallbackCookie;
178 frame_callback mPreviewCallback;
179 void *mPreviewCallbackCookie;
180 frame_callback mRecordingCallback;
181 void *mRecordingCallbackCookie;
182 error_callback mErrorCallback;
183 void *mErrorCallbackCookie;
184 autofocus_callback mAutoFocusCallback;
185 void *mAutoFocusCallbackCookie;
186
187 friend class DeathNotifier;
188
189 static Mutex mLock;
190 static sp<ICameraService> mCameraService;
191
192};
193
194}; // namespace android
195
196#endif
197