blob: e3544ab0f1557ef48b311ec2e5c7cfe5b46bb182 [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 Sparksc06b7cb2009-06-26 13:33:32 -070066// msgType in notifyCallback and dataCallback functions
Dave Sparks93b94582009-05-07 19:27:32 -070067enum {
Dave Sparksc06b7cb2009-06-26 13:33:32 -070068 CAMERA_MSG_ERROR = 0,
Dave Sparks93b94582009-05-07 19:27:32 -070069 CAMERA_MSG_SHUTTER,
70 CAMERA_MSG_FOCUS,
Dave Sparksc06b7cb2009-06-26 13:33:32 -070071 CAMERA_MSG_ZOOM,
Dave Sparks93b94582009-05-07 19:27:32 -070072 CAMERA_MSG_PREVIEW_FRAME,
73 CAMERA_MSG_VIDEO_FRAME,
74 CAMERA_MSG_POSTVIEW_FRAME,
75 CAMERA_MSG_RAW_IMAGE,
76 CAMERA_MSG_COMPRESSED_IMAGE
77};
78
James Dong16f3d352009-07-02 10:04:20 -070079// camera fatal errors
80enum {
81 CAMERA_ERROR_UKNOWN = 1,
82 CAMERA_ERROR_SERVER_DIED = 100
83};
84
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085class ICameraService;
86class ICamera;
87class Surface;
88class Mutex;
89class String8;
90
Dave Sparksbbbc7cb2009-06-23 17:30:11 -070091// ref-counted object for callbacks
92class CameraListener: virtual public RefBase
93{
94public:
95 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
96 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr) = 0;
97};
98
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099class Camera : public BnCameraClient, public IBinder::DeathRecipient
100{
101public:
102 // construct a camera client from an existing remote
James Dongf1a53142009-04-23 14:07:23 -0700103 static sp<Camera> create(const sp<ICamera>& camera);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104 static sp<Camera> connect();
105 ~Camera();
106 void init();
107
108 status_t reconnect();
109 void disconnect();
110 status_t lock();
111 status_t unlock();
112
113 status_t getStatus() { return mStatus; }
114
115 // pass the buffered ISurface to the camera service
116 status_t setPreviewDisplay(const sp<Surface>& surface);
117 status_t setPreviewDisplay(const sp<ISurface>& surface);
118
119 // start preview mode, must call setPreviewDisplay first
120 status_t startPreview();
121
122 // stop preview mode
123 void stopPreview();
124
125 // get preview state
126 bool previewEnabled();
127
128 // start recording mode, must call setPreviewDisplay first
129 status_t startRecording();
130
131 // stop recording mode
132 void stopRecording();
133
134 // get recording state
135 bool recordingEnabled();
136
137 // release a recording frame
138 void releaseRecordingFrame(const sp<IMemory>& mem);
139
140 // autoFocus - status returned from callback
141 status_t autoFocus();
142
143 // take a picture - picture returned from callback
144 status_t takePicture();
145
146 // set preview/capture parameters - key/value pairs
147 status_t setParameters(const String8& params);
148
149 // get preview/capture parameters - key/value pairs
150 String8 getParameters() const;
151
Dave Sparksbbbc7cb2009-06-23 17:30:11 -0700152 void setListener(const sp<CameraListener>& listener);
153 void setPreviewCallbackFlags(int preview_callback_flag);
154
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800155 // 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();
Dave Sparksf5a8faa2009-06-24 10:42:53 -0700163 Camera(const Camera&);
164 Camera& operator=(const Camera);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165 virtual void binderDied(const wp<IBinder>& who);
166
167 class DeathNotifier: public IBinder::DeathRecipient
168 {
169 public:
170 DeathNotifier() {
171 }
172
173 virtual void binderDied(const wp<IBinder>& who);
174 };
175
176 static sp<DeathNotifier> mDeathNotifier;
177
178 // helper function to obtain camera service handle
179 static const sp<ICameraService>& getCameraService();
180
181 sp<ICamera> mCamera;
182 status_t mStatus;
183
Dave Sparksbbbc7cb2009-06-23 17:30:11 -0700184 sp<CameraListener> mListener;
185
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800186 friend class DeathNotifier;
187
188 static Mutex mLock;
189 static sp<ICameraService> mCameraService;
190
191};
192
193}; // namespace android
194
195#endif
196