blob: f70128063d70dc066c0118d4aeef74997900433d [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;
49};
50
Mathias Agopian3cf61352010-02-09 17:46:37 -080051class ICameraService;
52class ICamera;
53class Surface;
54class Mutex;
55class String8;
56
57// 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;
62 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr) = 0;
63 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
64};
65
66class Camera : public BnCameraClient, public IBinder::DeathRecipient
67{
68public:
69 // construct a camera client from an existing remote
70 static sp<Camera> create(const sp<ICamera>& camera);
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080071 static int32_t getNumberOfCameras();
Chih-Chung Changddbdb352010-06-10 13:32:16 +080072 static status_t getCameraInfo(int cameraId,
73 struct CameraInfo* cameraInfo);
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080074 static sp<Camera> connect(int cameraId);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080075 virtual ~Camera();
Mathias Agopian3cf61352010-02-09 17:46:37 -080076 void init();
77
78 status_t reconnect();
79 void disconnect();
80 status_t lock();
81 status_t unlock();
82
83 status_t getStatus() { return mStatus; }
84
Jamie Gennis4b791682010-08-10 16:37:53 -070085 // pass the buffered Surface to the camera service
Mathias Agopian3cf61352010-02-09 17:46:37 -080086 status_t setPreviewDisplay(const sp<Surface>& surface);
Mathias Agopian3cf61352010-02-09 17:46:37 -080087
Jamie Gennisbfa33aa2010-12-20 11:51:31 -080088 // pass the buffered ISurfaceTexture to the camera service
89 status_t setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture);
90
Mathias Agopian3cf61352010-02-09 17:46:37 -080091 // start preview mode, must call setPreviewDisplay first
92 status_t startPreview();
93
94 // stop preview mode
95 void stopPreview();
96
97 // get preview state
98 bool previewEnabled();
99
100 // start recording mode, must call setPreviewDisplay first
101 status_t startRecording();
102
103 // stop recording mode
104 void stopRecording();
105
106 // get recording state
107 bool recordingEnabled();
108
109 // release a recording frame
110 void releaseRecordingFrame(const sp<IMemory>& mem);
111
112 // autoFocus - status returned from callback
113 status_t autoFocus();
114
115 // cancel auto focus
116 status_t cancelAutoFocus();
117
118 // take a picture - picture returned from callback
James Donge468ac52011-02-17 16:38:06 -0800119 status_t takePicture(int msgType);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800120
121 // set preview/capture parameters - key/value pairs
122 status_t setParameters(const String8& params);
123
124 // get preview/capture parameters - key/value pairs
125 String8 getParameters() const;
126
127 // send command to camera driver
128 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
129
James Donge2ad6732010-10-18 20:42:51 -0700130 // tell camera hal to store meta data or real YUV in video buffers.
131 status_t storeMetaDataInBuffers(bool enabled);
132
Mathias Agopian3cf61352010-02-09 17:46:37 -0800133 void setListener(const sp<CameraListener>& listener);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800134 void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800135 void setPreviewCallbackFlags(int preview_callback_flag);
136
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800137 sp<ICameraRecordingProxy> getRecordingProxy();
138
Mathias Agopian3cf61352010-02-09 17:46:37 -0800139 // ICameraClient interface
140 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
141 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr);
142 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
143
144 sp<ICamera> remote();
145
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800146 class RecordingProxy : public BnCameraRecordingProxy
147 {
148 public:
149 RecordingProxy(const sp<Camera>& camera);
150
151 // ICameraRecordingProxy interface
152 virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
153 virtual void stopRecording();
154 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
155
156 private:
157 sp<Camera> mCamera;
158 };
159
Mathias Agopian3cf61352010-02-09 17:46:37 -0800160private:
161 Camera();
162 Camera(const Camera&);
163 Camera& operator=(const Camera);
164 virtual void binderDied(const wp<IBinder>& who);
165
166 class DeathNotifier: public IBinder::DeathRecipient
167 {
168 public:
169 DeathNotifier() {
170 }
171
172 virtual void binderDied(const wp<IBinder>& who);
173 };
174
175 static sp<DeathNotifier> mDeathNotifier;
176
177 // helper function to obtain camera service handle
178 static const sp<ICameraService>& getCameraService();
179
180 sp<ICamera> mCamera;
181 status_t mStatus;
182
183 sp<CameraListener> mListener;
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800184 sp<ICameraRecordingProxyListener> mRecordingProxyListener;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800185
186 friend class DeathNotifier;
187
188 static Mutex mLock;
189 static sp<ICameraService> mCameraService;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800190};
191
192}; // namespace android
193
194#endif