Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #define LOG_TAG "ICamera" |
| 20 | #include <utils/Log.h> |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <binder/Parcel.h> |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 24 | #include <camera/CameraUtils.h> |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 25 | #include <android/hardware/ICamera.h> |
| 26 | #include <android/hardware/ICameraClient.h> |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 27 | #include <gui/IGraphicBufferProducer.h> |
Mathias Agopian | df712ea | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 28 | #include <gui/Surface.h> |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 29 | #include <media/hardware/HardwareAPI.h> |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 32 | namespace hardware { |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 33 | |
| 34 | enum { |
| 35 | DISCONNECT = IBinder::FIRST_CALL_TRANSACTION, |
Eino-Ville Talvala | 1ce7c34 | 2013-08-21 13:57:21 -0700 | [diff] [blame] | 36 | SET_PREVIEW_TARGET, |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 37 | SET_PREVIEW_CALLBACK_FLAG, |
Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 38 | SET_PREVIEW_CALLBACK_TARGET, |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 39 | START_PREVIEW, |
| 40 | STOP_PREVIEW, |
| 41 | AUTO_FOCUS, |
| 42 | CANCEL_AUTO_FOCUS, |
| 43 | TAKE_PICTURE, |
| 44 | SET_PARAMETERS, |
| 45 | GET_PARAMETERS, |
| 46 | SEND_COMMAND, |
| 47 | CONNECT, |
| 48 | LOCK, |
| 49 | UNLOCK, |
| 50 | PREVIEW_ENABLED, |
| 51 | START_RECORDING, |
| 52 | STOP_RECORDING, |
| 53 | RECORDING_ENABLED, |
| 54 | RELEASE_RECORDING_FRAME, |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 55 | SET_VIDEO_BUFFER_MODE, |
| 56 | SET_VIDEO_BUFFER_TARGET, |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 57 | RELEASE_RECORDING_FRAME_HANDLE, |
Yin-Chia Yeh | b5df547 | 2017-03-20 19:32:19 -0700 | [diff] [blame] | 58 | RELEASE_RECORDING_FRAME_HANDLE_BATCH, |
Yin-Chia Yeh | dba0323 | 2019-08-19 15:54:28 -0700 | [diff] [blame] | 59 | SET_AUDIO_RESTRICTION, |
Yin-Chia Yeh | cfab4e1 | 2019-09-09 13:08:28 -0700 | [diff] [blame] | 60 | GET_GLOBAL_AUDIO_RESTRICTION, |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | class BpCamera: public BpInterface<ICamera> |
| 64 | { |
| 65 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 66 | explicit BpCamera(const sp<IBinder>& impl) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 67 | : BpInterface<ICamera>(impl) |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | // disconnect from camera service |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 72 | binder::Status disconnect() |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 73 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 74 | ALOGV("disconnect"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 75 | Parcel data, reply; |
| 76 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 77 | remote()->transact(DISCONNECT, data, &reply); |
Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 78 | reply.readExceptionCode(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 79 | return binder::Status::ok(); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 82 | // pass the buffered IGraphicBufferProducer to the camera service |
Eino-Ville Talvala | 1ce7c34 | 2013-08-21 13:57:21 -0700 | [diff] [blame] | 83 | status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer) |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 84 | { |
Eino-Ville Talvala | 1ce7c34 | 2013-08-21 13:57:21 -0700 | [diff] [blame] | 85 | ALOGV("setPreviewTarget"); |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 86 | Parcel data, reply; |
| 87 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 88 | sp<IBinder> b(IInterface::asBinder(bufferProducer)); |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 89 | data.writeStrongBinder(b); |
Eino-Ville Talvala | 1ce7c34 | 2013-08-21 13:57:21 -0700 | [diff] [blame] | 90 | remote()->transact(SET_PREVIEW_TARGET, data, &reply); |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 91 | return reply.readInt32(); |
| 92 | } |
| 93 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 94 | // set the preview callback flag to affect how the received frames from |
| 95 | // preview are handled. See Camera.h for details. |
| 96 | void setPreviewCallbackFlag(int flag) |
| 97 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 98 | ALOGV("setPreviewCallbackFlag(%d)", flag); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 99 | Parcel data, reply; |
| 100 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 101 | data.writeInt32(flag); |
| 102 | remote()->transact(SET_PREVIEW_CALLBACK_FLAG, data, &reply); |
| 103 | } |
| 104 | |
Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 105 | status_t setPreviewCallbackTarget( |
| 106 | const sp<IGraphicBufferProducer>& callbackProducer) |
| 107 | { |
| 108 | ALOGV("setPreviewCallbackTarget"); |
| 109 | Parcel data, reply; |
| 110 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 111 | sp<IBinder> b(IInterface::asBinder(callbackProducer)); |
Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 112 | data.writeStrongBinder(b); |
| 113 | remote()->transact(SET_PREVIEW_CALLBACK_TARGET, data, &reply); |
| 114 | return reply.readInt32(); |
| 115 | } |
| 116 | |
Eino-Ville Talvala | 1ce7c34 | 2013-08-21 13:57:21 -0700 | [diff] [blame] | 117 | // start preview mode, must call setPreviewTarget first |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 118 | status_t startPreview() |
| 119 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 120 | ALOGV("startPreview"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 121 | Parcel data, reply; |
| 122 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 123 | remote()->transact(START_PREVIEW, data, &reply); |
| 124 | return reply.readInt32(); |
| 125 | } |
| 126 | |
Eino-Ville Talvala | 1ce7c34 | 2013-08-21 13:57:21 -0700 | [diff] [blame] | 127 | // start recording mode, must call setPreviewTarget first |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 128 | status_t startRecording() |
| 129 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 130 | ALOGV("startRecording"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 131 | Parcel data, reply; |
| 132 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 133 | remote()->transact(START_RECORDING, data, &reply); |
| 134 | return reply.readInt32(); |
| 135 | } |
| 136 | |
| 137 | // stop preview mode |
| 138 | void stopPreview() |
| 139 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 140 | ALOGV("stopPreview"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 141 | Parcel data, reply; |
| 142 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 143 | remote()->transact(STOP_PREVIEW, data, &reply); |
| 144 | } |
| 145 | |
| 146 | // stop recording mode |
| 147 | void stopRecording() |
| 148 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 149 | ALOGV("stopRecording"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 150 | Parcel data, reply; |
| 151 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 152 | remote()->transact(STOP_RECORDING, data, &reply); |
| 153 | } |
| 154 | |
| 155 | void releaseRecordingFrame(const sp<IMemory>& mem) |
| 156 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 157 | ALOGV("releaseRecordingFrame"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 158 | Parcel data, reply; |
| 159 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 160 | data.writeStrongBinder(IInterface::asBinder(mem)); |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 161 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 162 | remote()->transact(RELEASE_RECORDING_FRAME, data, &reply); |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 163 | } |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 164 | |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 165 | void releaseRecordingFrameHandle(native_handle_t *handle) { |
| 166 | ALOGV("releaseRecordingFrameHandle"); |
| 167 | Parcel data, reply; |
| 168 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 169 | data.writeNativeHandle(handle); |
| 170 | |
| 171 | remote()->transact(RELEASE_RECORDING_FRAME_HANDLE, data, &reply); |
| 172 | |
| 173 | // Close the native handle because camera received a dup copy. |
| 174 | native_handle_close(handle); |
| 175 | native_handle_delete(handle); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Yin-Chia Yeh | b5df547 | 2017-03-20 19:32:19 -0700 | [diff] [blame] | 178 | void releaseRecordingFrameHandleBatch(const std::vector<native_handle_t*>& handles) { |
| 179 | ALOGV("releaseRecordingFrameHandleBatch"); |
| 180 | Parcel data, reply; |
| 181 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 182 | uint32_t n = handles.size(); |
| 183 | data.writeUint32(n); |
| 184 | for (auto& handle : handles) { |
| 185 | data.writeNativeHandle(handle); |
| 186 | } |
| 187 | remote()->transact(RELEASE_RECORDING_FRAME_HANDLE_BATCH, data, &reply); |
| 188 | |
| 189 | // Close the native handle because camera received a dup copy. |
| 190 | for (auto& handle : handles) { |
| 191 | native_handle_close(handle); |
| 192 | native_handle_delete(handle); |
| 193 | } |
| 194 | } |
| 195 | |
Yin-Chia Yeh | cfab4e1 | 2019-09-09 13:08:28 -0700 | [diff] [blame] | 196 | status_t setAudioRestriction(int32_t mode) { |
Yin-Chia Yeh | dba0323 | 2019-08-19 15:54:28 -0700 | [diff] [blame] | 197 | Parcel data, reply; |
| 198 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 199 | data.writeInt32(mode); |
| 200 | remote()->transact(SET_AUDIO_RESTRICTION, data, &reply); |
| 201 | return reply.readInt32(); |
| 202 | } |
| 203 | |
Yin-Chia Yeh | cfab4e1 | 2019-09-09 13:08:28 -0700 | [diff] [blame] | 204 | int32_t getGlobalAudioRestriction() { |
| 205 | Parcel data, reply; |
| 206 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 207 | remote()->transact(GET_GLOBAL_AUDIO_RESTRICTION, data, &reply); |
| 208 | return reply.readInt32(); |
| 209 | } |
| 210 | |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 211 | status_t setVideoBufferMode(int32_t videoBufferMode) |
James Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 212 | { |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 213 | ALOGV("setVideoBufferMode: %d", videoBufferMode); |
James Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 214 | Parcel data, reply; |
| 215 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 216 | data.writeInt32(videoBufferMode); |
| 217 | remote()->transact(SET_VIDEO_BUFFER_MODE, data, &reply); |
James Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 218 | return reply.readInt32(); |
| 219 | } |
| 220 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 221 | // check preview state |
| 222 | bool previewEnabled() |
| 223 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 224 | ALOGV("previewEnabled"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 225 | Parcel data, reply; |
| 226 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 227 | remote()->transact(PREVIEW_ENABLED, data, &reply); |
| 228 | return reply.readInt32(); |
| 229 | } |
| 230 | |
| 231 | // check recording state |
| 232 | bool recordingEnabled() |
| 233 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 234 | ALOGV("recordingEnabled"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 235 | Parcel data, reply; |
| 236 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 237 | remote()->transact(RECORDING_ENABLED, data, &reply); |
| 238 | return reply.readInt32(); |
| 239 | } |
| 240 | |
| 241 | // auto focus |
| 242 | status_t autoFocus() |
| 243 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 244 | ALOGV("autoFocus"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 245 | Parcel data, reply; |
| 246 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 247 | remote()->transact(AUTO_FOCUS, data, &reply); |
| 248 | status_t ret = reply.readInt32(); |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | // cancel focus |
| 253 | status_t cancelAutoFocus() |
| 254 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 255 | ALOGV("cancelAutoFocus"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 256 | Parcel data, reply; |
| 257 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 258 | remote()->transact(CANCEL_AUTO_FOCUS, data, &reply); |
| 259 | status_t ret = reply.readInt32(); |
| 260 | return ret; |
| 261 | } |
| 262 | |
| 263 | // take a picture - returns an IMemory (ref-counted mmap) |
James Dong | e468ac5 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 264 | status_t takePicture(int msgType) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 265 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 266 | ALOGV("takePicture: 0x%x", msgType); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 267 | Parcel data, reply; |
| 268 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
James Dong | e468ac5 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 269 | data.writeInt32(msgType); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 270 | remote()->transact(TAKE_PICTURE, data, &reply); |
| 271 | status_t ret = reply.readInt32(); |
| 272 | return ret; |
| 273 | } |
| 274 | |
| 275 | // set preview/capture parameters - key/value pairs |
| 276 | status_t setParameters(const String8& params) |
| 277 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 278 | ALOGV("setParameters"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 279 | Parcel data, reply; |
| 280 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 281 | data.writeString8(params); |
| 282 | remote()->transact(SET_PARAMETERS, data, &reply); |
| 283 | return reply.readInt32(); |
| 284 | } |
| 285 | |
| 286 | // get preview/capture parameters - key/value pairs |
| 287 | String8 getParameters() const |
| 288 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 289 | ALOGV("getParameters"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 290 | Parcel data, reply; |
| 291 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 292 | remote()->transact(GET_PARAMETERS, data, &reply); |
| 293 | return reply.readString8(); |
| 294 | } |
| 295 | virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) |
| 296 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 297 | ALOGV("sendCommand"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 298 | Parcel data, reply; |
| 299 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 300 | data.writeInt32(cmd); |
| 301 | data.writeInt32(arg1); |
| 302 | data.writeInt32(arg2); |
| 303 | remote()->transact(SEND_COMMAND, data, &reply); |
| 304 | return reply.readInt32(); |
| 305 | } |
| 306 | virtual status_t connect(const sp<ICameraClient>& cameraClient) |
| 307 | { |
| 308 | Parcel data, reply; |
| 309 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 310 | data.writeStrongBinder(IInterface::asBinder(cameraClient)); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 311 | remote()->transact(CONNECT, data, &reply); |
| 312 | return reply.readInt32(); |
| 313 | } |
| 314 | virtual status_t lock() |
| 315 | { |
| 316 | Parcel data, reply; |
| 317 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 318 | remote()->transact(LOCK, data, &reply); |
| 319 | return reply.readInt32(); |
| 320 | } |
| 321 | virtual status_t unlock() |
| 322 | { |
| 323 | Parcel data, reply; |
| 324 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 325 | remote()->transact(UNLOCK, data, &reply); |
| 326 | return reply.readInt32(); |
| 327 | } |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 328 | |
| 329 | status_t setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer) |
| 330 | { |
| 331 | ALOGV("setVideoTarget"); |
| 332 | Parcel data, reply; |
| 333 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 334 | sp<IBinder> b(IInterface::asBinder(bufferProducer)); |
| 335 | data.writeStrongBinder(b); |
| 336 | remote()->transact(SET_VIDEO_BUFFER_TARGET, data, &reply); |
| 337 | return reply.readInt32(); |
| 338 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | IMPLEMENT_META_INTERFACE(Camera, "android.hardware.ICamera"); |
| 342 | |
| 343 | // ---------------------------------------------------------------------- |
| 344 | |
| 345 | status_t BnCamera::onTransact( |
| 346 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 347 | { |
| 348 | switch(code) { |
| 349 | case DISCONNECT: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 350 | ALOGV("DISCONNECT"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 351 | CHECK_INTERFACE(ICamera, data, reply); |
| 352 | disconnect(); |
Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 353 | reply->writeNoException(); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 354 | return NO_ERROR; |
| 355 | } break; |
Eino-Ville Talvala | 1ce7c34 | 2013-08-21 13:57:21 -0700 | [diff] [blame] | 356 | case SET_PREVIEW_TARGET: { |
| 357 | ALOGV("SET_PREVIEW_TARGET"); |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 358 | CHECK_INTERFACE(ICamera, data, reply); |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 359 | sp<IGraphicBufferProducer> st = |
| 360 | interface_cast<IGraphicBufferProducer>(data.readStrongBinder()); |
Eino-Ville Talvala | 1ce7c34 | 2013-08-21 13:57:21 -0700 | [diff] [blame] | 361 | reply->writeInt32(setPreviewTarget(st)); |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 362 | return NO_ERROR; |
| 363 | } break; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 364 | case SET_PREVIEW_CALLBACK_FLAG: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 365 | ALOGV("SET_PREVIEW_CALLBACK_TYPE"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 366 | CHECK_INTERFACE(ICamera, data, reply); |
| 367 | int callback_flag = data.readInt32(); |
| 368 | setPreviewCallbackFlag(callback_flag); |
| 369 | return NO_ERROR; |
| 370 | } break; |
Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 371 | case SET_PREVIEW_CALLBACK_TARGET: { |
| 372 | ALOGV("SET_PREVIEW_CALLBACK_TARGET"); |
| 373 | CHECK_INTERFACE(ICamera, data, reply); |
| 374 | sp<IGraphicBufferProducer> cp = |
| 375 | interface_cast<IGraphicBufferProducer>(data.readStrongBinder()); |
| 376 | reply->writeInt32(setPreviewCallbackTarget(cp)); |
| 377 | return NO_ERROR; |
| 378 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 379 | case START_PREVIEW: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 380 | ALOGV("START_PREVIEW"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 381 | CHECK_INTERFACE(ICamera, data, reply); |
| 382 | reply->writeInt32(startPreview()); |
| 383 | return NO_ERROR; |
| 384 | } break; |
| 385 | case START_RECORDING: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 386 | ALOGV("START_RECORDING"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 387 | CHECK_INTERFACE(ICamera, data, reply); |
| 388 | reply->writeInt32(startRecording()); |
| 389 | return NO_ERROR; |
| 390 | } break; |
| 391 | case STOP_PREVIEW: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 392 | ALOGV("STOP_PREVIEW"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 393 | CHECK_INTERFACE(ICamera, data, reply); |
| 394 | stopPreview(); |
| 395 | return NO_ERROR; |
| 396 | } break; |
| 397 | case STOP_RECORDING: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 398 | ALOGV("STOP_RECORDING"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 399 | CHECK_INTERFACE(ICamera, data, reply); |
| 400 | stopRecording(); |
| 401 | return NO_ERROR; |
| 402 | } break; |
| 403 | case RELEASE_RECORDING_FRAME: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 404 | ALOGV("RELEASE_RECORDING_FRAME"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 405 | CHECK_INTERFACE(ICamera, data, reply); |
| 406 | sp<IMemory> mem = interface_cast<IMemory>(data.readStrongBinder()); |
| 407 | releaseRecordingFrame(mem); |
| 408 | return NO_ERROR; |
| 409 | } break; |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 410 | case RELEASE_RECORDING_FRAME_HANDLE: { |
| 411 | ALOGV("RELEASE_RECORDING_FRAME_HANDLE"); |
| 412 | CHECK_INTERFACE(ICamera, data, reply); |
| 413 | // releaseRecordingFrameHandle will be responsble to close the native handle. |
| 414 | releaseRecordingFrameHandle(data.readNativeHandle()); |
| 415 | return NO_ERROR; |
| 416 | } break; |
Yin-Chia Yeh | b5df547 | 2017-03-20 19:32:19 -0700 | [diff] [blame] | 417 | case RELEASE_RECORDING_FRAME_HANDLE_BATCH: { |
| 418 | ALOGV("RELEASE_RECORDING_FRAME_HANDLE_BATCH"); |
| 419 | CHECK_INTERFACE(ICamera, data, reply); |
| 420 | // releaseRecordingFrameHandle will be responsble to close the native handle. |
| 421 | uint32_t n = data.readUint32(); |
| 422 | std::vector<native_handle_t*> handles; |
| 423 | handles.reserve(n); |
| 424 | for (uint32_t i = 0; i < n; i++) { |
| 425 | handles.push_back(data.readNativeHandle()); |
| 426 | } |
| 427 | releaseRecordingFrameHandleBatch(handles); |
| 428 | return NO_ERROR; |
| 429 | } break; |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 430 | case SET_VIDEO_BUFFER_MODE: { |
| 431 | ALOGV("SET_VIDEO_BUFFER_MODE"); |
James Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 432 | CHECK_INTERFACE(ICamera, data, reply); |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 433 | int32_t mode = data.readInt32(); |
| 434 | reply->writeInt32(setVideoBufferMode(mode)); |
James Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 435 | return NO_ERROR; |
| 436 | } break; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 437 | case PREVIEW_ENABLED: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 438 | ALOGV("PREVIEW_ENABLED"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 439 | CHECK_INTERFACE(ICamera, data, reply); |
| 440 | reply->writeInt32(previewEnabled()); |
| 441 | return NO_ERROR; |
| 442 | } break; |
| 443 | case RECORDING_ENABLED: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 444 | ALOGV("RECORDING_ENABLED"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 445 | CHECK_INTERFACE(ICamera, data, reply); |
| 446 | reply->writeInt32(recordingEnabled()); |
| 447 | return NO_ERROR; |
| 448 | } break; |
| 449 | case AUTO_FOCUS: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 450 | ALOGV("AUTO_FOCUS"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 451 | CHECK_INTERFACE(ICamera, data, reply); |
| 452 | reply->writeInt32(autoFocus()); |
| 453 | return NO_ERROR; |
| 454 | } break; |
| 455 | case CANCEL_AUTO_FOCUS: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 456 | ALOGV("CANCEL_AUTO_FOCUS"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 457 | CHECK_INTERFACE(ICamera, data, reply); |
| 458 | reply->writeInt32(cancelAutoFocus()); |
| 459 | return NO_ERROR; |
| 460 | } break; |
| 461 | case TAKE_PICTURE: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 462 | ALOGV("TAKE_PICTURE"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 463 | CHECK_INTERFACE(ICamera, data, reply); |
James Dong | e468ac5 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 464 | int msgType = data.readInt32(); |
| 465 | reply->writeInt32(takePicture(msgType)); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 466 | return NO_ERROR; |
| 467 | } break; |
| 468 | case SET_PARAMETERS: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 469 | ALOGV("SET_PARAMETERS"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 470 | CHECK_INTERFACE(ICamera, data, reply); |
| 471 | String8 params(data.readString8()); |
| 472 | reply->writeInt32(setParameters(params)); |
| 473 | return NO_ERROR; |
| 474 | } break; |
| 475 | case GET_PARAMETERS: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 476 | ALOGV("GET_PARAMETERS"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 477 | CHECK_INTERFACE(ICamera, data, reply); |
| 478 | reply->writeString8(getParameters()); |
| 479 | return NO_ERROR; |
| 480 | } break; |
| 481 | case SEND_COMMAND: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 482 | ALOGV("SEND_COMMAND"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 483 | CHECK_INTERFACE(ICamera, data, reply); |
| 484 | int command = data.readInt32(); |
| 485 | int arg1 = data.readInt32(); |
| 486 | int arg2 = data.readInt32(); |
| 487 | reply->writeInt32(sendCommand(command, arg1, arg2)); |
| 488 | return NO_ERROR; |
| 489 | } break; |
| 490 | case CONNECT: { |
| 491 | CHECK_INTERFACE(ICamera, data, reply); |
| 492 | sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder()); |
| 493 | reply->writeInt32(connect(cameraClient)); |
| 494 | return NO_ERROR; |
| 495 | } break; |
| 496 | case LOCK: { |
| 497 | CHECK_INTERFACE(ICamera, data, reply); |
| 498 | reply->writeInt32(lock()); |
| 499 | return NO_ERROR; |
| 500 | } break; |
| 501 | case UNLOCK: { |
| 502 | CHECK_INTERFACE(ICamera, data, reply); |
| 503 | reply->writeInt32(unlock()); |
| 504 | return NO_ERROR; |
| 505 | } break; |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 506 | case SET_VIDEO_BUFFER_TARGET: { |
| 507 | ALOGV("SET_VIDEO_BUFFER_TARGET"); |
| 508 | CHECK_INTERFACE(ICamera, data, reply); |
| 509 | sp<IGraphicBufferProducer> st = |
| 510 | interface_cast<IGraphicBufferProducer>(data.readStrongBinder()); |
| 511 | reply->writeInt32(setVideoTarget(st)); |
| 512 | return NO_ERROR; |
| 513 | } break; |
Yin-Chia Yeh | dba0323 | 2019-08-19 15:54:28 -0700 | [diff] [blame] | 514 | case SET_AUDIO_RESTRICTION: { |
| 515 | CHECK_INTERFACE(ICamera, data, reply); |
| 516 | int32_t mode = data.readInt32(); |
| 517 | reply->writeInt32(setAudioRestriction(mode)); |
| 518 | return NO_ERROR; |
| 519 | } break; |
Yin-Chia Yeh | cfab4e1 | 2019-09-09 13:08:28 -0700 | [diff] [blame] | 520 | case GET_GLOBAL_AUDIO_RESTRICTION: { |
| 521 | CHECK_INTERFACE(ICamera, data, reply); |
| 522 | reply->writeInt32(getGlobalAudioRestriction()); |
| 523 | return NO_ERROR; |
| 524 | } break; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 525 | default: |
| 526 | return BBinder::onTransact(code, data, reply, flags); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | // ---------------------------------------------------------------------------- |
| 531 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 532 | } // namespace hardware |
| 533 | } // namespace android |