Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 3 | * |
| 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 Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 21 | #include <gui/ISurfaceTexture.h> |
Iliyan Malchev | 9e62652 | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 22 | #include <system/camera.h> |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame^] | 23 | #include <camera/ICameraClient.h> |
| 24 | #include <camera/ICameraRecordingProxy.h> |
| 25 | #include <camera/ICameraRecordingProxyListener.h> |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 29 | struct CameraInfo { |
Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 30 | /** |
Iliyan Malchev | 9e62652 | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 31 | * The direction that the camera faces to. It should be CAMERA_FACING_BACK |
| 32 | * or CAMERA_FACING_FRONT. |
Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 33 | */ |
| 34 | int facing; |
| 35 | |
| 36 | /** |
| 37 | * The orientation of the camera image. The value is the angle that the |
Iliyan Malchev | 9e62652 | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 38 | * 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 Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 40 | * |
Wu-cheng Li | c2c8868 | 2010-11-19 15:56:16 +0800 | [diff] [blame] | 41 | * 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 Malchev | 9e62652 | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 45 | * 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 Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 47 | */ |
| 48 | int orientation; |
| 49 | }; |
| 50 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 51 | class ICameraService; |
| 52 | class ICamera; |
| 53 | class Surface; |
| 54 | class Mutex; |
| 55 | class String8; |
| 56 | |
| 57 | // ref-counted object for callbacks |
| 58 | class CameraListener: virtual public RefBase |
| 59 | { |
| 60 | public: |
| 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 | |
| 66 | class Camera : public BnCameraClient, public IBinder::DeathRecipient |
| 67 | { |
| 68 | public: |
| 69 | // construct a camera client from an existing remote |
| 70 | static sp<Camera> create(const sp<ICamera>& camera); |
Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 71 | static int32_t getNumberOfCameras(); |
Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 72 | static status_t getCameraInfo(int cameraId, |
| 73 | struct CameraInfo* cameraInfo); |
Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 74 | static sp<Camera> connect(int cameraId); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame^] | 75 | virtual ~Camera(); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 76 | 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 Gennis | 4b79168 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 85 | // pass the buffered Surface to the camera service |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 86 | status_t setPreviewDisplay(const sp<Surface>& surface); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 87 | |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 88 | // pass the buffered ISurfaceTexture to the camera service |
| 89 | status_t setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture); |
| 90 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 91 | // 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 Dong | e468ac5 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 119 | status_t takePicture(int msgType); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 120 | |
| 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 Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 130 | // tell camera hal to store meta data or real YUV in video buffers. |
| 131 | status_t storeMetaDataInBuffers(bool enabled); |
| 132 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 133 | void setListener(const sp<CameraListener>& listener); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame^] | 134 | void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 135 | void setPreviewCallbackFlags(int preview_callback_flag); |
| 136 | |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame^] | 137 | sp<ICameraRecordingProxy> getRecordingProxy(); |
| 138 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 139 | // 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 Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame^] | 146 | 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 Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 160 | private: |
| 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 Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame^] | 184 | sp<ICameraRecordingProxyListener> mRecordingProxyListener; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 185 | |
| 186 | friend class DeathNotifier; |
| 187 | |
| 188 | static Mutex mLock; |
| 189 | static sp<ICameraService> mCameraService; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | }; // namespace android |
| 193 | |
| 194 | #endif |