blob: 40801a26d070c9194ec55a7c53399f33eaf40141 [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,
Jamie Gennis33a78142010-08-30 16:48:38 -070024 ENABLE_GRAPHIC_BUFFERS,
Andreas Hubere46b7be2009-07-14 16:56:47 -070025 USE_BUFFER,
Jamie Gennis33a78142010-08-30 16:48:38 -070026 USE_GRAPHIC_BUFFER,
Andreas Hubere46b7be2009-07-14 16:56:47 -070027 ALLOC_BUFFER,
28 ALLOC_BUFFER_WITH_BACKUP,
29 FREE_BUFFER,
Andreas Hubere46b7be2009-07-14 16:56:47 -070030 FILL_BUFFER,
31 EMPTY_BUFFER,
Andreas Huberbe06d262009-08-14 14:37:10 -070032 GET_EXTENSION_INDEX,
Andreas Huber1de13162009-07-31 11:52:50 -070033 CREATE_RENDERER,
Andreas Hubere46b7be2009-07-14 16:56:47 -070034 OBSERVER_ON_MSG,
Andreas Huber1de13162009-07-31 11:52:50 -070035 RENDERER_RENDER,
Andreas Hubere46b7be2009-07-14 16:56:47 -070036};
37
Andreas Huberccf8b942009-08-07 12:01:29 -070038sp<IOMXRenderer> IOMX::createRenderer(
39 const sp<Surface> &surface,
40 const char *componentName,
41 OMX_COLOR_FORMATTYPE colorFormat,
42 size_t encodedWidth, size_t encodedHeight,
43 size_t displayWidth, size_t displayHeight) {
44 return createRenderer(
45 surface->getISurface(),
46 componentName, colorFormat, encodedWidth, encodedHeight,
47 displayWidth, displayHeight);
48}
49
Andreas Huber9f9afef2009-09-15 12:49:11 -070050sp<IOMXRenderer> IOMX::createRendererFromJavaSurface(
51 JNIEnv *env, jobject javaSurface,
52 const char *componentName,
53 OMX_COLOR_FORMATTYPE colorFormat,
54 size_t encodedWidth, size_t encodedHeight,
55 size_t displayWidth, size_t displayHeight) {
56 jclass surfaceClass = env->FindClass("android/view/Surface");
57 if (surfaceClass == NULL) {
58 LOGE("Can't find android/view/Surface");
59 return NULL;
60 }
61
Mathias Agopian8b138322010-04-12 16:22:15 -070062 jfieldID surfaceID = env->GetFieldID(surfaceClass, ANDROID_VIEW_SURFACE_JNI_ID, "I");
Andreas Huber9f9afef2009-09-15 12:49:11 -070063 if (surfaceID == NULL) {
64 LOGE("Can't find Surface.mSurface");
65 return NULL;
66 }
67
68 sp<Surface> surface = (Surface *)env->GetIntField(javaSurface, surfaceID);
69
70 return createRenderer(
71 surface, componentName, colorFormat, encodedWidth,
72 encodedHeight, displayWidth, displayHeight);
73}
74
Andreas Hubere46b7be2009-07-14 16:56:47 -070075class BpOMX : public BpInterface<IOMX> {
76public:
77 BpOMX(const sp<IBinder> &impl)
78 : BpInterface<IOMX>(impl) {
79 }
80
Andreas Huberf1fe0642010-01-15 15:28:19 -080081 virtual bool livesLocally(pid_t pid) {
82 Parcel data, reply;
83 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
84 data.writeInt32(pid);
85 remote()->transact(LIVES_LOCALLY, data, &reply);
86
87 return reply.readInt32() != 0;
88 }
89
Andreas Huber2ea14e22009-12-16 09:30:55 -080090 virtual status_t listNodes(List<ComponentInfo> *list) {
Andreas Hubere46b7be2009-07-14 16:56:47 -070091 list->clear();
92
93 Parcel data, reply;
94 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
95 remote()->transact(LIST_NODES, data, &reply);
96
97 int32_t n = reply.readInt32();
98 for (int32_t i = 0; i < n; ++i) {
Andreas Huber2ea14e22009-12-16 09:30:55 -080099 list->push_back(ComponentInfo());
100 ComponentInfo &info = *--list->end();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700101
Andreas Huber2ea14e22009-12-16 09:30:55 -0800102 info.mName = reply.readString8();
103 int32_t numRoles = reply.readInt32();
104 for (int32_t j = 0; j < numRoles; ++j) {
105 info.mRoles.push_back(reply.readString8());
106 }
Andreas Hubere46b7be2009-07-14 16:56:47 -0700107 }
108
109 return OK;
110 }
111
Andreas Huber784202e2009-10-15 13:46:54 -0700112 virtual status_t allocateNode(
113 const char *name, const sp<IOMXObserver> &observer, node_id *node) {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700114 Parcel data, reply;
115 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
116 data.writeCString(name);
Andreas Huber784202e2009-10-15 13:46:54 -0700117 data.writeStrongBinder(observer->asBinder());
Andreas Hubere46b7be2009-07-14 16:56:47 -0700118 remote()->transact(ALLOCATE_NODE, data, &reply);
119
120 status_t err = reply.readInt32();
121 if (err == OK) {
Andreas Huber2f10ae02009-08-17 13:33:27 -0700122 *node = (void*)reply.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700123 } else {
124 *node = 0;
125 }
126
127 return err;
128 }
129
Andreas Huber784202e2009-10-15 13:46:54 -0700130 virtual status_t freeNode(node_id node) {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700131 Parcel data, reply;
132 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700133 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700134 remote()->transact(FREE_NODE, data, &reply);
135
136 return reply.readInt32();
137 }
138
Andreas Huber784202e2009-10-15 13:46:54 -0700139 virtual status_t sendCommand(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700140 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) {
141 Parcel data, reply;
142 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700143 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700144 data.writeInt32(cmd);
145 data.writeInt32(param);
146 remote()->transact(SEND_COMMAND, data, &reply);
147
148 return reply.readInt32();
149 }
150
Andreas Huber784202e2009-10-15 13:46:54 -0700151 virtual status_t getParameter(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700152 node_id node, OMX_INDEXTYPE index,
153 void *params, size_t size) {
154 Parcel data, reply;
155 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700156 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700157 data.writeInt32(index);
158 data.writeInt32(size);
159 data.write(params, size);
160 remote()->transact(GET_PARAMETER, data, &reply);
161
162 status_t err = reply.readInt32();
163 if (err != OK) {
164 return err;
165 }
166
167 reply.read(params, size);
168
169 return OK;
170 }
171
Andreas Huber784202e2009-10-15 13:46:54 -0700172 virtual status_t setParameter(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700173 node_id node, OMX_INDEXTYPE index,
174 const void *params, size_t size) {
175 Parcel data, reply;
176 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700177 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700178 data.writeInt32(index);
179 data.writeInt32(size);
180 data.write(params, size);
181 remote()->transact(SET_PARAMETER, data, &reply);
182
183 return reply.readInt32();
184 }
185
Andreas Huber784202e2009-10-15 13:46:54 -0700186 virtual status_t getConfig(
Andreas Huberbe06d262009-08-14 14:37:10 -0700187 node_id node, OMX_INDEXTYPE index,
188 void *params, size_t size) {
189 Parcel data, reply;
190 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700191 data.writeIntPtr((intptr_t)node);
Andreas Huberbe06d262009-08-14 14:37:10 -0700192 data.writeInt32(index);
193 data.writeInt32(size);
194 data.write(params, size);
195 remote()->transact(GET_CONFIG, data, &reply);
196
197 status_t err = reply.readInt32();
198 if (err != OK) {
199 return err;
200 }
201
202 reply.read(params, size);
203
204 return OK;
205 }
206
Andreas Huber784202e2009-10-15 13:46:54 -0700207 virtual status_t setConfig(
Andreas Huberbe06d262009-08-14 14:37:10 -0700208 node_id node, OMX_INDEXTYPE index,
209 const void *params, size_t size) {
210 Parcel data, reply;
211 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700212 data.writeIntPtr((intptr_t)node);
Andreas Huberbe06d262009-08-14 14:37:10 -0700213 data.writeInt32(index);
214 data.writeInt32(size);
215 data.write(params, size);
216 remote()->transact(SET_CONFIG, data, &reply);
217
218 return reply.readInt32();
219 }
220
Jamie Gennis33a78142010-08-30 16:48:38 -0700221 virtual status_t enableGraphicBuffers(
222 node_id node, OMX_U32 port_index, OMX_BOOL enable) {
223 Parcel data, reply;
224 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
225 data.writeIntPtr((intptr_t)node);
226 data.writeInt32(port_index);
227 data.writeInt32((uint32_t)enable);
228 remote()->transact(ENABLE_GRAPHIC_BUFFERS, data, &reply);
229
230 status_t err = reply.readInt32();
231 return err;
232 }
233
Andreas Huber784202e2009-10-15 13:46:54 -0700234 virtual status_t useBuffer(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700235 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
236 buffer_id *buffer) {
237 Parcel data, reply;
238 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700239 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700240 data.writeInt32(port_index);
241 data.writeStrongBinder(params->asBinder());
242 remote()->transact(USE_BUFFER, data, &reply);
243
244 status_t err = reply.readInt32();
245 if (err != OK) {
246 *buffer = 0;
247
248 return err;
249 }
250
Andreas Huber2f10ae02009-08-17 13:33:27 -0700251 *buffer = (void*)reply.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700252
253 return err;
254 }
255
Jamie Gennis33a78142010-08-30 16:48:38 -0700256
257 virtual status_t useGraphicBuffer(
258 node_id node, OMX_U32 port_index,
259 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) {
260 Parcel data, reply;
261 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
262 data.writeIntPtr((intptr_t)node);
263 data.writeInt32(port_index);
264 data.write(*graphicBuffer);
265 remote()->transact(USE_GRAPHIC_BUFFER, data, &reply);
266
267 status_t err = reply.readInt32();
268 if (err != OK) {
269 *buffer = 0;
270
271 return err;
272 }
273
274 *buffer = (void*)reply.readIntPtr();
275
276 return err;
277 }
278
Andreas Huber784202e2009-10-15 13:46:54 -0700279 virtual status_t allocateBuffer(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700280 node_id node, OMX_U32 port_index, size_t size,
Andreas Huberc712b9f2010-01-20 15:05:46 -0800281 buffer_id *buffer, void **buffer_data) {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700282 Parcel data, reply;
283 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700284 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700285 data.writeInt32(port_index);
286 data.writeInt32(size);
287 remote()->transact(ALLOC_BUFFER, data, &reply);
288
289 status_t err = reply.readInt32();
290 if (err != OK) {
291 *buffer = 0;
292
293 return err;
294 }
295
Andreas Huberc712b9f2010-01-20 15:05:46 -0800296 *buffer = (void *)reply.readIntPtr();
297 *buffer_data = (void *)reply.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700298
299 return err;
300 }
301
Andreas Huber784202e2009-10-15 13:46:54 -0700302 virtual status_t allocateBufferWithBackup(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700303 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
304 buffer_id *buffer) {
305 Parcel data, reply;
306 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700307 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700308 data.writeInt32(port_index);
309 data.writeStrongBinder(params->asBinder());
310 remote()->transact(ALLOC_BUFFER_WITH_BACKUP, data, &reply);
311
312 status_t err = reply.readInt32();
313 if (err != OK) {
314 *buffer = 0;
315
316 return err;
317 }
318
Andreas Huber2f10ae02009-08-17 13:33:27 -0700319 *buffer = (void*)reply.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700320
321 return err;
322 }
323
Andreas Huber784202e2009-10-15 13:46:54 -0700324 virtual status_t freeBuffer(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700325 node_id node, OMX_U32 port_index, buffer_id buffer) {
326 Parcel data, reply;
327 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700328 data.writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700329 data.writeInt32(port_index);
Andreas Huber2f10ae02009-08-17 13:33:27 -0700330 data.writeIntPtr((intptr_t)buffer);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700331 remote()->transact(FREE_BUFFER, data, &reply);
332
333 return reply.readInt32();
334 }
335
Andreas Huber784202e2009-10-15 13:46:54 -0700336 virtual status_t fillBuffer(node_id node, buffer_id buffer) {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700337 Parcel data, reply;
338 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700339 data.writeIntPtr((intptr_t)node);
340 data.writeIntPtr((intptr_t)buffer);
Andreas Huber3f427072009-10-08 11:02:27 -0700341 remote()->transact(FILL_BUFFER, data, &reply);
342
343 return reply.readInt32();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700344 }
345
Andreas Huber784202e2009-10-15 13:46:54 -0700346 virtual status_t emptyBuffer(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700347 node_id node,
348 buffer_id buffer,
349 OMX_U32 range_offset, OMX_U32 range_length,
350 OMX_U32 flags, OMX_TICKS timestamp) {
351 Parcel data, reply;
352 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700353 data.writeIntPtr((intptr_t)node);
354 data.writeIntPtr((intptr_t)buffer);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700355 data.writeInt32(range_offset);
356 data.writeInt32(range_length);
357 data.writeInt32(flags);
358 data.writeInt64(timestamp);
Andreas Huber3f427072009-10-08 11:02:27 -0700359 remote()->transact(EMPTY_BUFFER, data, &reply);
360
361 return reply.readInt32();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700362 }
Andreas Huber1de13162009-07-31 11:52:50 -0700363
Andreas Huber784202e2009-10-15 13:46:54 -0700364 virtual status_t getExtensionIndex(
Andreas Huberbe06d262009-08-14 14:37:10 -0700365 node_id node,
366 const char *parameter_name,
367 OMX_INDEXTYPE *index) {
368 Parcel data, reply;
369 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700370 data.writeIntPtr((intptr_t)node);
Andreas Huberbe06d262009-08-14 14:37:10 -0700371 data.writeCString(parameter_name);
372
373 remote()->transact(GET_EXTENSION_INDEX, data, &reply);
374
375 status_t err = reply.readInt32();
376 if (err == OK) {
377 *index = static_cast<OMX_INDEXTYPE>(reply.readInt32());
378 } else {
379 *index = OMX_IndexComponentStartUnused;
380 }
381
382 return err;
383 }
384
Andreas Huber1de13162009-07-31 11:52:50 -0700385 virtual sp<IOMXRenderer> createRenderer(
386 const sp<ISurface> &surface,
387 const char *componentName,
388 OMX_COLOR_FORMATTYPE colorFormat,
389 size_t encodedWidth, size_t encodedHeight,
390 size_t displayWidth, size_t displayHeight) {
391 Parcel data, reply;
392 data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
393
394 data.writeStrongBinder(surface->asBinder());
395 data.writeCString(componentName);
396 data.writeInt32(colorFormat);
397 data.writeInt32(encodedWidth);
398 data.writeInt32(encodedHeight);
399 data.writeInt32(displayWidth);
400 data.writeInt32(displayHeight);
401
402 remote()->transact(CREATE_RENDERER, data, &reply);
403
404 return interface_cast<IOMXRenderer>(reply.readStrongBinder());
405 }
Andreas Hubere46b7be2009-07-14 16:56:47 -0700406};
407
408IMPLEMENT_META_INTERFACE(OMX, "android.hardware.IOMX");
409
410////////////////////////////////////////////////////////////////////////////////
411
412#define CHECK_INTERFACE(interface, data, reply) \
413 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
414 LOGW("Call incorrectly routed to " #interface); \
415 return PERMISSION_DENIED; \
416 } } while (0)
417
418status_t BnOMX::onTransact(
419 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
420 switch (code) {
Andreas Huberf1fe0642010-01-15 15:28:19 -0800421 case LIVES_LOCALLY:
422 {
423 CHECK_INTERFACE(IOMX, data, reply);
424 reply->writeInt32(livesLocally((pid_t)data.readInt32()));
425
426 return OK;
427 }
428
Andreas Hubere46b7be2009-07-14 16:56:47 -0700429 case LIST_NODES:
430 {
431 CHECK_INTERFACE(IOMX, data, reply);
432
Andreas Huber2ea14e22009-12-16 09:30:55 -0800433 List<ComponentInfo> list;
Andreas Huber784202e2009-10-15 13:46:54 -0700434 listNodes(&list);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700435
436 reply->writeInt32(list.size());
Andreas Huber2ea14e22009-12-16 09:30:55 -0800437 for (List<ComponentInfo>::iterator it = list.begin();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700438 it != list.end(); ++it) {
Andreas Huber2ea14e22009-12-16 09:30:55 -0800439 ComponentInfo &cur = *it;
440
441 reply->writeString8(cur.mName);
442 reply->writeInt32(cur.mRoles.size());
443 for (List<String8>::iterator role_it = cur.mRoles.begin();
444 role_it != cur.mRoles.end(); ++role_it) {
445 reply->writeString8(*role_it);
446 }
Andreas Hubere46b7be2009-07-14 16:56:47 -0700447 }
448
449 return NO_ERROR;
450 }
451
452 case ALLOCATE_NODE:
453 {
454 CHECK_INTERFACE(IOMX, data, reply);
455
Andreas Huber784202e2009-10-15 13:46:54 -0700456 const char *name = data.readCString();
457
458 sp<IOMXObserver> observer =
459 interface_cast<IOMXObserver>(data.readStrongBinder());
460
Andreas Hubere46b7be2009-07-14 16:56:47 -0700461 node_id node;
Andreas Huber784202e2009-10-15 13:46:54 -0700462
463 status_t err = allocateNode(name, observer, &node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700464 reply->writeInt32(err);
465 if (err == OK) {
Andreas Huber2f10ae02009-08-17 13:33:27 -0700466 reply->writeIntPtr((intptr_t)node);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700467 }
Andreas Huberf1fe0642010-01-15 15:28:19 -0800468
Andreas Hubere46b7be2009-07-14 16:56:47 -0700469 return NO_ERROR;
470 }
471
472 case FREE_NODE:
473 {
474 CHECK_INTERFACE(IOMX, data, reply);
475
Andreas Huber2f10ae02009-08-17 13:33:27 -0700476 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700477
Andreas Huber784202e2009-10-15 13:46:54 -0700478 reply->writeInt32(freeNode(node));
Andreas Huberf1fe0642010-01-15 15:28:19 -0800479
Andreas Hubere46b7be2009-07-14 16:56:47 -0700480 return NO_ERROR;
481 }
482
483 case SEND_COMMAND:
484 {
485 CHECK_INTERFACE(IOMX, data, reply);
486
Andreas Huber2f10ae02009-08-17 13:33:27 -0700487 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700488
489 OMX_COMMANDTYPE cmd =
490 static_cast<OMX_COMMANDTYPE>(data.readInt32());
491
492 OMX_S32 param = data.readInt32();
Andreas Huber784202e2009-10-15 13:46:54 -0700493 reply->writeInt32(sendCommand(node, cmd, param));
Andreas Hubere46b7be2009-07-14 16:56:47 -0700494
495 return NO_ERROR;
496 }
497
498 case GET_PARAMETER:
499 {
500 CHECK_INTERFACE(IOMX, data, reply);
501
Andreas Huber2f10ae02009-08-17 13:33:27 -0700502 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700503 OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32());
504
505 size_t size = data.readInt32();
506
507 // XXX I am not happy with this but Parcel::readInplace didn't work.
508 void *params = malloc(size);
509 data.read(params, size);
510
Andreas Huber784202e2009-10-15 13:46:54 -0700511 status_t err = getParameter(node, index, params, size);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700512
513 reply->writeInt32(err);
514
515 if (err == OK) {
516 reply->write(params, size);
517 }
518
519 free(params);
520 params = NULL;
521
522 return NO_ERROR;
523 }
524
525 case SET_PARAMETER:
526 {
527 CHECK_INTERFACE(IOMX, data, reply);
528
Andreas Huber2f10ae02009-08-17 13:33:27 -0700529 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700530 OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32());
531
532 size_t size = data.readInt32();
533 void *params = const_cast<void *>(data.readInplace(size));
534
Andreas Huber784202e2009-10-15 13:46:54 -0700535 reply->writeInt32(setParameter(node, index, params, size));
Andreas Hubere46b7be2009-07-14 16:56:47 -0700536
537 return NO_ERROR;
538 }
539
Andreas Huberbe06d262009-08-14 14:37:10 -0700540 case GET_CONFIG:
541 {
542 CHECK_INTERFACE(IOMX, data, reply);
543
Andreas Huber2f10ae02009-08-17 13:33:27 -0700544 node_id node = (void*)data.readIntPtr();
Andreas Huberbe06d262009-08-14 14:37:10 -0700545 OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32());
546
547 size_t size = data.readInt32();
548
549 // XXX I am not happy with this but Parcel::readInplace didn't work.
550 void *params = malloc(size);
551 data.read(params, size);
552
Andreas Huber784202e2009-10-15 13:46:54 -0700553 status_t err = getConfig(node, index, params, size);
Andreas Huberbe06d262009-08-14 14:37:10 -0700554
555 reply->writeInt32(err);
556
557 if (err == OK) {
558 reply->write(params, size);
559 }
560
561 free(params);
562 params = NULL;
563
564 return NO_ERROR;
565 }
566
567 case SET_CONFIG:
568 {
569 CHECK_INTERFACE(IOMX, data, reply);
570
Andreas Huber2f10ae02009-08-17 13:33:27 -0700571 node_id node = (void*)data.readIntPtr();
Andreas Huberbe06d262009-08-14 14:37:10 -0700572 OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32());
573
574 size_t size = data.readInt32();
575 void *params = const_cast<void *>(data.readInplace(size));
576
Andreas Huber784202e2009-10-15 13:46:54 -0700577 reply->writeInt32(setConfig(node, index, params, size));
Andreas Huberbe06d262009-08-14 14:37:10 -0700578
579 return NO_ERROR;
580 }
581
Jamie Gennis33a78142010-08-30 16:48:38 -0700582 case ENABLE_GRAPHIC_BUFFERS:
583 {
584 CHECK_INTERFACE(IOMX, data, reply);
585
586 node_id node = (void*)data.readIntPtr();
587 OMX_U32 port_index = data.readInt32();
588 OMX_BOOL enable = (OMX_BOOL)data.readInt32();
589
590 status_t err = enableGraphicBuffers(node, port_index, enable);
591 reply->writeInt32(err);
592
593 return NO_ERROR;
594 }
595
Andreas Hubere46b7be2009-07-14 16:56:47 -0700596 case USE_BUFFER:
597 {
598 CHECK_INTERFACE(IOMX, data, reply);
599
Andreas Huber2f10ae02009-08-17 13:33:27 -0700600 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700601 OMX_U32 port_index = data.readInt32();
602 sp<IMemory> params =
603 interface_cast<IMemory>(data.readStrongBinder());
604
605 buffer_id buffer;
Andreas Huber784202e2009-10-15 13:46:54 -0700606 status_t err = useBuffer(node, port_index, params, &buffer);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700607 reply->writeInt32(err);
608
609 if (err == OK) {
Andreas Huber2f10ae02009-08-17 13:33:27 -0700610 reply->writeIntPtr((intptr_t)buffer);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700611 }
612
613 return NO_ERROR;
614 }
615
Jamie Gennis33a78142010-08-30 16:48:38 -0700616 case USE_GRAPHIC_BUFFER:
617 {
618 CHECK_INTERFACE(IOMX, data, reply);
619
620 node_id node = (void*)data.readIntPtr();
621 OMX_U32 port_index = data.readInt32();
622 sp<GraphicBuffer> graphicBuffer = new GraphicBuffer();
623 data.read(*graphicBuffer);
624
625 buffer_id buffer;
626 status_t err = useGraphicBuffer(
627 node, port_index, graphicBuffer, &buffer);
628 reply->writeInt32(err);
629
630 if (err == OK) {
631 reply->writeIntPtr((intptr_t)buffer);
632 }
633
634 return NO_ERROR;
635 }
636
Andreas Hubere46b7be2009-07-14 16:56:47 -0700637 case ALLOC_BUFFER:
638 {
639 CHECK_INTERFACE(IOMX, data, reply);
640
Andreas Huber2f10ae02009-08-17 13:33:27 -0700641 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700642 OMX_U32 port_index = data.readInt32();
643 size_t size = data.readInt32();
644
645 buffer_id buffer;
Andreas Huberc712b9f2010-01-20 15:05:46 -0800646 void *buffer_data;
647 status_t err = allocateBuffer(
648 node, port_index, size, &buffer, &buffer_data);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700649 reply->writeInt32(err);
650
651 if (err == OK) {
Andreas Huber2f10ae02009-08-17 13:33:27 -0700652 reply->writeIntPtr((intptr_t)buffer);
Andreas Huberc712b9f2010-01-20 15:05:46 -0800653 reply->writeIntPtr((intptr_t)buffer_data);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700654 }
655
656 return NO_ERROR;
657 }
658
659 case ALLOC_BUFFER_WITH_BACKUP:
660 {
661 CHECK_INTERFACE(IOMX, data, reply);
662
Andreas Huber2f10ae02009-08-17 13:33:27 -0700663 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700664 OMX_U32 port_index = data.readInt32();
665 sp<IMemory> params =
666 interface_cast<IMemory>(data.readStrongBinder());
667
668 buffer_id buffer;
Andreas Huber784202e2009-10-15 13:46:54 -0700669 status_t err = allocateBufferWithBackup(
Andreas Hubere46b7be2009-07-14 16:56:47 -0700670 node, port_index, params, &buffer);
671
672 reply->writeInt32(err);
673
674 if (err == OK) {
Andreas Huber2f10ae02009-08-17 13:33:27 -0700675 reply->writeIntPtr((intptr_t)buffer);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700676 }
677
678 return NO_ERROR;
679 }
680
681 case FREE_BUFFER:
682 {
683 CHECK_INTERFACE(IOMX, data, reply);
684
Andreas Huber2f10ae02009-08-17 13:33:27 -0700685 node_id node = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700686 OMX_U32 port_index = data.readInt32();
Andreas Huber2f10ae02009-08-17 13:33:27 -0700687 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber784202e2009-10-15 13:46:54 -0700688 reply->writeInt32(freeBuffer(node, port_index, buffer));
Andreas Hubere46b7be2009-07-14 16:56:47 -0700689
690 return NO_ERROR;
691 }
692
693 case FILL_BUFFER:
694 {
695 CHECK_INTERFACE(IOMX, data, reply);
696
Andreas Huber2f10ae02009-08-17 13:33:27 -0700697 node_id node = (void*)data.readIntPtr();
698 buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber784202e2009-10-15 13:46:54 -0700699 reply->writeInt32(fillBuffer(node, buffer));
Andreas Hubere46b7be2009-07-14 16:56:47 -0700700
701 return NO_ERROR;
702 }
703
704 case EMPTY_BUFFER:
705 {
706 CHECK_INTERFACE(IOMX, data, reply);
707
Andreas Huber2f10ae02009-08-17 13:33:27 -0700708 node_id node = (void*)data.readIntPtr();
709 buffer_id buffer = (void*)data.readIntPtr();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700710 OMX_U32 range_offset = data.readInt32();
711 OMX_U32 range_length = data.readInt32();
712 OMX_U32 flags = data.readInt32();
713 OMX_TICKS timestamp = data.readInt64();
714
Andreas Huber3f427072009-10-08 11:02:27 -0700715 reply->writeInt32(
Andreas Huber784202e2009-10-15 13:46:54 -0700716 emptyBuffer(
Andreas Huber3f427072009-10-08 11:02:27 -0700717 node, buffer, range_offset, range_length,
718 flags, timestamp));
Andreas Hubere46b7be2009-07-14 16:56:47 -0700719
720 return NO_ERROR;
721 }
Andreas Hubere46b7be2009-07-14 16:56:47 -0700722
Andreas Huberbe06d262009-08-14 14:37:10 -0700723 case GET_EXTENSION_INDEX:
724 {
725 CHECK_INTERFACE(IOMX, data, reply);
726
Andreas Huber2f10ae02009-08-17 13:33:27 -0700727 node_id node = (void*)data.readIntPtr();
Andreas Huberbe06d262009-08-14 14:37:10 -0700728 const char *parameter_name = data.readCString();
Andreas Huberf1fe0642010-01-15 15:28:19 -0800729
Andreas Huberbe06d262009-08-14 14:37:10 -0700730 OMX_INDEXTYPE index;
Andreas Huber784202e2009-10-15 13:46:54 -0700731 status_t err = getExtensionIndex(node, parameter_name, &index);
Andreas Huberbe06d262009-08-14 14:37:10 -0700732
733 reply->writeInt32(err);
734
735 if (err == OK) {
736 reply->writeInt32(index);
737 }
738
739 return OK;
740 }
741
Andreas Huber1de13162009-07-31 11:52:50 -0700742 case CREATE_RENDERER:
743 {
744 CHECK_INTERFACE(IOMX, data, reply);
745
746 sp<ISurface> isurface =
747 interface_cast<ISurface>(data.readStrongBinder());
748
749 const char *componentName = data.readCString();
750
751 OMX_COLOR_FORMATTYPE colorFormat =
752 static_cast<OMX_COLOR_FORMATTYPE>(data.readInt32());
753
754 size_t encodedWidth = (size_t)data.readInt32();
755 size_t encodedHeight = (size_t)data.readInt32();
756 size_t displayWidth = (size_t)data.readInt32();
757 size_t displayHeight = (size_t)data.readInt32();
758
759 sp<IOMXRenderer> renderer =
760 createRenderer(isurface, componentName, colorFormat,
761 encodedWidth, encodedHeight,
762 displayWidth, displayHeight);
763
764 reply->writeStrongBinder(renderer->asBinder());
765
766 return OK;
767 }
768
Andreas Hubere46b7be2009-07-14 16:56:47 -0700769 default:
770 return BBinder::onTransact(code, data, reply, flags);
771 }
772}
773
774////////////////////////////////////////////////////////////////////////////////
775
776class BpOMXObserver : public BpInterface<IOMXObserver> {
777public:
778 BpOMXObserver(const sp<IBinder> &impl)
779 : BpInterface<IOMXObserver>(impl) {
780 }
781
Andreas Huber784202e2009-10-15 13:46:54 -0700782 virtual void onMessage(const omx_message &msg) {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700783 Parcel data, reply;
784 data.writeInterfaceToken(IOMXObserver::getInterfaceDescriptor());
785 data.write(&msg, sizeof(msg));
786
787 remote()->transact(OBSERVER_ON_MSG, data, &reply, IBinder::FLAG_ONEWAY);
788 }
789};
790
791IMPLEMENT_META_INTERFACE(OMXObserver, "android.hardware.IOMXObserver");
792
793status_t BnOMXObserver::onTransact(
794 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
795 switch (code) {
796 case OBSERVER_ON_MSG:
797 {
798 CHECK_INTERFACE(IOMXObserver, data, reply);
799
800 omx_message msg;
801 data.read(&msg, sizeof(msg));
802
803 // XXX Could use readInplace maybe?
Andreas Huber784202e2009-10-15 13:46:54 -0700804 onMessage(msg);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700805
806 return NO_ERROR;
807 }
808
809 default:
810 return BBinder::onTransact(code, data, reply, flags);
811 }
812}
813
Andreas Huber1de13162009-07-31 11:52:50 -0700814////////////////////////////////////////////////////////////////////////////////
815
816class BpOMXRenderer : public BpInterface<IOMXRenderer> {
817public:
818 BpOMXRenderer(const sp<IBinder> &impl)
819 : BpInterface<IOMXRenderer>(impl) {
820 }
821
822 virtual void render(IOMX::buffer_id buffer) {
823 Parcel data, reply;
824 data.writeInterfaceToken(IOMXRenderer::getInterfaceDescriptor());
Andreas Huber2f10ae02009-08-17 13:33:27 -0700825 data.writeIntPtr((intptr_t)buffer);
Andreas Huber1de13162009-07-31 11:52:50 -0700826
827 // NOTE: Do NOT make this a ONE_WAY call, it must be synchronous
828 // so that the caller knows when to recycle the buffer.
829 remote()->transact(RENDERER_RENDER, data, &reply);
830 }
831};
832
833IMPLEMENT_META_INTERFACE(OMXRenderer, "android.hardware.IOMXRenderer");
834
835status_t BnOMXRenderer::onTransact(
836 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
837 switch (code) {
838 case RENDERER_RENDER:
839 {
840 CHECK_INTERFACE(IOMXRenderer, data, reply);
841
Andreas Huber2f10ae02009-08-17 13:33:27 -0700842 IOMX::buffer_id buffer = (void*)data.readIntPtr();
Andreas Huber1de13162009-07-31 11:52:50 -0700843
844 render(buffer);
845
846 return NO_ERROR;
847 }
848
849 default:
850 return BBinder::onTransact(code, data, reply, flags);
851 }
852}
853
Andreas Hubere46b7be2009-07-14 16:56:47 -0700854} // namespace android