James Dong | 27c1744 | 2011-03-17 11:02:04 -0700 | [diff] [blame] | 1 | /* |
| 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 Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "IOMX" |
| 19 | #include <utils/Log.h> |
| 20 | |
Marco Nelissen | 2720c8b | 2016-02-29 12:47:20 -0800 | [diff] [blame] | 21 | #include <sys/mman.h> |
| 22 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 23 | #include <binder/IMemory.h> |
| 24 | #include <binder/Parcel.h> |
| 25 | #include <media/IOMX.h> |
Andreas Huber | b391290 | 2011-01-19 10:34:52 -0800 | [diff] [blame] | 26 | #include <media/stagefright/foundation/ADebug.h> |
Marco Nelissen | c1c50e7 | 2016-03-10 15:02:13 -0800 | [diff] [blame] | 27 | #include <media/openmax/OMX_IndexExt.h> |
Lajos Molnar | 7e0bef8 | 2016-05-09 10:48:30 -0700 | [diff] [blame] | 28 | #include <utils/NativeHandle.h> |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 29 | |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 30 | #include <android/IGraphicBufferSource.h> |
| 31 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | |
| 34 | enum { |
| 35 | CONNECT = IBinder::FIRST_CALL_TRANSACTION, |
| 36 | LIST_NODES, |
| 37 | ALLOCATE_NODE, |
| 38 | FREE_NODE, |
| 39 | SEND_COMMAND, |
| 40 | GET_PARAMETER, |
| 41 | SET_PARAMETER, |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 42 | GET_CONFIG, |
| 43 | SET_CONFIG, |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 44 | ENABLE_NATIVE_BUFFERS, |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 45 | USE_BUFFER, |
Jamie Gennis | 83750ea | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 46 | USE_GRAPHIC_BUFFER, |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 47 | CREATE_INPUT_SURFACE, |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 48 | CREATE_PERSISTENT_INPUT_SURFACE, |
Chong Zhang | 8f469e1 | 2015-05-13 10:21:33 -0700 | [diff] [blame] | 49 | SET_INPUT_SURFACE, |
James Dong | e870772 | 2010-10-20 17:38:41 -0700 | [diff] [blame] | 50 | STORE_META_DATA_IN_BUFFERS, |
Lajos Molnar | 56ce726 | 2013-05-02 16:30:48 -0700 | [diff] [blame] | 51 | PREPARE_FOR_ADAPTIVE_PLAYBACK, |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 52 | ALLOC_SECURE_BUFFER, |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 53 | FREE_BUFFER, |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 54 | FILL_BUFFER, |
| 55 | EMPTY_BUFFER, |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 56 | EMPTY_GRAPHIC_BUFFER, |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 57 | GET_EXTENSION_INDEX, |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 58 | OBSERVER_ON_MSG, |
Jamie Gennis | e2ce645 | 2011-02-23 19:01:28 -0800 | [diff] [blame] | 59 | GET_GRAPHIC_BUFFER_USAGE, |
Lajos Molnar | d071586 | 2013-07-22 12:57:43 -0700 | [diff] [blame] | 60 | UPDATE_GRAPHIC_BUFFER_IN_META, |
Rachad | 5a446aa | 2014-07-29 16:47:56 -0700 | [diff] [blame] | 61 | CONFIGURE_VIDEO_TUNNEL_MODE, |
Lajos Molnar | 7e0bef8 | 2016-05-09 10:48:30 -0700 | [diff] [blame] | 62 | UPDATE_NATIVE_HANDLE_IN_META, |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 63 | DISPATCH_MESSAGE, |
Chong Zhang | 21b4658 | 2016-10-04 12:44:53 -0700 | [diff] [blame^] | 64 | SET_QUIRKS, |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 67 | class BpOMX : public BpInterface<IOMX> { |
| 68 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 69 | explicit BpOMX(const sp<IBinder> &impl) |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 70 | : BpInterface<IOMX>(impl) { |
| 71 | } |
| 72 | |
Andreas Huber | 134ee6a | 2009-12-16 09:30:55 -0800 | [diff] [blame] | 73 | virtual status_t listNodes(List<ComponentInfo> *list) { |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 74 | list->clear(); |
| 75 | |
| 76 | Parcel data, reply; |
| 77 | data.writeInterfaceToken(IOMX::getInterfaceDescriptor()); |
| 78 | remote()->transact(LIST_NODES, data, &reply); |
| 79 | |
| 80 | int32_t n = reply.readInt32(); |
| 81 | for (int32_t i = 0; i < n; ++i) { |
Andreas Huber | 134ee6a | 2009-12-16 09:30:55 -0800 | [diff] [blame] | 82 | list->push_back(ComponentInfo()); |
| 83 | ComponentInfo &info = *--list->end(); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 84 | |
Andreas Huber | 134ee6a | 2009-12-16 09:30:55 -0800 | [diff] [blame] | 85 | info.mName = reply.readString8(); |
| 86 | int32_t numRoles = reply.readInt32(); |
| 87 | for (int32_t j = 0; j < numRoles; ++j) { |
| 88 | info.mRoles.push_back(reply.readString8()); |
| 89 | } |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | return OK; |
| 93 | } |
| 94 | |
Andreas Huber | 318ad9c | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 95 | virtual status_t allocateNode( |
Marco Nelissen | 2385887 | 2016-02-17 13:12:13 -0800 | [diff] [blame] | 96 | const char *name, const sp<IOMXObserver> &observer, |
Chong Zhang | 1d2e9cf | 2016-10-05 21:08:36 -0700 | [diff] [blame] | 97 | sp<IOMXNode> *omxNode) { |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 98 | Parcel data, reply; |
| 99 | data.writeInterfaceToken(IOMX::getInterfaceDescriptor()); |
| 100 | data.writeCString(name); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 101 | data.writeStrongBinder(IInterface::asBinder(observer)); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 102 | remote()->transact(ALLOCATE_NODE, data, &reply); |
| 103 | |
| 104 | status_t err = reply.readInt32(); |
| 105 | if (err == OK) { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 106 | *omxNode = IOMXNode::asInterface(reply.readStrongBinder()); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 107 | } else { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 108 | omxNode->clear(); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | return err; |
| 112 | } |
| 113 | |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 114 | virtual status_t createPersistentInputSurface( |
| 115 | sp<IGraphicBufferProducer> *bufferProducer, |
| 116 | sp<IGraphicBufferConsumer> *bufferConsumer) { |
| 117 | Parcel data, reply; |
| 118 | status_t err; |
| 119 | data.writeInterfaceToken(IOMX::getInterfaceDescriptor()); |
| 120 | err = remote()->transact(CREATE_PERSISTENT_INPUT_SURFACE, data, &reply); |
| 121 | if (err != OK) { |
| 122 | ALOGW("binder transaction failed: %d", err); |
| 123 | return err; |
| 124 | } |
| 125 | |
| 126 | err = reply.readInt32(); |
| 127 | if (err != OK) { |
| 128 | return err; |
| 129 | } |
| 130 | |
| 131 | *bufferProducer = IGraphicBufferProducer::asInterface( |
| 132 | reply.readStrongBinder()); |
| 133 | *bufferConsumer = IGraphicBufferConsumer::asInterface( |
| 134 | reply.readStrongBinder()); |
| 135 | |
| 136 | return err; |
| 137 | } |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | class BpOMXNode : public BpInterface<IOMXNode> { |
| 141 | public: |
| 142 | explicit BpOMXNode(const sp<IBinder> &impl) |
| 143 | : BpInterface<IOMXNode>(impl) { |
| 144 | } |
| 145 | |
| 146 | virtual status_t freeNode() { |
| 147 | Parcel data, reply; |
| 148 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 149 | remote()->transact(FREE_NODE, data, &reply); |
| 150 | |
| 151 | return reply.readInt32(); |
| 152 | } |
| 153 | |
| 154 | virtual status_t sendCommand( |
| 155 | OMX_COMMANDTYPE cmd, OMX_S32 param) { |
| 156 | Parcel data, reply; |
| 157 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 158 | data.writeInt32(cmd); |
| 159 | data.writeInt32(param); |
| 160 | remote()->transact(SEND_COMMAND, data, &reply); |
| 161 | |
| 162 | return reply.readInt32(); |
| 163 | } |
| 164 | |
| 165 | virtual status_t getParameter( |
| 166 | OMX_INDEXTYPE index, |
| 167 | void *params, size_t size) { |
| 168 | Parcel data, reply; |
| 169 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 170 | data.writeInt32(index); |
| 171 | data.writeInt64(size); |
| 172 | data.write(params, size); |
| 173 | remote()->transact(GET_PARAMETER, data, &reply); |
| 174 | |
| 175 | status_t err = reply.readInt32(); |
| 176 | if (err != OK) { |
| 177 | return err; |
| 178 | } |
| 179 | |
| 180 | reply.read(params, size); |
| 181 | |
| 182 | return OK; |
| 183 | } |
| 184 | |
| 185 | virtual status_t setParameter( |
| 186 | OMX_INDEXTYPE index, |
| 187 | const void *params, size_t size) { |
| 188 | Parcel data, reply; |
| 189 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 190 | data.writeInt32(index); |
| 191 | data.writeInt64(size); |
| 192 | data.write(params, size); |
| 193 | remote()->transact(SET_PARAMETER, data, &reply); |
| 194 | |
| 195 | return reply.readInt32(); |
| 196 | } |
| 197 | |
| 198 | virtual status_t getConfig( |
| 199 | OMX_INDEXTYPE index, |
| 200 | void *params, size_t size) { |
| 201 | Parcel data, reply; |
| 202 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 203 | data.writeInt32(index); |
| 204 | data.writeInt64(size); |
| 205 | data.write(params, size); |
| 206 | remote()->transact(GET_CONFIG, data, &reply); |
| 207 | |
| 208 | status_t err = reply.readInt32(); |
| 209 | if (err != OK) { |
| 210 | return err; |
| 211 | } |
| 212 | |
| 213 | reply.read(params, size); |
| 214 | |
| 215 | return OK; |
| 216 | } |
| 217 | |
| 218 | virtual status_t setConfig( |
| 219 | OMX_INDEXTYPE index, |
| 220 | const void *params, size_t size) { |
| 221 | Parcel data, reply; |
| 222 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 223 | data.writeInt32(index); |
| 224 | data.writeInt64(size); |
| 225 | data.write(params, size); |
| 226 | remote()->transact(SET_CONFIG, data, &reply); |
| 227 | |
| 228 | return reply.readInt32(); |
| 229 | } |
| 230 | |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 231 | virtual status_t enableNativeBuffers( |
| 232 | OMX_U32 port_index, OMX_BOOL graphic, OMX_BOOL enable) { |
| 233 | Parcel data, reply; |
| 234 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 235 | data.writeInt32(port_index); |
| 236 | data.writeInt32((uint32_t)graphic); |
| 237 | data.writeInt32((uint32_t)enable); |
| 238 | remote()->transact(ENABLE_NATIVE_BUFFERS, data, &reply); |
| 239 | |
| 240 | status_t err = reply.readInt32(); |
| 241 | return err; |
| 242 | } |
| 243 | |
| 244 | virtual status_t getGraphicBufferUsage( |
| 245 | OMX_U32 port_index, OMX_U32* usage) { |
| 246 | Parcel data, reply; |
| 247 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 248 | data.writeInt32(port_index); |
| 249 | remote()->transact(GET_GRAPHIC_BUFFER_USAGE, data, &reply); |
| 250 | |
| 251 | status_t err = reply.readInt32(); |
| 252 | *usage = reply.readInt32(); |
| 253 | return err; |
| 254 | } |
| 255 | |
| 256 | virtual status_t useBuffer( |
| 257 | OMX_U32 port_index, const sp<IMemory> ¶ms, |
| 258 | buffer_id *buffer, OMX_U32 allottedSize) { |
| 259 | Parcel data, reply; |
| 260 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 261 | data.writeInt32(port_index); |
| 262 | data.writeStrongBinder(IInterface::asBinder(params)); |
| 263 | data.writeInt32(allottedSize); |
| 264 | remote()->transact(USE_BUFFER, data, &reply); |
| 265 | |
| 266 | status_t err = reply.readInt32(); |
| 267 | if (err != OK) { |
| 268 | *buffer = 0; |
| 269 | |
| 270 | return err; |
| 271 | } |
| 272 | |
| 273 | *buffer = (buffer_id)reply.readInt32(); |
| 274 | |
| 275 | return err; |
| 276 | } |
| 277 | |
| 278 | |
| 279 | virtual status_t useGraphicBuffer( |
| 280 | OMX_U32 port_index, |
| 281 | const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) { |
| 282 | Parcel data, reply; |
| 283 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 284 | data.writeInt32(port_index); |
| 285 | data.write(*graphicBuffer); |
| 286 | remote()->transact(USE_GRAPHIC_BUFFER, data, &reply); |
| 287 | |
| 288 | status_t err = reply.readInt32(); |
| 289 | if (err != OK) { |
| 290 | *buffer = 0; |
| 291 | |
| 292 | return err; |
| 293 | } |
| 294 | |
| 295 | *buffer = (buffer_id)reply.readInt32(); |
| 296 | |
| 297 | return err; |
| 298 | } |
| 299 | |
| 300 | virtual status_t updateGraphicBufferInMeta( |
| 301 | OMX_U32 port_index, |
| 302 | const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer) { |
| 303 | Parcel data, reply; |
| 304 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 305 | data.writeInt32(port_index); |
| 306 | data.write(*graphicBuffer); |
| 307 | data.writeInt32((int32_t)buffer); |
| 308 | remote()->transact(UPDATE_GRAPHIC_BUFFER_IN_META, data, &reply); |
| 309 | |
| 310 | status_t err = reply.readInt32(); |
| 311 | return err; |
| 312 | } |
| 313 | |
| 314 | virtual status_t updateNativeHandleInMeta( |
| 315 | OMX_U32 port_index, |
| 316 | const sp<NativeHandle> &nativeHandle, buffer_id buffer) { |
| 317 | Parcel data, reply; |
| 318 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 319 | data.writeInt32(port_index); |
| 320 | data.writeInt32(nativeHandle != NULL); |
| 321 | if (nativeHandle != NULL) { |
| 322 | data.writeNativeHandle(nativeHandle->handle()); |
| 323 | } |
| 324 | data.writeInt32((int32_t)buffer); |
| 325 | remote()->transact(UPDATE_NATIVE_HANDLE_IN_META, data, &reply); |
| 326 | |
| 327 | status_t err = reply.readInt32(); |
| 328 | return err; |
| 329 | } |
| 330 | |
| 331 | virtual status_t createInputSurface( |
| 332 | OMX_U32 port_index, android_dataspace dataSpace, |
| 333 | sp<IGraphicBufferProducer> *bufferProducer, |
| 334 | sp<IGraphicBufferSource> *bufferSource, |
| 335 | MetadataBufferType *type) { |
| 336 | Parcel data, reply; |
| 337 | status_t err; |
| 338 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 339 | data.writeInt32(port_index); |
| 340 | data.writeInt32(dataSpace); |
| 341 | err = remote()->transact(CREATE_INPUT_SURFACE, data, &reply); |
| 342 | if (err != OK) { |
| 343 | ALOGW("binder transaction failed: %d", err); |
| 344 | return err; |
| 345 | } |
| 346 | |
| 347 | // read type even if createInputSurface failed |
| 348 | int negotiatedType = reply.readInt32(); |
| 349 | if (type != NULL) { |
| 350 | *type = (MetadataBufferType)negotiatedType; |
| 351 | } |
| 352 | |
| 353 | err = reply.readInt32(); |
| 354 | if (err != OK) { |
| 355 | return err; |
| 356 | } |
| 357 | |
| 358 | *bufferProducer = IGraphicBufferProducer::asInterface( |
| 359 | reply.readStrongBinder()); |
| 360 | *bufferSource = IGraphicBufferSource::asInterface( |
| 361 | reply.readStrongBinder()); |
| 362 | |
| 363 | return err; |
| 364 | } |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 365 | |
Chong Zhang | 8f469e1 | 2015-05-13 10:21:33 -0700 | [diff] [blame] | 366 | virtual status_t setInputSurface( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 367 | OMX_U32 port_index, |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 368 | const sp<IGraphicBufferConsumer> &bufferConsumer, |
| 369 | sp<IGraphicBufferSource> *bufferSource, |
| 370 | MetadataBufferType *type) { |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 371 | Parcel data, reply; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 372 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 373 | status_t err; |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 374 | data.writeInt32(port_index); |
| 375 | data.writeStrongBinder(IInterface::asBinder(bufferConsumer)); |
| 376 | |
Chong Zhang | 8f469e1 | 2015-05-13 10:21:33 -0700 | [diff] [blame] | 377 | err = remote()->transact(SET_INPUT_SURFACE, data, &reply); |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 378 | |
| 379 | if (err != OK) { |
| 380 | ALOGW("binder transaction failed: %d", err); |
| 381 | return err; |
| 382 | } |
Lajos Molnar | 0542198 | 2015-05-15 20:39:14 -0700 | [diff] [blame] | 383 | |
| 384 | // read type even if setInputSurface failed |
| 385 | int negotiatedType = reply.readInt32(); |
| 386 | if (type != NULL) { |
| 387 | *type = (MetadataBufferType)negotiatedType; |
| 388 | } |
| 389 | |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 390 | err = reply.readInt32(); |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 391 | if (err != OK) { |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 392 | return err; |
| 393 | } |
| 394 | |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 395 | *bufferSource = IGraphicBufferSource::asInterface( |
| 396 | reply.readStrongBinder()); |
| 397 | |
| 398 | return err; |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 399 | } |
| 400 | |
James Dong | e870772 | 2010-10-20 17:38:41 -0700 | [diff] [blame] | 401 | virtual status_t storeMetaDataInBuffers( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 402 | OMX_U32 port_index, OMX_BOOL enable, MetadataBufferType *type) { |
James Dong | e870772 | 2010-10-20 17:38:41 -0700 | [diff] [blame] | 403 | Parcel data, reply; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 404 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
James Dong | e870772 | 2010-10-20 17:38:41 -0700 | [diff] [blame] | 405 | data.writeInt32(port_index); |
Lajos Molnar | 3e32878 | 2016-05-09 10:56:46 -0700 | [diff] [blame] | 406 | data.writeInt32((int32_t)enable); |
| 407 | data.writeInt32(type == NULL ? kMetadataBufferTypeANWBuffer : *type); |
| 408 | |
James Dong | e870772 | 2010-10-20 17:38:41 -0700 | [diff] [blame] | 409 | remote()->transact(STORE_META_DATA_IN_BUFFERS, data, &reply); |
| 410 | |
Lajos Molnar | 0542198 | 2015-05-15 20:39:14 -0700 | [diff] [blame] | 411 | // read type even storeMetaDataInBuffers failed |
| 412 | int negotiatedType = reply.readInt32(); |
| 413 | if (type != NULL) { |
| 414 | *type = (MetadataBufferType)negotiatedType; |
| 415 | } |
| 416 | |
| 417 | return reply.readInt32(); |
James Dong | e870772 | 2010-10-20 17:38:41 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Lajos Molnar | 56ce726 | 2013-05-02 16:30:48 -0700 | [diff] [blame] | 420 | virtual status_t prepareForAdaptivePlayback( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 421 | OMX_U32 port_index, OMX_BOOL enable, |
Lajos Molnar | 56ce726 | 2013-05-02 16:30:48 -0700 | [diff] [blame] | 422 | OMX_U32 max_width, OMX_U32 max_height) { |
| 423 | Parcel data, reply; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 424 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
Lajos Molnar | 56ce726 | 2013-05-02 16:30:48 -0700 | [diff] [blame] | 425 | data.writeInt32(port_index); |
| 426 | data.writeInt32((int32_t)enable); |
| 427 | data.writeInt32(max_width); |
| 428 | data.writeInt32(max_height); |
| 429 | remote()->transact(PREPARE_FOR_ADAPTIVE_PLAYBACK, data, &reply); |
| 430 | |
| 431 | status_t err = reply.readInt32(); |
| 432 | return err; |
| 433 | } |
| 434 | |
Rachad | 5a446aa | 2014-07-29 16:47:56 -0700 | [diff] [blame] | 435 | virtual status_t configureVideoTunnelMode( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 436 | OMX_U32 portIndex, OMX_BOOL tunneled, |
Rachad | 5a446aa | 2014-07-29 16:47:56 -0700 | [diff] [blame] | 437 | OMX_U32 audioHwSync, native_handle_t **sidebandHandle ) { |
| 438 | Parcel data, reply; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 439 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
Rachad | 5a446aa | 2014-07-29 16:47:56 -0700 | [diff] [blame] | 440 | data.writeInt32(portIndex); |
| 441 | data.writeInt32((int32_t)tunneled); |
| 442 | data.writeInt32(audioHwSync); |
| 443 | remote()->transact(CONFIGURE_VIDEO_TUNNEL_MODE, data, &reply); |
| 444 | |
| 445 | status_t err = reply.readInt32(); |
mspector@google.com | 9d72eb0 | 2016-02-08 10:56:13 -0800 | [diff] [blame] | 446 | if (err == OK && sidebandHandle) { |
Rachad | 5a446aa | 2014-07-29 16:47:56 -0700 | [diff] [blame] | 447 | *sidebandHandle = (native_handle_t *)reply.readNativeHandle(); |
| 448 | } |
| 449 | return err; |
| 450 | } |
| 451 | |
| 452 | |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 453 | virtual status_t allocateSecureBuffer( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 454 | OMX_U32 port_index, size_t size, |
Lajos Molnar | 1b40f28 | 2016-05-09 22:24:52 -0700 | [diff] [blame] | 455 | buffer_id *buffer, void **buffer_data, sp<NativeHandle> *native_handle) { |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 456 | Parcel data, reply; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 457 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 458 | data.writeInt32(port_index); |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 459 | data.writeInt64(size); |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 460 | remote()->transact(ALLOC_SECURE_BUFFER, data, &reply); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 461 | |
| 462 | status_t err = reply.readInt32(); |
| 463 | if (err != OK) { |
| 464 | *buffer = 0; |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 465 | *buffer_data = NULL; |
| 466 | *native_handle = NULL; |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 467 | return err; |
| 468 | } |
| 469 | |
Andy Hung | 609b815 | 2014-05-02 11:05:04 -0700 | [diff] [blame] | 470 | *buffer = (buffer_id)reply.readInt32(); |
| 471 | *buffer_data = (void *)reply.readInt64(); |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 472 | if (*buffer_data == NULL) { |
Lajos Molnar | 1b40f28 | 2016-05-09 22:24:52 -0700 | [diff] [blame] | 473 | *native_handle = NativeHandle::create( |
| 474 | reply.readNativeHandle(), true /* ownsHandle */); |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 475 | } else { |
| 476 | *native_handle = NULL; |
| 477 | } |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 478 | return err; |
| 479 | } |
| 480 | |
Andreas Huber | 318ad9c | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 481 | virtual status_t freeBuffer( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 482 | OMX_U32 port_index, buffer_id buffer) { |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 483 | Parcel data, reply; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 484 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 485 | data.writeInt32(port_index); |
Andy Hung | 609b815 | 2014-05-02 11:05:04 -0700 | [diff] [blame] | 486 | data.writeInt32((int32_t)buffer); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 487 | remote()->transact(FREE_BUFFER, data, &reply); |
| 488 | |
| 489 | return reply.readInt32(); |
| 490 | } |
| 491 | |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 492 | virtual status_t fillBuffer(buffer_id buffer, int fenceFd) { |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 493 | Parcel data, reply; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 494 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
Andy Hung | 609b815 | 2014-05-02 11:05:04 -0700 | [diff] [blame] | 495 | data.writeInt32((int32_t)buffer); |
Lajos Molnar | 15ab499 | 2015-06-01 10:54:31 -0700 | [diff] [blame] | 496 | data.writeInt32(fenceFd >= 0); |
| 497 | if (fenceFd >= 0) { |
| 498 | data.writeFileDescriptor(fenceFd, true /* takeOwnership */); |
| 499 | } |
Andreas Huber | 36efa03 | 2009-10-08 11:02:27 -0700 | [diff] [blame] | 500 | remote()->transact(FILL_BUFFER, data, &reply); |
| 501 | |
| 502 | return reply.readInt32(); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Andreas Huber | 318ad9c | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 505 | virtual status_t emptyBuffer( |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 506 | buffer_id buffer, |
| 507 | OMX_U32 range_offset, OMX_U32 range_length, |
Lajos Molnar | 15ab499 | 2015-06-01 10:54:31 -0700 | [diff] [blame] | 508 | OMX_U32 flags, OMX_TICKS timestamp, int fenceFd) { |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 509 | Parcel data, reply; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 510 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
Andy Hung | 609b815 | 2014-05-02 11:05:04 -0700 | [diff] [blame] | 511 | data.writeInt32((int32_t)buffer); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 512 | data.writeInt32(range_offset); |
| 513 | data.writeInt32(range_length); |
| 514 | data.writeInt32(flags); |
| 515 | data.writeInt64(timestamp); |
Lajos Molnar | 15ab499 | 2015-06-01 10:54:31 -0700 | [diff] [blame] | 516 | data.writeInt32(fenceFd >= 0); |
| 517 | if (fenceFd >= 0) { |
| 518 | data.writeFileDescriptor(fenceFd, true /* takeOwnership */); |
| 519 | } |
Andreas Huber | 36efa03 | 2009-10-08 11:02:27 -0700 | [diff] [blame] | 520 | remote()->transact(EMPTY_BUFFER, data, &reply); |
| 521 | |
| 522 | return reply.readInt32(); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 523 | } |
Andreas Huber | 8b938cd | 2009-07-31 11:52:50 -0700 | [diff] [blame] | 524 | |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 525 | virtual status_t emptyGraphicBuffer( |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 526 | buffer_id buffer, |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 527 | const sp<GraphicBuffer> &graphicBuffer, OMX_U32 flags, |
| 528 | OMX_TICKS timestamp, OMX_TICKS origTimestamp, int fenceFd) { |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 529 | Parcel data, reply; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 530 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 531 | data.writeInt32((int32_t)buffer); |
| 532 | data.write(*graphicBuffer); |
| 533 | data.writeInt32(flags); |
| 534 | data.writeInt64(timestamp); |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 535 | data.writeInt64(origTimestamp); |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 536 | data.writeInt32(fenceFd >= 0); |
| 537 | if (fenceFd >= 0) { |
| 538 | data.writeFileDescriptor(fenceFd, true /* takeOwnership */); |
| 539 | } |
| 540 | remote()->transact(EMPTY_GRAPHIC_BUFFER, data, &reply); |
| 541 | |
| 542 | return reply.readInt32(); |
| 543 | } |
| 544 | |
Andreas Huber | 318ad9c | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 545 | virtual status_t getExtensionIndex( |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 546 | const char *parameter_name, |
| 547 | OMX_INDEXTYPE *index) { |
| 548 | Parcel data, reply; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 549 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 550 | data.writeCString(parameter_name); |
| 551 | |
| 552 | remote()->transact(GET_EXTENSION_INDEX, data, &reply); |
| 553 | |
| 554 | status_t err = reply.readInt32(); |
| 555 | if (err == OK) { |
| 556 | *index = static_cast<OMX_INDEXTYPE>(reply.readInt32()); |
| 557 | } else { |
| 558 | *index = OMX_IndexComponentStartUnused; |
| 559 | } |
| 560 | |
| 561 | return err; |
| 562 | } |
Andreas Huber | e40cda7 | 2013-07-17 13:55:26 -0700 | [diff] [blame] | 563 | |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 564 | virtual status_t dispatchMessage(const omx_message &msg) { |
| 565 | Parcel data, reply; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 566 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 567 | data.writeInt32(msg.fenceFd >= 0); |
| 568 | if (msg.fenceFd >= 0) { |
| 569 | data.writeFileDescriptor(msg.fenceFd, true /* takeOwnership */); |
| 570 | } |
| 571 | data.writeInt32(msg.type); |
| 572 | data.write(&msg.u, sizeof(msg.u)); |
| 573 | |
| 574 | remote()->transact(DISPATCH_MESSAGE, data, &reply); |
| 575 | |
| 576 | return reply.readInt32(); |
| 577 | } |
Chong Zhang | 21b4658 | 2016-10-04 12:44:53 -0700 | [diff] [blame^] | 578 | |
| 579 | virtual status_t setQuirks(OMX_U32 quirks) { |
| 580 | Parcel data, reply; |
| 581 | data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor()); |
| 582 | data.writeInt32(quirks); |
| 583 | |
| 584 | remote()->transact(SET_QUIRKS, data, &reply); |
| 585 | |
| 586 | return reply.readInt32(); |
| 587 | } |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 588 | }; |
| 589 | |
| 590 | IMPLEMENT_META_INTERFACE(OMX, "android.hardware.IOMX"); |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 591 | IMPLEMENT_META_INTERFACE(OMXNode, "android.hardware.IOMXNode"); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 592 | |
| 593 | //////////////////////////////////////////////////////////////////////////////// |
| 594 | |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 595 | #define CHECK_OMX_INTERFACE(interface, data, reply) \ |
Chih-Hung Hsieh | 83fbbb8 | 2016-05-17 15:08:10 -0700 | [diff] [blame] | 596 | do { if (!(data).enforceInterface(interface::getInterfaceDescriptor())) { \ |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 597 | ALOGW("Call incorrectly routed to " #interface); \ |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 598 | return PERMISSION_DENIED; \ |
| 599 | } } while (0) |
| 600 | |
| 601 | status_t BnOMX::onTransact( |
| 602 | uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) { |
| 603 | switch (code) { |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 604 | case LIST_NODES: |
| 605 | { |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 606 | CHECK_OMX_INTERFACE(IOMX, data, reply); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 607 | |
Andreas Huber | 134ee6a | 2009-12-16 09:30:55 -0800 | [diff] [blame] | 608 | List<ComponentInfo> list; |
Andreas Huber | 318ad9c | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 609 | listNodes(&list); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 610 | |
| 611 | reply->writeInt32(list.size()); |
Andreas Huber | 134ee6a | 2009-12-16 09:30:55 -0800 | [diff] [blame] | 612 | for (List<ComponentInfo>::iterator it = list.begin(); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 613 | it != list.end(); ++it) { |
Andreas Huber | 134ee6a | 2009-12-16 09:30:55 -0800 | [diff] [blame] | 614 | ComponentInfo &cur = *it; |
| 615 | |
| 616 | reply->writeString8(cur.mName); |
| 617 | reply->writeInt32(cur.mRoles.size()); |
| 618 | for (List<String8>::iterator role_it = cur.mRoles.begin(); |
| 619 | role_it != cur.mRoles.end(); ++role_it) { |
| 620 | reply->writeString8(*role_it); |
| 621 | } |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | return NO_ERROR; |
| 625 | } |
| 626 | |
| 627 | case ALLOCATE_NODE: |
| 628 | { |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 629 | CHECK_OMX_INTERFACE(IOMX, data, reply); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 630 | |
Andreas Huber | 318ad9c | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 631 | const char *name = data.readCString(); |
| 632 | |
| 633 | sp<IOMXObserver> observer = |
| 634 | interface_cast<IOMXObserver>(data.readStrongBinder()); |
| 635 | |
Wei Jia | 56c95c9 | 2016-01-06 10:30:46 -0800 | [diff] [blame] | 636 | if (name == NULL || observer == NULL) { |
| 637 | ALOGE("b/26392700"); |
| 638 | reply->writeInt32(INVALID_OPERATION); |
| 639 | return NO_ERROR; |
| 640 | } |
| 641 | |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 642 | sp<IOMXNode> omxNode; |
Andreas Huber | 318ad9c | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 643 | |
Chong Zhang | 1d2e9cf | 2016-10-05 21:08:36 -0700 | [diff] [blame] | 644 | status_t err = allocateNode(name, observer, &omxNode); |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 645 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 646 | reply->writeInt32(err); |
| 647 | if (err == OK) { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 648 | reply->writeStrongBinder(IInterface::asBinder(omxNode)); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 649 | } |
Andreas Huber | 7eaa9c9 | 2010-01-15 15:28:19 -0800 | [diff] [blame] | 650 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 651 | return NO_ERROR; |
| 652 | } |
| 653 | |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 654 | case CREATE_PERSISTENT_INPUT_SURFACE: |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 655 | { |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 656 | CHECK_OMX_INTERFACE(IOMX, data, reply); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 657 | |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 658 | sp<IGraphicBufferProducer> bufferProducer; |
| 659 | sp<IGraphicBufferConsumer> bufferConsumer; |
| 660 | status_t err = createPersistentInputSurface( |
| 661 | &bufferProducer, &bufferConsumer); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 662 | |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 663 | reply->writeInt32(err); |
| 664 | |
| 665 | if (err == OK) { |
| 666 | reply->writeStrongBinder(IInterface::asBinder(bufferProducer)); |
| 667 | reply->writeStrongBinder(IInterface::asBinder(bufferConsumer)); |
| 668 | } |
| 669 | |
| 670 | return NO_ERROR; |
| 671 | } |
| 672 | |
| 673 | default: |
| 674 | return BBinder::onTransact(code, data, reply, flags); |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | status_t BnOMXNode::onTransact( |
| 679 | uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) { |
| 680 | switch (code) { |
| 681 | case FREE_NODE: |
| 682 | { |
| 683 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
| 684 | |
| 685 | reply->writeInt32(freeNode()); |
Andreas Huber | 7eaa9c9 | 2010-01-15 15:28:19 -0800 | [diff] [blame] | 686 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 687 | return NO_ERROR; |
| 688 | } |
| 689 | |
| 690 | case SEND_COMMAND: |
| 691 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 692 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 693 | |
| 694 | OMX_COMMANDTYPE cmd = |
| 695 | static_cast<OMX_COMMANDTYPE>(data.readInt32()); |
| 696 | |
| 697 | OMX_S32 param = data.readInt32(); |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 698 | reply->writeInt32(sendCommand(cmd, param)); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 699 | |
| 700 | return NO_ERROR; |
| 701 | } |
| 702 | |
| 703 | case GET_PARAMETER: |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 704 | case SET_PARAMETER: |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 705 | case GET_CONFIG: |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 706 | case SET_CONFIG: |
| 707 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 708 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 709 | |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 710 | OMX_INDEXTYPE index = static_cast<OMX_INDEXTYPE>(data.readInt32()); |
| 711 | |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 712 | size_t size = data.readInt64(); |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 713 | |
Marco Nelissen | 2720c8b | 2016-02-29 12:47:20 -0800 | [diff] [blame] | 714 | status_t err = NOT_ENOUGH_DATA; |
| 715 | void *params = NULL; |
| 716 | size_t pageSize = 0; |
| 717 | size_t allocSize = 0; |
Marco Nelissen | 788b0b6 | 2016-03-21 11:31:53 -0700 | [diff] [blame] | 718 | bool isUsageBits = (index == (OMX_INDEXTYPE) OMX_IndexParamConsumerUsageBits); |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 719 | if ((isUsageBits && size < 4) || (!isUsageBits && size < 8)) { |
Marco Nelissen | 2720c8b | 2016-02-29 12:47:20 -0800 | [diff] [blame] | 720 | // we expect the structure to contain at least the size and |
| 721 | // version, 8 bytes total |
Marco Nelissen | 788b0b6 | 2016-03-21 11:31:53 -0700 | [diff] [blame] | 722 | ALOGE("b/27207275 (%zu) (%d/%d)", size, int(index), int(code)); |
Marco Nelissen | 2720c8b | 2016-02-29 12:47:20 -0800 | [diff] [blame] | 723 | android_errorWriteLog(0x534e4554, "27207275"); |
| 724 | } else { |
| 725 | err = NO_MEMORY; |
| 726 | pageSize = (size_t) sysconf(_SC_PAGE_SIZE); |
| 727 | if (size > SIZE_MAX - (pageSize * 2)) { |
| 728 | ALOGE("requested param size too big"); |
Marco Nelissen | f7a3882 | 2016-02-22 13:05:15 -0800 | [diff] [blame] | 729 | } else { |
Marco Nelissen | 2720c8b | 2016-02-29 12:47:20 -0800 | [diff] [blame] | 730 | allocSize = (size + pageSize * 2) & ~(pageSize - 1); |
| 731 | params = mmap(NULL, allocSize, PROT_READ | PROT_WRITE, |
| 732 | MAP_PRIVATE | MAP_ANONYMOUS, -1 /* fd */, 0 /* offset */); |
| 733 | } |
| 734 | if (params != MAP_FAILED) { |
| 735 | err = data.read(params, size); |
| 736 | if (err != OK) { |
| 737 | android_errorWriteLog(0x534e4554, "26914474"); |
| 738 | } else { |
| 739 | err = NOT_ENOUGH_DATA; |
| 740 | OMX_U32 declaredSize = *(OMX_U32*)params; |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 741 | if (index != (OMX_INDEXTYPE) OMX_IndexParamConsumerUsageBits && |
Marco Nelissen | c1c50e7 | 2016-03-10 15:02:13 -0800 | [diff] [blame] | 742 | declaredSize > size) { |
Marco Nelissen | 2720c8b | 2016-02-29 12:47:20 -0800 | [diff] [blame] | 743 | // the buffer says it's bigger than it actually is |
| 744 | ALOGE("b/27207275 (%u/%zu)", declaredSize, size); |
| 745 | android_errorWriteLog(0x534e4554, "27207275"); |
| 746 | } else { |
| 747 | // mark the last page as inaccessible, to avoid exploitation |
| 748 | // of codecs that access past the end of the allocation because |
| 749 | // they didn't check the size |
Marco Nelissen | 866c800 | 2016-09-20 13:36:40 -0700 | [diff] [blame] | 750 | if (mprotect((char*)params + allocSize - pageSize, pageSize, |
| 751 | PROT_NONE) != 0) { |
| 752 | ALOGE("mprotect failed: %s", strerror(errno)); |
| 753 | } else { |
| 754 | switch (code) { |
| 755 | case GET_PARAMETER: |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 756 | err = getParameter(index, params, size); |
Marco Nelissen | 866c800 | 2016-09-20 13:36:40 -0700 | [diff] [blame] | 757 | break; |
| 758 | case SET_PARAMETER: |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 759 | err = setParameter(index, params, size); |
Marco Nelissen | 866c800 | 2016-09-20 13:36:40 -0700 | [diff] [blame] | 760 | break; |
| 761 | case GET_CONFIG: |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 762 | err = getConfig(index, params, size); |
Marco Nelissen | 866c800 | 2016-09-20 13:36:40 -0700 | [diff] [blame] | 763 | break; |
| 764 | case SET_CONFIG: |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 765 | err = setConfig(index, params, size); |
Marco Nelissen | 866c800 | 2016-09-20 13:36:40 -0700 | [diff] [blame] | 766 | break; |
Marco Nelissen | 866c800 | 2016-09-20 13:36:40 -0700 | [diff] [blame] | 767 | default: |
| 768 | TRESPASS(); |
Marco Nelissen | 2720c8b | 2016-02-29 12:47:20 -0800 | [diff] [blame] | 769 | } |
Marco Nelissen | 2720c8b | 2016-02-29 12:47:20 -0800 | [diff] [blame] | 770 | } |
Marco Nelissen | f7a3882 | 2016-02-22 13:05:15 -0800 | [diff] [blame] | 771 | } |
Marco Nelissen | f7a3882 | 2016-02-22 13:05:15 -0800 | [diff] [blame] | 772 | } |
Marco Nelissen | 2720c8b | 2016-02-29 12:47:20 -0800 | [diff] [blame] | 773 | } else { |
| 774 | ALOGE("couldn't map: %s", strerror(errno)); |
Andreas Huber | e40cda7 | 2013-07-17 13:55:26 -0700 | [diff] [blame] | 775 | } |
Andreas Huber | b391290 | 2011-01-19 10:34:52 -0800 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | reply->writeInt32(err); |
| 779 | |
| 780 | if ((code == GET_PARAMETER || code == GET_CONFIG) && err == OK) { |
| 781 | reply->write(params, size); |
| 782 | } |
| 783 | |
Marco Nelissen | 2720c8b | 2016-02-29 12:47:20 -0800 | [diff] [blame] | 784 | if (params) { |
| 785 | munmap(params, allocSize); |
| 786 | } |
Andreas Huber | b391290 | 2011-01-19 10:34:52 -0800 | [diff] [blame] | 787 | params = NULL; |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 788 | |
| 789 | return NO_ERROR; |
| 790 | } |
| 791 | |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 792 | case ENABLE_NATIVE_BUFFERS: |
Jamie Gennis | 83750ea | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 793 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 794 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Jamie Gennis | 83750ea | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 795 | |
Jamie Gennis | 83750ea | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 796 | OMX_U32 port_index = data.readInt32(); |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 797 | OMX_BOOL graphic = (OMX_BOOL)data.readInt32(); |
Jamie Gennis | 83750ea | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 798 | OMX_BOOL enable = (OMX_BOOL)data.readInt32(); |
| 799 | |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 800 | status_t err = enableNativeBuffers(port_index, graphic, enable); |
Jamie Gennis | 83750ea | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 801 | reply->writeInt32(err); |
| 802 | |
| 803 | return NO_ERROR; |
| 804 | } |
| 805 | |
Jamie Gennis | e2ce645 | 2011-02-23 19:01:28 -0800 | [diff] [blame] | 806 | case GET_GRAPHIC_BUFFER_USAGE: |
| 807 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 808 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Jamie Gennis | e2ce645 | 2011-02-23 19:01:28 -0800 | [diff] [blame] | 809 | |
Jamie Gennis | e2ce645 | 2011-02-23 19:01:28 -0800 | [diff] [blame] | 810 | OMX_U32 port_index = data.readInt32(); |
| 811 | |
| 812 | OMX_U32 usage = 0; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 813 | status_t err = getGraphicBufferUsage(port_index, &usage); |
Jamie Gennis | e2ce645 | 2011-02-23 19:01:28 -0800 | [diff] [blame] | 814 | reply->writeInt32(err); |
| 815 | reply->writeInt32(usage); |
| 816 | |
| 817 | return NO_ERROR; |
| 818 | } |
| 819 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 820 | case USE_BUFFER: |
| 821 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 822 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 823 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 824 | OMX_U32 port_index = data.readInt32(); |
| 825 | sp<IMemory> params = |
| 826 | interface_cast<IMemory>(data.readStrongBinder()); |
Lajos Molnar | cc7cc67 | 2015-06-01 14:58:37 -0700 | [diff] [blame] | 827 | OMX_U32 allottedSize = data.readInt32(); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 828 | |
Wei Jia | 56c95c9 | 2016-01-06 10:30:46 -0800 | [diff] [blame] | 829 | if (params == NULL) { |
| 830 | ALOGE("b/26392700"); |
| 831 | reply->writeInt32(INVALID_OPERATION); |
| 832 | return NO_ERROR; |
| 833 | } |
| 834 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 835 | buffer_id buffer; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 836 | status_t err = useBuffer(port_index, params, &buffer, allottedSize); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 837 | reply->writeInt32(err); |
| 838 | |
| 839 | if (err == OK) { |
Andy Hung | 609b815 | 2014-05-02 11:05:04 -0700 | [diff] [blame] | 840 | reply->writeInt32((int32_t)buffer); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | return NO_ERROR; |
| 844 | } |
| 845 | |
Jamie Gennis | 83750ea | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 846 | case USE_GRAPHIC_BUFFER: |
| 847 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 848 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Jamie Gennis | 83750ea | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 849 | |
Jamie Gennis | 83750ea | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 850 | OMX_U32 port_index = data.readInt32(); |
| 851 | sp<GraphicBuffer> graphicBuffer = new GraphicBuffer(); |
| 852 | data.read(*graphicBuffer); |
| 853 | |
| 854 | buffer_id buffer; |
| 855 | status_t err = useGraphicBuffer( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 856 | port_index, graphicBuffer, &buffer); |
Jamie Gennis | 83750ea | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 857 | reply->writeInt32(err); |
| 858 | |
| 859 | if (err == OK) { |
Andy Hung | 609b815 | 2014-05-02 11:05:04 -0700 | [diff] [blame] | 860 | reply->writeInt32((int32_t)buffer); |
Jamie Gennis | 83750ea | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | return NO_ERROR; |
| 864 | } |
| 865 | |
Lajos Molnar | d071586 | 2013-07-22 12:57:43 -0700 | [diff] [blame] | 866 | case UPDATE_GRAPHIC_BUFFER_IN_META: |
| 867 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 868 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Lajos Molnar | d071586 | 2013-07-22 12:57:43 -0700 | [diff] [blame] | 869 | |
Lajos Molnar | d071586 | 2013-07-22 12:57:43 -0700 | [diff] [blame] | 870 | OMX_U32 port_index = data.readInt32(); |
| 871 | sp<GraphicBuffer> graphicBuffer = new GraphicBuffer(); |
| 872 | data.read(*graphicBuffer); |
Andy Hung | 609b815 | 2014-05-02 11:05:04 -0700 | [diff] [blame] | 873 | buffer_id buffer = (buffer_id)data.readInt32(); |
Lajos Molnar | d071586 | 2013-07-22 12:57:43 -0700 | [diff] [blame] | 874 | |
| 875 | status_t err = updateGraphicBufferInMeta( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 876 | port_index, graphicBuffer, buffer); |
Lajos Molnar | d071586 | 2013-07-22 12:57:43 -0700 | [diff] [blame] | 877 | reply->writeInt32(err); |
| 878 | |
| 879 | return NO_ERROR; |
| 880 | } |
| 881 | |
Lajos Molnar | 7e0bef8 | 2016-05-09 10:48:30 -0700 | [diff] [blame] | 882 | case UPDATE_NATIVE_HANDLE_IN_META: |
| 883 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 884 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Lajos Molnar | 7e0bef8 | 2016-05-09 10:48:30 -0700 | [diff] [blame] | 885 | |
Lajos Molnar | 7e0bef8 | 2016-05-09 10:48:30 -0700 | [diff] [blame] | 886 | OMX_U32 port_index = data.readInt32(); |
| 887 | native_handle *handle = NULL; |
| 888 | if (data.readInt32()) { |
| 889 | handle = data.readNativeHandle(); |
| 890 | } |
| 891 | buffer_id buffer = (buffer_id)data.readInt32(); |
| 892 | |
| 893 | status_t err = updateNativeHandleInMeta( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 894 | port_index, NativeHandle::create(handle, true /* ownshandle */), buffer); |
Lajos Molnar | 7e0bef8 | 2016-05-09 10:48:30 -0700 | [diff] [blame] | 895 | reply->writeInt32(err); |
| 896 | |
| 897 | return NO_ERROR; |
| 898 | } |
| 899 | |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 900 | case CREATE_INPUT_SURFACE: |
| 901 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 902 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 903 | |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 904 | OMX_U32 port_index = data.readInt32(); |
Lajos Molnar | 57fad3c | 2016-03-08 13:09:35 -0800 | [diff] [blame] | 905 | android_dataspace dataSpace = (android_dataspace)data.readInt32(); |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 906 | |
| 907 | sp<IGraphicBufferProducer> bufferProducer; |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 908 | sp<IGraphicBufferSource> bufferSource; |
mspector@google.com | da9ca91 | 2016-02-08 17:07:06 -0800 | [diff] [blame] | 909 | MetadataBufferType type = kMetadataBufferTypeInvalid; |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 910 | status_t err = createInputSurface( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 911 | port_index, dataSpace, &bufferProducer, &bufferSource, &type); |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 912 | |
mspector@google.com | da9ca91 | 2016-02-08 17:07:06 -0800 | [diff] [blame] | 913 | if ((err != OK) && (type == kMetadataBufferTypeInvalid)) { |
| 914 | android_errorWriteLog(0x534e4554, "26324358"); |
| 915 | } |
| 916 | |
Lajos Molnar | 0542198 | 2015-05-15 20:39:14 -0700 | [diff] [blame] | 917 | reply->writeInt32(type); |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 918 | reply->writeInt32(err); |
| 919 | |
| 920 | if (err == OK) { |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 921 | reply->writeStrongBinder(IInterface::asBinder(bufferProducer)); |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 922 | reply->writeStrongBinder(IInterface::asBinder(bufferSource)); |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | return NO_ERROR; |
| 926 | } |
| 927 | |
Chong Zhang | 8f469e1 | 2015-05-13 10:21:33 -0700 | [diff] [blame] | 928 | case SET_INPUT_SURFACE: |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 929 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 930 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 931 | |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 932 | OMX_U32 port_index = data.readInt32(); |
| 933 | |
| 934 | sp<IGraphicBufferConsumer> bufferConsumer = |
| 935 | interface_cast<IGraphicBufferConsumer>(data.readStrongBinder()); |
| 936 | |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 937 | sp<IGraphicBufferSource> bufferSource; |
Wei Jia | 56c95c9 | 2016-01-06 10:30:46 -0800 | [diff] [blame] | 938 | MetadataBufferType type = kMetadataBufferTypeInvalid; |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 939 | |
Wei Jia | 56c95c9 | 2016-01-06 10:30:46 -0800 | [diff] [blame] | 940 | status_t err = INVALID_OPERATION; |
| 941 | if (bufferConsumer == NULL) { |
| 942 | ALOGE("b/26392700"); |
| 943 | } else { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 944 | err = setInputSurface(port_index, bufferConsumer, &bufferSource, &type); |
mspector@google.com | c3ed9d0 | 2016-02-18 19:52:08 -0800 | [diff] [blame] | 945 | |
| 946 | if ((err != OK) && (type == kMetadataBufferTypeInvalid)) { |
| 947 | android_errorWriteLog(0x534e4554, "26324358"); |
| 948 | } |
Wei Jia | 56c95c9 | 2016-01-06 10:30:46 -0800 | [diff] [blame] | 949 | } |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 950 | |
Lajos Molnar | 0542198 | 2015-05-15 20:39:14 -0700 | [diff] [blame] | 951 | reply->writeInt32(type); |
Chong Zhang | d291c22 | 2015-04-30 18:15:52 -0700 | [diff] [blame] | 952 | reply->writeInt32(err); |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 953 | if (err == OK) { |
| 954 | reply->writeStrongBinder(IInterface::asBinder(bufferSource)); |
| 955 | } |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 956 | return NO_ERROR; |
| 957 | } |
| 958 | |
James Dong | e870772 | 2010-10-20 17:38:41 -0700 | [diff] [blame] | 959 | case STORE_META_DATA_IN_BUFFERS: |
| 960 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 961 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
James Dong | e870772 | 2010-10-20 17:38:41 -0700 | [diff] [blame] | 962 | |
James Dong | e870772 | 2010-10-20 17:38:41 -0700 | [diff] [blame] | 963 | OMX_U32 port_index = data.readInt32(); |
| 964 | OMX_BOOL enable = (OMX_BOOL)data.readInt32(); |
| 965 | |
Lajos Molnar | 3e32878 | 2016-05-09 10:56:46 -0700 | [diff] [blame] | 966 | MetadataBufferType type = (MetadataBufferType)data.readInt32(); |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 967 | status_t err = storeMetaDataInBuffers(port_index, enable, &type); |
mspector@google.com | da9ca91 | 2016-02-08 17:07:06 -0800 | [diff] [blame] | 968 | |
Lajos Molnar | 0542198 | 2015-05-15 20:39:14 -0700 | [diff] [blame] | 969 | reply->writeInt32(type); |
James Dong | e870772 | 2010-10-20 17:38:41 -0700 | [diff] [blame] | 970 | reply->writeInt32(err); |
| 971 | |
| 972 | return NO_ERROR; |
| 973 | } |
| 974 | |
Lajos Molnar | 56ce726 | 2013-05-02 16:30:48 -0700 | [diff] [blame] | 975 | case PREPARE_FOR_ADAPTIVE_PLAYBACK: |
| 976 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 977 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Lajos Molnar | 56ce726 | 2013-05-02 16:30:48 -0700 | [diff] [blame] | 978 | |
Lajos Molnar | 56ce726 | 2013-05-02 16:30:48 -0700 | [diff] [blame] | 979 | OMX_U32 port_index = data.readInt32(); |
| 980 | OMX_BOOL enable = (OMX_BOOL)data.readInt32(); |
| 981 | OMX_U32 max_width = data.readInt32(); |
| 982 | OMX_U32 max_height = data.readInt32(); |
| 983 | |
| 984 | status_t err = prepareForAdaptivePlayback( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 985 | port_index, enable, max_width, max_height); |
Lajos Molnar | 56ce726 | 2013-05-02 16:30:48 -0700 | [diff] [blame] | 986 | reply->writeInt32(err); |
| 987 | |
| 988 | return NO_ERROR; |
| 989 | } |
| 990 | |
Rachad | 5a446aa | 2014-07-29 16:47:56 -0700 | [diff] [blame] | 991 | case CONFIGURE_VIDEO_TUNNEL_MODE: |
| 992 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 993 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Rachad | 5a446aa | 2014-07-29 16:47:56 -0700 | [diff] [blame] | 994 | |
Rachad | 5a446aa | 2014-07-29 16:47:56 -0700 | [diff] [blame] | 995 | OMX_U32 port_index = data.readInt32(); |
| 996 | OMX_BOOL tunneled = (OMX_BOOL)data.readInt32(); |
| 997 | OMX_U32 audio_hw_sync = data.readInt32(); |
| 998 | |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 999 | native_handle_t *sideband_handle = NULL; |
Rachad | 5a446aa | 2014-07-29 16:47:56 -0700 | [diff] [blame] | 1000 | status_t err = configureVideoTunnelMode( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1001 | port_index, tunneled, audio_hw_sync, &sideband_handle); |
Rachad | 5a446aa | 2014-07-29 16:47:56 -0700 | [diff] [blame] | 1002 | reply->writeInt32(err); |
mspector@google.com | 9d72eb0 | 2016-02-08 10:56:13 -0800 | [diff] [blame] | 1003 | if(err == OK){ |
| 1004 | reply->writeNativeHandle(sideband_handle); |
| 1005 | } |
Rachad | 5a446aa | 2014-07-29 16:47:56 -0700 | [diff] [blame] | 1006 | |
| 1007 | return NO_ERROR; |
| 1008 | } |
| 1009 | |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 1010 | case ALLOC_SECURE_BUFFER: |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1011 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1012 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1013 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1014 | OMX_U32 port_index = data.readInt32(); |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1015 | if (!isSecure() || port_index != 0 /* kPortIndexInput */) { |
Wei Jia | 8dde726 | 2015-09-28 11:32:23 -0700 | [diff] [blame] | 1016 | ALOGE("b/24310423"); |
| 1017 | reply->writeInt32(INVALID_OPERATION); |
| 1018 | return NO_ERROR; |
| 1019 | } |
| 1020 | |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 1021 | size_t size = data.readInt64(); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1022 | |
| 1023 | buffer_id buffer; |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 1024 | void *buffer_data = NULL; |
Lajos Molnar | 1b40f28 | 2016-05-09 22:24:52 -0700 | [diff] [blame] | 1025 | sp<NativeHandle> native_handle; |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 1026 | status_t err = allocateSecureBuffer( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1027 | port_index, size, &buffer, &buffer_data, &native_handle); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1028 | reply->writeInt32(err); |
| 1029 | |
| 1030 | if (err == OK) { |
Andy Hung | 609b815 | 2014-05-02 11:05:04 -0700 | [diff] [blame] | 1031 | reply->writeInt32((int32_t)buffer); |
| 1032 | reply->writeInt64((uintptr_t)buffer_data); |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 1033 | if (buffer_data == NULL) { |
Lajos Molnar | 1b40f28 | 2016-05-09 22:24:52 -0700 | [diff] [blame] | 1034 | reply->writeNativeHandle(native_handle == NULL ? NULL : native_handle->handle()); |
Lajos Molnar | a63141a | 2016-02-11 16:40:36 -0800 | [diff] [blame] | 1035 | } |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | return NO_ERROR; |
| 1039 | } |
| 1040 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1041 | case FREE_BUFFER: |
| 1042 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1043 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1044 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1045 | OMX_U32 port_index = data.readInt32(); |
Andy Hung | 609b815 | 2014-05-02 11:05:04 -0700 | [diff] [blame] | 1046 | buffer_id buffer = (buffer_id)data.readInt32(); |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1047 | reply->writeInt32(freeBuffer(port_index, buffer)); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1048 | |
| 1049 | return NO_ERROR; |
| 1050 | } |
| 1051 | |
| 1052 | case FILL_BUFFER: |
| 1053 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1054 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1055 | |
Andy Hung | 609b815 | 2014-05-02 11:05:04 -0700 | [diff] [blame] | 1056 | buffer_id buffer = (buffer_id)data.readInt32(); |
Lajos Molnar | 15ab499 | 2015-06-01 10:54:31 -0700 | [diff] [blame] | 1057 | bool haveFence = data.readInt32(); |
| 1058 | int fenceFd = haveFence ? ::dup(data.readFileDescriptor()) : -1; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1059 | reply->writeInt32(fillBuffer(buffer, fenceFd)); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1060 | |
| 1061 | return NO_ERROR; |
| 1062 | } |
| 1063 | |
| 1064 | case EMPTY_BUFFER: |
| 1065 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1066 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1067 | |
Andy Hung | 609b815 | 2014-05-02 11:05:04 -0700 | [diff] [blame] | 1068 | buffer_id buffer = (buffer_id)data.readInt32(); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1069 | OMX_U32 range_offset = data.readInt32(); |
| 1070 | OMX_U32 range_length = data.readInt32(); |
| 1071 | OMX_U32 flags = data.readInt32(); |
| 1072 | OMX_TICKS timestamp = data.readInt64(); |
Lajos Molnar | 15ab499 | 2015-06-01 10:54:31 -0700 | [diff] [blame] | 1073 | bool haveFence = data.readInt32(); |
| 1074 | int fenceFd = haveFence ? ::dup(data.readFileDescriptor()) : -1; |
| 1075 | reply->writeInt32(emptyBuffer( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1076 | buffer, range_offset, range_length, flags, timestamp, fenceFd)); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1077 | |
| 1078 | return NO_ERROR; |
| 1079 | } |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1080 | |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 1081 | case EMPTY_GRAPHIC_BUFFER: |
| 1082 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1083 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 1084 | |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 1085 | buffer_id buffer = (buffer_id)data.readInt32(); |
| 1086 | sp<GraphicBuffer> graphicBuffer = new GraphicBuffer(); |
| 1087 | data.read(*graphicBuffer); |
| 1088 | OMX_U32 flags = data.readInt32(); |
| 1089 | OMX_TICKS timestamp = data.readInt64(); |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 1090 | OMX_TICKS origTimestamp = data.readInt64(); |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 1091 | bool haveFence = data.readInt32(); |
| 1092 | int fenceFd = haveFence ? ::dup(data.readFileDescriptor()) : -1; |
| 1093 | reply->writeInt32(emptyGraphicBuffer( |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1094 | buffer, graphicBuffer, flags, |
Chong Zhang | 6d332d2 | 2016-09-07 12:06:50 -0700 | [diff] [blame] | 1095 | timestamp, origTimestamp, fenceFd)); |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 1096 | |
| 1097 | return NO_ERROR; |
| 1098 | } |
| 1099 | |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 1100 | case GET_EXTENSION_INDEX: |
| 1101 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1102 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 1103 | |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 1104 | const char *parameter_name = data.readCString(); |
Andreas Huber | 7eaa9c9 | 2010-01-15 15:28:19 -0800 | [diff] [blame] | 1105 | |
Wei Jia | 56c95c9 | 2016-01-06 10:30:46 -0800 | [diff] [blame] | 1106 | if (parameter_name == NULL) { |
| 1107 | ALOGE("b/26392700"); |
| 1108 | reply->writeInt32(INVALID_OPERATION); |
| 1109 | return NO_ERROR; |
| 1110 | } |
| 1111 | |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 1112 | OMX_INDEXTYPE index; |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1113 | status_t err = getExtensionIndex(parameter_name, &index); |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 1114 | |
| 1115 | reply->writeInt32(err); |
| 1116 | |
| 1117 | if (err == OK) { |
| 1118 | reply->writeInt32(index); |
| 1119 | } |
| 1120 | |
| 1121 | return OK; |
| 1122 | } |
| 1123 | |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 1124 | case DISPATCH_MESSAGE: |
| 1125 | { |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1126 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 1127 | omx_message msg; |
Chong Zhang | 6cf9a12 | 2016-09-08 23:25:52 -0700 | [diff] [blame] | 1128 | int haveFence = data.readInt32(); |
| 1129 | msg.fenceFd = haveFence ? ::dup(data.readFileDescriptor()) : -1; |
| 1130 | msg.type = (typeof(msg.type))data.readInt32(); |
| 1131 | status_t err = data.read(&msg.u, sizeof(msg.u)); |
| 1132 | |
| 1133 | if (err == OK) { |
| 1134 | err = dispatchMessage(msg); |
| 1135 | } |
| 1136 | reply->writeInt32(err); |
| 1137 | |
| 1138 | return NO_ERROR; |
| 1139 | } |
| 1140 | |
Chong Zhang | 21b4658 | 2016-10-04 12:44:53 -0700 | [diff] [blame^] | 1141 | case SET_QUIRKS: |
| 1142 | { |
| 1143 | CHECK_OMX_INTERFACE(IOMXNode, data, reply); |
| 1144 | |
| 1145 | OMX_U32 quirks = data.readInt32(); |
| 1146 | |
| 1147 | reply->writeInt32(setQuirks(quirks)); |
| 1148 | |
| 1149 | return NO_ERROR; |
| 1150 | } |
| 1151 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1152 | default: |
| 1153 | return BBinder::onTransact(code, data, reply, flags); |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | //////////////////////////////////////////////////////////////////////////////// |
| 1158 | |
| 1159 | class BpOMXObserver : public BpInterface<IOMXObserver> { |
| 1160 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 1161 | explicit BpOMXObserver(const sp<IBinder> &impl) |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1162 | : BpInterface<IOMXObserver>(impl) { |
| 1163 | } |
| 1164 | |
Lajos Molnar | 26a48f3 | 2015-06-04 10:30:02 -0700 | [diff] [blame] | 1165 | virtual void onMessages(const std::list<omx_message> &messages) { |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1166 | Parcel data, reply; |
Lajos Molnar | 26a48f3 | 2015-06-04 10:30:02 -0700 | [diff] [blame] | 1167 | std::list<omx_message>::const_iterator it = messages.cbegin(); |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1168 | if (messages.empty()) { |
| 1169 | return; |
| 1170 | } |
| 1171 | data.writeInterfaceToken(IOMXObserver::getInterfaceDescriptor()); |
Lajos Molnar | 26a48f3 | 2015-06-04 10:30:02 -0700 | [diff] [blame] | 1172 | while (it != messages.cend()) { |
| 1173 | const omx_message &msg = *it++; |
Lajos Molnar | 26a48f3 | 2015-06-04 10:30:02 -0700 | [diff] [blame] | 1174 | data.writeInt32(msg.fenceFd >= 0); |
| 1175 | if (msg.fenceFd >= 0) { |
| 1176 | data.writeFileDescriptor(msg.fenceFd, true /* takeOwnership */); |
| 1177 | } |
| 1178 | data.writeInt32(msg.type); |
| 1179 | data.write(&msg.u, sizeof(msg.u)); |
| 1180 | ALOGV("onMessage writing message %d, size %zu", msg.type, sizeof(msg)); |
Lajos Molnar | 15ab499 | 2015-06-01 10:54:31 -0700 | [diff] [blame] | 1181 | } |
Chong Zhang | d59b972 | 2016-09-20 16:31:18 -0700 | [diff] [blame] | 1182 | data.writeInt32(-1); // mark end |
| 1183 | remote()->transact(OBSERVER_ON_MSG, data, &reply, IBinder::FLAG_ONEWAY); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1184 | } |
| 1185 | }; |
| 1186 | |
| 1187 | IMPLEMENT_META_INTERFACE(OMXObserver, "android.hardware.IOMXObserver"); |
| 1188 | |
| 1189 | status_t BnOMXObserver::onTransact( |
| 1190 | uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) { |
| 1191 | switch (code) { |
| 1192 | case OBSERVER_ON_MSG: |
| 1193 | { |
Andy McFadden | 7cd5853 | 2013-02-19 07:28:30 -0800 | [diff] [blame] | 1194 | CHECK_OMX_INTERFACE(IOMXObserver, data, reply); |
Lajos Molnar | 26a48f3 | 2015-06-04 10:30:02 -0700 | [diff] [blame] | 1195 | std::list<omx_message> messages; |
| 1196 | status_t err = FAILED_TRANSACTION; // must receive at least one message |
| 1197 | do { |
| 1198 | int haveFence = data.readInt32(); |
| 1199 | if (haveFence < 0) { // we use -1 to mark end of messages |
| 1200 | break; |
| 1201 | } |
| 1202 | omx_message msg; |
Lajos Molnar | 26a48f3 | 2015-06-04 10:30:02 -0700 | [diff] [blame] | 1203 | msg.fenceFd = haveFence ? ::dup(data.readFileDescriptor()) : -1; |
| 1204 | msg.type = (typeof(msg.type))data.readInt32(); |
| 1205 | err = data.read(&msg.u, sizeof(msg.u)); |
| 1206 | ALOGV("onTransact reading message %d, size %zu", msg.type, sizeof(msg)); |
| 1207 | messages.push_back(msg); |
| 1208 | } while (err == OK); |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1209 | |
Lajos Molnar | 26a48f3 | 2015-06-04 10:30:02 -0700 | [diff] [blame] | 1210 | if (err == OK) { |
| 1211 | onMessages(messages); |
Lajos Molnar | 15ab499 | 2015-06-01 10:54:31 -0700 | [diff] [blame] | 1212 | } |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1213 | |
Lajos Molnar | 26a48f3 | 2015-06-04 10:30:02 -0700 | [diff] [blame] | 1214 | return err; |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | default: |
| 1218 | return BBinder::onTransact(code, data, reply, flags); |
| 1219 | } |
| 1220 | } |
| 1221 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1222 | } // namespace android |