blob: b9cd14d839f315efdb1c634aa56285732a141a78 [file] [log] [blame]
Igor Murashkin634a5152013-02-20 17:15:11 -08001/*
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
Igor Murashkina91537e2013-02-21 12:02:29 -080031#include <system/camera_metadata.h>
32
Igor Murashkin634a5152013-02-20 17:15:11 -080033namespace android {
34
35enum {
36 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
Igor Murashkin53765732013-02-20 17:41:57 -080037 LOCK_STATUS_CHANGED,
Igor Murashkina91537e2013-02-21 12:02:29 -080038 RESULT_RECEIVED,
Igor Murashkin634a5152013-02-20 17:15:11 -080039};
40
Igor Murashkina91537e2013-02-21 12:02:29 -080041void readMetadata(const Parcel& data, camera_metadata_t** out);
42void writeMetadata(Parcel& data, camera_metadata_t* metadata);
43
Igor Murashkin634a5152013-02-20 17:15:11 -080044class BpProCameraCallbacks: public BpInterface<IProCameraCallbacks>
45{
46public:
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
Igor Murashkin53765732013-02-20 17:41:57 -080064 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 }
Igor Murashkina91537e2013-02-21 12:02:29 -080072
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 }
Igor Murashkin634a5152013-02-20 17:15:11 -080081};
82
83IMPLEMENT_META_INTERFACE(ProCameraCallbacks,
84 "android.hardware.IProCameraCallbacks");
85
86// ----------------------------------------------------------------------
87
88status_t BnProCameraCallbacks::onTransact(
89 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
90{
Igor Murashkin53765732013-02-20 17:41:57 -080091 ALOGV("onTransact - code = %d", code);
Igor Murashkin634a5152013-02-20 17:15:11 -080092 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;
Igor Murashkin53765732013-02-20 17:41:57 -0800102 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;
Igor Murashkina91537e2013-02-21 12:02:29 -0800110 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 }
Igor Murashkin634a5152013-02-20 17:15:11 -0800120 default:
121 return BBinder::onTransact(code, data, reply, flags);
122 }
123}
124
125// ----------------------------------------------------------------------------
126
127}; // namespace android
128