blob: 756fba2ae9c695e7935ed5eba1a83e7082c61f6d [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
31namespace android {
32
33enum {
34 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
35 DATA_CALLBACK,
36 DATA_CALLBACK_TIMESTAMP,
Igor Murashkin53765732013-02-20 17:41:57 -080037 LOCK_STATUS_CHANGED,
Igor Murashkin634a5152013-02-20 17:15:11 -080038};
39
40class BpProCameraCallbacks: public BpInterface<IProCameraCallbacks>
41{
42public:
43 BpProCameraCallbacks(const sp<IBinder>& impl)
44 : BpInterface<IProCameraCallbacks>(impl)
45 {
46 }
47
48 // generic callback from camera service to app
49 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
50 {
51 ALOGV("notifyCallback");
52 Parcel data, reply;
53 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
54 data.writeInt32(msgType);
55 data.writeInt32(ext1);
56 data.writeInt32(ext2);
57 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
58 }
59
60 // generic data callback from camera service to app with image data
61 void dataCallback(int32_t msgType, const sp<IMemory>& imageData,
62 camera_frame_metadata_t *metadata)
63 {
64 ALOGV("dataCallback");
65 Parcel data, reply;
66 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
67 data.writeInt32(msgType);
68 data.writeStrongBinder(imageData->asBinder());
69 if (metadata) {
70 data.writeInt32(metadata->number_of_faces);
71 data.write(metadata->faces,
72 sizeof(camera_face_t) * metadata->number_of_faces);
73 }
74 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
75 }
76
77 // generic data callback from camera service to app with image data
78 void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType,
79 const sp<IMemory>& imageData)
80 {
81 ALOGV("dataCallback");
82 Parcel data, reply;
83 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
84 data.writeInt64(timestamp);
85 data.writeInt32(msgType);
86 data.writeStrongBinder(imageData->asBinder());
87 remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply,
88 IBinder::FLAG_ONEWAY);
89 }
Igor Murashkin53765732013-02-20 17:41:57 -080090
91 void onLockStatusChanged(LockStatus newLockStatus) {
92 ALOGV("onLockStatusChanged");
93 Parcel data, reply;
94 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
95 data.writeInt32(newLockStatus);
96 remote()->transact(LOCK_STATUS_CHANGED, data, &reply,
97 IBinder::FLAG_ONEWAY);
98 }
Igor Murashkin634a5152013-02-20 17:15:11 -080099};
100
101IMPLEMENT_META_INTERFACE(ProCameraCallbacks,
102 "android.hardware.IProCameraCallbacks");
103
104// ----------------------------------------------------------------------
105
106status_t BnProCameraCallbacks::onTransact(
107 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
108{
Igor Murashkin53765732013-02-20 17:41:57 -0800109 ALOGV("onTransact - code = %d", code);
Igor Murashkin634a5152013-02-20 17:15:11 -0800110 switch(code) {
111 case NOTIFY_CALLBACK: {
112 ALOGV("NOTIFY_CALLBACK");
113 CHECK_INTERFACE(IProCameraCallbacks, data, reply);
114 int32_t msgType = data.readInt32();
115 int32_t ext1 = data.readInt32();
116 int32_t ext2 = data.readInt32();
117 notifyCallback(msgType, ext1, ext2);
118 return NO_ERROR;
119 } break;
120 case DATA_CALLBACK: {
121 ALOGV("DATA_CALLBACK");
122 CHECK_INTERFACE(IProCameraCallbacks, data, reply);
123 int32_t msgType = data.readInt32();
124 sp<IMemory> imageData = interface_cast<IMemory>(
125 data.readStrongBinder());
126 camera_frame_metadata_t *metadata = NULL;
127 if (data.dataAvail() > 0) {
128 metadata = new camera_frame_metadata_t;
129 metadata->number_of_faces = data.readInt32();
130 metadata->faces = (camera_face_t *) data.readInplace(
131 sizeof(camera_face_t) * metadata->number_of_faces);
132 }
133 dataCallback(msgType, imageData, metadata);
134 if (metadata) delete metadata;
135 return NO_ERROR;
136 } break;
137 case DATA_CALLBACK_TIMESTAMP: {
138 ALOGV("DATA_CALLBACK_TIMESTAMP");
139 CHECK_INTERFACE(IProCameraCallbacks, data, reply);
140 nsecs_t timestamp = data.readInt64();
141 int32_t msgType = data.readInt32();
142 sp<IMemory> imageData = interface_cast<IMemory>(
143 data.readStrongBinder());
144 dataCallbackTimestamp(timestamp, msgType, imageData);
145 return NO_ERROR;
146 } break;
Igor Murashkin53765732013-02-20 17:41:57 -0800147 case LOCK_STATUS_CHANGED: {
148 ALOGV("LOCK_STATUS_CHANGED");
149 CHECK_INTERFACE(IProCameraCallbacks, data, reply);
150 LockStatus newLockStatus
151 = static_cast<LockStatus>(data.readInt32());
152 onLockStatusChanged(newLockStatus);
153 return NO_ERROR;
154 } break;
Igor Murashkin634a5152013-02-20 17:15:11 -0800155 default:
156 return BBinder::onTransact(code, data, reply, flags);
157 }
158}
159
160// ----------------------------------------------------------------------------
161
162}; // namespace android
163