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