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