1 /* 2 ** 3 ** Copyright 2013, 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 "IProCameraCallbacks" 20 #include <utils/Log.h> 21 #include <stdint.h> 22 #include <sys/types.h> 23 24 #include <binder/Parcel.h> 25 #include <gui/IGraphicBufferProducer.h> 26 #include <gui/Surface.h> 27 #include <utils/Mutex.h> 28 29 #include <camera/IProCameraCallbacks.h> 30 31 #include <system/camera_metadata.h> 32 33 namespace android { 34 35 enum { 36 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION, 37 LOCK_STATUS_CHANGED, 38 RESULT_RECEIVED, 39 }; 40 41 void readMetadata(const Parcel& data, camera_metadata_t** out); 42 void writeMetadata(Parcel& data, camera_metadata_t* metadata); 43 44 class BpProCameraCallbacks: public BpInterface<IProCameraCallbacks> 45 { 46 public: 47 BpProCameraCallbacks(const sp<IBinder>& impl) 48 : BpInterface<IProCameraCallbacks>(impl) 49 { 50 } 51 52 // generic callback from camera service to app 53 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) 54 { 55 ALOGV("notifyCallback"); 56 Parcel data, reply; 57 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor()); 58 data.writeInt32(msgType); 59 data.writeInt32(ext1); 60 data.writeInt32(ext2); 61 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); 62 } 63 64 void onLockStatusChanged(LockStatus newLockStatus) { 65 ALOGV("onLockStatusChanged"); 66 Parcel data, reply; 67 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor()); 68 data.writeInt32(newLockStatus); 69 remote()->transact(LOCK_STATUS_CHANGED, data, &reply, 70 IBinder::FLAG_ONEWAY); 71 } 72 73 void onResultReceived(int32_t frameId, camera_metadata* result) { 74 ALOGV("onResultReceived"); 75 Parcel data, reply; 76 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor()); 77 data.writeInt32(frameId); 78 writeMetadata(data, result); 79 remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY); 80 } 81 }; 82 83 IMPLEMENT_META_INTERFACE(ProCameraCallbacks, 84 "android.hardware.IProCameraCallbacks"); 85 86 // ---------------------------------------------------------------------- 87 88 status_t BnProCameraCallbacks::onTransact( 89 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 90 { 91 ALOGV("onTransact - code = %d", code); 92 switch(code) { 93 case NOTIFY_CALLBACK: { 94 ALOGV("NOTIFY_CALLBACK"); 95 CHECK_INTERFACE(IProCameraCallbacks, data, reply); 96 int32_t msgType = data.readInt32(); 97 int32_t ext1 = data.readInt32(); 98 int32_t ext2 = data.readInt32(); 99 notifyCallback(msgType, ext1, ext2); 100 return NO_ERROR; 101 } break; 102 case LOCK_STATUS_CHANGED: { 103 ALOGV("LOCK_STATUS_CHANGED"); 104 CHECK_INTERFACE(IProCameraCallbacks, data, reply); 105 LockStatus newLockStatus 106 = static_cast<LockStatus>(data.readInt32()); 107 onLockStatusChanged(newLockStatus); 108 return NO_ERROR; 109 } break; 110 case RESULT_RECEIVED: { 111 ALOGV("RESULT_RECEIVED"); 112 CHECK_INTERFACE(IProCameraCallbacks, data, reply); 113 int32_t frameId = data.readInt32(); 114 camera_metadata_t *result = NULL; 115 readMetadata(data, &result); 116 onResultReceived(frameId, result); 117 return NO_ERROR; 118 break; 119 } 120 default: 121 return BBinder::onTransact(code, data, reply, flags); 122 } 123 } 124 125 // ---------------------------------------------------------------------------- 126 127 }; // namespace android 128 129