blob: ad4db3b65e1753c714e4953b864f42b246cec8f3 [file] [log] [blame]
Mathias Agopian3cf61352010-02-09 17:46:37 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
Mathias Agopian3cf61352010-02-09 17:46:37 -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
20#include <utils/Timers.h>
Jamie Gennisbfa33aa2010-12-20 11:51:31 -080021#include <gui/ISurfaceTexture.h>
Iliyan Malchev9e626522011-04-14 16:51:21 -070022#include <system/camera.h>
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080023#include <camera/ICameraClient.h>
24#include <camera/ICameraRecordingProxy.h>
25#include <camera/ICameraRecordingProxyListener.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080026
27namespace android {
28
Chih-Chung Changddbdb352010-06-10 13:32:16 +080029struct CameraInfo {
Chih-Chung Changddbdb352010-06-10 13:32:16 +080030 /**
Iliyan Malchev9e626522011-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 Changddbdb352010-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 Malchev9e626522011-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 Changddbdb352010-06-10 13:32:16 +080040 *
Wu-cheng Lic2c88682010-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 Malchev9e626522011-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 Changddbdb352010-06-10 13:32:16 +080047 */
48 int orientation;
Dorian Snyder0c79b482013-05-27 02:34:37 -070049#ifdef QCOM_HARDWARE
50 int mode;
51#endif
Chih-Chung Changddbdb352010-06-10 13:32:16 +080052};
53
Mathias Agopian3cf61352010-02-09 17:46:37 -080054class ICameraService;
55class ICamera;
56class Surface;
57class Mutex;
58class String8;
59
60// ref-counted object for callbacks
61class CameraListener: virtual public RefBase
62{
63public:
64 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
Wu-cheng Li57c86182011-07-30 05:00:37 +080065 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr,
66 camera_frame_metadata_t *metadata) = 0;
Mathias Agopian3cf61352010-02-09 17:46:37 -080067 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
68};
69
70class Camera : public BnCameraClient, public IBinder::DeathRecipient
71{
72public:
73 // construct a camera client from an existing remote
74 static sp<Camera> create(const sp<ICamera>& camera);
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080075 static int32_t getNumberOfCameras();
Chih-Chung Changddbdb352010-06-10 13:32:16 +080076 static status_t getCameraInfo(int cameraId,
77 struct CameraInfo* cameraInfo);
Wu-cheng Li08ad5ef2012-04-19 12:35:00 +080078 static sp<Camera> connect(int cameraId);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080079 virtual ~Camera();
Mathias Agopian3cf61352010-02-09 17:46:37 -080080 void init();
81
82 status_t reconnect();
83 void disconnect();
84 status_t lock();
85 status_t unlock();
86
87 status_t getStatus() { return mStatus; }
88
Jamie Gennis4b791682010-08-10 16:37:53 -070089 // pass the buffered Surface to the camera service
Mathias Agopian3cf61352010-02-09 17:46:37 -080090 status_t setPreviewDisplay(const sp<Surface>& surface);
Mathias Agopian3cf61352010-02-09 17:46:37 -080091
Jamie Gennisbfa33aa2010-12-20 11:51:31 -080092 // pass the buffered ISurfaceTexture to the camera service
93 status_t setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture);
94
Mathias Agopian3cf61352010-02-09 17:46:37 -080095 // start preview mode, must call setPreviewDisplay first
96 status_t startPreview();
97
98 // stop preview mode
99 void stopPreview();
100
101 // get preview state
102 bool previewEnabled();
103
104 // start recording mode, must call setPreviewDisplay first
105 status_t startRecording();
106
107 // stop recording mode
108 void stopRecording();
109
110 // get recording state
111 bool recordingEnabled();
112
113 // release a recording frame
114 void releaseRecordingFrame(const sp<IMemory>& mem);
115
116 // autoFocus - status returned from callback
117 status_t autoFocus();
118
119 // cancel auto focus
120 status_t cancelAutoFocus();
121
122 // take a picture - picture returned from callback
James Donge468ac52011-02-17 16:38:06 -0800123 status_t takePicture(int msgType);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800124
125 // set preview/capture parameters - key/value pairs
126 status_t setParameters(const String8& params);
127
128 // get preview/capture parameters - key/value pairs
129 String8 getParameters() const;
130
131 // send command to camera driver
132 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
133
James Donge2ad6732010-10-18 20:42:51 -0700134 // tell camera hal to store meta data or real YUV in video buffers.
135 status_t storeMetaDataInBuffers(bool enabled);
136
Mathias Agopian3cf61352010-02-09 17:46:37 -0800137 void setListener(const sp<CameraListener>& listener);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800138 void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800139 void setPreviewCallbackFlags(int preview_callback_flag);
140
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800141 sp<ICameraRecordingProxy> getRecordingProxy();
142
Mathias Agopian3cf61352010-02-09 17:46:37 -0800143 // ICameraClient interface
144 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
Wu-cheng Li57c86182011-07-30 05:00:37 +0800145 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
146 camera_frame_metadata_t *metadata);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800147 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
148
149 sp<ICamera> remote();
150
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800151 class RecordingProxy : public BnCameraRecordingProxy
152 {
153 public:
154 RecordingProxy(const sp<Camera>& camera);
155
156 // ICameraRecordingProxy interface
157 virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
158 virtual void stopRecording();
159 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
160
161 private:
162 sp<Camera> mCamera;
163 };
164
Mathias Agopian3cf61352010-02-09 17:46:37 -0800165private:
166 Camera();
167 Camera(const Camera&);
168 Camera& operator=(const Camera);
169 virtual void binderDied(const wp<IBinder>& who);
170
171 class DeathNotifier: public IBinder::DeathRecipient
172 {
173 public:
174 DeathNotifier() {
175 }
176
177 virtual void binderDied(const wp<IBinder>& who);
178 };
179
180 static sp<DeathNotifier> mDeathNotifier;
181
182 // helper function to obtain camera service handle
183 static const sp<ICameraService>& getCameraService();
184
185 sp<ICamera> mCamera;
186 status_t mStatus;
187
188 sp<CameraListener> mListener;
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800189 sp<ICameraRecordingProxyListener> mRecordingProxyListener;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800190
191 friend class DeathNotifier;
192
193 static Mutex mLock;
194 static sp<ICameraService> mCameraService;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800195};
196
197}; // namespace android
198
199#endif