blob: 7106bfa6606f75221f7f875a8889b9c97befaf81 [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>
Mathias Agopian000479f2010-02-09 17:46:37 -080021#include <camera/ICameraClient.h>
Jamie Gennisff2dc462010-12-20 11:51:31 -080022#include <gui/ISurfaceTexture.h>
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -070023#include <system/camera.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25namespace android {
26
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080027struct CameraInfo {
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080028 /**
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -070029 * The direction that the camera faces to. It should be CAMERA_FACING_BACK
30 * or CAMERA_FACING_FRONT.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080031 */
32 int facing;
33
34 /**
35 * The orientation of the camera image. The value is the angle that the
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -070036 * camera image needs to be rotated clockwise so it shows correctly on the
37 * display in its natural orientation. It should be 0, 90, 180, or 270.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080038 *
Wu-cheng Li99a3f3e2010-11-19 15:56:16 +080039 * For example, suppose a device has a naturally tall screen. The
40 * back-facing camera sensor is mounted in landscape. You are looking at
41 * the screen. If the top side of the camera sensor is aligned with the
42 * right edge of the screen in natural orientation, the value should be
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -070043 * 90. If the top side of a front-facing camera sensor is aligned with the
44 * right of the screen, the value should be 270.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080045 */
46 int orientation;
47};
48
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049class ICameraService;
50class ICamera;
51class Surface;
52class Mutex;
53class String8;
54
Dave Sparks5e271152009-06-23 17:30:11 -070055// ref-counted object for callbacks
56class CameraListener: virtual public RefBase
57{
58public:
59 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
60 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr) = 0;
Dave Sparks59c1a932009-07-08 15:56:53 -070061 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
Dave Sparks5e271152009-06-23 17:30:11 -070062};
63
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064class Camera : public BnCameraClient, public IBinder::DeathRecipient
65{
66public:
67 // construct a camera client from an existing remote
James Dong2adc2db2009-04-23 14:07:23 -070068 static sp<Camera> create(const sp<ICamera>& camera);
Chih-Chung Change25cc652010-05-06 16:36:58 +080069 static int32_t getNumberOfCameras();
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080070 static status_t getCameraInfo(int cameraId,
71 struct CameraInfo* cameraInfo);
Chih-Chung Change25cc652010-05-06 16:36:58 +080072 static sp<Camera> connect(int cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 ~Camera();
74 void init();
75
76 status_t reconnect();
77 void disconnect();
78 status_t lock();
79 status_t unlock();
80
81 status_t getStatus() { return mStatus; }
82
Jamie Gennis85cfdd02010-08-10 16:37:53 -070083 // pass the buffered Surface to the camera service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 status_t setPreviewDisplay(const sp<Surface>& surface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085
Jamie Gennisff2dc462010-12-20 11:51:31 -080086 // pass the buffered ISurfaceTexture to the camera service
87 status_t setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture);
88
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 // start preview mode, must call setPreviewDisplay first
90 status_t startPreview();
91
92 // stop preview mode
93 void stopPreview();
94
95 // get preview state
96 bool previewEnabled();
97
98 // start recording mode, must call setPreviewDisplay first
99 status_t startRecording();
100
101 // stop recording mode
102 void stopRecording();
103
104 // get recording state
105 bool recordingEnabled();
106
107 // release a recording frame
108 void releaseRecordingFrame(const sp<IMemory>& mem);
109
110 // autoFocus - status returned from callback
111 status_t autoFocus();
112
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800113 // cancel auto focus
114 status_t cancelAutoFocus();
115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 // take a picture - picture returned from callback
James Donge00cab72011-02-17 16:38:06 -0800117 status_t takePicture(int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118
119 // set preview/capture parameters - key/value pairs
120 status_t setParameters(const String8& params);
121
122 // get preview/capture parameters - key/value pairs
123 String8 getParameters() const;
124
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700125 // send command to camera driver
126 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
127
James Dong38311852010-10-18 20:42:51 -0700128 // tell camera hal to store meta data or real YUV in video buffers.
129 status_t storeMetaDataInBuffers(bool enabled);
130
Dave Sparks5e271152009-06-23 17:30:11 -0700131 void setListener(const sp<CameraListener>& listener);
132 void setPreviewCallbackFlags(int preview_callback_flag);
133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 // ICameraClient interface
Dave Sparks2a04aef2009-05-07 12:25:25 -0700135 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
Dave Sparksd6289b12009-05-07 19:27:32 -0700136 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr);
Dave Sparks59c1a932009-07-08 15:56:53 -0700137 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138
139 sp<ICamera> remote();
140
141private:
142 Camera();
Dave Sparks6f0602e2009-06-24 10:42:53 -0700143 Camera(const Camera&);
144 Camera& operator=(const Camera);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 virtual void binderDied(const wp<IBinder>& who);
146
147 class DeathNotifier: public IBinder::DeathRecipient
148 {
149 public:
150 DeathNotifier() {
151 }
152
153 virtual void binderDied(const wp<IBinder>& who);
154 };
155
156 static sp<DeathNotifier> mDeathNotifier;
157
158 // helper function to obtain camera service handle
159 static const sp<ICameraService>& getCameraService();
160
161 sp<ICamera> mCamera;
162 status_t mStatus;
163
Dave Sparks5e271152009-06-23 17:30:11 -0700164 sp<CameraListener> mListener;
165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 friend class DeathNotifier;
167
168 static Mutex mLock;
169 static sp<ICameraService> mCameraService;
170
171};
172
173}; // namespace android
174
175#endif