blob: d6a1757ca9fdbfd28ef3da3b736c12cb9fecc1a2 [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,
Jamie Gennise2ce6452011-02-23 19:01:28 -080036 GET_GRAPHIC_BUFFER_USAGE,
Andreas Huber20111aa2009-07-14 16:56:47 -070037};
38
Andreas Huber20111aa2009-07-14 16:56:47 -070039class BpOMX : public BpInterface<IOMX> {
40public:
41 BpOMX(const sp<IBinder> &impl)
42 : BpInterface<IOMX>(impl) {
43 }
44
Andreas Huber7eaa9c92010-01-15 15:28:19 -080045 virtual bool livesLocally(pid_t pid) {
46 Parcel data, reply;
47 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
48 data.writeInt32(pid);
49 remote()->transact(LIVES_LOCALLY, data, &reply);
50
51 return reply.readInt32() != 0;
52 }
53
Andreas Huber134ee6a2009-12-16 09:30:55 -080054 virtual status_t listNodes(List<ComponentInfo> *list) {
Andreas Huber20111aa2009-07-14 16:56:47 -070055 list->clear();
56
57 Parcel data, reply;
58 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
59 remote()->transact(LIST_NODES, data, &reply);
60
61 int32_t n = reply.readInt32();
62 for (int32_t i = 0; i < n; ++i) {
Andreas Huber134ee6a2009-12-16 09:30:55 -080063 list->push_back(ComponentInfo());
64 ComponentInfo &info = *--list->end();
Andreas Huber20111aa2009-07-14 16:56:47 -070065
Andreas Huber134ee6a2009-12-16 09:30:55 -080066 info.mName = reply.readString8();
67 int32_t numRoles = reply.readInt32();
68 for (int32_t j = 0; j < numRoles; ++j) {
69 info.mRoles.push_back(reply.readString8());
70 }
Andreas Huber20111aa2009-07-14 16:56:47 -070071 }
72
73 return OK;
74 }
75
Andreas Huber318ad9c2009-10-15 13:46:54 -070076 virtual status_t allocateNode(
77 const char *name, const sp<IOMXObserver> &observer, node_id *node) {
Andreas Huber20111aa2009-07-14 16:56:47 -070078 Parcel data, reply;
79 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
80 data.writeCString(name);
Andreas Huber318ad9c2009-10-15 13:46:54 -070081 data.writeStrongBinder(observer->asBinder());
Andreas Huber20111aa2009-07-14 16:56:47 -070082 remote()->transact(ALLOCATE_NODE, data, &reply);
83
84 status_t err = reply.readInt32();
85 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -070086 *node = (void*)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -070087 } else {
88 *node = 0;
89 }
90
91 return err;
92 }
93
Andreas Huber318ad9c2009-10-15 13:46:54 -070094 virtual status_t freeNode(node_id node) {
Andreas Huber20111aa2009-07-14 16:56:47 -070095 Parcel data, reply;
96 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -070097 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -070098 remote()->transact(FREE_NODE, data, &reply);
99
100 return reply.readInt32();
101 }
102
Andreas Huber318ad9c2009-10-15 13:46:54 -0700103 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -0700104 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) {
105 Parcel data, reply;
106 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700107 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700108 data.writeInt32(cmd);
109 data.writeInt32(param);
110 remote()->transact(SEND_COMMAND, data, &reply);
111
112 return reply.readInt32();
113 }
114
Andreas Huber318ad9c2009-10-15 13:46:54 -0700115 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -0700116 node_id node, OMX_INDEXTYPE index,
117 void *params, size_t size) {
118 Parcel data, reply;
119 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700120 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700121 data.writeInt32(index);
122 data.writeInt32(size);
123 data.write(params, size);
124 remote()->transact(GET_PARAMETER, data, &reply);
125
126 status_t err = reply.readInt32();
127 if (err != OK) {
128 return err;
129 }
130
131 reply.read(params, size);
132
133 return OK;
134 }
135
Andreas Huber318ad9c2009-10-15 13:46:54 -0700136 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -0700137 node_id node, OMX_INDEXTYPE index,
138 const void *params, size_t size) {
139 Parcel data, reply;
140 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700141 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700142 data.writeInt32(index);
143 data.writeInt32(size);
144 data.write(params, size);
145 remote()->transact(SET_PARAMETER, data, &reply);
146
147 return reply.readInt32();
148 }
149
Andreas Huber318ad9c2009-10-15 13:46:54 -0700150 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -0700151 node_id node, OMX_INDEXTYPE index,
152 void *params, size_t size) {
153 Parcel data, reply;
154 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700155 data.writeIntPtr((intptr_t)node);
Andreas Huber693d2712009-08-14 14:37:10 -0700156 data.writeInt32(index);
157 data.writeInt32(size);
158 data.write(params, size);
159 remote()->transact(GET_CONFIG, data, &reply);
160
161 status_t err = reply.readInt32();
162 if (err != OK) {
163 return err;
164 }
165
166 reply.read(params, size);
167
168 return OK;
169 }
170
Andreas Huber318ad9c2009-10-15 13:46:54 -0700171 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -0700172 node_id node, OMX_INDEXTYPE index,
173 const void *params, size_t size) {
174 Parcel data, reply;
175 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700176 data.writeIntPtr((intptr_t)node);
Andreas Huber693d2712009-08-14 14:37:10 -0700177 data.writeInt32(index);
178 data.writeInt32(size);
179 data.write(params, size);
180 remote()->transact(SET_CONFIG, data, &reply);
181
182 return reply.readInt32();
183 }
184
Jamie Gennis83750ea2010-08-30 16:48:38 -0700185 virtual status_t enableGraphicBuffers(
186 node_id node, OMX_U32 port_index, OMX_BOOL enable) {
187 Parcel data, reply;
188 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
189 data.writeIntPtr((intptr_t)node);
190 data.writeInt32(port_index);
191 data.writeInt32((uint32_t)enable);
192 remote()->transact(ENABLE_GRAPHIC_BUFFERS, data, &reply);
193
194 status_t err = reply.readInt32();
195 return err;
196 }
197
Jamie Gennise2ce6452011-02-23 19:01:28 -0800198 virtual status_t getGraphicBufferUsage(
199 node_id node, OMX_U32 port_index, OMX_U32* usage) {
200 Parcel data, reply;
201 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
202 data.writeIntPtr((intptr_t)node);
203 data.writeInt32(port_index);
204 remote()->transact(GET_GRAPHIC_BUFFER_USAGE, data, &reply);
205
206 status_t err = reply.readInt32();
207 *usage = reply.readInt32();
208 return err;
209 }
210
Andreas Huber318ad9c2009-10-15 13:46:54 -0700211 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700212 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
213 buffer_id *buffer) {
214 Parcel data, reply;
215 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700216 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700217 data.writeInt32(port_index);
218 data.writeStrongBinder(params->asBinder());
219 remote()->transact(USE_BUFFER, data, &reply);
220
221 status_t err = reply.readInt32();
222 if (err != OK) {
223 *buffer = 0;
224
225 return err;
226 }
227
Andreas Huberc6b59b72009-08-17 13:33:27 -0700228 *buffer = (void*)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700229
230 return err;
231 }
232
Jamie Gennis83750ea2010-08-30 16:48:38 -0700233
234 virtual status_t useGraphicBuffer(
235 node_id node, OMX_U32 port_index,
236 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) {
237 Parcel data, reply;
238 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
239 data.writeIntPtr((intptr_t)node);
240 data.writeInt32(port_index);
241 data.write(*graphicBuffer);
242 remote()->transact(USE_GRAPHIC_BUFFER, data, &reply);
243
244 status_t err = reply.readInt32();
245 if (err != OK) {
246 *buffer = 0;
247
248 return err;
249 }
250
251 *buffer = (void*)reply.readIntPtr();
252
253 return err;
254 }
255
James Donge8707722010-10-20 17:38:41 -0700256 virtual status_t storeMetaDataInBuffers(
257 node_id node, OMX_U32 port_index, OMX_BOOL enable) {
258 Parcel data, reply;
259 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
260 data.writeIntPtr((intptr_t)node);
261 data.writeInt32(port_index);
262 data.writeInt32((uint32_t)enable);
263 remote()->transact(STORE_META_DATA_IN_BUFFERS, data, &reply);
264
265 status_t err = reply.readInt32();
266 return err;
267 }
268
Andreas Huber318ad9c2009-10-15 13:46:54 -0700269 virtual status_t allocateBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700270 node_id node, OMX_U32 port_index, size_t size,
Andreas Huber570a3cb2010-01-20 15:05:46 -0800271 buffer_id *buffer, void **buffer_data) {
Andreas Huber20111aa2009-07-14 16:56:47 -0700272 Parcel data, reply;
273 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700274 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700275 data.writeInt32(port_index);
276 data.writeInt32(size);
277 remote()->transact(ALLOC_BUFFER, data, &reply);
278
279 status_t err = reply.readInt32();
280 if (err != OK) {
281 *buffer = 0;
282
283 return err;
284 }
285
Andreas Huber570a3cb2010-01-20 15:05:46 -0800286 *buffer = (void *)reply.readIntPtr();
287 *buffer_data = (void *)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700288
289 return err;
290 }
291
Andreas Huber318ad9c2009-10-15 13:46:54 -0700292 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700293 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
294 buffer_id *buffer) {
295 Parcel data, reply;
296 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700297 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700298 data.writeInt32(port_index);
299 data.writeStrongBinder(params->asBinder());
300 remote()->transact(ALLOC_BUFFER_WITH_BACKUP, data, &reply);
301
302 status_t err = reply.readInt32();
303 if (err != OK) {
304 *buffer = 0;
305
306 return err;
307 }
308
Andreas Huberc6b59b72009-08-17 13:33:27 -0700309 *buffer = (void*)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700310
311 return err;
312 }
313
Andreas Huber318ad9c2009-10-15 13:46:54 -0700314 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700315 node_id node, OMX_U32 port_index, buffer_id buffer) {
316 Parcel data, reply;
317 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700318 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700319 data.writeInt32(port_index);
Andreas Huberc6b59b72009-08-17 13:33:27 -0700320 data.writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700321 remote()->transact(FREE_BUFFER, data, &reply);
322
323 return reply.readInt32();
324 }
325
Andreas Huber318ad9c2009-10-15 13:46:54 -0700326 virtual status_t fillBuffer(node_id node, buffer_id buffer) {
Andreas Huber20111aa2009-07-14 16:56:47 -0700327 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 Huber36efa032009-10-08 11:02:27 -0700331 remote()->transact(FILL_BUFFER, data, &reply);
332
333 return reply.readInt32();
Andreas Huber20111aa2009-07-14 16:56:47 -0700334 }
335
Andreas Huber318ad9c2009-10-15 13:46:54 -0700336 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700337 node_id node,
338 buffer_id buffer,
339 OMX_U32 range_offset, OMX_U32 range_length,
340 OMX_U32 flags, OMX_TICKS timestamp) {
341 Parcel data, reply;
342 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700343 data.writeIntPtr((intptr_t)node);
344 data.writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700345 data.writeInt32(range_offset);
346 data.writeInt32(range_length);
347 data.writeInt32(flags);
348 data.writeInt64(timestamp);
Andreas Huber36efa032009-10-08 11:02:27 -0700349 remote()->transact(EMPTY_BUFFER, data, &reply);
350
351 return reply.readInt32();
Andreas Huber20111aa2009-07-14 16:56:47 -0700352 }
Andreas Huber8b938cd2009-07-31 11:52:50 -0700353
Andreas Huber318ad9c2009-10-15 13:46:54 -0700354 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700355 node_id node,
356 const char *parameter_name,
357 OMX_INDEXTYPE *index) {
358 Parcel data, reply;
359 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700360 data.writeIntPtr((intptr_t)node);
Andreas Huber693d2712009-08-14 14:37:10 -0700361 data.writeCString(parameter_name);
362
363 remote()->transact(GET_EXTENSION_INDEX, data, &reply);
364
365 status_t err = reply.readInt32();
366 if (err == OK) {
367 *index = static_cast<OMX_INDEXTYPE>(reply.readInt32());
368 } else {
369 *index = OMX_IndexComponentStartUnused;
370 }
371
372 return err;
373 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700374};
375
376IMPLEMENT_META_INTERFACE(OMX, "android.hardware.IOMX");
377
378////////////////////////////////////////////////////////////////////////////////
379
380#define CHECK_INTERFACE(interface, data, reply) \
381 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
382 LOGW("Call incorrectly routed to " #interface); \
383 return PERMISSION_DENIED; \
384 } } while (0)
385
386status_t BnOMX::onTransact(
387 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
388 switch (code) {
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800389 case LIVES_LOCALLY:
390 {
391 CHECK_INTERFACE(IOMX, data, reply);
392 reply->writeInt32(livesLocally((pid_t)data.readInt32()));
393
394 return OK;
395 }
396
Andreas Huber20111aa2009-07-14 16:56:47 -0700397 case LIST_NODES:
398 {
399 CHECK_INTERFACE(IOMX, data, reply);
400
Andreas Huber134ee6a2009-12-16 09:30:55 -0800401 List<ComponentInfo> list;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700402 listNodes(&list);
Andreas Huber20111aa2009-07-14 16:56:47 -0700403
404 reply->writeInt32(list.size());
Andreas Huber134ee6a2009-12-16 09:30:55 -0800405 for (List<ComponentInfo>::iterator it = list.begin();
Andreas Huber20111aa2009-07-14 16:56:47 -0700406 it != list.end(); ++it) {
Andreas Huber134ee6a2009-12-16 09:30:55 -0800407 ComponentInfo &cur = *it;
408
409 reply->writeString8(cur.mName);
410 reply->writeInt32(cur.mRoles.size());
411 for (List<String8>::iterator role_it = cur.mRoles.begin();
412 role_it != cur.mRoles.end(); ++role_it) {
413 reply->writeString8(*role_it);
414 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700415 }
416
417 return NO_ERROR;
418 }
419
420 case ALLOCATE_NODE:
421 {
422 CHECK_INTERFACE(IOMX, data, reply);
423
Andreas Huber318ad9c2009-10-15 13:46:54 -0700424 const char *name = data.readCString();
425
426 sp<IOMXObserver> observer =
427 interface_cast<IOMXObserver>(data.readStrongBinder());
428
Andreas Huber20111aa2009-07-14 16:56:47 -0700429 node_id node;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700430
431 status_t err = allocateNode(name, observer, &node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700432 reply->writeInt32(err);
433 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700434 reply->writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700435 }
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800436
Andreas Huber20111aa2009-07-14 16:56:47 -0700437 return NO_ERROR;
438 }
439
440 case FREE_NODE:
441 {
442 CHECK_INTERFACE(IOMX, data, reply);
443
Andreas Huberc6b59b72009-08-17 13:33:27 -0700444 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700445
Andreas Huber318ad9c2009-10-15 13:46:54 -0700446 reply->writeInt32(freeNode(node));
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800447
Andreas Huber20111aa2009-07-14 16:56:47 -0700448 return NO_ERROR;
449 }
450
451 case SEND_COMMAND:
452 {
453 CHECK_INTERFACE(IOMX, data, reply);
454
Andreas Huberc6b59b72009-08-17 13:33:27 -0700455 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700456
457 OMX_COMMANDTYPE cmd =
458 static_cast<OMX_COMMANDTYPE>(data.readInt32());
459
460 OMX_S32 param = data.readInt32();
Andreas Huber318ad9c2009-10-15 13:46:54 -0700461 reply->writeInt32(sendCommand(node, cmd, param));
Andreas Huber20111aa2009-07-14 16:56:47 -0700462
463 return NO_ERROR;
464 }
465
466 case GET_PARAMETER:
Andreas Huber20111aa2009-07-14 16:56:47 -0700467 case SET_PARAMETER:
Andreas Huber693d2712009-08-14 14:37:10 -0700468 case GET_CONFIG:
Andreas Huber693d2712009-08-14 14:37:10 -0700469 case SET_CONFIG:
470 {
471 CHECK_INTERFACE(IOMX, data, reply);
472
Andreas Huberc6b59b72009-08-17 13:33:27 -0700473 node_id node = (void*)data.readIntPtr();
Andreas Huber693d2712009-08-14 14:37:10 -0700474 OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32());
475
476 size_t size = data.readInt32();
Andreas Huber693d2712009-08-14 14:37:10 -0700477
Andreas Huberb3912902011-01-19 10:34:52 -0800478 void *params = malloc(size);
479 data.read(params, size);
480
481 status_t err;
482 switch (code) {
483 case GET_PARAMETER:
484 err = getParameter(node, index, params, size);
485 break;
486 case SET_PARAMETER:
487 err = setParameter(node, index, params, size);
488 break;
489 case GET_CONFIG:
490 err = getConfig(node, index, params, size);
491 break;
492 case SET_CONFIG:
493 err = setConfig(node, index, params, size);
494 break;
495 default:
496 TRESPASS();
497 }
498
499 reply->writeInt32(err);
500
501 if ((code == GET_PARAMETER || code == GET_CONFIG) && err == OK) {
502 reply->write(params, size);
503 }
504
505 free(params);
506 params = NULL;
Andreas Huber693d2712009-08-14 14:37:10 -0700507
508 return NO_ERROR;
509 }
510
Jamie Gennis83750ea2010-08-30 16:48:38 -0700511 case ENABLE_GRAPHIC_BUFFERS:
512 {
513 CHECK_INTERFACE(IOMX, data, reply);
514
515 node_id node = (void*)data.readIntPtr();
516 OMX_U32 port_index = data.readInt32();
517 OMX_BOOL enable = (OMX_BOOL)data.readInt32();
518
519 status_t err = enableGraphicBuffers(node, port_index, enable);
520 reply->writeInt32(err);
521
522 return NO_ERROR;
523 }
524
Jamie Gennise2ce6452011-02-23 19:01:28 -0800525 case GET_GRAPHIC_BUFFER_USAGE:
526 {
527 CHECK_INTERFACE(IOMX, data, reply);
528
529 node_id node = (void*)data.readIntPtr();
530 OMX_U32 port_index = data.readInt32();
531
532 OMX_U32 usage = 0;
533 status_t err = getGraphicBufferUsage(node, port_index, &usage);
534 reply->writeInt32(err);
535 reply->writeInt32(usage);
536
537 return NO_ERROR;
538 }
539
Andreas Huber20111aa2009-07-14 16:56:47 -0700540 case USE_BUFFER:
541 {
542 CHECK_INTERFACE(IOMX, data, reply);
543
Andreas Huberc6b59b72009-08-17 13:33:27 -0700544 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700545 OMX_U32 port_index = data.readInt32();
546 sp<IMemory> params =
547 interface_cast<IMemory>(data.readStrongBinder());
548
549 buffer_id buffer;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700550 status_t err = useBuffer(node, port_index, params, &buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700551 reply->writeInt32(err);
552
553 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700554 reply->writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700555 }
556
557 return NO_ERROR;
558 }
559
Jamie Gennis83750ea2010-08-30 16:48:38 -0700560 case USE_GRAPHIC_BUFFER:
561 {
562 CHECK_INTERFACE(IOMX, data, reply);
563
564 node_id node = (void*)data.readIntPtr();
565 OMX_U32 port_index = data.readInt32();
566 sp<GraphicBuffer> graphicBuffer = new GraphicBuffer();
567 data.read(*graphicBuffer);
568
569 buffer_id buffer;
570 status_t err = useGraphicBuffer(
571 node, port_index, graphicBuffer, &buffer);
572 reply->writeInt32(err);
573
574 if (err == OK) {
575 reply->writeIntPtr((intptr_t)buffer);
576 }
577
578 return NO_ERROR;
579 }
580
James Donge8707722010-10-20 17:38:41 -0700581 case STORE_META_DATA_IN_BUFFERS:
582 {
583 CHECK_INTERFACE(IOMX, data, reply);
584
585 node_id node = (void*)data.readIntPtr();
586 OMX_U32 port_index = data.readInt32();
587 OMX_BOOL enable = (OMX_BOOL)data.readInt32();
588
589 status_t err = storeMetaDataInBuffers(node, port_index, enable);
590 reply->writeInt32(err);
591
592 return NO_ERROR;
593 }
594
Andreas Huber20111aa2009-07-14 16:56:47 -0700595 case ALLOC_BUFFER:
596 {
597 CHECK_INTERFACE(IOMX, data, reply);
598
Andreas Huberc6b59b72009-08-17 13:33:27 -0700599 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700600 OMX_U32 port_index = data.readInt32();
601 size_t size = data.readInt32();
602
603 buffer_id buffer;
Andreas Huber570a3cb2010-01-20 15:05:46 -0800604 void *buffer_data;
605 status_t err = allocateBuffer(
606 node, port_index, size, &buffer, &buffer_data);
Andreas Huber20111aa2009-07-14 16:56:47 -0700607 reply->writeInt32(err);
608
609 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700610 reply->writeIntPtr((intptr_t)buffer);
Andreas Huber570a3cb2010-01-20 15:05:46 -0800611 reply->writeIntPtr((intptr_t)buffer_data);
Andreas Huber20111aa2009-07-14 16:56:47 -0700612 }
613
614 return NO_ERROR;
615 }
616
617 case ALLOC_BUFFER_WITH_BACKUP:
618 {
619 CHECK_INTERFACE(IOMX, data, reply);
620
Andreas Huberc6b59b72009-08-17 13:33:27 -0700621 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700622 OMX_U32 port_index = data.readInt32();
623 sp<IMemory> params =
624 interface_cast<IMemory>(data.readStrongBinder());
625
626 buffer_id buffer;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700627 status_t err = allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700628 node, port_index, params, &buffer);
629
630 reply->writeInt32(err);
631
632 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700633 reply->writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700634 }
635
636 return NO_ERROR;
637 }
638
639 case FREE_BUFFER:
640 {
641 CHECK_INTERFACE(IOMX, data, reply);
642
Andreas Huberc6b59b72009-08-17 13:33:27 -0700643 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700644 OMX_U32 port_index = data.readInt32();
Andreas Huberc6b59b72009-08-17 13:33:27 -0700645 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber318ad9c2009-10-15 13:46:54 -0700646 reply->writeInt32(freeBuffer(node, port_index, buffer));
Andreas Huber20111aa2009-07-14 16:56:47 -0700647
648 return NO_ERROR;
649 }
650
651 case FILL_BUFFER:
652 {
653 CHECK_INTERFACE(IOMX, data, reply);
654
Andreas Huberc6b59b72009-08-17 13:33:27 -0700655 node_id node = (void*)data.readIntPtr();
656 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber318ad9c2009-10-15 13:46:54 -0700657 reply->writeInt32(fillBuffer(node, buffer));
Andreas Huber20111aa2009-07-14 16:56:47 -0700658
659 return NO_ERROR;
660 }
661
662 case EMPTY_BUFFER:
663 {
664 CHECK_INTERFACE(IOMX, data, reply);
665
Andreas Huberc6b59b72009-08-17 13:33:27 -0700666 node_id node = (void*)data.readIntPtr();
667 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700668 OMX_U32 range_offset = data.readInt32();
669 OMX_U32 range_length = data.readInt32();
670 OMX_U32 flags = data.readInt32();
671 OMX_TICKS timestamp = data.readInt64();
672
Andreas Huber36efa032009-10-08 11:02:27 -0700673 reply->writeInt32(
Andreas Huber318ad9c2009-10-15 13:46:54 -0700674 emptyBuffer(
Andreas Huber36efa032009-10-08 11:02:27 -0700675 node, buffer, range_offset, range_length,
676 flags, timestamp));
Andreas Huber20111aa2009-07-14 16:56:47 -0700677
678 return NO_ERROR;
679 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700680
Andreas Huber693d2712009-08-14 14:37:10 -0700681 case GET_EXTENSION_INDEX:
682 {
683 CHECK_INTERFACE(IOMX, data, reply);
684
Andreas Huberc6b59b72009-08-17 13:33:27 -0700685 node_id node = (void*)data.readIntPtr();
Andreas Huber693d2712009-08-14 14:37:10 -0700686 const char *parameter_name = data.readCString();
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800687
Andreas Huber693d2712009-08-14 14:37:10 -0700688 OMX_INDEXTYPE index;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700689 status_t err = getExtensionIndex(node, parameter_name, &index);
Andreas Huber693d2712009-08-14 14:37:10 -0700690
691 reply->writeInt32(err);
692
693 if (err == OK) {
694 reply->writeInt32(index);
695 }
696
697 return OK;
698 }
699
Andreas Huber20111aa2009-07-14 16:56:47 -0700700 default:
701 return BBinder::onTransact(code, data, reply, flags);
702 }
703}
704
705////////////////////////////////////////////////////////////////////////////////
706
707class BpOMXObserver : public BpInterface<IOMXObserver> {
708public:
709 BpOMXObserver(const sp<IBinder> &impl)
710 : BpInterface<IOMXObserver>(impl) {
711 }
712
Andreas Huber318ad9c2009-10-15 13:46:54 -0700713 virtual void onMessage(const omx_message &msg) {
Andreas Huber20111aa2009-07-14 16:56:47 -0700714 Parcel data, reply;
715 data.writeInterfaceToken(IOMXObserver::getInterfaceDescriptor());
716 data.write(&msg, sizeof(msg));
717
718 remote()->transact(OBSERVER_ON_MSG, data, &reply, IBinder::FLAG_ONEWAY);
719 }
720};
721
722IMPLEMENT_META_INTERFACE(OMXObserver, "android.hardware.IOMXObserver");
723
724status_t BnOMXObserver::onTransact(
725 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
726 switch (code) {
727 case OBSERVER_ON_MSG:
728 {
729 CHECK_INTERFACE(IOMXObserver, data, reply);
730
731 omx_message msg;
732 data.read(&msg, sizeof(msg));
733
734 // XXX Could use readInplace maybe?
Andreas Huber318ad9c2009-10-15 13:46:54 -0700735 onMessage(msg);
Andreas Huber20111aa2009-07-14 16:56:47 -0700736
737 return NO_ERROR;
738 }
739
740 default:
741 return BBinder::onTransact(code, data, reply, flags);
742 }
743}
744
Andreas Huber20111aa2009-07-14 16:56:47 -0700745} // namespace android