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 { 44 ALOGV("notifyCallback"); 45 Parcel data, reply; 46 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); 47 data.writeInt32(msgType); 48 data.writeInt32(ext1); 49 data.writeInt32(ext2); 50 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); 51 } 52 53 // generic data callback from camera service to app with image data 54 void dataCallback(int32_t msgType, const sp<IMemory>& imageData, 55 camera_frame_metadata_t *metadata) 56 { 57 ALOGV("dataCallback"); 58 Parcel data, reply; 59 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); 60 data.writeInt32(msgType); 61 data.writeStrongBinder(imageData->asBinder()); 62 if (metadata) { 63 data.writeInt32(metadata->number_of_faces); 64 data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces); 65 } 66 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); 67 } 68 69 // generic data callback from camera service to app with image data 70 void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData) 71 { 72 ALOGV("dataCallback"); 73 Parcel data, reply; 74 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); 75 data.writeInt64(timestamp); 76 data.writeInt32(msgType); 77 data.writeStrongBinder(imageData->asBinder()); 78 remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY); 79 } 80 }; 81 82 IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient"); 83 84 // ---------------------------------------------------------------------- 85 86 status_t BnCameraClient::onTransact( 87 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 88 { 89 switch(code) { 90 case NOTIFY_CALLBACK: { 91 ALOGV("NOTIFY_CALLBACK"); 92 CHECK_INTERFACE(ICameraClient, data, reply); 93 int32_t msgType = data.readInt32(); 94 int32_t ext1 = data.readInt32(); 95 int32_t ext2 = data.readInt32(); 96 notifyCallback(msgType, ext1, ext2); 97 return NO_ERROR; 98 } break; 99 case DATA_CALLBACK: { 100 ALOGV("DATA_CALLBACK"); 101 CHECK_INTERFACE(ICameraClient, data, reply); 102 int32_t msgType = data.readInt32(); 103 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder()); 104 camera_frame_metadata_t *metadata = NULL; 105 if (data.dataAvail() > 0) { 106 metadata = new camera_frame_metadata_t; 107 metadata->number_of_faces = data.readInt32(); 108 metadata->faces = (camera_face_t *) data.readInplace( 109 sizeof(camera_face_t) * metadata->number_of_faces); 110 } 111 dataCallback(msgType, imageData, metadata); 112 if (metadata) delete metadata; 113 return NO_ERROR; 114 } break; 115 case DATA_CALLBACK_TIMESTAMP: { 116 ALOGV("DATA_CALLBACK_TIMESTAMP"); 117 CHECK_INTERFACE(ICameraClient, data, reply); 118 nsecs_t timestamp = data.readInt64(); 119 int32_t msgType = data.readInt32(); 120 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder()); 121 dataCallbackTimestamp(timestamp, msgType, imageData); 122 return NO_ERROR; 123 } break; 124 default: 125 return BBinder::onTransact(code, data, reply, flags); 126 } 127 } 128 129 // ---------------------------------------------------------------------------- 130 131 }; // namespace android 132 133