Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 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 |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 8 | ** |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 10 | ** |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 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 |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #define LOG_TAG "ICameraClient" |
| 20 | #include <utils/Log.h> |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 23 | #include <camera/CameraUtils.h> |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 24 | #include <android/hardware/ICameraClient.h> |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 25 | #include <media/hardware/HardwareAPI.h> |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 26 | |
| 27 | namespace android { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 28 | namespace hardware { |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 29 | |
| 30 | enum { |
| 31 | NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION, |
| 32 | DATA_CALLBACK, |
| 33 | DATA_CALLBACK_TIMESTAMP, |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 34 | RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP, |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | class BpCameraClient: public BpInterface<ICameraClient> |
| 38 | { |
| 39 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 40 | explicit BpCameraClient(const sp<IBinder>& impl) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 41 | : BpInterface<ICameraClient>(impl) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | // generic callback from camera service to app |
| 46 | void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) |
| 47 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 48 | ALOGV("notifyCallback"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 49 | Parcel data, reply; |
| 50 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 51 | data.writeInt32(msgType); |
| 52 | data.writeInt32(ext1); |
| 53 | data.writeInt32(ext2); |
| 54 | remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 55 | } |
| 56 | |
| 57 | // generic data callback from camera service to app with image data |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 58 | void dataCallback(int32_t msgType, const sp<IMemory>& imageData, |
| 59 | camera_frame_metadata_t *metadata) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 60 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 61 | ALOGV("dataCallback"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 62 | Parcel data, reply; |
| 63 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 64 | data.writeInt32(msgType); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 65 | data.writeStrongBinder(IInterface::asBinder(imageData)); |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 66 | if (metadata) { |
| 67 | data.writeInt32(metadata->number_of_faces); |
| 68 | data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces); |
| 69 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 70 | remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 71 | } |
| 72 | |
| 73 | // generic data callback from camera service to app with image data |
| 74 | void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData) |
| 75 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 76 | ALOGV("dataCallback"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 77 | Parcel data, reply; |
| 78 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 79 | data.writeInt64(timestamp); |
| 80 | data.writeInt32(msgType); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 81 | data.writeStrongBinder(IInterface::asBinder(imageData)); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 82 | remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY); |
| 83 | } |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 84 | |
| 85 | void recordingFrameHandleCallbackTimestamp(nsecs_t timestamp, native_handle_t* handle) { |
| 86 | ALOGV("recordingFrameHandleCallbackTimestamp"); |
| 87 | Parcel data, reply; |
| 88 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 89 | data.writeInt64(timestamp); |
| 90 | data.writeNativeHandle(handle); |
| 91 | remote()->transact(RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP, data, &reply, |
| 92 | IBinder::FLAG_ONEWAY); |
| 93 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient"); |
| 97 | |
| 98 | // ---------------------------------------------------------------------- |
| 99 | |
| 100 | status_t BnCameraClient::onTransact( |
| 101 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 102 | { |
| 103 | switch(code) { |
| 104 | case NOTIFY_CALLBACK: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 105 | ALOGV("NOTIFY_CALLBACK"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 106 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 107 | int32_t msgType = data.readInt32(); |
| 108 | int32_t ext1 = data.readInt32(); |
| 109 | int32_t ext2 = data.readInt32(); |
| 110 | notifyCallback(msgType, ext1, ext2); |
| 111 | return NO_ERROR; |
| 112 | } break; |
| 113 | case DATA_CALLBACK: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 114 | ALOGV("DATA_CALLBACK"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 115 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 116 | int32_t msgType = data.readInt32(); |
| 117 | sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder()); |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 118 | camera_frame_metadata_t *metadata = NULL; |
| 119 | if (data.dataAvail() > 0) { |
| 120 | metadata = new camera_frame_metadata_t; |
| 121 | metadata->number_of_faces = data.readInt32(); |
| 122 | metadata->faces = (camera_face_t *) data.readInplace( |
| 123 | sizeof(camera_face_t) * metadata->number_of_faces); |
| 124 | } |
| 125 | dataCallback(msgType, imageData, metadata); |
| 126 | if (metadata) delete metadata; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 127 | return NO_ERROR; |
| 128 | } break; |
| 129 | case DATA_CALLBACK_TIMESTAMP: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 130 | ALOGV("DATA_CALLBACK_TIMESTAMP"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 131 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 132 | nsecs_t timestamp = data.readInt64(); |
| 133 | int32_t msgType = data.readInt32(); |
| 134 | sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder()); |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 135 | dataCallbackTimestamp(timestamp, msgType, imageData); |
| 136 | return NO_ERROR; |
| 137 | } break; |
| 138 | case RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP: { |
| 139 | ALOGV("RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP"); |
| 140 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 141 | nsecs_t timestamp; |
| 142 | status_t res = data.readInt64(×tamp); |
| 143 | if (res != OK) { |
| 144 | ALOGE("%s: Failed to read timestamp: %s (%d)", __FUNCTION__, strerror(-res), res); |
| 145 | return BAD_VALUE; |
| 146 | } |
| 147 | native_handle_t* handle = data.readNativeHandle(); |
| 148 | if (handle == nullptr) { |
| 149 | ALOGE("%s: Received a null native handle", __FUNCTION__); |
| 150 | return BAD_VALUE; |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 153 | // The native handle will be freed in BpCamera::releaseRecordingFrameHandle. |
| 154 | recordingFrameHandleCallbackTimestamp(timestamp, handle); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 155 | return NO_ERROR; |
| 156 | } break; |
| 157 | default: |
| 158 | return BBinder::onTransact(code, data, reply, flags); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // ---------------------------------------------------------------------------- |
| 163 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 164 | } // namespace hardware |
| 165 | } // namespace android |