The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -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 | |
Dave Sparks | 59c1a93 | 2009-07-08 15:56:53 -0700 | [diff] [blame] | 20 | #include <utils/Timers.h> |
Jamie Gennis | ff2dc46 | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 21 | #include <gui/ISurfaceTexture.h> |
Iliyan Malchev | 9c7ac0d | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 22 | #include <system/camera.h> |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 23 | #include <camera/ICameraClient.h> |
| 24 | #include <camera/ICameraRecordingProxy.h> |
| 25 | #include <camera/ICameraRecordingProxyListener.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 29 | struct CameraInfo { |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 30 | /** |
Iliyan Malchev | 9c7ac0d | 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 | b8bb78f | 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 | 9c7ac0d | 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 | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 40 | * |
Wu-cheng Li | 99a3f3e | 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 | 9c7ac0d | 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 | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 47 | */ |
| 48 | int orientation; |
| 49 | }; |
| 50 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | class ICameraService; |
| 52 | class ICamera; |
| 53 | class Surface; |
| 54 | class Mutex; |
| 55 | class String8; |
| 56 | |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 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; |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 62 | virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr, |
| 63 | camera_frame_metadata_t *metadata) = 0; |
Dave Sparks | 59c1a93 | 2009-07-08 15:56:53 -0700 | [diff] [blame] | 64 | virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0; |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | class Camera : public BnCameraClient, public IBinder::DeathRecipient |
| 68 | { |
| 69 | public: |
| 70 | // construct a camera client from an existing remote |
James Dong | 2adc2db | 2009-04-23 14:07:23 -0700 | [diff] [blame] | 71 | static sp<Camera> create(const sp<ICamera>& camera); |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 72 | static int32_t getNumberOfCameras(); |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 73 | static status_t getCameraInfo(int cameraId, |
| 74 | struct CameraInfo* cameraInfo); |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 75 | static sp<Camera> connect(int cameraId); |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 76 | virtual ~Camera(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | void init(); |
| 78 | |
| 79 | status_t reconnect(); |
| 80 | void disconnect(); |
| 81 | status_t lock(); |
| 82 | status_t unlock(); |
| 83 | |
| 84 | status_t getStatus() { return mStatus; } |
| 85 | |
Jamie Gennis | 85cfdd0 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 86 | // pass the buffered Surface to the camera service |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | status_t setPreviewDisplay(const sp<Surface>& surface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | |
Jamie Gennis | ff2dc46 | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 89 | // pass the buffered ISurfaceTexture to the camera service |
| 90 | status_t setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture); |
| 91 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | // start preview mode, must call setPreviewDisplay first |
| 93 | status_t startPreview(); |
| 94 | |
| 95 | // stop preview mode |
| 96 | void stopPreview(); |
| 97 | |
| 98 | // get preview state |
| 99 | bool previewEnabled(); |
| 100 | |
| 101 | // start recording mode, must call setPreviewDisplay first |
| 102 | status_t startRecording(); |
| 103 | |
| 104 | // stop recording mode |
| 105 | void stopRecording(); |
| 106 | |
| 107 | // get recording state |
| 108 | bool recordingEnabled(); |
| 109 | |
| 110 | // release a recording frame |
| 111 | void releaseRecordingFrame(const sp<IMemory>& mem); |
| 112 | |
| 113 | // autoFocus - status returned from callback |
| 114 | status_t autoFocus(); |
| 115 | |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 116 | // cancel auto focus |
| 117 | status_t cancelAutoFocus(); |
| 118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | // take a picture - picture returned from callback |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 120 | status_t takePicture(int msgType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | |
| 122 | // set preview/capture parameters - key/value pairs |
| 123 | status_t setParameters(const String8& params); |
| 124 | |
| 125 | // get preview/capture parameters - key/value pairs |
| 126 | String8 getParameters() const; |
| 127 | |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 128 | // send command to camera driver |
| 129 | status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); |
| 130 | |
James Dong | 3831185 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 131 | // tell camera hal to store meta data or real YUV in video buffers. |
| 132 | status_t storeMetaDataInBuffers(bool enabled); |
| 133 | |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 134 | void setListener(const sp<CameraListener>& listener); |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 135 | void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 136 | void setPreviewCallbackFlags(int preview_callback_flag); |
| 137 | |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 138 | sp<ICameraRecordingProxy> getRecordingProxy(); |
| 139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | // ICameraClient interface |
Dave Sparks | 2a04aef | 2009-05-07 12:25:25 -0700 | [diff] [blame] | 141 | virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2); |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 142 | virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, |
| 143 | camera_frame_metadata_t *metadata); |
Dave Sparks | 59c1a93 | 2009-07-08 15:56:53 -0700 | [diff] [blame] | 144 | virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | |
| 146 | sp<ICamera> remote(); |
| 147 | |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 148 | class RecordingProxy : public BnCameraRecordingProxy |
| 149 | { |
| 150 | public: |
| 151 | RecordingProxy(const sp<Camera>& camera); |
| 152 | |
| 153 | // ICameraRecordingProxy interface |
| 154 | virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener); |
| 155 | virtual void stopRecording(); |
| 156 | virtual void releaseRecordingFrame(const sp<IMemory>& mem); |
| 157 | |
| 158 | private: |
| 159 | sp<Camera> mCamera; |
| 160 | }; |
| 161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | private: |
| 163 | Camera(); |
Dave Sparks | 6f0602e | 2009-06-24 10:42:53 -0700 | [diff] [blame] | 164 | Camera(const Camera&); |
| 165 | Camera& operator=(const Camera); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | virtual void binderDied(const wp<IBinder>& who); |
| 167 | |
| 168 | class DeathNotifier: public IBinder::DeathRecipient |
| 169 | { |
| 170 | public: |
| 171 | DeathNotifier() { |
| 172 | } |
| 173 | |
| 174 | virtual void binderDied(const wp<IBinder>& who); |
| 175 | }; |
| 176 | |
| 177 | static sp<DeathNotifier> mDeathNotifier; |
| 178 | |
| 179 | // helper function to obtain camera service handle |
| 180 | static const sp<ICameraService>& getCameraService(); |
| 181 | |
| 182 | sp<ICamera> mCamera; |
| 183 | status_t mStatus; |
| 184 | |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 185 | sp<CameraListener> mListener; |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 186 | sp<ICameraRecordingProxyListener> mRecordingProxyListener; |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | friend class DeathNotifier; |
| 189 | |
| 190 | static Mutex mLock; |
| 191 | static sp<ICameraService> mCameraService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | }; // namespace android |
| 195 | |
| 196 | #endif |