blob: f3804b8cfd494e415583c5989d611a44127f2414 [file] [log] [blame]
Andreas Hubere46b7be2009-07-14 16:56:47 -07001//#define LOG_NDEBUG 0
2#define LOG_TAG "IOMX"
3#include <utils/Log.h>
4
5#include <binder/IMemory.h>
6#include <binder/Parcel.h>
7#include <media/IOMX.h>
Mathias Agopian000479f2010-02-09 17:46:37 -08008#include <surfaceflinger/ISurface.h>
9#include <surfaceflinger/Surface.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070010
11namespace android {
12
13enum {
14 CONNECT = IBinder::FIRST_CALL_TRANSACTION,
Andreas Huberf1fe0642010-01-15 15:28:19 -080015 LIVES_LOCALLY,
Andreas Hubere46b7be2009-07-14 16:56:47 -070016 LIST_NODES,
17 ALLOCATE_NODE,
18 FREE_NODE,
19 SEND_COMMAND,
20 GET_PARAMETER,
21 SET_PARAMETER,
Andreas Huberbe06d262009-08-14 14:37:10 -070022 GET_CONFIG,
23 SET_CONFIG,
Andreas Hubere46b7be2009-07-14 16:56:47 -070024 USE_BUFFER,
25 ALLOC_BUFFER,
26 ALLOC_BUFFER_WITH_BACKUP,
27 FREE_BUFFER,
Andreas Hubere46b7be2009-07-14 16:56:47 -070028 FILL_BUFFER,
29 EMPTY_BUFFER,
Andreas Huberbe06d262009-08-14 14:37:10 -070030 GET_EXTENSION_INDEX,
Andreas Huber1de13162009-07-31 11:52:50 -070031 CREATE_RENDERER,
Andreas Hubere46b7be2009-07-14 16:56:47 -070032 OBSERVER_ON_MSG,
Andreas Huber1de13162009-07-31 11:52:50 -070033 RENDERER_RENDER,
Andreas Hubere46b7be2009-07-14 16:56:47 -070034};
35
Andreas Huberccf8b942009-08-07 12:01:29 -070036sp<IOMXRenderer> IOMX::createRenderer(
37 const sp<Surface> &surface,
38 const char *componentName,
39 OMX_COLOR_FORMATTYPE colorFormat,
40 size_t encodedWidth, size_t encodedHeight,
41 size_t displayWidth, size_t displayHeight) {
42 return createRenderer(
43 surface->getISurface(),
44 componentName, colorFormat, encodedWidth, encodedHeight,
45 displayWidth, displayHeight);
46}
47
Andreas Huber9f9afef2009-09-15 12:49:11 -070048sp<IOMXRenderer> IOMX::createRendererFromJavaSurface(
49 JNIEnv *env, jobject javaSurface,
50 const char *componentName,
51 OMX_COLOR_FORMATTYPE colorFormat,
52 size_t encodedWidth, size_t encodedHeight,
53 size_t displayWidth, size_t displayHeight) {
54 jclass surfaceClass = env->FindClass("android/view/Surface");
55 if (surfaceClass == NULL) {
56 LOGE("Can't find android/view/Surface");
57 return NULL;
58 }
59
Mathias Agopian8b138322010-04-12 16:22:15 -070060 jfieldID surfaceID = env->GetFieldID(surfaceClass, ANDROID_VIEW_SURFACE_JNI_ID, "I");
Andreas Huber9f9afef2009-09-15 12:49:11 -070061 if (surfaceID == NULL) {
62 LOGE("Can't find Surface.mSurface");
63 return NULL;
64 }
65
66 sp<Surface> surface = (Surface *)env->GetIntField(javaSurface, surfaceID);
67
68 return createRenderer(
69 surface, componentName, colorFormat, encodedWidth,
70 encodedHeight, displayWidth, displayHeight);
71}
72
Andreas Hubere46b7be2009-07-14 16:56:47 -070073class BpOMX : public BpInterface<IOMX> {
74public:
75 BpOMX(const sp<IBinder> &impl)
76 : BpInterface<IOMX>(impl) {
77 }
78
Andreas Huberf1fe0642010-01-15 15:28:19 -080079 virtual bool livesLocally(pid_t pid) {
80 Parcel data, reply;
81 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
82 data.writeInt32(pid);
83 remote()->transact(LIVES_LOCALLY, data, &reply);
84
85 return reply.readInt32() != 0;
86 }
87
Andreas Huber2ea14e22009-12-16 09:30:55 -080088 virtual status_t listNodes(List<ComponentInfo> *list) {
Andreas Hubere46b7be2009-07-14 16:56:47 -070089 list->clear();
90
91 Parcel data, reply;
92 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
93 remote()->transact(LIST_NODES, data, &reply);
94
95 int32_t n = reply.readInt32();
96 for (int32_t i = 0; i < n; ++i) {
Andreas Huber2ea14e22009-12-16 09:30:55 -080097 list->push_back(ComponentInfo());
98 ComponentInfo &info = *--list->end();
Andreas Hubere46b7be2009-07-14 16:56:47 -070099
Andreas Huber2ea14e22009-12-16 09:30:55 -0800100 info.mName = reply.readString8();
101 int32_t numRoles = reply.readInt32();
102 for (int32_t j = 0; j < numRoles; ++j) {
103 info.mRoles.push_back(reply.readString8());
104 }
Andreas Hubere46b7be2009-07-14 16:56:47 -0700105 }
106
107 return OK;
108 }
109
Andreas Huber784202e2009-10-15 13:46:54 -0700110 virtual status_t allocateNode(
111 const char *name, const sp<IOMXObserver> &observer, node_id *node) {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700112 Parcel data, reply;
113 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
114 data.writeCString(name);
Andreas Huber784202e2009-10-15 13:46:54 -0700115 data.writeStrongBinder(observer->asBinder());
Andreas Hubere46b7be2009-07-14 16:56:47 -0700116 remote()->transact(ALLOCATE_NODE, data, &reply);
117
118 status_t err = reply.readInt32();
119 if (err == OK) {
Andreas Huber2f10ae02009-08-17 13:33:27 -0700120 *node = (void*)reply.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700121 } else {
122 *node = 0;
123 }
124
125 return err;
126 }
127
Andreas Huber784202e2009-10-15 13:46:54 -0700128 virtual status_t freeNode(node_id node) {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700129 Parcel data, reply;
130 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700131 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700132 remote()->transact(FREE_NODE, data, &reply);
133
134 return reply.readInt32();
135 }
136
Andreas Huber784202e2009-10-15 13:46:54 -0700137 virtual status_t sendCommand(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700138 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) {
139 Parcel data, reply;
140 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700141 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700142 data.writeInt32(cmd);
143 data.writeInt32(param);
144 remote()->transact(SEND_COMMAND, data, &reply);
145
146 return reply.readInt32();
147 }
148
Andreas Huber784202e2009-10-15 13:46:54 -0700149 virtual status_t getParameter(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700150 node_id node, OMX_INDEXTYPE index,
151 void *params, size_t size) {
152 Parcel data, reply;
153 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700154 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700155 data.writeInt32(index);
156 data.writeInt32(size);
157 data.write(params, size);
158 remote()->transact(GET_PARAMETER, data, &reply);
159
160 status_t err = reply.readInt32();
161 if (err != OK) {
162 return err;
163 }
164
165 reply.read(params, size);
166
167 return OK;
168 }
169
Andreas Huber784202e2009-10-15 13:46:54 -0700170 virtual status_t setParameter(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700171 node_id node, OMX_INDEXTYPE index,
172 const void *params, size_t size) {
173 Parcel data, reply;
174 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700175 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700176 data.writeInt32(index);
177 data.writeInt32(size);
178 data.write(params, size);
179 remote()->transact(SET_PARAMETER, data, &reply);
180
181 return reply.readInt32();
182 }
183
Andreas Huber784202e2009-10-15 13:46:54 -0700184 virtual status_t getConfig(
Andreas Huberbe06d262009-08-14 14:37:10 -0700185 node_id node, OMX_INDEXTYPE index,
186 void *params, size_t size) {
187 Parcel data, reply;
188 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700189 data.writeIntPtr((intptr_t)node);
Andreas Huberbe06d262009-08-14 14:37:10 -0700190 data.writeInt32(index);
191 data.writeInt32(size);
192 data.write(params, size);
193 remote()->transact(GET_CONFIG, data, &reply);
194
195 status_t err = reply.readInt32();
196 if (err != OK) {
197 return err;
198 }
199
200 reply.read(params, size);
201
202 return OK;
203 }
204
Andreas Huber784202e2009-10-15 13:46:54 -0700205 virtual status_t setConfig(
Andreas Huberbe06d262009-08-14 14:37:10 -0700206 node_id node, OMX_INDEXTYPE index,
207 const void *params, size_t size) {
208 Parcel data, reply;
209 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700210 data.writeIntPtr((intptr_t)node);
Andreas Huberbe06d262009-08-14 14:37:10 -0700211 data.writeInt32(index);
212 data.writeInt32(size);
213 data.write(params, size);
214 remote()->transact(SET_CONFIG, data, &reply);
215
216 return reply.readInt32();
217 }
218
Andreas Huber784202e2009-10-15 13:46:54 -0700219 virtual status_t useBuffer(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700220 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
221 buffer_id *buffer) {
222 Parcel data, reply;
223 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700224 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700225 data.writeInt32(port_index);
226 data.writeStrongBinder(params->asBinder());
227 remote()->transact(USE_BUFFER, data, &reply);
228
229 status_t err = reply.readInt32();
230 if (err != OK) {
231 *buffer = 0;
232
233 return err;
234 }
235
Andreas Huber2f10ae02009-08-17 13:33:27 -0700236 *buffer = (void*)reply.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700237
238 return err;
239 }
240
Andreas Huber784202e2009-10-15 13:46:54 -0700241 virtual status_t allocateBuffer(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700242 node_id node, OMX_U32 port_index, size_t size,
Andreas Huberc712b9f2010-01-20 15:05:46 -0800243 buffer_id *buffer, void **buffer_data) {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700244 Parcel data, reply;
245 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700246 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700247 data.writeInt32(port_index);
248 data.writeInt32(size);
249 remote()->transact(ALLOC_BUFFER, data, &reply);
250
251 status_t err = reply.readInt32();
252 if (err != OK) {
253 *buffer = 0;
254
255 return err;
256 }
257
Andreas Huberc712b9f2010-01-20 15:05:46 -0800258 *buffer = (void *)reply.readIntPtr();
259 *buffer_data = (void *)reply.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700260
261 return err;
262 }
263
Andreas Huber784202e2009-10-15 13:46:54 -0700264 virtual status_t allocateBufferWithBackup(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700265 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
266 buffer_id *buffer) {
267 Parcel data, reply;
268 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700269 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700270 data.writeInt32(port_index);
271 data.writeStrongBinder(params->asBinder());
272 remote()->transact(ALLOC_BUFFER_WITH_BACKUP, data, &reply);
273
274 status_t err = reply.readInt32();
275 if (err != OK) {
276 *buffer = 0;
277
278 return err;
279 }
280
Andreas Huber2f10ae02009-08-17 13:33:27 -0700281 *buffer = (void*)reply.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700282
283 return err;
284 }
285
Andreas Huber784202e2009-10-15 13:46:54 -0700286 virtual status_t freeBuffer(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700287 node_id node, OMX_U32 port_index, buffer_id buffer) {
288 Parcel data, reply;
289 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700290 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700291 data.writeInt32(port_index);
Andreas Huber2f10ae02009-08-17 13:33:27 -0700292 data.writeIntPtr((intptr_t)buffer);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700293 remote()->transact(FREE_BUFFER, data, &reply);
294
295 return reply.readInt32();
296 }
297
Andreas Huber784202e2009-10-15 13:46:54 -0700298 virtual status_t fillBuffer(node_id node, buffer_id buffer) {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700299 Parcel data, reply;
300 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700301 data.writeIntPtr((intptr_t)node);
302 data.writeIntPtr((intptr_t)buffer);
Andreas Huber3f427072009-10-08 11:02:27 -0700303 remote()->transact(FILL_BUFFER, data, &reply);
304
305 return reply.readInt32();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700306 }
307
Andreas Huber784202e2009-10-15 13:46:54 -0700308 virtual status_t emptyBuffer(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700309 node_id node,
310 buffer_id buffer,
311 OMX_U32 range_offset, OMX_U32 range_length,
312 OMX_U32 flags, OMX_TICKS timestamp) {
313 Parcel data, reply;
314 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700315 data.writeIntPtr((intptr_t)node);
316 data.writeIntPtr((intptr_t)buffer);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700317 data.writeInt32(range_offset);
318 data.writeInt32(range_length);
319 data.writeInt32(flags);
320 data.writeInt64(timestamp);
Andreas Huber3f427072009-10-08 11:02:27 -0700321 remote()->transact(EMPTY_BUFFER, data, &reply);
322
323 return reply.readInt32();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700324 }
Andreas Huber1de13162009-07-31 11:52:50 -0700325
Andreas Huber784202e2009-10-15 13:46:54 -0700326 virtual status_t getExtensionIndex(
Andreas Huberbe06d262009-08-14 14:37:10 -0700327 node_id node,
328 const char *parameter_name,
329 OMX_INDEXTYPE *index) {
330 Parcel data, reply;
331 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700332 data.writeIntPtr((intptr_t)node);
Andreas Huberbe06d262009-08-14 14:37:10 -0700333 data.writeCString(parameter_name);
334
335 remote()->transact(GET_EXTENSION_INDEX, data, &reply);
336
337 status_t err = reply.readInt32();
338 if (err == OK) {
339 *index = static_cast<OMX_INDEXTYPE>(reply.readInt32());
340 } else {
341 *index = OMX_IndexComponentStartUnused;
342 }
343
344 return err;
345 }
346
Andreas Huber1de13162009-07-31 11:52:50 -0700347 virtual sp<IOMXRenderer> createRenderer(
348 const sp<ISurface> &surface,
349 const char *componentName,
350 OMX_COLOR_FORMATTYPE colorFormat,
351 size_t encodedWidth, size_t encodedHeight,
352 size_t displayWidth, size_t displayHeight) {
353 Parcel data, reply;
354 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
355
356 data.writeStrongBinder(surface->asBinder());
357 data.writeCString(componentName);
358 data.writeInt32(colorFormat);
359 data.writeInt32(encodedWidth);
360 data.writeInt32(encodedHeight);
361 data.writeInt32(displayWidth);
362 data.writeInt32(displayHeight);
363
364 remote()->transact(CREATE_RENDERER, data, &reply);
365
366 return interface_cast<IOMXRenderer>(reply.readStrongBinder());
367 }
Andreas Hubere46b7be2009-07-14 16:56:47 -0700368};
369
370IMPLEMENT_META_INTERFACE(OMX, "android.hardware.IOMX");
371
372////////////////////////////////////////////////////////////////////////////////
373
374#define CHECK_INTERFACE(interface, data, reply) \
375 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
376 LOGW("Call incorrectly routed to " #interface); \
377 return PERMISSION_DENIED; \
378 } } while (0)
379
380status_t BnOMX::onTransact(
381 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
382 switch (code) {
Andreas Huberf1fe0642010-01-15 15:28:19 -0800383 case LIVES_LOCALLY:
384 {
385 CHECK_INTERFACE(IOMX, data, reply);
386 reply->writeInt32(livesLocally((pid_t)data.readInt32()));
387
388 return OK;
389 }
390
Andreas Hubere46b7be2009-07-14 16:56:47 -0700391 case LIST_NODES:
392 {
393 CHECK_INTERFACE(IOMX, data, reply);
394
Andreas Huber2ea14e22009-12-16 09:30:55 -0800395 List<ComponentInfo> list;
Andreas Huber784202e2009-10-15 13:46:54 -0700396 listNodes(&list);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700397
398 reply->writeInt32(list.size());
Andreas Huber2ea14e22009-12-16 09:30:55 -0800399 for (List<ComponentInfo>::iterator it = list.begin();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700400 it != list.end(); ++it) {
Andreas Huber2ea14e22009-12-16 09:30:55 -0800401 ComponentInfo &cur = *it;
402
403 reply->writeString8(cur.mName);
404 reply->writeInt32(cur.mRoles.size());
405 for (List<String8>::iterator role_it = cur.mRoles.begin();
406 role_it != cur.mRoles.end(); ++role_it) {
407 reply->writeString8(*role_it);
408 }
Andreas Hubere46b7be2009-07-14 16:56:47 -0700409 }
410
411 return NO_ERROR;
412 }
413
414 case ALLOCATE_NODE:
415 {
416 CHECK_INTERFACE(IOMX, data, reply);
417
Andreas Huber784202e2009-10-15 13:46:54 -0700418 const char *name = data.readCString();
419
420 sp<IOMXObserver> observer =
421 interface_cast<IOMXObserver>(data.readStrongBinder());
422
Andreas Hubere46b7be2009-07-14 16:56:47 -0700423 node_id node;
Andreas Huber784202e2009-10-15 13:46:54 -0700424
425 status_t err = allocateNode(name, observer, &node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700426 reply->writeInt32(err);
427 if (err == OK) {
Andreas Huber2f10ae02009-08-17 13:33:27 -0700428 reply->writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700429 }
Andreas Huberf1fe0642010-01-15 15:28:19 -0800430
Andreas Hubere46b7be2009-07-14 16:56:47 -0700431 return NO_ERROR;
432 }
433
434 case FREE_NODE:
435 {
436 CHECK_INTERFACE(IOMX, data, reply);
437
Andreas Huber2f10ae02009-08-17 13:33:27 -0700438 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700439
Andreas Huber784202e2009-10-15 13:46:54 -0700440 reply->writeInt32(freeNode(node));
Andreas Huberf1fe0642010-01-15 15:28:19 -0800441
Andreas Hubere46b7be2009-07-14 16:56:47 -0700442 return NO_ERROR;
443 }
444
445 case SEND_COMMAND:
446 {
447 CHECK_INTERFACE(IOMX, data, reply);
448
Andreas Huber2f10ae02009-08-17 13:33:27 -0700449 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700450
451 OMX_COMMANDTYPE cmd =
452 static_cast<OMX_COMMANDTYPE>(data.readInt32());
453
454 OMX_S32 param = data.readInt32();
Andreas Huber784202e2009-10-15 13:46:54 -0700455 reply->writeInt32(sendCommand(node, cmd, param));
Andreas Hubere46b7be2009-07-14 16:56:47 -0700456
457 return NO_ERROR;
458 }
459
460 case GET_PARAMETER:
461 {
462 CHECK_INTERFACE(IOMX, data, reply);
463
Andreas Huber2f10ae02009-08-17 13:33:27 -0700464 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700465 OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32());
466
467 size_t size = data.readInt32();
468
469 // XXX I am not happy with this but Parcel::readInplace didn't work.
470 void *params = malloc(size);
471 data.read(params, size);
472
Andreas Huber784202e2009-10-15 13:46:54 -0700473 status_t err = getParameter(node, index, params, size);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700474
475 reply->writeInt32(err);
476
477 if (err == OK) {
478 reply->write(params, size);
479 }
480
481 free(params);
482 params = NULL;
483
484 return NO_ERROR;
485 }
486
487 case SET_PARAMETER:
488 {
489 CHECK_INTERFACE(IOMX, data, reply);
490
Andreas Huber2f10ae02009-08-17 13:33:27 -0700491 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700492 OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32());
493
494 size_t size = data.readInt32();
495 void *params = const_cast<void *>(data.readInplace(size));
496
Andreas Huber784202e2009-10-15 13:46:54 -0700497 reply->writeInt32(setParameter(node, index, params, size));
Andreas Hubere46b7be2009-07-14 16:56:47 -0700498
499 return NO_ERROR;
500 }
501
Andreas Huberbe06d262009-08-14 14:37:10 -0700502 case GET_CONFIG:
503 {
504 CHECK_INTERFACE(IOMX, data, reply);
505
Andreas Huber2f10ae02009-08-17 13:33:27 -0700506 node_id node = (void*)data.readIntPtr();
Andreas Huberbe06d262009-08-14 14:37:10 -0700507 OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32());
508
509 size_t size = data.readInt32();
510
511 // XXX I am not happy with this but Parcel::readInplace didn't work.
512 void *params = malloc(size);
513 data.read(params, size);
514
Andreas Huber784202e2009-10-15 13:46:54 -0700515 status_t err = getConfig(node, index, params, size);
Andreas Huberbe06d262009-08-14 14:37:10 -0700516
517 reply->writeInt32(err);
518
519 if (err == OK) {
520 reply->write(params, size);
521 }
522
523 free(params);
524 params = NULL;
525
526 return NO_ERROR;
527 }
528
529 case SET_CONFIG:
530 {
531 CHECK_INTERFACE(IOMX, data, reply);
532
Andreas Huber2f10ae02009-08-17 13:33:27 -0700533 node_id node = (void*)data.readIntPtr();
Andreas Huberbe06d262009-08-14 14:37:10 -0700534 OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32());
535
536 size_t size = data.readInt32();
537 void *params = const_cast<void *>(data.readInplace(size));
538
Andreas Huber784202e2009-10-15 13:46:54 -0700539 reply->writeInt32(setConfig(node, index, params, size));
Andreas Huberbe06d262009-08-14 14:37:10 -0700540
541 return NO_ERROR;
542 }
543
Andreas Hubere46b7be2009-07-14 16:56:47 -0700544 case USE_BUFFER:
545 {
546 CHECK_INTERFACE(IOMX, data, reply);
547
Andreas Huber2f10ae02009-08-17 13:33:27 -0700548 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700549 OMX_U32 port_index = data.readInt32();
550 sp<IMemory> params =
551 interface_cast<IMemory>(data.readStrongBinder());
552
553 buffer_id buffer;
Andreas Huber784202e2009-10-15 13:46:54 -0700554 status_t err = useBuffer(node, port_index, params, &buffer);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700555 reply->writeInt32(err);
556
557 if (err == OK) {
Andreas Huber2f10ae02009-08-17 13:33:27 -0700558 reply->writeIntPtr((intptr_t)buffer);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700559 }
560
561 return NO_ERROR;
562 }
563
564 case ALLOC_BUFFER:
565 {
566 CHECK_INTERFACE(IOMX, data, reply);
567
Andreas Huber2f10ae02009-08-17 13:33:27 -0700568 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700569 OMX_U32 port_index = data.readInt32();
570 size_t size = data.readInt32();
571
572 buffer_id buffer;
Andreas Huberc712b9f2010-01-20 15:05:46 -0800573 void *buffer_data;
574 status_t err = allocateBuffer(
575 node, port_index, size, &buffer, &buffer_data);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700576 reply->writeInt32(err);
577
578 if (err == OK) {
Andreas Huber2f10ae02009-08-17 13:33:27 -0700579 reply->writeIntPtr((intptr_t)buffer);
Andreas Huberc712b9f2010-01-20 15:05:46 -0800580 reply->writeIntPtr((intptr_t)buffer_data);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700581 }
582
583 return NO_ERROR;
584 }
585
586 case ALLOC_BUFFER_WITH_BACKUP:
587 {
588 CHECK_INTERFACE(IOMX, data, reply);
589
Andreas Huber2f10ae02009-08-17 13:33:27 -0700590 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700591 OMX_U32 port_index = data.readInt32();
592 sp<IMemory> params =
593 interface_cast<IMemory>(data.readStrongBinder());
594
595 buffer_id buffer;
Andreas Huber784202e2009-10-15 13:46:54 -0700596 status_t err = allocateBufferWithBackup(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700597 node, port_index, params, &buffer);
598
599 reply->writeInt32(err);
600
601 if (err == OK) {
Andreas Huber2f10ae02009-08-17 13:33:27 -0700602 reply->writeIntPtr((intptr_t)buffer);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700603 }
604
605 return NO_ERROR;
606 }
607
608 case FREE_BUFFER:
609 {
610 CHECK_INTERFACE(IOMX, data, reply);
611
Andreas Huber2f10ae02009-08-17 13:33:27 -0700612 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700613 OMX_U32 port_index = data.readInt32();
Andreas Huber2f10ae02009-08-17 13:33:27 -0700614 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber784202e2009-10-15 13:46:54 -0700615 reply->writeInt32(freeBuffer(node, port_index, buffer));
Andreas Hubere46b7be2009-07-14 16:56:47 -0700616
617 return NO_ERROR;
618 }
619
620 case FILL_BUFFER:
621 {
622 CHECK_INTERFACE(IOMX, data, reply);
623
Andreas Huber2f10ae02009-08-17 13:33:27 -0700624 node_id node = (void*)data.readIntPtr();
625 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber784202e2009-10-15 13:46:54 -0700626 reply->writeInt32(fillBuffer(node, buffer));
Andreas Hubere46b7be2009-07-14 16:56:47 -0700627
628 return NO_ERROR;
629 }
630
631 case EMPTY_BUFFER:
632 {
633 CHECK_INTERFACE(IOMX, data, reply);
634
Andreas Huber2f10ae02009-08-17 13:33:27 -0700635 node_id node = (void*)data.readIntPtr();
636 buffer_id buffer = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700637 OMX_U32 range_offset = data.readInt32();
638 OMX_U32 range_length = data.readInt32();
639 OMX_U32 flags = data.readInt32();
640 OMX_TICKS timestamp = data.readInt64();
641
Andreas Huber3f427072009-10-08 11:02:27 -0700642 reply->writeInt32(
Andreas Huber784202e2009-10-15 13:46:54 -0700643 emptyBuffer(
Andreas Huber3f427072009-10-08 11:02:27 -0700644 node, buffer, range_offset, range_length,
645 flags, timestamp));
Andreas Hubere46b7be2009-07-14 16:56:47 -0700646
647 return NO_ERROR;
648 }
Andreas Hubere46b7be2009-07-14 16:56:47 -0700649
Andreas Huberbe06d262009-08-14 14:37:10 -0700650 case GET_EXTENSION_INDEX:
651 {
652 CHECK_INTERFACE(IOMX, data, reply);
653
Andreas Huber2f10ae02009-08-17 13:33:27 -0700654 node_id node = (void*)data.readIntPtr();
Andreas Huberbe06d262009-08-14 14:37:10 -0700655 const char *parameter_name = data.readCString();
Andreas Huberf1fe0642010-01-15 15:28:19 -0800656
Andreas Huberbe06d262009-08-14 14:37:10 -0700657 OMX_INDEXTYPE index;
Andreas Huber784202e2009-10-15 13:46:54 -0700658 status_t err = getExtensionIndex(node, parameter_name, &index);
Andreas Huberbe06d262009-08-14 14:37:10 -0700659
660 reply->writeInt32(err);
661
662 if (err == OK) {
663 reply->writeInt32(index);
664 }
665
666 return OK;
667 }
668
Andreas Huber1de13162009-07-31 11:52:50 -0700669 case CREATE_RENDERER:
670 {
671 CHECK_INTERFACE(IOMX, data, reply);
672
673 sp<ISurface> isurface =
674 interface_cast<ISurface>(data.readStrongBinder());
675
676 const char *componentName = data.readCString();
677
678 OMX_COLOR_FORMATTYPE colorFormat =
679 static_cast<OMX_COLOR_FORMATTYPE>(data.readInt32());
680
681 size_t encodedWidth = (size_t)data.readInt32();
682 size_t encodedHeight = (size_t)data.readInt32();
683 size_t displayWidth = (size_t)data.readInt32();
684 size_t displayHeight = (size_t)data.readInt32();
685
686 sp<IOMXRenderer> renderer =
687 createRenderer(isurface, componentName, colorFormat,
688 encodedWidth, encodedHeight,
689 displayWidth, displayHeight);
690
691 reply->writeStrongBinder(renderer->asBinder());
692
693 return OK;
694 }
695
Andreas Hubere46b7be2009-07-14 16:56:47 -0700696 default:
697 return BBinder::onTransact(code, data, reply, flags);
698 }
699}
700
701////////////////////////////////////////////////////////////////////////////////
702
703class BpOMXObserver : public BpInterface<IOMXObserver> {
704public:
705 BpOMXObserver(const sp<IBinder> &impl)
706 : BpInterface<IOMXObserver>(impl) {
707 }
708
Andreas Huber784202e2009-10-15 13:46:54 -0700709 virtual void onMessage(const omx_message &msg) {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700710 Parcel data, reply;
711 data.writeInterfaceToken(IOMXObserver::getInterfaceDescriptor());
712 data.write(&msg, sizeof(msg));
713
714 remote()->transact(OBSERVER_ON_MSG, data, &reply, IBinder::FLAG_ONEWAY);
715 }
716};
717
718IMPLEMENT_META_INTERFACE(OMXObserver, "android.hardware.IOMXObserver");
719
720status_t BnOMXObserver::onTransact(
721 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
722 switch (code) {
723 case OBSERVER_ON_MSG:
724 {
725 CHECK_INTERFACE(IOMXObserver, data, reply);
726
727 omx_message msg;
728 data.read(&msg, sizeof(msg));
729
730 // XXX Could use readInplace maybe?
Andreas Huber784202e2009-10-15 13:46:54 -0700731 onMessage(msg);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700732
733 return NO_ERROR;
734 }
735
736 default:
737 return BBinder::onTransact(code, data, reply, flags);
738 }
739}
740
Andreas Huber1de13162009-07-31 11:52:50 -0700741////////////////////////////////////////////////////////////////////////////////
742
743class BpOMXRenderer : public BpInterface<IOMXRenderer> {
744public:
745 BpOMXRenderer(const sp<IBinder> &impl)
746 : BpInterface<IOMXRenderer>(impl) {
747 }
748
749 virtual void render(IOMX::buffer_id buffer) {
750 Parcel data, reply;
751 data.writeInterfaceToken(IOMXRenderer::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700752 data.writeIntPtr((intptr_t)buffer);
Andreas Huber1de13162009-07-31 11:52:50 -0700753
754 // NOTE: Do NOT make this a ONE_WAY call, it must be synchronous
755 // so that the caller knows when to recycle the buffer.
756 remote()->transact(RENDERER_RENDER, data, &reply);
757 }
758};
759
760IMPLEMENT_META_INTERFACE(OMXRenderer, "android.hardware.IOMXRenderer");
761
762status_t BnOMXRenderer::onTransact(
763 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
764 switch (code) {
765 case RENDERER_RENDER:
766 {
767 CHECK_INTERFACE(IOMXRenderer, data, reply);
768
Andreas Huber2f10ae02009-08-17 13:33:27 -0700769 IOMX::buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber1de13162009-07-31 11:52:50 -0700770
771 render(buffer);
772
773 return NO_ERROR;
774 }
775
776 default:
777 return BBinder::onTransact(code, data, reply, flags);
778 }
779}
780
Andreas Hubere46b7be2009-07-14 16:56:47 -0700781} // namespace android