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