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, |
| 34 | }; |
| 35 | |
| 36 | class BpCameraClient: public BpInterface<ICameraClient> |
| 37 | { |
| 38 | public: |
| 39 | BpCameraClient(const sp<IBinder>& impl) |
| 40 | : BpInterface<ICameraClient>(impl) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | // generic callback from camera service to app |
| 45 | void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) |
| 46 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 47 | ALOGV("notifyCallback"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 48 | Parcel data, reply; |
| 49 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 50 | data.writeInt32(msgType); |
| 51 | data.writeInt32(ext1); |
| 52 | data.writeInt32(ext2); |
| 53 | remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 54 | } |
| 55 | |
| 56 | // generic data callback from camera service to app with image data |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 57 | void dataCallback(int32_t msgType, const sp<IMemory>& imageData, |
| 58 | camera_frame_metadata_t *metadata) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 59 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 60 | ALOGV("dataCallback"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 61 | Parcel data, reply; |
| 62 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 63 | data.writeInt32(msgType); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 64 | data.writeStrongBinder(IInterface::asBinder(imageData)); |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 65 | if (metadata) { |
| 66 | data.writeInt32(metadata->number_of_faces); |
| 67 | data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces); |
| 68 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 69 | remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 70 | } |
| 71 | |
| 72 | // generic data callback from camera service to app with image data |
| 73 | void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData) |
| 74 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 75 | ALOGV("dataCallback"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 76 | Parcel data, reply; |
| 77 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 78 | data.writeInt64(timestamp); |
| 79 | data.writeInt32(msgType); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 80 | data.writeStrongBinder(IInterface::asBinder(imageData)); |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 81 | // If imageData is metadata and it contains a native handle, write the native handle to |
| 82 | // parcel. |
| 83 | if (CameraUtils::isNativeHandleMetadata(imageData)) { |
| 84 | VideoNativeHandleMetadata *metadata = |
| 85 | (VideoNativeHandleMetadata*)(imageData->pointer()); |
| 86 | data.writeNativeHandle(metadata->pHandle); |
| 87 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 88 | remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY); |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient"); |
| 93 | |
| 94 | // ---------------------------------------------------------------------- |
| 95 | |
| 96 | status_t BnCameraClient::onTransact( |
| 97 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 98 | { |
| 99 | switch(code) { |
| 100 | case NOTIFY_CALLBACK: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 101 | ALOGV("NOTIFY_CALLBACK"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 102 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 103 | int32_t msgType = data.readInt32(); |
| 104 | int32_t ext1 = data.readInt32(); |
| 105 | int32_t ext2 = data.readInt32(); |
| 106 | notifyCallback(msgType, ext1, ext2); |
| 107 | return NO_ERROR; |
| 108 | } break; |
| 109 | case DATA_CALLBACK: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 110 | ALOGV("DATA_CALLBACK"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 111 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 112 | int32_t msgType = data.readInt32(); |
| 113 | sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder()); |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 114 | camera_frame_metadata_t *metadata = NULL; |
| 115 | if (data.dataAvail() > 0) { |
| 116 | metadata = new camera_frame_metadata_t; |
| 117 | metadata->number_of_faces = data.readInt32(); |
| 118 | metadata->faces = (camera_face_t *) data.readInplace( |
| 119 | sizeof(camera_face_t) * metadata->number_of_faces); |
| 120 | } |
| 121 | dataCallback(msgType, imageData, metadata); |
| 122 | if (metadata) delete metadata; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 123 | return NO_ERROR; |
| 124 | } break; |
| 125 | case DATA_CALLBACK_TIMESTAMP: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 126 | ALOGV("DATA_CALLBACK_TIMESTAMP"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 127 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 128 | nsecs_t timestamp = data.readInt64(); |
| 129 | int32_t msgType = data.readInt32(); |
| 130 | sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder()); |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 131 | |
| 132 | // If the image data contains a native handle, read the native handle from the parcel |
| 133 | // and replace the native handle in the image data. (The native handle in image data is |
| 134 | // not serielized/deserialized so it's not valid in the process.) |
| 135 | if (CameraUtils::isNativeHandleMetadata(imageData)) { |
| 136 | VideoNativeHandleMetadata *metadata = |
| 137 | (VideoNativeHandleMetadata*)(imageData->pointer()); |
| 138 | metadata->pHandle = data.readNativeHandle(); |
| 139 | |
| 140 | // The native handle will be freed in |
| 141 | // BpCameraRecordingProxyListener::releaseRecordingFrame. |
| 142 | } |
| 143 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 144 | dataCallbackTimestamp(timestamp, msgType, imageData); |
| 145 | return NO_ERROR; |
| 146 | } break; |
| 147 | default: |
| 148 | return BBinder::onTransact(code, data, reply, flags); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // ---------------------------------------------------------------------------- |
| 153 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 154 | } // namespace hardware |
| 155 | } // namespace android |