blob: ae4cf698e0906d433eedd91accd9ccfca6a787f7 [file] [log] [blame]
Igor Murashkine7ee7632013-06-11 18:10:18 -07001/*
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 "ICameraDeviceUser"
20#include <utils/Log.h>
21#include <stdint.h>
22#include <sys/types.h>
23#include <binder/Parcel.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070024#include <camera/camera2/ICameraDeviceUser.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070025#include <gui/IGraphicBufferProducer.h>
26#include <gui/Surface.h>
27#include <camera/CameraMetadata.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070028#include <camera/camera2/CaptureRequest.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070029
30namespace android {
31
32typedef Parcel::WritableBlob WritableBlob;
33typedef Parcel::ReadableBlob ReadableBlob;
34
35enum {
36 DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
37 SUBMIT_REQUEST,
38 CANCEL_REQUEST,
39 DELETE_STREAM,
40 CREATE_STREAM,
41 CREATE_DEFAULT_REQUEST,
42 GET_CAMERA_INFO,
Zhijun He2ab500c2013-07-23 08:02:53 -070043 WAIT_UNTIL_IDLE,
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -070044 FLUSH
Igor Murashkine7ee7632013-06-11 18:10:18 -070045};
46
47class BpCameraDeviceUser : public BpInterface<ICameraDeviceUser>
48{
49public:
50 BpCameraDeviceUser(const sp<IBinder>& impl)
51 : BpInterface<ICameraDeviceUser>(impl)
52 {
53 }
54
55 // disconnect from camera service
56 void disconnect()
57 {
58 ALOGV("disconnect");
59 Parcel data, reply;
60 data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
61 remote()->transact(DISCONNECT, data, &reply);
62 reply.readExceptionCode();
63 }
64
65 virtual int submitRequest(sp<CaptureRequest> request, bool streaming)
66 {
67 Parcel data, reply;
68 data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
69
70 // arg0 = CaptureRequest
71 if (request != 0) {
72 data.writeInt32(1);
73 request->writeToParcel(&data);
74 } else {
75 data.writeInt32(0);
76 }
77
78 // arg1 = streaming (bool)
79 data.writeInt32(streaming);
80
81 remote()->transact(SUBMIT_REQUEST, data, &reply);
82
83 reply.readExceptionCode();
84 return reply.readInt32();
85 }
86
87 virtual status_t cancelRequest(int requestId)
88 {
89 Parcel data, reply;
90 data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
91 data.writeInt32(requestId);
92
93 remote()->transact(CANCEL_REQUEST, data, &reply);
94
95 reply.readExceptionCode();
96 return reply.readInt32();
97 }
98
99 virtual status_t deleteStream(int streamId)
100 {
101 Parcel data, reply;
102 data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
103 data.writeInt32(streamId);
104
105 remote()->transact(DELETE_STREAM, data, &reply);
106
107 reply.readExceptionCode();
108 return reply.readInt32();
109 }
110
111 virtual status_t createStream(int width, int height, int format,
112 const sp<IGraphicBufferProducer>& bufferProducer)
113 {
114 Parcel data, reply;
115 data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
116 data.writeInt32(width);
117 data.writeInt32(height);
118 data.writeInt32(format);
119
120 data.writeInt32(1); // marker that bufferProducer is not null
121 data.writeString16(String16("unknown_name")); // name of surface
122 sp<IBinder> b(bufferProducer->asBinder());
123 data.writeStrongBinder(b);
124
125 remote()->transact(CREATE_STREAM, data, &reply);
126
127 reply.readExceptionCode();
128 return reply.readInt32();
129 }
130
131 // Create a request object from a template.
132 virtual status_t createDefaultRequest(int templateId,
133 /*out*/
134 CameraMetadata* request)
135 {
136 Parcel data, reply;
137 data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
138 data.writeInt32(templateId);
139 remote()->transact(CREATE_DEFAULT_REQUEST, data, &reply);
140
141 reply.readExceptionCode();
142 status_t result = reply.readInt32();
143
144 CameraMetadata out;
145 if (reply.readInt32() != 0) {
146 out.readFromParcel(&reply);
147 }
148
149 if (request != NULL) {
150 request->swap(out);
151 }
152 return result;
153 }
154
155
Igor Murashkin099b4572013-07-12 17:52:16 -0700156 virtual status_t getCameraInfo(CameraMetadata* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -0700157 {
158 Parcel data, reply;
159 data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700160 remote()->transact(GET_CAMERA_INFO, data, &reply);
161
Igor Murashkine7ee7632013-06-11 18:10:18 -0700162 reply.readExceptionCode();
163 status_t result = reply.readInt32();
164
Igor Murashkin099b4572013-07-12 17:52:16 -0700165 CameraMetadata out;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700166 if (reply.readInt32() != 0) {
Igor Murashkin099b4572013-07-12 17:52:16 -0700167 out.readFromParcel(&reply);
168 }
169
170 if (info != NULL) {
171 info->swap(out);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700172 }
173
174 return result;
175 }
176
Zhijun He2ab500c2013-07-23 08:02:53 -0700177 virtual status_t waitUntilIdle()
178 {
179 ALOGV("waitUntilIdle");
180 Parcel data, reply;
181 data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
182 remote()->transact(WAIT_UNTIL_IDLE, data, &reply);
183 reply.readExceptionCode();
184 return reply.readInt32();
185 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700186
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700187 virtual status_t flush()
188 {
189 ALOGV("flush");
190 Parcel data, reply;
191 data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
192 remote()->transact(FLUSH, data, &reply);
193 reply.readExceptionCode();
194 return reply.readInt32();
195 }
196
Igor Murashkine7ee7632013-06-11 18:10:18 -0700197private:
198
199
200};
201
202IMPLEMENT_META_INTERFACE(CameraDeviceUser,
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700203 "android.hardware.camera2.ICameraDeviceUser");
Igor Murashkine7ee7632013-06-11 18:10:18 -0700204
205// ----------------------------------------------------------------------
206
207status_t BnCameraDeviceUser::onTransact(
208 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
209{
210 switch(code) {
211 case DISCONNECT: {
212 ALOGV("DISCONNECT");
213 CHECK_INTERFACE(ICameraDeviceUser, data, reply);
214 disconnect();
215 reply->writeNoException();
216 return NO_ERROR;
217 } break;
218 case SUBMIT_REQUEST: {
219 CHECK_INTERFACE(ICameraDeviceUser, data, reply);
220
221 // arg0 = request
222 sp<CaptureRequest> request;
223 if (data.readInt32() != 0) {
224 request = new CaptureRequest();
225 request->readFromParcel(const_cast<Parcel*>(&data));
226 }
227
228 // arg1 = streaming (bool)
229 bool streaming = data.readInt32();
230
231 // return code: requestId (int32)
232 reply->writeNoException();
233 reply->writeInt32(submitRequest(request, streaming));
234
235 return NO_ERROR;
236 } break;
237 case CANCEL_REQUEST: {
238 CHECK_INTERFACE(ICameraDeviceUser, data, reply);
239 int requestId = data.readInt32();
240 reply->writeNoException();
241 reply->writeInt32(cancelRequest(requestId));
242 return NO_ERROR;
243 } break;
244 case DELETE_STREAM: {
245 CHECK_INTERFACE(ICameraDeviceUser, data, reply);
246 int streamId = data.readInt32();
247 reply->writeNoException();
248 reply->writeInt32(deleteStream(streamId));
249 return NO_ERROR;
250 } break;
251 case CREATE_STREAM: {
252 CHECK_INTERFACE(ICameraDeviceUser, data, reply);
253 int width, height, format;
254
255 width = data.readInt32();
256 ALOGV("%s: CREATE_STREAM: width = %d", __FUNCTION__, width);
257 height = data.readInt32();
258 ALOGV("%s: CREATE_STREAM: height = %d", __FUNCTION__, height);
259 format = data.readInt32();
260 ALOGV("%s: CREATE_STREAM: format = %d", __FUNCTION__, format);
261
262 sp<IGraphicBufferProducer> bp;
263 if (data.readInt32() != 0) {
264 String16 name = data.readString16();
265 bp = interface_cast<IGraphicBufferProducer>(
266 data.readStrongBinder());
267
268 ALOGV("%s: CREATE_STREAM: bp = %p, name = %s", __FUNCTION__,
269 bp.get(), String8(name).string());
270 } else {
271 ALOGV("%s: CREATE_STREAM: bp = unset, name = unset",
272 __FUNCTION__);
273 }
274
275 status_t ret;
276 ret = createStream(width, height, format, bp);
277
278 reply->writeNoException();
279 ALOGV("%s: CREATE_STREAM: write noException", __FUNCTION__);
280 reply->writeInt32(ret);
281 ALOGV("%s: CREATE_STREAM: write ret = %d", __FUNCTION__, ret);
282
283 return NO_ERROR;
284 } break;
285
286 case CREATE_DEFAULT_REQUEST: {
287 CHECK_INTERFACE(ICameraDeviceUser, data, reply);
288
289 int templateId = data.readInt32();
290
291 CameraMetadata request;
292 status_t ret;
293 ret = createDefaultRequest(templateId, &request);
294
295 reply->writeNoException();
296 reply->writeInt32(ret);
297
Igor Murashkin099b4572013-07-12 17:52:16 -0700298 // out-variables are after exception and return value
Igor Murashkine7ee7632013-06-11 18:10:18 -0700299 reply->writeInt32(1); // to mark presence of metadata object
300 request.writeToParcel(const_cast<Parcel*>(reply));
301
302 return NO_ERROR;
303 } break;
304 case GET_CAMERA_INFO: {
305 CHECK_INTERFACE(ICameraDeviceUser, data, reply);
306
Igor Murashkin099b4572013-07-12 17:52:16 -0700307 CameraMetadata info;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700308 status_t ret;
Igor Murashkin099b4572013-07-12 17:52:16 -0700309 ret = getCameraInfo(&info);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700310
311 reply->writeNoException();
312 reply->writeInt32(ret);
313
Igor Murashkin099b4572013-07-12 17:52:16 -0700314 // out-variables are after exception and return value
315 reply->writeInt32(1); // to mark presence of metadata object
316 info.writeToParcel(reply);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700317
318 return NO_ERROR;
319 } break;
Zhijun He2ab500c2013-07-23 08:02:53 -0700320 case WAIT_UNTIL_IDLE: {
321 CHECK_INTERFACE(ICameraDeviceUser, data, reply);
322 reply->writeNoException();
323 reply->writeInt32(waitUntilIdle());
324 return NO_ERROR;
325 } break;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700326 case FLUSH: {
327 CHECK_INTERFACE(ICameraDeviceUser, data, reply);
328 reply->writeNoException();
329 reply->writeInt32(flush());
330 return NO_ERROR;
331 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700332 default:
333 return BBinder::onTransact(code, data, reply, flags);
334 }
335}
336
337// ----------------------------------------------------------------------------
338
339}; // namespace android