blob: ae07b67a8ead8b03bbfc853e71d27bafa657a66f [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 <ui/ICameraClient.h>
24
25namespace android {
26
27enum {
28 SHUTTER_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
29 RAW_CALLBACK,
30 JPEG_CALLBACK,
31 PREVIEW_CALLBACK,
32 ERROR_CALLBACK,
33 AUTOFOCUS_CALLBACK,
34 RECORDING_CALLBACK,
Dave Sparks9b352332009-05-07 12:25:25 -070035 NOTIFY_CALLBACK,
36 DATA_CALLBACK,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037};
38
39class BpCameraClient: public BpInterface<ICameraClient>
40{
41public:
42 BpCameraClient(const sp<IBinder>& impl)
43 : BpInterface<ICameraClient>(impl)
44 {
45 }
46
47 // callback to let the app know the shutter has closed, ideal for playing the shutter sound
48 void shutterCallback()
49 {
50 LOGV("shutterCallback");
51 Parcel data, reply;
52 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
53 remote()->transact(SHUTTER_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
54 }
55
56 // callback from camera service to app with picture data
57 void rawCallback(const sp<IMemory>& picture)
58 {
59 LOGV("rawCallback");
60 Parcel data, reply;
61 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
62 data.writeStrongBinder(picture->asBinder());
63 remote()->transact(RAW_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
64 }
65
66 // callback from camera service to app with picture data
67 void jpegCallback(const sp<IMemory>& picture)
68 {
69 LOGV("jpegCallback");
70 Parcel data, reply;
71 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
72 data.writeStrongBinder(picture->asBinder());
73 remote()->transact(JPEG_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
74 }
75
76 // callback from camera service to app with preview frame data
77 void previewCallback(const sp<IMemory>& frame)
78 {
79 LOGV("previewCallback");
80 Parcel data, reply;
81 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
82 data.writeStrongBinder(frame->asBinder());
83 remote()->transact(PREVIEW_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
84 }
85
86 // callback from camera service to app with recording frame data
87 void recordingCallback(const sp<IMemory>& frame)
88 {
89 LOGV("recordingCallback");
90 Parcel data, reply;
91 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
92 data.writeStrongBinder(frame->asBinder());
93 remote()->transact(RECORDING_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
94 }
95
96 // callback from camera service to app to report error
97 void errorCallback(status_t error)
98 {
99 LOGV("errorCallback");
100 Parcel data, reply;
101 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
102 data.writeInt32(error);
103 remote()->transact(ERROR_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
104 }
105
106 // callback from camera service to app to report autofocus completion
107 void autoFocusCallback(bool focused)
108 {
109 LOGV("autoFocusCallback");
110 Parcel data, reply;
111 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
112 data.writeInt32(focused);
113 remote()->transact(AUTOFOCUS_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
114 }
Dave Sparks9b352332009-05-07 12:25:25 -0700115
116 // generic callback from camera service to app
117 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
118 {
119 LOGV("notifyCallback");
120 Parcel data, reply;
121 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
122 data.writeInt32(msgType);
123 data.writeInt32(ext1);
124 data.writeInt32(ext2);
125 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
126 }
127
128 // generic data callback from camera service to app with image data
129 void dataCallback(int32_t msgType, const sp<IMemory>& imageData)
130 {
131 LOGV("dataCallback");
132 Parcel data, reply;
133 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
134 data.writeInt32(msgType);
135 data.writeStrongBinder(imageData->asBinder());
136 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
137 }
138
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800139};
140
141IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
142
143// ----------------------------------------------------------------------
144
145#define CHECK_INTERFACE(interface, data, reply) \
146 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
147 LOGW("Call incorrectly routed to " #interface); \
148 return PERMISSION_DENIED; \
149 } } while (0)
150
151status_t BnCameraClient::onTransact(
152 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
153{
154 switch(code) {
155 case SHUTTER_CALLBACK: {
156 LOGV("SHUTTER_CALLBACK");
157 CHECK_INTERFACE(ICameraClient, data, reply);
158 shutterCallback();
159 return NO_ERROR;
160 } break;
161 case RAW_CALLBACK: {
162 LOGV("RAW_CALLBACK");
163 CHECK_INTERFACE(ICameraClient, data, reply);
164 sp<IMemory> picture = interface_cast<IMemory>(data.readStrongBinder());
165 rawCallback(picture);
166 return NO_ERROR;
167 } break;
168 case JPEG_CALLBACK: {
169 LOGV("JPEG_CALLBACK");
170 CHECK_INTERFACE(ICameraClient, data, reply);
171 sp<IMemory> picture = interface_cast<IMemory>(data.readStrongBinder());
172 jpegCallback(picture);
173 return NO_ERROR;
174 } break;
175 case PREVIEW_CALLBACK: {
176 LOGV("PREVIEW_CALLBACK");
177 CHECK_INTERFACE(ICameraClient, data, reply);
178 sp<IMemory> frame = interface_cast<IMemory>(data.readStrongBinder());
179 previewCallback(frame);
180 return NO_ERROR;
181 } break;
182 case RECORDING_CALLBACK: {
183 LOGV("RECORDING_CALLBACK");
184 CHECK_INTERFACE(ICameraClient, data, reply);
185 sp<IMemory> frame = interface_cast<IMemory>(data.readStrongBinder());
186 recordingCallback(frame);
187 return NO_ERROR;
188 } break;
189 case ERROR_CALLBACK: {
190 LOGV("ERROR_CALLBACK");
191 CHECK_INTERFACE(ICameraClient, data, reply);
192 status_t error = data.readInt32();
193 errorCallback(error);
194 return NO_ERROR;
195 } break;
196 case AUTOFOCUS_CALLBACK: {
197 LOGV("AUTOFOCUS_CALLBACK");
198 CHECK_INTERFACE(ICameraClient, data, reply);
199 bool focused = (bool)data.readInt32();
200 autoFocusCallback(focused);
201 return NO_ERROR;
202 } break;
Dave Sparks9b352332009-05-07 12:25:25 -0700203 case NOTIFY_CALLBACK: {
204 LOGV("NOTIFY_CALLBACK");
205 CHECK_INTERFACE(ICameraClient, data, reply);
206 int32_t msgType = data.readInt32();
207 int32_t ext1 = data.readInt32();
208 int32_t ext2 = data.readInt32();
209 notifyCallback(msgType, ext1, ext2);
210 return NO_ERROR;
211 } break;
212 case DATA_CALLBACK: {
213 LOGV("RAW_CALLBACK");
214 CHECK_INTERFACE(ICameraClient, data, reply);
215 int32_t msgType = data.readInt32();
216 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
217 dataCallback(msgType, imageData);
218 return NO_ERROR;
219 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800220 default:
221 return BBinder::onTransact(code, data, reply, flags);
222 }
223}
224
225// ----------------------------------------------------------------------------
226
227}; // namespace android
228