Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, 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 "ICameraClient" |
| 20 | #include <utils/Log.h> |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <camera/ICameraClient.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | enum { |
| 28 | NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION, |
| 29 | DATA_CALLBACK, |
| 30 | DATA_CALLBACK_TIMESTAMP, |
| 31 | }; |
| 32 | |
| 33 | class BpCameraClient: public BpInterface<ICameraClient> |
| 34 | { |
| 35 | public: |
| 36 | BpCameraClient(const sp<IBinder>& impl) |
| 37 | : BpInterface<ICameraClient>(impl) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | // generic callback from camera service to app |
| 42 | void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) |
| 43 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 44 | ALOGV("notifyCallback"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 45 | Parcel data, reply; |
| 46 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 47 | data.writeInt32(msgType); |
| 48 | data.writeInt32(ext1); |
Susmitha Gummalla | c46f5e16 | 2014-04-29 12:18:30 -0700 | [diff] [blame] | 49 | if ((msgType == CAMERA_MSG_PREVIEW_FRAME) && (ext1 == CAMERA_FRAME_DATA_FD)) { |
| 50 | ALOGD("notifyCallback: CAMERA_MSG_PREVIEW_FRAME fd = %d", ext2); |
| 51 | data.writeFileDescriptor(ext2); |
| 52 | } else { |
| 53 | data.writeInt32(ext2); |
| 54 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 55 | remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 56 | } |
| 57 | |
| 58 | // generic data callback from camera service to app with image data |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 59 | void dataCallback(int32_t msgType, const sp<IMemory>& imageData, |
| 60 | camera_frame_metadata_t *metadata) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 61 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 62 | ALOGV("dataCallback"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 63 | Parcel data, reply; |
| 64 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 65 | data.writeInt32(msgType); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 66 | data.writeStrongBinder(IInterface::asBinder(imageData)); |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 67 | if (metadata) { |
| 68 | data.writeInt32(metadata->number_of_faces); |
| 69 | data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces); |
| 70 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 71 | remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 72 | } |
| 73 | |
| 74 | // generic data callback from camera service to app with image data |
| 75 | void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData) |
| 76 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 77 | ALOGV("dataCallback"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 78 | Parcel data, reply; |
| 79 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 80 | data.writeInt64(timestamp); |
| 81 | data.writeInt32(msgType); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 82 | data.writeStrongBinder(IInterface::asBinder(imageData)); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 83 | remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY); |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient"); |
| 88 | |
| 89 | // ---------------------------------------------------------------------- |
| 90 | |
| 91 | status_t BnCameraClient::onTransact( |
| 92 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 93 | { |
| 94 | switch(code) { |
| 95 | case NOTIFY_CALLBACK: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 96 | ALOGV("NOTIFY_CALLBACK"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 97 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 98 | int32_t msgType = data.readInt32(); |
Susmitha Gummalla | c46f5e16 | 2014-04-29 12:18:30 -0700 | [diff] [blame] | 99 | int32_t ext1 = data.readInt32(); |
| 100 | int32_t ext2 = 0; |
| 101 | if ((msgType == CAMERA_MSG_PREVIEW_FRAME) && (ext1 == CAMERA_FRAME_DATA_FD)) { |
| 102 | ext2 = data.readFileDescriptor(); |
| 103 | ALOGD("onTransact: CAMERA_MSG_PREVIEW_FRAME fd = %d", ext2); |
| 104 | } else { |
| 105 | ext2 = data.readInt32(); |
| 106 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 107 | notifyCallback(msgType, ext1, ext2); |
| 108 | return NO_ERROR; |
| 109 | } break; |
| 110 | case DATA_CALLBACK: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 111 | ALOGV("DATA_CALLBACK"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 112 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 113 | int32_t msgType = data.readInt32(); |
| 114 | sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder()); |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 115 | camera_frame_metadata_t *metadata = NULL; |
| 116 | if (data.dataAvail() > 0) { |
| 117 | metadata = new camera_frame_metadata_t; |
| 118 | metadata->number_of_faces = data.readInt32(); |
| 119 | metadata->faces = (camera_face_t *) data.readInplace( |
| 120 | sizeof(camera_face_t) * metadata->number_of_faces); |
| 121 | } |
| 122 | dataCallback(msgType, imageData, metadata); |
| 123 | if (metadata) delete metadata; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 124 | return NO_ERROR; |
| 125 | } break; |
| 126 | case DATA_CALLBACK_TIMESTAMP: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 127 | ALOGV("DATA_CALLBACK_TIMESTAMP"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 128 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 129 | nsecs_t timestamp = data.readInt64(); |
| 130 | int32_t msgType = data.readInt32(); |
| 131 | sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder()); |
| 132 | dataCallbackTimestamp(timestamp, msgType, imageData); |
| 133 | return NO_ERROR; |
| 134 | } break; |
| 135 | default: |
| 136 | return BBinder::onTransact(code, data, reply, flags); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // ---------------------------------------------------------------------------- |
| 141 | |
| 142 | }; // namespace android |
| 143 | |