blob: 234e1657eef88cc5dcd30f9ec0ed60379028badb [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
The Android Open Source Project9066cfe2009-03-03 19:31:44 -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
Dave Sparks59c1a932009-07-08 15:56:53 -070020#include <utils/Timers.h>
Jamie Gennisff2dc462010-12-20 11:51:31 -080021#include <gui/ISurfaceTexture.h>
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -070022#include <system/camera.h>
Wu-cheng Li42419ce2011-06-01 17:22:24 +080023#include <camera/ICameraClient.h>
24#include <camera/ICameraRecordingProxy.h>
25#include <camera/ICameraRecordingProxyListener.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026
27namespace android {
28
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080029struct CameraInfo {
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080030 /**
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -070031 * The direction that the camera faces to. It should be CAMERA_FACING_BACK
32 * or CAMERA_FACING_FRONT.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080033 */
34 int facing;
35
36 /**
37 * The orientation of the camera image. The value is the angle that the
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -070038 * camera image needs to be rotated clockwise so it shows correctly on the
39 * display in its natural orientation. It should be 0, 90, 180, or 270.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080040 *
Wu-cheng Li99a3f3e2010-11-19 15:56:16 +080041 * For example, suppose a device has a naturally tall screen. The
42 * back-facing camera sensor is mounted in landscape. You are looking at
43 * the screen. If the top side of the camera sensor is aligned with the
44 * right edge of the screen in natural orientation, the value should be
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -070045 * 90. If the top side of a front-facing camera sensor is aligned with the
46 * right of the screen, the value should be 270.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080047 */
48 int orientation;
49};
50
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051class ICameraService;
52class ICamera;
53class Surface;
54class Mutex;
55class String8;
56
Dave Sparks5e271152009-06-23 17:30:11 -070057// ref-counted object for callbacks
58class CameraListener: virtual public RefBase
59{
60public:
61 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
Wu-cheng Libb1e2752011-07-30 05:00:37 +080062 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr,
63 camera_frame_metadata_t *metadata) = 0;
Dave Sparks59c1a932009-07-08 15:56:53 -070064 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
Dave Sparks5e271152009-06-23 17:30:11 -070065};
66
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067class Camera : public BnCameraClient, public IBinder::DeathRecipient
68{
69public:
70 // construct a camera client from an existing remote
James Dong2adc2db2009-04-23 14:07:23 -070071 static sp<Camera> create(const sp<ICamera>& camera);
Chih-Chung Change25cc652010-05-06 16:36:58 +080072 static int32_t getNumberOfCameras();
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080073 static status_t getCameraInfo(int cameraId,
74 struct CameraInfo* cameraInfo);
Chih-Chung Change25cc652010-05-06 16:36:58 +080075 static sp<Camera> connect(int cameraId);
Wu-cheng Li42419ce2011-06-01 17:22:24 +080076 virtual ~Camera();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 void init();
78
79 status_t reconnect();
80 void disconnect();
81 status_t lock();
82 status_t unlock();
83
84 status_t getStatus() { return mStatus; }
85
Jamie Gennis85cfdd02010-08-10 16:37:53 -070086 // pass the buffered Surface to the camera service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 status_t setPreviewDisplay(const sp<Surface>& surface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
Jamie Gennisff2dc462010-12-20 11:51:31 -080089 // pass the buffered ISurfaceTexture to the camera service
90 status_t setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture);
91
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 // start preview mode, must call setPreviewDisplay first
93 status_t startPreview();
94
95 // stop preview mode
96 void stopPreview();
97
98 // get preview state
99 bool previewEnabled();
100
101 // start recording mode, must call setPreviewDisplay first
102 status_t startRecording();
103
104 // stop recording mode
105 void stopRecording();
106
107 // get recording state
108 bool recordingEnabled();
109
110 // release a recording frame
111 void releaseRecordingFrame(const sp<IMemory>& mem);
112
113 // autoFocus - status returned from callback
114 status_t autoFocus();
115
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800116 // cancel auto focus
117 status_t cancelAutoFocus();
118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 // take a picture - picture returned from callback
James Donge00cab72011-02-17 16:38:06 -0800120 status_t takePicture(int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121
122 // set preview/capture parameters - key/value pairs
123 status_t setParameters(const String8& params);
124
125 // get preview/capture parameters - key/value pairs
126 String8 getParameters() const;
127
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700128 // send command to camera driver
129 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
130
James Dong38311852010-10-18 20:42:51 -0700131 // tell camera hal to store meta data or real YUV in video buffers.
132 status_t storeMetaDataInBuffers(bool enabled);
133
Dave Sparks5e271152009-06-23 17:30:11 -0700134 void setListener(const sp<CameraListener>& listener);
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800135 void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
Dave Sparks5e271152009-06-23 17:30:11 -0700136 void setPreviewCallbackFlags(int preview_callback_flag);
137
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800138 sp<ICameraRecordingProxy> getRecordingProxy();
139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 // ICameraClient interface
Dave Sparks2a04aef2009-05-07 12:25:25 -0700141 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800142 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
143 camera_frame_metadata_t *metadata);
Dave Sparks59c1a932009-07-08 15:56:53 -0700144 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145
146 sp<ICamera> remote();
147
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800148 class RecordingProxy : public BnCameraRecordingProxy
149 {
150 public:
151 RecordingProxy(const sp<Camera>& camera);
152
153 // ICameraRecordingProxy interface
154 virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
155 virtual void stopRecording();
156 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
157
158 private:
159 sp<Camera> mCamera;
160 };
161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162private:
163 Camera();
Dave Sparks6f0602e2009-06-24 10:42:53 -0700164 Camera(const Camera&);
165 Camera& operator=(const Camera);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 virtual void binderDied(const wp<IBinder>& who);
167
168 class DeathNotifier: public IBinder::DeathRecipient
169 {
170 public:
171 DeathNotifier() {
172 }
173
174 virtual void binderDied(const wp<IBinder>& who);
175 };
176
177 static sp<DeathNotifier> mDeathNotifier;
178
179 // helper function to obtain camera service handle
180 static const sp<ICameraService>& getCameraService();
181
182 sp<ICamera> mCamera;
183 status_t mStatus;
184
Dave Sparks5e271152009-06-23 17:30:11 -0700185 sp<CameraListener> mListener;
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800186 sp<ICameraRecordingProxyListener> mRecordingProxyListener;
Dave Sparks5e271152009-06-23 17:30:11 -0700187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 friend class DeathNotifier;
189
190 static Mutex mLock;
191 static sp<ICameraService> mCameraService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192};
193
194}; // namespace android
195
196#endif