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