| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 1 | /* | 
 | 2 | ** | 
 | 3 | ** Copyright 2013, 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 "ICameraDeviceUser" | 
 | 20 | #include <utils/Log.h> | 
 | 21 | #include <stdint.h> | 
 | 22 | #include <sys/types.h> | 
 | 23 | #include <binder/Parcel.h> | 
| Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 24 | #include <camera/camera2/ICameraDeviceUser.h> | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 25 | #include <gui/IGraphicBufferProducer.h> | 
 | 26 | #include <gui/Surface.h> | 
 | 27 | #include <camera/CameraMetadata.h> | 
| Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 28 | #include <camera/camera2/CaptureRequest.h> | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 29 | #include <camera/camera2/OutputConfiguration.h> | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 30 |  | 
 | 31 | namespace android { | 
 | 32 |  | 
 | 33 | typedef Parcel::WritableBlob WritableBlob; | 
 | 34 | typedef Parcel::ReadableBlob ReadableBlob; | 
 | 35 |  | 
 | 36 | enum { | 
 | 37 |     DISCONNECT = IBinder::FIRST_CALL_TRANSACTION, | 
 | 38 |     SUBMIT_REQUEST, | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 39 |     SUBMIT_REQUEST_LIST, | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 40 |     CANCEL_REQUEST, | 
| Ruben Brunk | 2947840 | 2014-05-22 13:09:57 -0700 | [diff] [blame] | 41 |     BEGIN_CONFIGURE, | 
 | 42 |     END_CONFIGURE, | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 43 |     DELETE_STREAM, | 
 | 44 |     CREATE_STREAM, | 
| Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 45 |     CREATE_INPUT_STREAM, | 
 | 46 |     GET_INPUT_SURFACE, | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 47 |     CREATE_DEFAULT_REQUEST, | 
 | 48 |     GET_CAMERA_INFO, | 
| Zhijun He | 2ab500c | 2013-07-23 08:02:53 -0700 | [diff] [blame] | 49 |     WAIT_UNTIL_IDLE, | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 50 |     FLUSH, | 
 | 51 |     PREPARE | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 52 | }; | 
 | 53 |  | 
| Igor Murashkin | 88aef23 | 2013-08-23 17:47:06 -0700 | [diff] [blame] | 54 | namespace { | 
 | 55 |     // Read empty strings without printing a false error message. | 
 | 56 |     String16 readMaybeEmptyString16(const Parcel& parcel) { | 
 | 57 |         size_t len; | 
 | 58 |         const char16_t* str = parcel.readString16Inplace(&len); | 
 | 59 |         if (str != NULL) { | 
 | 60 |             return String16(str, len); | 
 | 61 |         } else { | 
 | 62 |             return String16(); | 
 | 63 |         } | 
 | 64 |     } | 
 | 65 | }; | 
 | 66 |  | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 67 | class BpCameraDeviceUser : public BpInterface<ICameraDeviceUser> | 
 | 68 | { | 
 | 69 | public: | 
 | 70 |     BpCameraDeviceUser(const sp<IBinder>& impl) | 
 | 71 |         : BpInterface<ICameraDeviceUser>(impl) | 
 | 72 |     { | 
 | 73 |     } | 
 | 74 |  | 
 | 75 |     // disconnect from camera service | 
 | 76 |     void disconnect() | 
 | 77 |     { | 
 | 78 |         ALOGV("disconnect"); | 
 | 79 |         Parcel data, reply; | 
 | 80 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 81 |         remote()->transact(DISCONNECT, data, &reply); | 
 | 82 |         reply.readExceptionCode(); | 
 | 83 |     } | 
 | 84 |  | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 85 |     virtual status_t submitRequest(sp<CaptureRequest> request, bool repeating, | 
 | 86 |                               int64_t *lastFrameNumber) | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 87 |     { | 
 | 88 |         Parcel data, reply; | 
 | 89 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 90 |  | 
 | 91 |         // arg0 = CaptureRequest | 
 | 92 |         if (request != 0) { | 
 | 93 |             data.writeInt32(1); | 
 | 94 |             request->writeToParcel(&data); | 
 | 95 |         } else { | 
 | 96 |             data.writeInt32(0); | 
 | 97 |         } | 
 | 98 |  | 
 | 99 |         // arg1 = streaming (bool) | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 100 |         data.writeInt32(repeating); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 101 |  | 
 | 102 |         remote()->transact(SUBMIT_REQUEST, data, &reply); | 
 | 103 |  | 
 | 104 |         reply.readExceptionCode(); | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 105 |         status_t res = reply.readInt32(); | 
 | 106 |  | 
 | 107 |         status_t resFrameNumber = BAD_VALUE; | 
 | 108 |         if (reply.readInt32() != 0) { | 
 | 109 |             if (lastFrameNumber != NULL) { | 
 | 110 |                 resFrameNumber = reply.readInt64(lastFrameNumber); | 
 | 111 |             } | 
 | 112 |         } | 
 | 113 |  | 
| John Lin | 19fa0fe | 2015-02-02 18:10:42 +0800 | [diff] [blame] | 114 | 	if ((res < NO_ERROR) || (resFrameNumber != NO_ERROR)) { | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 115 |             res = FAILED_TRANSACTION; | 
 | 116 |         } | 
 | 117 |         return res; | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 118 |     } | 
 | 119 |  | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 120 |     virtual status_t submitRequestList(List<sp<CaptureRequest> > requestList, bool repeating, | 
 | 121 |                                   int64_t *lastFrameNumber) | 
 | 122 |     { | 
 | 123 |         Parcel data, reply; | 
 | 124 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 125 |  | 
 | 126 |         data.writeInt32(requestList.size()); | 
 | 127 |  | 
 | 128 |         for (List<sp<CaptureRequest> >::iterator it = requestList.begin(); | 
 | 129 |                 it != requestList.end(); ++it) { | 
 | 130 |             sp<CaptureRequest> request = *it; | 
 | 131 |             if (request != 0) { | 
 | 132 |                 data.writeInt32(1); | 
 | 133 |                 if (request->writeToParcel(&data) != OK) { | 
 | 134 |                     return BAD_VALUE; | 
 | 135 |                 } | 
 | 136 |             } else { | 
 | 137 |                 data.writeInt32(0); | 
 | 138 |             } | 
 | 139 |         } | 
 | 140 |  | 
 | 141 |         data.writeInt32(repeating); | 
 | 142 |  | 
 | 143 |         remote()->transact(SUBMIT_REQUEST_LIST, data, &reply); | 
 | 144 |  | 
 | 145 |         reply.readExceptionCode(); | 
 | 146 |         status_t res = reply.readInt32(); | 
 | 147 |  | 
 | 148 |         status_t resFrameNumber = BAD_VALUE; | 
 | 149 |         if (reply.readInt32() != 0) { | 
 | 150 |             if (lastFrameNumber != NULL) { | 
 | 151 |                 resFrameNumber = reply.readInt64(lastFrameNumber); | 
 | 152 |             } | 
 | 153 |         } | 
| John Lin | 19fa0fe | 2015-02-02 18:10:42 +0800 | [diff] [blame] | 154 |         if ((res < NO_ERROR) || (resFrameNumber != NO_ERROR)) { | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 155 |             res = FAILED_TRANSACTION; | 
 | 156 |         } | 
 | 157 |         return res; | 
 | 158 |     } | 
 | 159 |  | 
 | 160 |     virtual status_t cancelRequest(int requestId, int64_t *lastFrameNumber) | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 161 |     { | 
 | 162 |         Parcel data, reply; | 
 | 163 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 164 |         data.writeInt32(requestId); | 
 | 165 |  | 
 | 166 |         remote()->transact(CANCEL_REQUEST, data, &reply); | 
 | 167 |  | 
 | 168 |         reply.readExceptionCode(); | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 169 |         status_t res = reply.readInt32(); | 
 | 170 |  | 
 | 171 |         status_t resFrameNumber = BAD_VALUE; | 
 | 172 |         if (reply.readInt32() != 0) { | 
 | 173 |             if (lastFrameNumber != NULL) { | 
| John Lin | 19fa0fe | 2015-02-02 18:10:42 +0800 | [diff] [blame] | 174 |                 resFrameNumber = reply.readInt64(lastFrameNumber); | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 175 |             } | 
 | 176 |         } | 
 | 177 |         if ((res != NO_ERROR) || (resFrameNumber != NO_ERROR)) { | 
 | 178 |             res = FAILED_TRANSACTION; | 
 | 179 |         } | 
 | 180 |         return res; | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 181 |     } | 
 | 182 |  | 
| Ruben Brunk | 2947840 | 2014-05-22 13:09:57 -0700 | [diff] [blame] | 183 |     virtual status_t beginConfigure() | 
 | 184 |     { | 
 | 185 |         ALOGV("beginConfigure"); | 
 | 186 |         Parcel data, reply; | 
 | 187 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 188 |         remote()->transact(BEGIN_CONFIGURE, data, &reply); | 
 | 189 |         reply.readExceptionCode(); | 
 | 190 |         return reply.readInt32(); | 
 | 191 |     } | 
 | 192 |  | 
 | 193 |     virtual status_t endConfigure() | 
 | 194 |     { | 
 | 195 |         ALOGV("endConfigure"); | 
 | 196 |         Parcel data, reply; | 
 | 197 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 198 |         remote()->transact(END_CONFIGURE, data, &reply); | 
 | 199 |         reply.readExceptionCode(); | 
 | 200 |         return reply.readInt32(); | 
 | 201 |     } | 
 | 202 |  | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 203 |     virtual status_t deleteStream(int streamId) | 
 | 204 |     { | 
 | 205 |         Parcel data, reply; | 
 | 206 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 207 |         data.writeInt32(streamId); | 
 | 208 |  | 
 | 209 |         remote()->transact(DELETE_STREAM, data, &reply); | 
 | 210 |  | 
 | 211 |         reply.readExceptionCode(); | 
 | 212 |         return reply.readInt32(); | 
 | 213 |     } | 
 | 214 |  | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 215 |     virtual status_t createStream(const OutputConfiguration& outputConfiguration) | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 216 |     { | 
 | 217 |         Parcel data, reply; | 
 | 218 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 219 |         if (outputConfiguration.getGraphicBufferProducer() != NULL) { | 
 | 220 |             data.writeInt32(1); // marker that OutputConfiguration is not null. Mimic aidl behavior | 
 | 221 |             outputConfiguration.writeToParcel(data); | 
 | 222 |         } else { | 
 | 223 |             data.writeInt32(0); | 
 | 224 |         } | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 225 |         remote()->transact(CREATE_STREAM, data, &reply); | 
 | 226 |  | 
 | 227 |         reply.readExceptionCode(); | 
 | 228 |         return reply.readInt32(); | 
 | 229 |     } | 
 | 230 |  | 
| Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 231 |     virtual status_t createInputStream(int width, int height, int format) | 
 | 232 |     { | 
 | 233 |         Parcel data, reply; | 
 | 234 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 235 |         data.writeInt32(width); | 
 | 236 |         data.writeInt32(height); | 
 | 237 |         data.writeInt32(format); | 
 | 238 |  | 
 | 239 |         remote()->transact(CREATE_INPUT_STREAM, data, &reply); | 
 | 240 |  | 
 | 241 |         reply.readExceptionCode(); | 
 | 242 |         return reply.readInt32(); | 
 | 243 |     } | 
 | 244 |  | 
 | 245 |     // get the buffer producer of the input stream | 
 | 246 |     virtual status_t getInputBufferProducer( | 
 | 247 |             sp<IGraphicBufferProducer> *producer) { | 
 | 248 |         if (producer == NULL) { | 
 | 249 |             return BAD_VALUE; | 
 | 250 |         } | 
 | 251 |  | 
 | 252 |         Parcel data, reply; | 
 | 253 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 254 |  | 
 | 255 |         remote()->transact(GET_INPUT_SURFACE, data, &reply); | 
 | 256 |  | 
 | 257 |         reply.readExceptionCode(); | 
 | 258 |         status_t result = reply.readInt32() ; | 
 | 259 |         if (result != OK) { | 
 | 260 |             return result; | 
 | 261 |         } | 
 | 262 |  | 
 | 263 |         sp<IGraphicBufferProducer> bp = NULL; | 
 | 264 |         if (reply.readInt32() != 0) { | 
 | 265 |             String16 name = readMaybeEmptyString16(reply); | 
 | 266 |             bp = interface_cast<IGraphicBufferProducer>( | 
 | 267 |                     reply.readStrongBinder()); | 
 | 268 |         } | 
 | 269 |  | 
 | 270 |         *producer = bp; | 
 | 271 |  | 
 | 272 |         return *producer == NULL ? INVALID_OPERATION : OK; | 
 | 273 |     } | 
 | 274 |  | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 275 |     // Create a request object from a template. | 
 | 276 |     virtual status_t createDefaultRequest(int templateId, | 
 | 277 |                                           /*out*/ | 
 | 278 |                                           CameraMetadata* request) | 
 | 279 |     { | 
 | 280 |         Parcel data, reply; | 
 | 281 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 282 |         data.writeInt32(templateId); | 
 | 283 |         remote()->transact(CREATE_DEFAULT_REQUEST, data, &reply); | 
 | 284 |  | 
 | 285 |         reply.readExceptionCode(); | 
 | 286 |         status_t result = reply.readInt32(); | 
 | 287 |  | 
 | 288 |         CameraMetadata out; | 
 | 289 |         if (reply.readInt32() != 0) { | 
 | 290 |             out.readFromParcel(&reply); | 
 | 291 |         } | 
 | 292 |  | 
 | 293 |         if (request != NULL) { | 
 | 294 |             request->swap(out); | 
 | 295 |         } | 
 | 296 |         return result; | 
 | 297 |     } | 
 | 298 |  | 
 | 299 |  | 
| Igor Murashkin | 099b457 | 2013-07-12 17:52:16 -0700 | [diff] [blame] | 300 |     virtual status_t getCameraInfo(CameraMetadata* info) | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 301 |     { | 
 | 302 |         Parcel data, reply; | 
 | 303 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 304 |         remote()->transact(GET_CAMERA_INFO, data, &reply); | 
 | 305 |  | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 306 |         reply.readExceptionCode(); | 
 | 307 |         status_t result = reply.readInt32(); | 
 | 308 |  | 
| Igor Murashkin | 099b457 | 2013-07-12 17:52:16 -0700 | [diff] [blame] | 309 |         CameraMetadata out; | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 310 |         if (reply.readInt32() != 0) { | 
| Igor Murashkin | 099b457 | 2013-07-12 17:52:16 -0700 | [diff] [blame] | 311 |             out.readFromParcel(&reply); | 
 | 312 |         } | 
 | 313 |  | 
 | 314 |         if (info != NULL) { | 
 | 315 |             info->swap(out); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 316 |         } | 
 | 317 |  | 
 | 318 |         return result; | 
 | 319 |     } | 
 | 320 |  | 
| Zhijun He | 2ab500c | 2013-07-23 08:02:53 -0700 | [diff] [blame] | 321 |     virtual status_t waitUntilIdle() | 
 | 322 |     { | 
 | 323 |         ALOGV("waitUntilIdle"); | 
 | 324 |         Parcel data, reply; | 
 | 325 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 326 |         remote()->transact(WAIT_UNTIL_IDLE, data, &reply); | 
 | 327 |         reply.readExceptionCode(); | 
 | 328 |         return reply.readInt32(); | 
 | 329 |     } | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 330 |  | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 331 |     virtual status_t flush(int64_t *lastFrameNumber) | 
| Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 332 |     { | 
 | 333 |         ALOGV("flush"); | 
 | 334 |         Parcel data, reply; | 
 | 335 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 336 |         remote()->transact(FLUSH, data, &reply); | 
 | 337 |         reply.readExceptionCode(); | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 338 |         status_t res = reply.readInt32(); | 
 | 339 |  | 
 | 340 |         status_t resFrameNumber = BAD_VALUE; | 
 | 341 |         if (reply.readInt32() != 0) { | 
 | 342 |             if (lastFrameNumber != NULL) { | 
| John Lin | 19fa0fe | 2015-02-02 18:10:42 +0800 | [diff] [blame] | 343 |                 resFrameNumber = reply.readInt64(lastFrameNumber); | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 344 |             } | 
 | 345 |         } | 
 | 346 |         if ((res != NO_ERROR) || (resFrameNumber != NO_ERROR)) { | 
 | 347 |             res = FAILED_TRANSACTION; | 
 | 348 |         } | 
 | 349 |         return res; | 
| Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 350 |     } | 
 | 351 |  | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 352 |     virtual status_t prepare(int streamId) | 
 | 353 |     { | 
 | 354 |         ALOGV("prepare"); | 
 | 355 |         Parcel data, reply; | 
 | 356 |  | 
 | 357 |         data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); | 
 | 358 |         data.writeInt32(streamId); | 
 | 359 |  | 
 | 360 |         remote()->transact(PREPARE, data, &reply); | 
 | 361 |  | 
 | 362 |         reply.readExceptionCode(); | 
 | 363 |         return reply.readInt32(); | 
 | 364 |     } | 
 | 365 |  | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 366 | private: | 
 | 367 |  | 
 | 368 |  | 
 | 369 | }; | 
 | 370 |  | 
 | 371 | IMPLEMENT_META_INTERFACE(CameraDeviceUser, | 
| Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 372 |                          "android.hardware.camera2.ICameraDeviceUser"); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 373 |  | 
 | 374 | // ---------------------------------------------------------------------- | 
 | 375 |  | 
 | 376 | status_t BnCameraDeviceUser::onTransact( | 
 | 377 |     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
 | 378 | { | 
 | 379 |     switch(code) { | 
 | 380 |         case DISCONNECT: { | 
 | 381 |             ALOGV("DISCONNECT"); | 
 | 382 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 383 |             disconnect(); | 
 | 384 |             reply->writeNoException(); | 
 | 385 |             return NO_ERROR; | 
 | 386 |         } break; | 
 | 387 |         case SUBMIT_REQUEST: { | 
 | 388 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 389 |  | 
 | 390 |             // arg0 = request | 
 | 391 |             sp<CaptureRequest> request; | 
 | 392 |             if (data.readInt32() != 0) { | 
 | 393 |                 request = new CaptureRequest(); | 
 | 394 |                 request->readFromParcel(const_cast<Parcel*>(&data)); | 
 | 395 |             } | 
 | 396 |  | 
 | 397 |             // arg1 = streaming (bool) | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 398 |             bool repeating = data.readInt32(); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 399 |  | 
 | 400 |             // return code: requestId (int32) | 
 | 401 |             reply->writeNoException(); | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 402 |             int64_t lastFrameNumber = -1; | 
 | 403 |             reply->writeInt32(submitRequest(request, repeating, &lastFrameNumber)); | 
 | 404 |             reply->writeInt32(1); | 
 | 405 |             reply->writeInt64(lastFrameNumber); | 
 | 406 |  | 
 | 407 |             return NO_ERROR; | 
 | 408 |         } break; | 
 | 409 |         case SUBMIT_REQUEST_LIST: { | 
 | 410 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 411 |  | 
 | 412 |             List<sp<CaptureRequest> > requestList; | 
 | 413 |             int requestListSize = data.readInt32(); | 
 | 414 |             for (int i = 0; i < requestListSize; i++) { | 
 | 415 |                 if (data.readInt32() != 0) { | 
 | 416 |                     sp<CaptureRequest> request = new CaptureRequest(); | 
 | 417 |                     if (request->readFromParcel(const_cast<Parcel*>(&data)) != OK) { | 
 | 418 |                         return BAD_VALUE; | 
 | 419 |                     } | 
 | 420 |                     requestList.push_back(request); | 
 | 421 |                 } else { | 
 | 422 |                     sp<CaptureRequest> request = 0; | 
 | 423 |                     requestList.push_back(request); | 
 | 424 |                     ALOGE("A request is missing. Sending in null request."); | 
 | 425 |                 } | 
 | 426 |             } | 
 | 427 |  | 
 | 428 |             bool repeating = data.readInt32(); | 
 | 429 |  | 
 | 430 |             reply->writeNoException(); | 
 | 431 |             int64_t lastFrameNumber = -1; | 
 | 432 |             reply->writeInt32(submitRequestList(requestList, repeating, &lastFrameNumber)); | 
 | 433 |             reply->writeInt32(1); | 
 | 434 |             reply->writeInt64(lastFrameNumber); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 435 |  | 
 | 436 |             return NO_ERROR; | 
 | 437 |         } break; | 
 | 438 |         case CANCEL_REQUEST: { | 
 | 439 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 440 |             int requestId = data.readInt32(); | 
 | 441 |             reply->writeNoException(); | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 442 |             int64_t lastFrameNumber = -1; | 
 | 443 |             reply->writeInt32(cancelRequest(requestId, &lastFrameNumber)); | 
 | 444 |             reply->writeInt32(1); | 
 | 445 |             reply->writeInt64(lastFrameNumber); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 446 |             return NO_ERROR; | 
 | 447 |         } break; | 
 | 448 |         case DELETE_STREAM: { | 
 | 449 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 450 |             int streamId = data.readInt32(); | 
 | 451 |             reply->writeNoException(); | 
 | 452 |             reply->writeInt32(deleteStream(streamId)); | 
 | 453 |             return NO_ERROR; | 
 | 454 |         } break; | 
 | 455 |         case CREATE_STREAM: { | 
 | 456 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 457 |  | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 458 |             status_t ret = BAD_VALUE; | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 459 |             if (data.readInt32() != 0) { | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 460 |                 OutputConfiguration outputConfiguration(data); | 
 | 461 |                 ret = createStream(outputConfiguration); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 462 |             } else { | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 463 |                 ALOGE("%s: cannot take an empty OutputConfiguration", __FUNCTION__); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 464 |             } | 
 | 465 |  | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 466 |             reply->writeNoException(); | 
 | 467 |             ALOGV("%s: CREATE_STREAM: write noException", __FUNCTION__); | 
 | 468 |             reply->writeInt32(ret); | 
 | 469 |             ALOGV("%s: CREATE_STREAM: write ret = %d", __FUNCTION__, ret); | 
 | 470 |  | 
 | 471 |             return NO_ERROR; | 
 | 472 |         } break; | 
| Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 473 |         case CREATE_INPUT_STREAM: { | 
 | 474 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 475 |             int width, height, format; | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 476 |  | 
| Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 477 |             width = data.readInt32(); | 
 | 478 |             height = data.readInt32(); | 
 | 479 |             format = data.readInt32(); | 
 | 480 |             status_t ret = createInputStream(width, height, format); | 
 | 481 |  | 
 | 482 |             reply->writeNoException(); | 
 | 483 |             reply->writeInt32(ret); | 
 | 484 |             return NO_ERROR; | 
 | 485 |  | 
 | 486 |         } break; | 
 | 487 |         case GET_INPUT_SURFACE: { | 
 | 488 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 489 |  | 
 | 490 |             sp<IGraphicBufferProducer> bp; | 
 | 491 |             status_t ret = getInputBufferProducer(&bp); | 
 | 492 |             sp<IBinder> b(IInterface::asBinder(ret == OK ? bp : NULL)); | 
 | 493 |  | 
 | 494 |             reply->writeNoException(); | 
 | 495 |             reply->writeInt32(ret); | 
 | 496 |             reply->writeInt32(1); | 
 | 497 |             reply->writeString16(String16("camera input")); // name of surface | 
 | 498 |             reply->writeStrongBinder(b); | 
 | 499 |  | 
 | 500 |             return NO_ERROR; | 
 | 501 |         } break; | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 502 |         case CREATE_DEFAULT_REQUEST: { | 
 | 503 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 504 |  | 
 | 505 |             int templateId = data.readInt32(); | 
 | 506 |  | 
 | 507 |             CameraMetadata request; | 
 | 508 |             status_t ret; | 
 | 509 |             ret = createDefaultRequest(templateId, &request); | 
 | 510 |  | 
 | 511 |             reply->writeNoException(); | 
 | 512 |             reply->writeInt32(ret); | 
 | 513 |  | 
| Igor Murashkin | 099b457 | 2013-07-12 17:52:16 -0700 | [diff] [blame] | 514 |             // out-variables are after exception and return value | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 515 |             reply->writeInt32(1); // to mark presence of metadata object | 
 | 516 |             request.writeToParcel(const_cast<Parcel*>(reply)); | 
 | 517 |  | 
 | 518 |             return NO_ERROR; | 
 | 519 |         } break; | 
 | 520 |         case GET_CAMERA_INFO: { | 
 | 521 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 522 |  | 
| Igor Murashkin | 099b457 | 2013-07-12 17:52:16 -0700 | [diff] [blame] | 523 |             CameraMetadata info; | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 524 |             status_t ret; | 
| Igor Murashkin | 099b457 | 2013-07-12 17:52:16 -0700 | [diff] [blame] | 525 |             ret = getCameraInfo(&info); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 526 |  | 
 | 527 |             reply->writeNoException(); | 
 | 528 |             reply->writeInt32(ret); | 
 | 529 |  | 
| Igor Murashkin | 099b457 | 2013-07-12 17:52:16 -0700 | [diff] [blame] | 530 |             // out-variables are after exception and return value | 
 | 531 |             reply->writeInt32(1); // to mark presence of metadata object | 
 | 532 |             info.writeToParcel(reply); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 533 |  | 
 | 534 |             return NO_ERROR; | 
 | 535 |         } break; | 
| Zhijun He | 2ab500c | 2013-07-23 08:02:53 -0700 | [diff] [blame] | 536 |         case WAIT_UNTIL_IDLE: { | 
 | 537 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 538 |             reply->writeNoException(); | 
 | 539 |             reply->writeInt32(waitUntilIdle()); | 
 | 540 |             return NO_ERROR; | 
 | 541 |         } break; | 
| Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 542 |         case FLUSH: { | 
 | 543 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 544 |             reply->writeNoException(); | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 545 |             int64_t lastFrameNumber = -1; | 
 | 546 |             reply->writeInt32(flush(&lastFrameNumber)); | 
 | 547 |             reply->writeInt32(1); | 
 | 548 |             reply->writeInt64(lastFrameNumber); | 
| Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 549 |             return NO_ERROR; | 
 | 550 |         } | 
| Ruben Brunk | b2119af | 2014-05-09 19:57:56 -0700 | [diff] [blame] | 551 |         case BEGIN_CONFIGURE: { | 
 | 552 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 553 |             reply->writeNoException(); | 
 | 554 |             reply->writeInt32(beginConfigure()); | 
 | 555 |             return NO_ERROR; | 
 | 556 |         } break; | 
 | 557 |         case END_CONFIGURE: { | 
 | 558 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 559 |             reply->writeNoException(); | 
 | 560 |             reply->writeInt32(endConfigure()); | 
 | 561 |             return NO_ERROR; | 
 | 562 |         } break; | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 563 |         case PREPARE: { | 
 | 564 |             CHECK_INTERFACE(ICameraDeviceUser, data, reply); | 
 | 565 |             int streamId = data.readInt32(); | 
 | 566 |             reply->writeNoException(); | 
 | 567 |             reply->writeInt32(prepare(streamId)); | 
 | 568 |             return NO_ERROR; | 
 | 569 |         } break; | 
 | 570 |  | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 571 |         default: | 
 | 572 |             return BBinder::onTransact(code, data, reply, flags); | 
 | 573 |     } | 
 | 574 | } | 
 | 575 |  | 
 | 576 | // ---------------------------------------------------------------------------- | 
 | 577 |  | 
 | 578 | }; // namespace android |