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> |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 21 | #include <gui/IGraphicBufferProducer.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> |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame^] | 26 | #include <camera/ICameraService.h> |
| 27 | #include <camera/ICamera.h> |
| 28 | #include <camera/CameraBase.h> |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 32 | class Surface; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 33 | class String8; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 34 | class String16; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 35 | |
| 36 | // ref-counted object for callbacks |
| 37 | class CameraListener: virtual public RefBase |
| 38 | { |
| 39 | public: |
| 40 | virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0; |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 41 | virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr, |
| 42 | camera_frame_metadata_t *metadata) = 0; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 43 | virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0; |
| 44 | }; |
| 45 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame^] | 46 | class Camera; |
| 47 | |
| 48 | template <> |
| 49 | struct CameraTraits<Camera> |
| 50 | { |
| 51 | typedef CameraListener TCamListener; |
| 52 | typedef ICamera TCamUser; |
| 53 | typedef ICameraClient TCamCallbacks; |
| 54 | }; |
| 55 | |
| 56 | class Camera : |
| 57 | public CameraBase<Camera>, |
| 58 | public BnCameraClient |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 59 | { |
| 60 | public: |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 61 | enum { |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame^] | 62 | USE_CALLING_UID = ICameraService::USE_CALLING_UID |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 63 | }; |
| 64 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 65 | // construct a camera client from an existing remote |
| 66 | static sp<Camera> create(const sp<ICamera>& camera); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 67 | static sp<Camera> connect(int cameraId, |
| 68 | const String16& clientPackageName, |
| 69 | int clientUid); |
| 70 | |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 71 | virtual ~Camera(); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 72 | |
| 73 | status_t reconnect(); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 74 | status_t lock(); |
| 75 | status_t unlock(); |
| 76 | |
Jamie Gennis | 4b79168 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 77 | // pass the buffered Surface to the camera service |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 78 | status_t setPreviewDisplay(const sp<Surface>& surface); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 79 | |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 80 | // pass the buffered IGraphicBufferProducer to the camera service |
| 81 | status_t setPreviewTexture(const sp<IGraphicBufferProducer>& bufferProducer); |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 82 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 83 | // start preview mode, must call setPreviewDisplay first |
| 84 | status_t startPreview(); |
| 85 | |
| 86 | // stop preview mode |
| 87 | void stopPreview(); |
| 88 | |
| 89 | // get preview state |
| 90 | bool previewEnabled(); |
| 91 | |
| 92 | // start recording mode, must call setPreviewDisplay first |
| 93 | status_t startRecording(); |
| 94 | |
| 95 | // stop recording mode |
| 96 | void stopRecording(); |
| 97 | |
| 98 | // get recording state |
| 99 | bool recordingEnabled(); |
| 100 | |
| 101 | // release a recording frame |
| 102 | void releaseRecordingFrame(const sp<IMemory>& mem); |
| 103 | |
| 104 | // autoFocus - status returned from callback |
| 105 | status_t autoFocus(); |
| 106 | |
| 107 | // cancel auto focus |
| 108 | status_t cancelAutoFocus(); |
| 109 | |
| 110 | // take a picture - picture returned from callback |
James Dong | e468ac5 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 111 | status_t takePicture(int msgType); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 112 | |
| 113 | // set preview/capture parameters - key/value pairs |
| 114 | status_t setParameters(const String8& params); |
| 115 | |
| 116 | // get preview/capture parameters - key/value pairs |
| 117 | String8 getParameters() const; |
| 118 | |
| 119 | // send command to camera driver |
| 120 | status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); |
| 121 | |
James Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 122 | // tell camera hal to store meta data or real YUV in video buffers. |
| 123 | status_t storeMetaDataInBuffers(bool enabled); |
| 124 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 125 | void setListener(const sp<CameraListener>& listener); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 126 | void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 127 | void setPreviewCallbackFlags(int preview_callback_flag); |
| 128 | |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 129 | sp<ICameraRecordingProxy> getRecordingProxy(); |
| 130 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 131 | // ICameraClient interface |
| 132 | virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2); |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 133 | virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, |
| 134 | camera_frame_metadata_t *metadata); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 135 | virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr); |
| 136 | |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 137 | class RecordingProxy : public BnCameraRecordingProxy |
| 138 | { |
| 139 | public: |
| 140 | RecordingProxy(const sp<Camera>& camera); |
| 141 | |
| 142 | // ICameraRecordingProxy interface |
| 143 | virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener); |
| 144 | virtual void stopRecording(); |
| 145 | virtual void releaseRecordingFrame(const sp<IMemory>& mem); |
| 146 | |
| 147 | private: |
| 148 | sp<Camera> mCamera; |
| 149 | }; |
| 150 | |
Igor Murashkin | 1d88023 | 2013-02-20 16:50:13 -0800 | [diff] [blame] | 151 | protected: |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame^] | 152 | Camera(int cameraId); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 153 | Camera(const Camera&); |
| 154 | Camera& operator=(const Camera); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 155 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame^] | 156 | sp<ICameraRecordingProxyListener> mRecordingProxyListener; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 157 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame^] | 158 | friend class CameraBase; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | }; // namespace android |
| 162 | |
| 163 | #endif |