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 "ICameraDeviceCallbacks" 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/camera2/ICameraDeviceCallbacks.h> 30 #include "camera/CameraMetadata.h" 31 32 namespace android { 33 34 enum { 35 CAMERA_ERROR = IBinder::FIRST_CALL_TRANSACTION, 36 CAMERA_IDLE, 37 CAPTURE_STARTED, 38 RESULT_RECEIVED, 39 }; 40 41 class BpCameraDeviceCallbacks: public BpInterface<ICameraDeviceCallbacks> 42 { 43 public: 44 BpCameraDeviceCallbacks(const sp<IBinder>& impl) 45 : BpInterface<ICameraDeviceCallbacks>(impl) 46 { 47 } 48 49 void onDeviceError(CameraErrorCode errorCode) 50 { 51 ALOGV("onDeviceError"); 52 Parcel data, reply; 53 data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); 54 data.writeInt32(static_cast<int32_t>(errorCode)); 55 remote()->transact(CAMERA_ERROR, data, &reply, IBinder::FLAG_ONEWAY); 56 data.writeNoException(); 57 } 58 59 void onDeviceIdle() 60 { 61 ALOGV("onDeviceIdle"); 62 Parcel data, reply; 63 data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); 64 remote()->transact(CAMERA_IDLE, data, &reply, IBinder::FLAG_ONEWAY); 65 data.writeNoException(); 66 } 67 68 void onCaptureStarted(int32_t requestId, int64_t timestamp) 69 { 70 ALOGV("onCaptureStarted"); 71 Parcel data, reply; 72 data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); 73 data.writeInt32(requestId); 74 data.writeInt64(timestamp); 75 remote()->transact(CAPTURE_STARTED, data, &reply, IBinder::FLAG_ONEWAY); 76 data.writeNoException(); 77 } 78 79 80 void onResultReceived(int32_t requestId, const CameraMetadata& result) { 81 ALOGV("onResultReceived"); 82 Parcel data, reply; 83 data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); 84 data.writeInt32(requestId); 85 data.writeInt32(1); // to mark presence of metadata object 86 result.writeToParcel(&data); 87 remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY); 88 data.writeNoException(); 89 } 90 }; 91 92 IMPLEMENT_META_INTERFACE(CameraDeviceCallbacks, 93 "android.hardware.camera2.ICameraDeviceCallbacks"); 94 95 // ---------------------------------------------------------------------- 96 97 status_t BnCameraDeviceCallbacks::onTransact( 98 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 99 { 100 ALOGV("onTransact - code = %d", code); 101 switch(code) { 102 case CAMERA_ERROR: { 103 ALOGV("onDeviceError"); 104 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); 105 CameraErrorCode errorCode = 106 static_cast<CameraErrorCode>(data.readInt32()); 107 onDeviceError(errorCode); 108 data.readExceptionCode(); 109 return NO_ERROR; 110 } break; 111 case CAMERA_IDLE: { 112 ALOGV("onDeviceIdle"); 113 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); 114 onDeviceIdle(); 115 data.readExceptionCode(); 116 return NO_ERROR; 117 } break; 118 case CAPTURE_STARTED: { 119 ALOGV("onCaptureStarted"); 120 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); 121 int32_t requestId = data.readInt32(); 122 int64_t timestamp = data.readInt64(); 123 onCaptureStarted(requestId, timestamp); 124 data.readExceptionCode(); 125 return NO_ERROR; 126 } break; 127 case RESULT_RECEIVED: { 128 ALOGV("onResultReceived"); 129 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); 130 int32_t requestId = data.readInt32(); 131 CameraMetadata result; 132 if (data.readInt32() != 0) { 133 result.readFromParcel(const_cast<Parcel*>(&data)); 134 } else { 135 ALOGW("No metadata object is present in result"); 136 } 137 onResultReceived(requestId, result); 138 data.readExceptionCode(); 139 return NO_ERROR; 140 } break; 141 default: 142 return BBinder::onTransact(code, data, reply, flags); 143 } 144 } 145 146 // ---------------------------------------------------------------------------- 147 148 }; // namespace android 149