blob: af67175dbb0b6805178c6fe33ad7b930d588372b [file] [log] [blame]
Andreas Huber20111aa2009-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>
Andreas Huberb3912902011-01-19 10:34:52 -08008#include <media/stagefright/foundation/ADebug.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -08009#include <surfaceflinger/ISurface.h>
10#include <surfaceflinger/Surface.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070011
12namespace android {
13
14enum {
15 CONNECT = IBinder::FIRST_CALL_TRANSACTION,
Andreas Huber7eaa9c92010-01-15 15:28:19 -080016 LIVES_LOCALLY,
Andreas Huber20111aa2009-07-14 16:56:47 -070017 LIST_NODES,
18 ALLOCATE_NODE,
19 FREE_NODE,
20 SEND_COMMAND,
21 GET_PARAMETER,
22 SET_PARAMETER,
Andreas Huber693d2712009-08-14 14:37:10 -070023 GET_CONFIG,
24 SET_CONFIG,
Jamie Gennis83750ea2010-08-30 16:48:38 -070025 ENABLE_GRAPHIC_BUFFERS,
Andreas Huber20111aa2009-07-14 16:56:47 -070026 USE_BUFFER,
Jamie Gennis83750ea2010-08-30 16:48:38 -070027 USE_GRAPHIC_BUFFER,
James Donge8707722010-10-20 17:38:41 -070028 STORE_META_DATA_IN_BUFFERS,
Andreas Huber20111aa2009-07-14 16:56:47 -070029 ALLOC_BUFFER,
30 ALLOC_BUFFER_WITH_BACKUP,
31 FREE_BUFFER,
Andreas Huber20111aa2009-07-14 16:56:47 -070032 FILL_BUFFER,
33 EMPTY_BUFFER,
Andreas Huber693d2712009-08-14 14:37:10 -070034 GET_EXTENSION_INDEX,
Andreas Huber20111aa2009-07-14 16:56:47 -070035 OBSERVER_ON_MSG,
36};
37
Andreas Huber20111aa2009-07-14 16:56:47 -070038class BpOMX : public BpInterface<IOMX> {
39public:
40 BpOMX(const sp<IBinder> &impl)
41 : BpInterface<IOMX>(impl) {
42 }
43
Andreas Huber7eaa9c92010-01-15 15:28:19 -080044 virtual bool livesLocally(pid_t pid) {
45 Parcel data, reply;
46 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
47 data.writeInt32(pid);
48 remote()->transact(LIVES_LOCALLY, data, &reply);
49
50 return reply.readInt32() != 0;
51 }
52
Andreas Huber134ee6a2009-12-16 09:30:55 -080053 virtual status_t listNodes(List<ComponentInfo> *list) {
Andreas Huber20111aa2009-07-14 16:56:47 -070054 list->clear();
55
56 Parcel data, reply;
57 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
58 remote()->transact(LIST_NODES, data, &reply);
59
60 int32_t n = reply.readInt32();
61 for (int32_t i = 0; i < n; ++i) {
Andreas Huber134ee6a2009-12-16 09:30:55 -080062 list->push_back(ComponentInfo());
63 ComponentInfo &info = *--list->end();
Andreas Huber20111aa2009-07-14 16:56:47 -070064
Andreas Huber134ee6a2009-12-16 09:30:55 -080065 info.mName = reply.readString8();
66 int32_t numRoles = reply.readInt32();
67 for (int32_t j = 0; j < numRoles; ++j) {
68 info.mRoles.push_back(reply.readString8());
69 }
Andreas Huber20111aa2009-07-14 16:56:47 -070070 }
71
72 return OK;
73 }
74
Andreas Huber318ad9c2009-10-15 13:46:54 -070075 virtual status_t allocateNode(
76 const char *name, const sp<IOMXObserver> &observer, node_id *node) {
Andreas Huber20111aa2009-07-14 16:56:47 -070077 Parcel data, reply;
78 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
79 data.writeCString(name);
Andreas Huber318ad9c2009-10-15 13:46:54 -070080 data.writeStrongBinder(observer->asBinder());
Andreas Huber20111aa2009-07-14 16:56:47 -070081 remote()->transact(ALLOCATE_NODE, data, &reply);
82
83 status_t err = reply.readInt32();
84 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -070085 *node = (void*)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -070086 } else {
87 *node = 0;
88 }
89
90 return err;
91 }
92
Andreas Huber318ad9c2009-10-15 13:46:54 -070093 virtual status_t freeNode(node_id node) {
Andreas Huber20111aa2009-07-14 16:56:47 -070094 Parcel data, reply;
95 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -070096 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -070097 remote()->transact(FREE_NODE, data, &reply);
98
99 return reply.readInt32();
100 }
101
Andreas Huber318ad9c2009-10-15 13:46:54 -0700102 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -0700103 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) {
104 Parcel data, reply;
105 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700106 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700107 data.writeInt32(cmd);
108 data.writeInt32(param);
109 remote()->transact(SEND_COMMAND, data, &reply);
110
111 return reply.readInt32();
112 }
113
Andreas Huber318ad9c2009-10-15 13:46:54 -0700114 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -0700115 node_id node, OMX_INDEXTYPE index,
116 void *params, size_t size) {
117 Parcel data, reply;
118 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700119 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700120 data.writeInt32(index);
121 data.writeInt32(size);
122 data.write(params, size);
123 remote()->transact(GET_PARAMETER, data, &reply);
124
125 status_t err = reply.readInt32();
126 if (err != OK) {
127 return err;
128 }
129
130 reply.read(params, size);
131
132 return OK;
133 }
134
Andreas Huber318ad9c2009-10-15 13:46:54 -0700135 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -0700136 node_id node, OMX_INDEXTYPE index,
137 const void *params, size_t size) {
138 Parcel data, reply;
139 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700140 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700141 data.writeInt32(index);
142 data.writeInt32(size);
143 data.write(params, size);
144 remote()->transact(SET_PARAMETER, data, &reply);
145
146 return reply.readInt32();
147 }
148
Andreas Huber318ad9c2009-10-15 13:46:54 -0700149 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -0700150 node_id node, OMX_INDEXTYPE index,
151 void *params, size_t size) {
152 Parcel data, reply;
153 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700154 data.writeIntPtr((intptr_t)node);
Andreas Huber693d2712009-08-14 14:37:10 -0700155 data.writeInt32(index);
156 data.writeInt32(size);
157 data.write(params, size);
158 remote()->transact(GET_CONFIG, 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 Huber318ad9c2009-10-15 13:46:54 -0700170 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -0700171 node_id node, OMX_INDEXTYPE index,
172 const void *params, size_t size) {
173 Parcel data, reply;
174 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700175 data.writeIntPtr((intptr_t)node);
Andreas Huber693d2712009-08-14 14:37:10 -0700176 data.writeInt32(index);
177 data.writeInt32(size);
178 data.write(params, size);
179 remote()->transact(SET_CONFIG, data, &reply);
180
181 return reply.readInt32();
182 }
183
Jamie Gennis83750ea2010-08-30 16:48:38 -0700184 virtual status_t enableGraphicBuffers(
185 node_id node, OMX_U32 port_index, OMX_BOOL enable) {
186 Parcel data, reply;
187 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
188 data.writeIntPtr((intptr_t)node);
189 data.writeInt32(port_index);
190 data.writeInt32((uint32_t)enable);
191 remote()->transact(ENABLE_GRAPHIC_BUFFERS, data, &reply);
192
193 status_t err = reply.readInt32();
194 return err;
195 }
196
Andreas Huber318ad9c2009-10-15 13:46:54 -0700197 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700198 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
199 buffer_id *buffer) {
200 Parcel data, reply;
201 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700202 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700203 data.writeInt32(port_index);
204 data.writeStrongBinder(params->asBinder());
205 remote()->transact(USE_BUFFER, data, &reply);
206
207 status_t err = reply.readInt32();
208 if (err != OK) {
209 *buffer = 0;
210
211 return err;
212 }
213
Andreas Huberc6b59b72009-08-17 13:33:27 -0700214 *buffer = (void*)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700215
216 return err;
217 }
218
Jamie Gennis83750ea2010-08-30 16:48:38 -0700219
220 virtual status_t useGraphicBuffer(
221 node_id node, OMX_U32 port_index,
222 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) {
223 Parcel data, reply;
224 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
225 data.writeIntPtr((intptr_t)node);
226 data.writeInt32(port_index);
227 data.write(*graphicBuffer);
228 remote()->transact(USE_GRAPHIC_BUFFER, data, &reply);
229
230 status_t err = reply.readInt32();
231 if (err != OK) {
232 *buffer = 0;
233
234 return err;
235 }
236
237 *buffer = (void*)reply.readIntPtr();
238
239 return err;
240 }
241
James Donge8707722010-10-20 17:38:41 -0700242 virtual status_t storeMetaDataInBuffers(
243 node_id node, OMX_U32 port_index, OMX_BOOL enable) {
244 Parcel data, reply;
245 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
246 data.writeIntPtr((intptr_t)node);
247 data.writeInt32(port_index);
248 data.writeInt32((uint32_t)enable);
249 remote()->transact(STORE_META_DATA_IN_BUFFERS, data, &reply);
250
251 status_t err = reply.readInt32();
252 return err;
253 }
254
Andreas Huber318ad9c2009-10-15 13:46:54 -0700255 virtual status_t allocateBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700256 node_id node, OMX_U32 port_index, size_t size,
Andreas Huber570a3cb2010-01-20 15:05:46 -0800257 buffer_id *buffer, void **buffer_data) {
Andreas Huber20111aa2009-07-14 16:56:47 -0700258 Parcel data, reply;
259 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700260 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700261 data.writeInt32(port_index);
262 data.writeInt32(size);
263 remote()->transact(ALLOC_BUFFER, data, &reply);
264
265 status_t err = reply.readInt32();
266 if (err != OK) {
267 *buffer = 0;
268
269 return err;
270 }
271
Andreas Huber570a3cb2010-01-20 15:05:46 -0800272 *buffer = (void *)reply.readIntPtr();
273 *buffer_data = (void *)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700274
275 return err;
276 }
277
Andreas Huber318ad9c2009-10-15 13:46:54 -0700278 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700279 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
280 buffer_id *buffer) {
281 Parcel data, reply;
282 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700283 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700284 data.writeInt32(port_index);
285 data.writeStrongBinder(params->asBinder());
286 remote()->transact(ALLOC_BUFFER_WITH_BACKUP, data, &reply);
287
288 status_t err = reply.readInt32();
289 if (err != OK) {
290 *buffer = 0;
291
292 return err;
293 }
294
Andreas Huberc6b59b72009-08-17 13:33:27 -0700295 *buffer = (void*)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700296
297 return err;
298 }
299
Andreas Huber318ad9c2009-10-15 13:46:54 -0700300 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700301 node_id node, OMX_U32 port_index, buffer_id buffer) {
302 Parcel data, reply;
303 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700304 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700305 data.writeInt32(port_index);
Andreas Huberc6b59b72009-08-17 13:33:27 -0700306 data.writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700307 remote()->transact(FREE_BUFFER, data, &reply);
308
309 return reply.readInt32();
310 }
311
Andreas Huber318ad9c2009-10-15 13:46:54 -0700312 virtual status_t fillBuffer(node_id node, buffer_id buffer) {
Andreas Huber20111aa2009-07-14 16:56:47 -0700313 Parcel data, reply;
314 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700315 data.writeIntPtr((intptr_t)node);
316 data.writeIntPtr((intptr_t)buffer);
Andreas Huber36efa032009-10-08 11:02:27 -0700317 remote()->transact(FILL_BUFFER, data, &reply);
318
319 return reply.readInt32();
Andreas Huber20111aa2009-07-14 16:56:47 -0700320 }
321
Andreas Huber318ad9c2009-10-15 13:46:54 -0700322 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700323 node_id node,
324 buffer_id buffer,
325 OMX_U32 range_offset, OMX_U32 range_length,
326 OMX_U32 flags, OMX_TICKS timestamp) {
327 Parcel data, reply;
328 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700329 data.writeIntPtr((intptr_t)node);
330 data.writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700331 data.writeInt32(range_offset);
332 data.writeInt32(range_length);
333 data.writeInt32(flags);
334 data.writeInt64(timestamp);
Andreas Huber36efa032009-10-08 11:02:27 -0700335 remote()->transact(EMPTY_BUFFER, data, &reply);
336
337 return reply.readInt32();
Andreas Huber20111aa2009-07-14 16:56:47 -0700338 }
Andreas Huber8b938cd2009-07-31 11:52:50 -0700339
Andreas Huber318ad9c2009-10-15 13:46:54 -0700340 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700341 node_id node,
342 const char *parameter_name,
343 OMX_INDEXTYPE *index) {
344 Parcel data, reply;
345 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700346 data.writeIntPtr((intptr_t)node);
Andreas Huber693d2712009-08-14 14:37:10 -0700347 data.writeCString(parameter_name);
348
349 remote()->transact(GET_EXTENSION_INDEX, data, &reply);
350
351 status_t err = reply.readInt32();
352 if (err == OK) {
353 *index = static_cast<OMX_INDEXTYPE>(reply.readInt32());
354 } else {
355 *index = OMX_IndexComponentStartUnused;
356 }
357
358 return err;
359 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700360};
361
362IMPLEMENT_META_INTERFACE(OMX, "android.hardware.IOMX");
363
364////////////////////////////////////////////////////////////////////////////////
365
366#define CHECK_INTERFACE(interface, data, reply) \
367 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
368 LOGW("Call incorrectly routed to " #interface); \
369 return PERMISSION_DENIED; \
370 } } while (0)
371
372status_t BnOMX::onTransact(
373 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
374 switch (code) {
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800375 case LIVES_LOCALLY:
376 {
377 CHECK_INTERFACE(IOMX, data, reply);
378 reply->writeInt32(livesLocally((pid_t)data.readInt32()));
379
380 return OK;
381 }
382
Andreas Huber20111aa2009-07-14 16:56:47 -0700383 case LIST_NODES:
384 {
385 CHECK_INTERFACE(IOMX, data, reply);
386
Andreas Huber134ee6a2009-12-16 09:30:55 -0800387 List<ComponentInfo> list;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700388 listNodes(&list);
Andreas Huber20111aa2009-07-14 16:56:47 -0700389
390 reply->writeInt32(list.size());
Andreas Huber134ee6a2009-12-16 09:30:55 -0800391 for (List<ComponentInfo>::iterator it = list.begin();
Andreas Huber20111aa2009-07-14 16:56:47 -0700392 it != list.end(); ++it) {
Andreas Huber134ee6a2009-12-16 09:30:55 -0800393 ComponentInfo &cur = *it;
394
395 reply->writeString8(cur.mName);
396 reply->writeInt32(cur.mRoles.size());
397 for (List<String8>::iterator role_it = cur.mRoles.begin();
398 role_it != cur.mRoles.end(); ++role_it) {
399 reply->writeString8(*role_it);
400 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700401 }
402
403 return NO_ERROR;
404 }
405
406 case ALLOCATE_NODE:
407 {
408 CHECK_INTERFACE(IOMX, data, reply);
409
Andreas Huber318ad9c2009-10-15 13:46:54 -0700410 const char *name = data.readCString();
411
412 sp<IOMXObserver> observer =
413 interface_cast<IOMXObserver>(data.readStrongBinder());
414
Andreas Huber20111aa2009-07-14 16:56:47 -0700415 node_id node;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700416
417 status_t err = allocateNode(name, observer, &node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700418 reply->writeInt32(err);
419 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700420 reply->writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700421 }
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800422
Andreas Huber20111aa2009-07-14 16:56:47 -0700423 return NO_ERROR;
424 }
425
426 case FREE_NODE:
427 {
428 CHECK_INTERFACE(IOMX, data, reply);
429
Andreas Huberc6b59b72009-08-17 13:33:27 -0700430 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700431
Andreas Huber318ad9c2009-10-15 13:46:54 -0700432 reply->writeInt32(freeNode(node));
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800433
Andreas Huber20111aa2009-07-14 16:56:47 -0700434 return NO_ERROR;
435 }
436
437 case SEND_COMMAND:
438 {
439 CHECK_INTERFACE(IOMX, data, reply);
440
Andreas Huberc6b59b72009-08-17 13:33:27 -0700441 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700442
443 OMX_COMMANDTYPE cmd =
444 static_cast<OMX_COMMANDTYPE>(data.readInt32());
445
446 OMX_S32 param = data.readInt32();
Andreas Huber318ad9c2009-10-15 13:46:54 -0700447 reply->writeInt32(sendCommand(node, cmd, param));
Andreas Huber20111aa2009-07-14 16:56:47 -0700448
449 return NO_ERROR;
450 }
451
452 case GET_PARAMETER:
Andreas Huber20111aa2009-07-14 16:56:47 -0700453 case SET_PARAMETER:
Andreas Huber693d2712009-08-14 14:37:10 -0700454 case GET_CONFIG:
Andreas Huber693d2712009-08-14 14:37:10 -0700455 case SET_CONFIG:
456 {
457 CHECK_INTERFACE(IOMX, data, reply);
458
Andreas Huberc6b59b72009-08-17 13:33:27 -0700459 node_id node = (void*)data.readIntPtr();
Andreas Huber693d2712009-08-14 14:37:10 -0700460 OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32());
461
462 size_t size = data.readInt32();
Andreas Huber693d2712009-08-14 14:37:10 -0700463
Andreas Huberb3912902011-01-19 10:34:52 -0800464 void *params = malloc(size);
465 data.read(params, size);
466
467 status_t err;
468 switch (code) {
469 case GET_PARAMETER:
470 err = getParameter(node, index, params, size);
471 break;
472 case SET_PARAMETER:
473 err = setParameter(node, index, params, size);
474 break;
475 case GET_CONFIG:
476 err = getConfig(node, index, params, size);
477 break;
478 case SET_CONFIG:
479 err = setConfig(node, index, params, size);
480 break;
481 default:
482 TRESPASS();
483 }
484
485 reply->writeInt32(err);
486
487 if ((code == GET_PARAMETER || code == GET_CONFIG) && err == OK) {
488 reply->write(params, size);
489 }
490
491 free(params);
492 params = NULL;
Andreas Huber693d2712009-08-14 14:37:10 -0700493
494 return NO_ERROR;
495 }
496
Jamie Gennis83750ea2010-08-30 16:48:38 -0700497 case ENABLE_GRAPHIC_BUFFERS:
498 {
499 CHECK_INTERFACE(IOMX, data, reply);
500
501 node_id node = (void*)data.readIntPtr();
502 OMX_U32 port_index = data.readInt32();
503 OMX_BOOL enable = (OMX_BOOL)data.readInt32();
504
505 status_t err = enableGraphicBuffers(node, port_index, enable);
506 reply->writeInt32(err);
507
508 return NO_ERROR;
509 }
510
Andreas Huber20111aa2009-07-14 16:56:47 -0700511 case USE_BUFFER:
512 {
513 CHECK_INTERFACE(IOMX, data, reply);
514
Andreas Huberc6b59b72009-08-17 13:33:27 -0700515 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700516 OMX_U32 port_index = data.readInt32();
517 sp<IMemory> params =
518 interface_cast<IMemory>(data.readStrongBinder());
519
520 buffer_id buffer;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700521 status_t err = useBuffer(node, port_index, params, &buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700522 reply->writeInt32(err);
523
524 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700525 reply->writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700526 }
527
528 return NO_ERROR;
529 }
530
Jamie Gennis83750ea2010-08-30 16:48:38 -0700531 case USE_GRAPHIC_BUFFER:
532 {
533 CHECK_INTERFACE(IOMX, data, reply);
534
535 node_id node = (void*)data.readIntPtr();
536 OMX_U32 port_index = data.readInt32();
537 sp<GraphicBuffer> graphicBuffer = new GraphicBuffer();
538 data.read(*graphicBuffer);
539
540 buffer_id buffer;
541 status_t err = useGraphicBuffer(
542 node, port_index, graphicBuffer, &buffer);
543 reply->writeInt32(err);
544
545 if (err == OK) {
546 reply->writeIntPtr((intptr_t)buffer);
547 }
548
549 return NO_ERROR;
550 }
551
James Donge8707722010-10-20 17:38:41 -0700552 case STORE_META_DATA_IN_BUFFERS:
553 {
554 CHECK_INTERFACE(IOMX, data, reply);
555
556 node_id node = (void*)data.readIntPtr();
557 OMX_U32 port_index = data.readInt32();
558 OMX_BOOL enable = (OMX_BOOL)data.readInt32();
559
560 status_t err = storeMetaDataInBuffers(node, port_index, enable);
561 reply->writeInt32(err);
562
563 return NO_ERROR;
564 }
565
Andreas Huber20111aa2009-07-14 16:56:47 -0700566 case ALLOC_BUFFER:
567 {
568 CHECK_INTERFACE(IOMX, data, reply);
569
Andreas Huberc6b59b72009-08-17 13:33:27 -0700570 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700571 OMX_U32 port_index = data.readInt32();
572 size_t size = data.readInt32();
573
574 buffer_id buffer;
Andreas Huber570a3cb2010-01-20 15:05:46 -0800575 void *buffer_data;
576 status_t err = allocateBuffer(
577 node, port_index, size, &buffer, &buffer_data);
Andreas Huber20111aa2009-07-14 16:56:47 -0700578 reply->writeInt32(err);
579
580 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700581 reply->writeIntPtr((intptr_t)buffer);
Andreas Huber570a3cb2010-01-20 15:05:46 -0800582 reply->writeIntPtr((intptr_t)buffer_data);
Andreas Huber20111aa2009-07-14 16:56:47 -0700583 }
584
585 return NO_ERROR;
586 }
587
588 case ALLOC_BUFFER_WITH_BACKUP:
589 {
590 CHECK_INTERFACE(IOMX, data, reply);
591
Andreas Huberc6b59b72009-08-17 13:33:27 -0700592 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700593 OMX_U32 port_index = data.readInt32();
594 sp<IMemory> params =
595 interface_cast<IMemory>(data.readStrongBinder());
596
597 buffer_id buffer;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700598 status_t err = allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700599 node, port_index, params, &buffer);
600
601 reply->writeInt32(err);
602
603 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700604 reply->writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700605 }
606
607 return NO_ERROR;
608 }
609
610 case FREE_BUFFER:
611 {
612 CHECK_INTERFACE(IOMX, data, reply);
613
Andreas Huberc6b59b72009-08-17 13:33:27 -0700614 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700615 OMX_U32 port_index = data.readInt32();
Andreas Huberc6b59b72009-08-17 13:33:27 -0700616 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber318ad9c2009-10-15 13:46:54 -0700617 reply->writeInt32(freeBuffer(node, port_index, buffer));
Andreas Huber20111aa2009-07-14 16:56:47 -0700618
619 return NO_ERROR;
620 }
621
622 case FILL_BUFFER:
623 {
624 CHECK_INTERFACE(IOMX, data, reply);
625
Andreas Huberc6b59b72009-08-17 13:33:27 -0700626 node_id node = (void*)data.readIntPtr();
627 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber318ad9c2009-10-15 13:46:54 -0700628 reply->writeInt32(fillBuffer(node, buffer));
Andreas Huber20111aa2009-07-14 16:56:47 -0700629
630 return NO_ERROR;
631 }
632
633 case EMPTY_BUFFER:
634 {
635 CHECK_INTERFACE(IOMX, data, reply);
636
Andreas Huberc6b59b72009-08-17 13:33:27 -0700637 node_id node = (void*)data.readIntPtr();
638 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700639 OMX_U32 range_offset = data.readInt32();
640 OMX_U32 range_length = data.readInt32();
641 OMX_U32 flags = data.readInt32();
642 OMX_TICKS timestamp = data.readInt64();
643
Andreas Huber36efa032009-10-08 11:02:27 -0700644 reply->writeInt32(
Andreas Huber318ad9c2009-10-15 13:46:54 -0700645 emptyBuffer(
Andreas Huber36efa032009-10-08 11:02:27 -0700646 node, buffer, range_offset, range_length,
647 flags, timestamp));
Andreas Huber20111aa2009-07-14 16:56:47 -0700648
649 return NO_ERROR;
650 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700651
Andreas Huber693d2712009-08-14 14:37:10 -0700652 case GET_EXTENSION_INDEX:
653 {
654 CHECK_INTERFACE(IOMX, data, reply);
655
Andreas Huberc6b59b72009-08-17 13:33:27 -0700656 node_id node = (void*)data.readIntPtr();
Andreas Huber693d2712009-08-14 14:37:10 -0700657 const char *parameter_name = data.readCString();
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800658
Andreas Huber693d2712009-08-14 14:37:10 -0700659 OMX_INDEXTYPE index;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700660 status_t err = getExtensionIndex(node, parameter_name, &index);
Andreas Huber693d2712009-08-14 14:37:10 -0700661
662 reply->writeInt32(err);
663
664 if (err == OK) {
665 reply->writeInt32(index);
666 }
667
668 return OK;
669 }
670
Andreas Huber20111aa2009-07-14 16:56:47 -0700671 default:
672 return BBinder::onTransact(code, data, reply, flags);
673 }
674}
675
676////////////////////////////////////////////////////////////////////////////////
677
678class BpOMXObserver : public BpInterface<IOMXObserver> {
679public:
680 BpOMXObserver(const sp<IBinder> &impl)
681 : BpInterface<IOMXObserver>(impl) {
682 }
683
Andreas Huber318ad9c2009-10-15 13:46:54 -0700684 virtual void onMessage(const omx_message &msg) {
Andreas Huber20111aa2009-07-14 16:56:47 -0700685 Parcel data, reply;
686 data.writeInterfaceToken(IOMXObserver::getInterfaceDescriptor());
687 data.write(&msg, sizeof(msg));
688
689 remote()->transact(OBSERVER_ON_MSG, data, &reply, IBinder::FLAG_ONEWAY);
690 }
691};
692
693IMPLEMENT_META_INTERFACE(OMXObserver, "android.hardware.IOMXObserver");
694
695status_t BnOMXObserver::onTransact(
696 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
697 switch (code) {
698 case OBSERVER_ON_MSG:
699 {
700 CHECK_INTERFACE(IOMXObserver, data, reply);
701
702 omx_message msg;
703 data.read(&msg, sizeof(msg));
704
705 // XXX Could use readInplace maybe?
Andreas Huber318ad9c2009-10-15 13:46:54 -0700706 onMessage(msg);
Andreas Huber20111aa2009-07-14 16:56:47 -0700707
708 return NO_ERROR;
709 }
710
711 default:
712 return BBinder::onTransact(code, data, reply, flags);
713 }
714}
715
Andreas Huber20111aa2009-07-14 16:56:47 -0700716} // namespace android