blob: be2b7f43b8a12076dc0d9a7c2b166aecb8a24cc9 [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>
Andy McFadden8ba01022012-12-18 09:46:54 -080021#include <gui/IGraphicBufferProducer.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;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080056class String16;
Mathias Agopian3cf61352010-02-09 17:46:37 -080057
58// ref-counted object for callbacks
59class CameraListener: virtual public RefBase
60{
61public:
62 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
Wu-cheng Li57c86182011-07-30 05:00:37 +080063 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr,
64 camera_frame_metadata_t *metadata) = 0;
Mathias Agopian3cf61352010-02-09 17:46:37 -080065 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
66};
67
68class Camera : public BnCameraClient, public IBinder::DeathRecipient
69{
70public:
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080071 enum {
72 USE_CALLING_UID = -1
73 };
74
Mathias Agopian3cf61352010-02-09 17:46:37 -080075 // construct a camera client from an existing remote
76 static sp<Camera> create(const sp<ICamera>& camera);
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080077 static int32_t getNumberOfCameras();
Chih-Chung Changddbdb352010-06-10 13:32:16 +080078 static status_t getCameraInfo(int cameraId,
79 struct CameraInfo* cameraInfo);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080080 static sp<Camera> connect(int cameraId,
81 const String16& clientPackageName,
82 int clientUid);
83
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080084 virtual ~Camera();
Mathias Agopian3cf61352010-02-09 17:46:37 -080085 void init();
86
87 status_t reconnect();
88 void disconnect();
89 status_t lock();
90 status_t unlock();
91
92 status_t getStatus() { return mStatus; }
93
Jamie Gennis4b791682010-08-10 16:37:53 -070094 // pass the buffered Surface to the camera service
Mathias Agopian3cf61352010-02-09 17:46:37 -080095 status_t setPreviewDisplay(const sp<Surface>& surface);
Mathias Agopian3cf61352010-02-09 17:46:37 -080096
Andy McFadden8ba01022012-12-18 09:46:54 -080097 // pass the buffered IGraphicBufferProducer to the camera service
98 status_t setPreviewTexture(const sp<IGraphicBufferProducer>& bufferProducer);
Jamie Gennisbfa33aa2010-12-20 11:51:31 -080099
Mathias Agopian3cf61352010-02-09 17:46:37 -0800100 // start preview mode, must call setPreviewDisplay first
101 status_t startPreview();
102
103 // stop preview mode
104 void stopPreview();
105
106 // get preview state
107 bool previewEnabled();
108
109 // start recording mode, must call setPreviewDisplay first
110 status_t startRecording();
111
112 // stop recording mode
113 void stopRecording();
114
115 // get recording state
116 bool recordingEnabled();
117
118 // release a recording frame
119 void releaseRecordingFrame(const sp<IMemory>& mem);
120
121 // autoFocus - status returned from callback
122 status_t autoFocus();
123
124 // cancel auto focus
125 status_t cancelAutoFocus();
126
127 // take a picture - picture returned from callback
James Donge468ac52011-02-17 16:38:06 -0800128 status_t takePicture(int msgType);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800129
130 // set preview/capture parameters - key/value pairs
131 status_t setParameters(const String8& params);
132
133 // get preview/capture parameters - key/value pairs
134 String8 getParameters() const;
135
136 // send command to camera driver
137 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
138
James Donge2ad6732010-10-18 20:42:51 -0700139 // tell camera hal to store meta data or real YUV in video buffers.
140 status_t storeMetaDataInBuffers(bool enabled);
141
Mathias Agopian3cf61352010-02-09 17:46:37 -0800142 void setListener(const sp<CameraListener>& listener);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800143 void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800144 void setPreviewCallbackFlags(int preview_callback_flag);
145
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800146 sp<ICameraRecordingProxy> getRecordingProxy();
147
Mathias Agopian3cf61352010-02-09 17:46:37 -0800148 // ICameraClient interface
149 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
Wu-cheng Li57c86182011-07-30 05:00:37 +0800150 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
151 camera_frame_metadata_t *metadata);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800152 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
153
154 sp<ICamera> remote();
155
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800156 class RecordingProxy : public BnCameraRecordingProxy
157 {
158 public:
159 RecordingProxy(const sp<Camera>& camera);
160
161 // ICameraRecordingProxy interface
162 virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
163 virtual void stopRecording();
164 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
165
166 private:
167 sp<Camera> mCamera;
168 };
169
Igor Murashkin1d880232013-02-20 16:50:13 -0800170protected:
Mathias Agopian3cf61352010-02-09 17:46:37 -0800171 Camera();
172 Camera(const Camera&);
173 Camera& operator=(const Camera);
174 virtual void binderDied(const wp<IBinder>& who);
175
176 class DeathNotifier: public IBinder::DeathRecipient
177 {
178 public:
179 DeathNotifier() {
180 }
181
182 virtual void binderDied(const wp<IBinder>& who);
183 };
184
185 static sp<DeathNotifier> mDeathNotifier;
186
187 // helper function to obtain camera service handle
188 static const sp<ICameraService>& getCameraService();
189
190 sp<ICamera> mCamera;
191 status_t mStatus;
192
193 sp<CameraListener> mListener;
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800194 sp<ICameraRecordingProxyListener> mRecordingProxyListener;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800195
196 friend class DeathNotifier;
197
198 static Mutex mLock;
199 static sp<ICameraService> mCameraService;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800200};
201
202}; // namespace android
203
204#endif