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 "ICameraDeviceCallbacks" |
| 20 | #include <utils/Log.h> |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <binder/Parcel.h> |
| 25 | #include <gui/IGraphicBufferProducer.h> |
| 26 | #include <gui/Surface.h> |
| 27 | #include <utils/Mutex.h> |
| 28 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 29 | #include <camera/camera2/ICameraDeviceCallbacks.h> |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 30 | #include "camera/CameraMetadata.h" |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 31 | #include "camera/CaptureResult.h" |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | enum { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 36 | CAMERA_ERROR = IBinder::FIRST_CALL_TRANSACTION, |
| 37 | CAMERA_IDLE, |
| 38 | CAPTURE_STARTED, |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 39 | RESULT_RECEIVED, |
| 40 | }; |
| 41 | |
| 42 | class BpCameraDeviceCallbacks: public BpInterface<ICameraDeviceCallbacks> |
| 43 | { |
| 44 | public: |
| 45 | BpCameraDeviceCallbacks(const sp<IBinder>& impl) |
| 46 | : BpInterface<ICameraDeviceCallbacks>(impl) |
| 47 | { |
| 48 | } |
| 49 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 50 | void onDeviceError(CameraErrorCode errorCode, const CaptureResultExtras& resultExtras) |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 51 | { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 52 | ALOGV("onDeviceError"); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 53 | Parcel data, reply; |
| 54 | data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 55 | data.writeInt32(static_cast<int32_t>(errorCode)); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 56 | data.writeInt32(1); // to mark presence of CaptureResultExtras object |
| 57 | resultExtras.writeToParcel(&data); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 58 | remote()->transact(CAMERA_ERROR, data, &reply, IBinder::FLAG_ONEWAY); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 59 | data.writeNoException(); |
| 60 | } |
| 61 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 62 | void onDeviceIdle() |
| 63 | { |
| 64 | ALOGV("onDeviceIdle"); |
| 65 | Parcel data, reply; |
| 66 | data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); |
| 67 | remote()->transact(CAMERA_IDLE, data, &reply, IBinder::FLAG_ONEWAY); |
| 68 | data.writeNoException(); |
| 69 | } |
| 70 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 71 | void onCaptureStarted(const CaptureResultExtras& result, int64_t timestamp) |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 72 | { |
| 73 | ALOGV("onCaptureStarted"); |
| 74 | Parcel data, reply; |
| 75 | data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 76 | data.writeInt32(1); // to mark presence of CaptureResultExtras object |
| 77 | result.writeToParcel(&data); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 78 | data.writeInt64(timestamp); |
| 79 | remote()->transact(CAPTURE_STARTED, data, &reply, IBinder::FLAG_ONEWAY); |
| 80 | data.writeNoException(); |
| 81 | } |
| 82 | |
| 83 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 84 | void onResultReceived(const CameraMetadata& metadata, |
| 85 | const CaptureResultExtras& resultExtras) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 86 | ALOGV("onResultReceived"); |
| 87 | Parcel data, reply; |
| 88 | data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); |
Zhijun He | 11d0d44 | 2013-07-31 09:50:58 -0700 | [diff] [blame] | 89 | data.writeInt32(1); // to mark presence of metadata object |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 90 | metadata.writeToParcel(&data); |
| 91 | data.writeInt32(1); // to mark presence of CaptureResult object |
| 92 | resultExtras.writeToParcel(&data); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 93 | remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY); |
| 94 | data.writeNoException(); |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | IMPLEMENT_META_INTERFACE(CameraDeviceCallbacks, |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 99 | "android.hardware.camera2.ICameraDeviceCallbacks"); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 100 | |
| 101 | // ---------------------------------------------------------------------- |
| 102 | |
| 103 | status_t BnCameraDeviceCallbacks::onTransact( |
| 104 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 105 | { |
| 106 | ALOGV("onTransact - code = %d", code); |
| 107 | switch(code) { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 108 | case CAMERA_ERROR: { |
| 109 | ALOGV("onDeviceError"); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 110 | CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 111 | CameraErrorCode errorCode = |
| 112 | static_cast<CameraErrorCode>(data.readInt32()); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 113 | CaptureResultExtras resultExtras; |
| 114 | if (data.readInt32() != 0) { |
| 115 | resultExtras.readFromParcel(const_cast<Parcel*>(&data)); |
| 116 | } else { |
| 117 | ALOGE("No CaptureResultExtras object is present!"); |
| 118 | } |
| 119 | onDeviceError(errorCode, resultExtras); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 120 | data.readExceptionCode(); |
| 121 | return NO_ERROR; |
| 122 | } break; |
| 123 | case CAMERA_IDLE: { |
| 124 | ALOGV("onDeviceIdle"); |
| 125 | CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); |
| 126 | onDeviceIdle(); |
| 127 | data.readExceptionCode(); |
| 128 | return NO_ERROR; |
| 129 | } break; |
| 130 | case CAPTURE_STARTED: { |
| 131 | ALOGV("onCaptureStarted"); |
| 132 | CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 133 | CaptureResultExtras result; |
| 134 | if (data.readInt32() != 0) { |
| 135 | result.readFromParcel(const_cast<Parcel*>(&data)); |
| 136 | } else { |
| 137 | ALOGE("No CaptureResultExtras object is present in result!"); |
| 138 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 139 | int64_t timestamp = data.readInt64(); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 140 | onCaptureStarted(result, timestamp); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 141 | data.readExceptionCode(); |
| 142 | return NO_ERROR; |
| 143 | } break; |
| 144 | case RESULT_RECEIVED: { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 145 | ALOGV("onResultReceived"); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 146 | CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 147 | CameraMetadata metadata; |
Zhijun He | 11d0d44 | 2013-07-31 09:50:58 -0700 | [diff] [blame] | 148 | if (data.readInt32() != 0) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 149 | metadata.readFromParcel(const_cast<Parcel*>(&data)); |
Zhijun He | 11d0d44 | 2013-07-31 09:50:58 -0700 | [diff] [blame] | 150 | } else { |
| 151 | ALOGW("No metadata object is present in result"); |
| 152 | } |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 153 | CaptureResultExtras resultExtras; |
| 154 | if (data.readInt32() != 0) { |
| 155 | resultExtras.readFromParcel(const_cast<Parcel*>(&data)); |
| 156 | } else { |
| 157 | ALOGW("No capture result extras object is present in result"); |
| 158 | } |
| 159 | onResultReceived(metadata, resultExtras); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 160 | data.readExceptionCode(); |
| 161 | return NO_ERROR; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 162 | } break; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 163 | default: |
| 164 | return BBinder::onTransact(code, data, reply, flags); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | // ---------------------------------------------------------------------------- |
| 169 | |
| 170 | }; // namespace android |