blob: 48e427abe9b31be58bb687a6c90c89b596cb05ac [file] [log] [blame]
James Dong27c17442011-03-17 11:02:04 -07001/*
2 * Copyright (c) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andreas Huber20111aa2009-07-14 16:56:47 -070017//#define LOG_NDEBUG 0
18#define LOG_TAG "IOMX"
19#include <utils/Log.h>
20
21#include <binder/IMemory.h>
22#include <binder/Parcel.h>
23#include <media/IOMX.h>
Andreas Huberb3912902011-01-19 10:34:52 -080024#include <media/stagefright/foundation/ADebug.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070025
26namespace android {
27
28enum {
29 CONNECT = IBinder::FIRST_CALL_TRANSACTION,
Andreas Huber7eaa9c92010-01-15 15:28:19 -080030 LIVES_LOCALLY,
Andreas Huber20111aa2009-07-14 16:56:47 -070031 LIST_NODES,
32 ALLOCATE_NODE,
33 FREE_NODE,
34 SEND_COMMAND,
35 GET_PARAMETER,
36 SET_PARAMETER,
Andreas Huber693d2712009-08-14 14:37:10 -070037 GET_CONFIG,
38 SET_CONFIG,
Jamie Gennisb1d666f2011-10-19 21:14:13 -070039 GET_STATE,
Jamie Gennis83750ea2010-08-30 16:48:38 -070040 ENABLE_GRAPHIC_BUFFERS,
Andreas Huber20111aa2009-07-14 16:56:47 -070041 USE_BUFFER,
Jamie Gennis83750ea2010-08-30 16:48:38 -070042 USE_GRAPHIC_BUFFER,
James Donge8707722010-10-20 17:38:41 -070043 STORE_META_DATA_IN_BUFFERS,
Andreas Huber20111aa2009-07-14 16:56:47 -070044 ALLOC_BUFFER,
45 ALLOC_BUFFER_WITH_BACKUP,
46 FREE_BUFFER,
Andreas Huber20111aa2009-07-14 16:56:47 -070047 FILL_BUFFER,
48 EMPTY_BUFFER,
Andreas Huber693d2712009-08-14 14:37:10 -070049 GET_EXTENSION_INDEX,
Andreas Huber20111aa2009-07-14 16:56:47 -070050 OBSERVER_ON_MSG,
Jamie Gennise2ce6452011-02-23 19:01:28 -080051 GET_GRAPHIC_BUFFER_USAGE,
Andreas Huber20111aa2009-07-14 16:56:47 -070052};
53
Andreas Huber20111aa2009-07-14 16:56:47 -070054class BpOMX : public BpInterface<IOMX> {
55public:
56 BpOMX(const sp<IBinder> &impl)
57 : BpInterface<IOMX>(impl) {
58 }
59
Andreas Huberd459b482012-01-31 11:16:24 -080060 virtual bool livesLocally(node_id node, pid_t pid) {
Andreas Huber7eaa9c92010-01-15 15:28:19 -080061 Parcel data, reply;
62 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberd459b482012-01-31 11:16:24 -080063 data.writeIntPtr((intptr_t)node);
Andreas Huber7eaa9c92010-01-15 15:28:19 -080064 data.writeInt32(pid);
65 remote()->transact(LIVES_LOCALLY, data, &reply);
66
67 return reply.readInt32() != 0;
68 }
69
Andreas Huber134ee6a2009-12-16 09:30:55 -080070 virtual status_t listNodes(List<ComponentInfo> *list) {
Andreas Huber20111aa2009-07-14 16:56:47 -070071 list->clear();
72
73 Parcel data, reply;
74 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
75 remote()->transact(LIST_NODES, data, &reply);
76
77 int32_t n = reply.readInt32();
78 for (int32_t i = 0; i < n; ++i) {
Andreas Huber134ee6a2009-12-16 09:30:55 -080079 list->push_back(ComponentInfo());
80 ComponentInfo &info = *--list->end();
Andreas Huber20111aa2009-07-14 16:56:47 -070081
Andreas Huber134ee6a2009-12-16 09:30:55 -080082 info.mName = reply.readString8();
83 int32_t numRoles = reply.readInt32();
84 for (int32_t j = 0; j < numRoles; ++j) {
85 info.mRoles.push_back(reply.readString8());
86 }
Andreas Huber20111aa2009-07-14 16:56:47 -070087 }
88
89 return OK;
90 }
91
Andreas Huber318ad9c2009-10-15 13:46:54 -070092 virtual status_t allocateNode(
93 const char *name, const sp<IOMXObserver> &observer, node_id *node) {
Andreas Huber20111aa2009-07-14 16:56:47 -070094 Parcel data, reply;
95 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
96 data.writeCString(name);
Andreas Huber318ad9c2009-10-15 13:46:54 -070097 data.writeStrongBinder(observer->asBinder());
Andreas Huber20111aa2009-07-14 16:56:47 -070098 remote()->transact(ALLOCATE_NODE, data, &reply);
99
100 status_t err = reply.readInt32();
101 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700102 *node = (void*)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700103 } else {
104 *node = 0;
105 }
106
107 return err;
108 }
109
Andreas Huber318ad9c2009-10-15 13:46:54 -0700110 virtual status_t freeNode(node_id node) {
Andreas Huber20111aa2009-07-14 16:56:47 -0700111 Parcel data, reply;
112 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700113 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700114 remote()->transact(FREE_NODE, data, &reply);
115
116 return reply.readInt32();
117 }
118
Andreas Huber318ad9c2009-10-15 13:46:54 -0700119 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -0700120 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) {
121 Parcel data, reply;
122 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700123 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700124 data.writeInt32(cmd);
125 data.writeInt32(param);
126 remote()->transact(SEND_COMMAND, data, &reply);
127
128 return reply.readInt32();
129 }
130
Andreas Huber318ad9c2009-10-15 13:46:54 -0700131 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -0700132 node_id node, OMX_INDEXTYPE index,
133 void *params, size_t size) {
134 Parcel data, reply;
135 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700136 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700137 data.writeInt32(index);
138 data.writeInt32(size);
139 data.write(params, size);
140 remote()->transact(GET_PARAMETER, data, &reply);
141
142 status_t err = reply.readInt32();
143 if (err != OK) {
144 return err;
145 }
146
147 reply.read(params, size);
148
149 return OK;
150 }
151
Andreas Huber318ad9c2009-10-15 13:46:54 -0700152 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -0700153 node_id node, OMX_INDEXTYPE index,
154 const void *params, size_t size) {
155 Parcel data, reply;
156 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700157 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700158 data.writeInt32(index);
159 data.writeInt32(size);
160 data.write(params, size);
161 remote()->transact(SET_PARAMETER, data, &reply);
162
163 return reply.readInt32();
164 }
165
Andreas Huber318ad9c2009-10-15 13:46:54 -0700166 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -0700167 node_id node, OMX_INDEXTYPE index,
168 void *params, size_t size) {
169 Parcel data, reply;
170 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700171 data.writeIntPtr((intptr_t)node);
Andreas Huber693d2712009-08-14 14:37:10 -0700172 data.writeInt32(index);
173 data.writeInt32(size);
174 data.write(params, size);
175 remote()->transact(GET_CONFIG, data, &reply);
176
177 status_t err = reply.readInt32();
178 if (err != OK) {
179 return err;
180 }
181
182 reply.read(params, size);
183
184 return OK;
185 }
186
Andreas Huber318ad9c2009-10-15 13:46:54 -0700187 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -0700188 node_id node, OMX_INDEXTYPE index,
189 const void *params, size_t size) {
190 Parcel data, reply;
191 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700192 data.writeIntPtr((intptr_t)node);
Andreas Huber693d2712009-08-14 14:37:10 -0700193 data.writeInt32(index);
194 data.writeInt32(size);
195 data.write(params, size);
196 remote()->transact(SET_CONFIG, data, &reply);
197
198 return reply.readInt32();
199 }
200
Jamie Gennisb1d666f2011-10-19 21:14:13 -0700201 virtual status_t getState(
202 node_id node, OMX_STATETYPE* state) {
203 Parcel data, reply;
204 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
205 data.writeIntPtr((intptr_t)node);
206 remote()->transact(GET_STATE, data, &reply);
207
208 *state = static_cast<OMX_STATETYPE>(reply.readInt32());
209 return reply.readInt32();
210 }
211
Jamie Gennis83750ea2010-08-30 16:48:38 -0700212 virtual status_t enableGraphicBuffers(
213 node_id node, OMX_U32 port_index, OMX_BOOL enable) {
214 Parcel data, reply;
215 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
216 data.writeIntPtr((intptr_t)node);
217 data.writeInt32(port_index);
218 data.writeInt32((uint32_t)enable);
219 remote()->transact(ENABLE_GRAPHIC_BUFFERS, data, &reply);
220
221 status_t err = reply.readInt32();
222 return err;
223 }
224
Jamie Gennise2ce6452011-02-23 19:01:28 -0800225 virtual status_t getGraphicBufferUsage(
226 node_id node, OMX_U32 port_index, OMX_U32* usage) {
227 Parcel data, reply;
228 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
229 data.writeIntPtr((intptr_t)node);
230 data.writeInt32(port_index);
231 remote()->transact(GET_GRAPHIC_BUFFER_USAGE, data, &reply);
232
233 status_t err = reply.readInt32();
234 *usage = reply.readInt32();
235 return err;
236 }
237
Andreas Huber318ad9c2009-10-15 13:46:54 -0700238 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700239 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
240 buffer_id *buffer) {
241 Parcel data, reply;
242 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700243 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700244 data.writeInt32(port_index);
245 data.writeStrongBinder(params->asBinder());
246 remote()->transact(USE_BUFFER, data, &reply);
247
248 status_t err = reply.readInt32();
249 if (err != OK) {
250 *buffer = 0;
251
252 return err;
253 }
254
Andreas Huberc6b59b72009-08-17 13:33:27 -0700255 *buffer = (void*)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700256
257 return err;
258 }
259
Jamie Gennis83750ea2010-08-30 16:48:38 -0700260
261 virtual status_t useGraphicBuffer(
262 node_id node, OMX_U32 port_index,
263 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) {
264 Parcel data, reply;
265 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
266 data.writeIntPtr((intptr_t)node);
267 data.writeInt32(port_index);
268 data.write(*graphicBuffer);
269 remote()->transact(USE_GRAPHIC_BUFFER, data, &reply);
270
271 status_t err = reply.readInt32();
272 if (err != OK) {
273 *buffer = 0;
274
275 return err;
276 }
277
278 *buffer = (void*)reply.readIntPtr();
279
280 return err;
281 }
282
James Donge8707722010-10-20 17:38:41 -0700283 virtual status_t storeMetaDataInBuffers(
284 node_id node, OMX_U32 port_index, OMX_BOOL enable) {
285 Parcel data, reply;
286 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
287 data.writeIntPtr((intptr_t)node);
288 data.writeInt32(port_index);
289 data.writeInt32((uint32_t)enable);
290 remote()->transact(STORE_META_DATA_IN_BUFFERS, data, &reply);
291
292 status_t err = reply.readInt32();
293 return err;
294 }
295
Andreas Huber318ad9c2009-10-15 13:46:54 -0700296 virtual status_t allocateBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700297 node_id node, OMX_U32 port_index, size_t size,
Andreas Huber570a3cb2010-01-20 15:05:46 -0800298 buffer_id *buffer, void **buffer_data) {
Andreas Huber20111aa2009-07-14 16:56:47 -0700299 Parcel data, reply;
300 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700301 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700302 data.writeInt32(port_index);
303 data.writeInt32(size);
304 remote()->transact(ALLOC_BUFFER, data, &reply);
305
306 status_t err = reply.readInt32();
307 if (err != OK) {
308 *buffer = 0;
309
310 return err;
311 }
312
Andreas Huber570a3cb2010-01-20 15:05:46 -0800313 *buffer = (void *)reply.readIntPtr();
314 *buffer_data = (void *)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700315
316 return err;
317 }
318
Andreas Huber318ad9c2009-10-15 13:46:54 -0700319 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700320 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
321 buffer_id *buffer) {
322 Parcel data, reply;
323 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700324 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700325 data.writeInt32(port_index);
326 data.writeStrongBinder(params->asBinder());
327 remote()->transact(ALLOC_BUFFER_WITH_BACKUP, data, &reply);
328
329 status_t err = reply.readInt32();
330 if (err != OK) {
331 *buffer = 0;
332
333 return err;
334 }
335
Andreas Huberc6b59b72009-08-17 13:33:27 -0700336 *buffer = (void*)reply.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700337
338 return err;
339 }
340
Andreas Huber318ad9c2009-10-15 13:46:54 -0700341 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700342 node_id node, OMX_U32 port_index, buffer_id buffer) {
343 Parcel data, reply;
344 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700345 data.writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700346 data.writeInt32(port_index);
Andreas Huberc6b59b72009-08-17 13:33:27 -0700347 data.writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700348 remote()->transact(FREE_BUFFER, data, &reply);
349
350 return reply.readInt32();
351 }
352
Andreas Huber318ad9c2009-10-15 13:46:54 -0700353 virtual status_t fillBuffer(node_id node, buffer_id buffer) {
Andreas Huber20111aa2009-07-14 16:56:47 -0700354 Parcel data, reply;
355 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700356 data.writeIntPtr((intptr_t)node);
357 data.writeIntPtr((intptr_t)buffer);
Andreas Huber36efa032009-10-08 11:02:27 -0700358 remote()->transact(FILL_BUFFER, data, &reply);
359
360 return reply.readInt32();
Andreas Huber20111aa2009-07-14 16:56:47 -0700361 }
362
Andreas Huber318ad9c2009-10-15 13:46:54 -0700363 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700364 node_id node,
365 buffer_id buffer,
366 OMX_U32 range_offset, OMX_U32 range_length,
367 OMX_U32 flags, OMX_TICKS timestamp) {
368 Parcel data, reply;
369 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700370 data.writeIntPtr((intptr_t)node);
371 data.writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700372 data.writeInt32(range_offset);
373 data.writeInt32(range_length);
374 data.writeInt32(flags);
375 data.writeInt64(timestamp);
Andreas Huber36efa032009-10-08 11:02:27 -0700376 remote()->transact(EMPTY_BUFFER, data, &reply);
377
378 return reply.readInt32();
Andreas Huber20111aa2009-07-14 16:56:47 -0700379 }
Andreas Huber8b938cd2009-07-31 11:52:50 -0700380
Andreas Huber318ad9c2009-10-15 13:46:54 -0700381 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700382 node_id node,
383 const char *parameter_name,
384 OMX_INDEXTYPE *index) {
385 Parcel data, reply;
386 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huberc6b59b72009-08-17 13:33:27 -0700387 data.writeIntPtr((intptr_t)node);
Andreas Huber693d2712009-08-14 14:37:10 -0700388 data.writeCString(parameter_name);
389
390 remote()->transact(GET_EXTENSION_INDEX, data, &reply);
391
392 status_t err = reply.readInt32();
393 if (err == OK) {
394 *index = static_cast<OMX_INDEXTYPE>(reply.readInt32());
395 } else {
396 *index = OMX_IndexComponentStartUnused;
397 }
398
399 return err;
400 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700401};
402
403IMPLEMENT_META_INTERFACE(OMX, "android.hardware.IOMX");
404
405////////////////////////////////////////////////////////////////////////////////
406
407#define CHECK_INTERFACE(interface, data, reply) \
408 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
Steve Block5ff1dd52012-01-05 23:22:43 +0000409 ALOGW("Call incorrectly routed to " #interface); \
Andreas Huber20111aa2009-07-14 16:56:47 -0700410 return PERMISSION_DENIED; \
411 } } while (0)
412
413status_t BnOMX::onTransact(
414 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
415 switch (code) {
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800416 case LIVES_LOCALLY:
417 {
418 CHECK_INTERFACE(IOMX, data, reply);
Andreas Huberd459b482012-01-31 11:16:24 -0800419 node_id node = (void *)data.readIntPtr();
420 pid_t pid = (pid_t)data.readInt32();
421 reply->writeInt32(livesLocally(node, pid));
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800422
423 return OK;
424 }
425
Andreas Huber20111aa2009-07-14 16:56:47 -0700426 case LIST_NODES:
427 {
428 CHECK_INTERFACE(IOMX, data, reply);
429
Andreas Huber134ee6a2009-12-16 09:30:55 -0800430 List<ComponentInfo> list;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700431 listNodes(&list);
Andreas Huber20111aa2009-07-14 16:56:47 -0700432
433 reply->writeInt32(list.size());
Andreas Huber134ee6a2009-12-16 09:30:55 -0800434 for (List<ComponentInfo>::iterator it = list.begin();
Andreas Huber20111aa2009-07-14 16:56:47 -0700435 it != list.end(); ++it) {
Andreas Huber134ee6a2009-12-16 09:30:55 -0800436 ComponentInfo &cur = *it;
437
438 reply->writeString8(cur.mName);
439 reply->writeInt32(cur.mRoles.size());
440 for (List<String8>::iterator role_it = cur.mRoles.begin();
441 role_it != cur.mRoles.end(); ++role_it) {
442 reply->writeString8(*role_it);
443 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700444 }
445
446 return NO_ERROR;
447 }
448
449 case ALLOCATE_NODE:
450 {
451 CHECK_INTERFACE(IOMX, data, reply);
452
Andreas Huber318ad9c2009-10-15 13:46:54 -0700453 const char *name = data.readCString();
454
455 sp<IOMXObserver> observer =
456 interface_cast<IOMXObserver>(data.readStrongBinder());
457
Andreas Huber20111aa2009-07-14 16:56:47 -0700458 node_id node;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700459
460 status_t err = allocateNode(name, observer, &node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700461 reply->writeInt32(err);
462 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700463 reply->writeIntPtr((intptr_t)node);
Andreas Huber20111aa2009-07-14 16:56:47 -0700464 }
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800465
Andreas Huber20111aa2009-07-14 16:56:47 -0700466 return NO_ERROR;
467 }
468
469 case FREE_NODE:
470 {
471 CHECK_INTERFACE(IOMX, data, reply);
472
Andreas Huberc6b59b72009-08-17 13:33:27 -0700473 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700474
Andreas Huber318ad9c2009-10-15 13:46:54 -0700475 reply->writeInt32(freeNode(node));
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800476
Andreas Huber20111aa2009-07-14 16:56:47 -0700477 return NO_ERROR;
478 }
479
480 case SEND_COMMAND:
481 {
482 CHECK_INTERFACE(IOMX, data, reply);
483
Andreas Huberc6b59b72009-08-17 13:33:27 -0700484 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700485
486 OMX_COMMANDTYPE cmd =
487 static_cast<OMX_COMMANDTYPE>(data.readInt32());
488
489 OMX_S32 param = data.readInt32();
Andreas Huber318ad9c2009-10-15 13:46:54 -0700490 reply->writeInt32(sendCommand(node, cmd, param));
Andreas Huber20111aa2009-07-14 16:56:47 -0700491
492 return NO_ERROR;
493 }
494
495 case GET_PARAMETER:
Andreas Huber20111aa2009-07-14 16:56:47 -0700496 case SET_PARAMETER:
Andreas Huber693d2712009-08-14 14:37:10 -0700497 case GET_CONFIG:
Andreas Huber693d2712009-08-14 14:37:10 -0700498 case SET_CONFIG:
499 {
500 CHECK_INTERFACE(IOMX, data, reply);
501
Andreas Huberc6b59b72009-08-17 13:33:27 -0700502 node_id node = (void*)data.readIntPtr();
Andreas Huber693d2712009-08-14 14:37:10 -0700503 OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32());
504
505 size_t size = data.readInt32();
Andreas Huber693d2712009-08-14 14:37:10 -0700506
Andreas Huberb3912902011-01-19 10:34:52 -0800507 void *params = malloc(size);
508 data.read(params, size);
509
510 status_t err;
511 switch (code) {
512 case GET_PARAMETER:
513 err = getParameter(node, index, params, size);
514 break;
515 case SET_PARAMETER:
516 err = setParameter(node, index, params, size);
517 break;
518 case GET_CONFIG:
519 err = getConfig(node, index, params, size);
520 break;
521 case SET_CONFIG:
522 err = setConfig(node, index, params, size);
523 break;
524 default:
525 TRESPASS();
526 }
527
528 reply->writeInt32(err);
529
530 if ((code == GET_PARAMETER || code == GET_CONFIG) && err == OK) {
531 reply->write(params, size);
532 }
533
534 free(params);
535 params = NULL;
Andreas Huber693d2712009-08-14 14:37:10 -0700536
537 return NO_ERROR;
538 }
539
Jamie Gennisb1d666f2011-10-19 21:14:13 -0700540 case GET_STATE:
541 {
542 CHECK_INTERFACE(IOMX, data, reply);
543
544 node_id node = (void*)data.readIntPtr();
545 OMX_STATETYPE state = OMX_StateInvalid;
546
547 status_t err = getState(node, &state);
548 reply->writeInt32(state);
549 reply->writeInt32(err);
550
551 return NO_ERROR;
552 }
553
Jamie Gennis83750ea2010-08-30 16:48:38 -0700554 case ENABLE_GRAPHIC_BUFFERS:
555 {
556 CHECK_INTERFACE(IOMX, data, reply);
557
558 node_id node = (void*)data.readIntPtr();
559 OMX_U32 port_index = data.readInt32();
560 OMX_BOOL enable = (OMX_BOOL)data.readInt32();
561
562 status_t err = enableGraphicBuffers(node, port_index, enable);
563 reply->writeInt32(err);
564
565 return NO_ERROR;
566 }
567
Jamie Gennise2ce6452011-02-23 19:01:28 -0800568 case GET_GRAPHIC_BUFFER_USAGE:
569 {
570 CHECK_INTERFACE(IOMX, data, reply);
571
572 node_id node = (void*)data.readIntPtr();
573 OMX_U32 port_index = data.readInt32();
574
575 OMX_U32 usage = 0;
576 status_t err = getGraphicBufferUsage(node, port_index, &usage);
577 reply->writeInt32(err);
578 reply->writeInt32(usage);
579
580 return NO_ERROR;
581 }
582
Andreas Huber20111aa2009-07-14 16:56:47 -0700583 case USE_BUFFER:
584 {
585 CHECK_INTERFACE(IOMX, data, reply);
586
Andreas Huberc6b59b72009-08-17 13:33:27 -0700587 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700588 OMX_U32 port_index = data.readInt32();
589 sp<IMemory> params =
590 interface_cast<IMemory>(data.readStrongBinder());
591
592 buffer_id buffer;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700593 status_t err = useBuffer(node, port_index, params, &buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700594 reply->writeInt32(err);
595
596 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700597 reply->writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700598 }
599
600 return NO_ERROR;
601 }
602
Jamie Gennis83750ea2010-08-30 16:48:38 -0700603 case USE_GRAPHIC_BUFFER:
604 {
605 CHECK_INTERFACE(IOMX, data, reply);
606
607 node_id node = (void*)data.readIntPtr();
608 OMX_U32 port_index = data.readInt32();
609 sp<GraphicBuffer> graphicBuffer = new GraphicBuffer();
610 data.read(*graphicBuffer);
611
612 buffer_id buffer;
613 status_t err = useGraphicBuffer(
614 node, port_index, graphicBuffer, &buffer);
615 reply->writeInt32(err);
616
617 if (err == OK) {
618 reply->writeIntPtr((intptr_t)buffer);
619 }
620
621 return NO_ERROR;
622 }
623
James Donge8707722010-10-20 17:38:41 -0700624 case STORE_META_DATA_IN_BUFFERS:
625 {
626 CHECK_INTERFACE(IOMX, data, reply);
627
628 node_id node = (void*)data.readIntPtr();
629 OMX_U32 port_index = data.readInt32();
630 OMX_BOOL enable = (OMX_BOOL)data.readInt32();
631
632 status_t err = storeMetaDataInBuffers(node, port_index, enable);
633 reply->writeInt32(err);
634
635 return NO_ERROR;
636 }
637
Andreas Huber20111aa2009-07-14 16:56:47 -0700638 case ALLOC_BUFFER:
639 {
640 CHECK_INTERFACE(IOMX, data, reply);
641
Andreas Huberc6b59b72009-08-17 13:33:27 -0700642 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700643 OMX_U32 port_index = data.readInt32();
644 size_t size = data.readInt32();
645
646 buffer_id buffer;
Andreas Huber570a3cb2010-01-20 15:05:46 -0800647 void *buffer_data;
648 status_t err = allocateBuffer(
649 node, port_index, size, &buffer, &buffer_data);
Andreas Huber20111aa2009-07-14 16:56:47 -0700650 reply->writeInt32(err);
651
652 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700653 reply->writeIntPtr((intptr_t)buffer);
Andreas Huber570a3cb2010-01-20 15:05:46 -0800654 reply->writeIntPtr((intptr_t)buffer_data);
Andreas Huber20111aa2009-07-14 16:56:47 -0700655 }
656
657 return NO_ERROR;
658 }
659
660 case ALLOC_BUFFER_WITH_BACKUP:
661 {
662 CHECK_INTERFACE(IOMX, data, reply);
663
Andreas Huberc6b59b72009-08-17 13:33:27 -0700664 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700665 OMX_U32 port_index = data.readInt32();
666 sp<IMemory> params =
667 interface_cast<IMemory>(data.readStrongBinder());
668
669 buffer_id buffer;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700670 status_t err = allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700671 node, port_index, params, &buffer);
672
673 reply->writeInt32(err);
674
675 if (err == OK) {
Andreas Huberc6b59b72009-08-17 13:33:27 -0700676 reply->writeIntPtr((intptr_t)buffer);
Andreas Huber20111aa2009-07-14 16:56:47 -0700677 }
678
679 return NO_ERROR;
680 }
681
682 case FREE_BUFFER:
683 {
684 CHECK_INTERFACE(IOMX, data, reply);
685
Andreas Huberc6b59b72009-08-17 13:33:27 -0700686 node_id node = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700687 OMX_U32 port_index = data.readInt32();
Andreas Huberc6b59b72009-08-17 13:33:27 -0700688 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber318ad9c2009-10-15 13:46:54 -0700689 reply->writeInt32(freeBuffer(node, port_index, buffer));
Andreas Huber20111aa2009-07-14 16:56:47 -0700690
691 return NO_ERROR;
692 }
693
694 case FILL_BUFFER:
695 {
696 CHECK_INTERFACE(IOMX, data, reply);
697
Andreas Huberc6b59b72009-08-17 13:33:27 -0700698 node_id node = (void*)data.readIntPtr();
699 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber318ad9c2009-10-15 13:46:54 -0700700 reply->writeInt32(fillBuffer(node, buffer));
Andreas Huber20111aa2009-07-14 16:56:47 -0700701
702 return NO_ERROR;
703 }
704
705 case EMPTY_BUFFER:
706 {
707 CHECK_INTERFACE(IOMX, data, reply);
708
Andreas Huberc6b59b72009-08-17 13:33:27 -0700709 node_id node = (void*)data.readIntPtr();
710 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber20111aa2009-07-14 16:56:47 -0700711 OMX_U32 range_offset = data.readInt32();
712 OMX_U32 range_length = data.readInt32();
713 OMX_U32 flags = data.readInt32();
714 OMX_TICKS timestamp = data.readInt64();
715
Andreas Huber36efa032009-10-08 11:02:27 -0700716 reply->writeInt32(
Andreas Huber318ad9c2009-10-15 13:46:54 -0700717 emptyBuffer(
Andreas Huber36efa032009-10-08 11:02:27 -0700718 node, buffer, range_offset, range_length,
719 flags, timestamp));
Andreas Huber20111aa2009-07-14 16:56:47 -0700720
721 return NO_ERROR;
722 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700723
Andreas Huber693d2712009-08-14 14:37:10 -0700724 case GET_EXTENSION_INDEX:
725 {
726 CHECK_INTERFACE(IOMX, data, reply);
727
Andreas Huberc6b59b72009-08-17 13:33:27 -0700728 node_id node = (void*)data.readIntPtr();
Andreas Huber693d2712009-08-14 14:37:10 -0700729 const char *parameter_name = data.readCString();
Andreas Huber7eaa9c92010-01-15 15:28:19 -0800730
Andreas Huber693d2712009-08-14 14:37:10 -0700731 OMX_INDEXTYPE index;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700732 status_t err = getExtensionIndex(node, parameter_name, &index);
Andreas Huber693d2712009-08-14 14:37:10 -0700733
734 reply->writeInt32(err);
735
736 if (err == OK) {
737 reply->writeInt32(index);
738 }
739
740 return OK;
741 }
742
Andreas Huber20111aa2009-07-14 16:56:47 -0700743 default:
744 return BBinder::onTransact(code, data, reply, flags);
745 }
746}
747
748////////////////////////////////////////////////////////////////////////////////
749
750class BpOMXObserver : public BpInterface<IOMXObserver> {
751public:
752 BpOMXObserver(const sp<IBinder> &impl)
753 : BpInterface<IOMXObserver>(impl) {
754 }
755
Andreas Huber318ad9c2009-10-15 13:46:54 -0700756 virtual void onMessage(const omx_message &msg) {
Andreas Huber20111aa2009-07-14 16:56:47 -0700757 Parcel data, reply;
758 data.writeInterfaceToken(IOMXObserver::getInterfaceDescriptor());
759 data.write(&msg, sizeof(msg));
760
761 remote()->transact(OBSERVER_ON_MSG, data, &reply, IBinder::FLAG_ONEWAY);
762 }
763};
764
765IMPLEMENT_META_INTERFACE(OMXObserver, "android.hardware.IOMXObserver");
766
767status_t BnOMXObserver::onTransact(
768 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
769 switch (code) {
770 case OBSERVER_ON_MSG:
771 {
772 CHECK_INTERFACE(IOMXObserver, data, reply);
773
774 omx_message msg;
775 data.read(&msg, sizeof(msg));
776
777 // XXX Could use readInplace maybe?
Andreas Huber318ad9c2009-10-15 13:46:54 -0700778 onMessage(msg);
Andreas Huber20111aa2009-07-14 16:56:47 -0700779
780 return NO_ERROR;
781 }
782
783 default:
784 return BBinder::onTransact(code, data, reply, flags);
785 }
786}
787
Andreas Huber20111aa2009-07-14 16:56:47 -0700788} // namespace android