Andreas Huber | e46b7be | 2009-07-14 16:56:47 -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 | |
| 17 | #ifndef ANDROID_IOMX_H_ |
| 18 | |
| 19 | #define ANDROID_IOMX_H_ |
| 20 | |
| 21 | #include <binder/IInterface.h> |
Jamie Gennis | 33a7814 | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 22 | #include <ui/GraphicBuffer.h> |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 23 | #include <utils/List.h> |
| 24 | #include <utils/String8.h> |
| 25 | |
| 26 | #include <OMX_Core.h> |
Andreas Huber | 1de1316 | 2009-07-31 11:52:50 -0700 | [diff] [blame] | 27 | #include <OMX_Video.h> |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 28 | |
Andreas Huber | 9f9afef | 2009-09-15 12:49:11 -0700 | [diff] [blame] | 29 | #include "jni.h" |
| 30 | |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 31 | namespace android { |
| 32 | |
| 33 | class IMemory; |
| 34 | class IOMXObserver; |
Andreas Huber | 1de1316 | 2009-07-31 11:52:50 -0700 | [diff] [blame] | 35 | class IOMXRenderer; |
Andreas Huber | ccf8b94 | 2009-08-07 12:01:29 -0700 | [diff] [blame] | 36 | class Surface; |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 37 | |
| 38 | class IOMX : public IInterface { |
| 39 | public: |
| 40 | DECLARE_META_INTERFACE(OMX); |
| 41 | |
| 42 | typedef void *buffer_id; |
| 43 | typedef void *node_id; |
| 44 | |
Andreas Huber | f1fe064 | 2010-01-15 15:28:19 -0800 | [diff] [blame] | 45 | // Given the calling process' pid, returns true iff |
| 46 | // the implementation of the OMX interface lives in the same |
| 47 | // process. |
| 48 | virtual bool livesLocally(pid_t pid) = 0; |
| 49 | |
Andreas Huber | 2ea14e2 | 2009-12-16 09:30:55 -0800 | [diff] [blame] | 50 | struct ComponentInfo { |
| 51 | String8 mName; |
| 52 | List<String8> mRoles; |
| 53 | }; |
| 54 | virtual status_t listNodes(List<ComponentInfo> *list) = 0; |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 55 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 56 | virtual status_t allocateNode( |
| 57 | const char *name, const sp<IOMXObserver> &observer, |
| 58 | node_id *node) = 0; |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 59 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 60 | virtual status_t freeNode(node_id node) = 0; |
| 61 | |
| 62 | virtual status_t sendCommand( |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 63 | node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0; |
| 64 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 65 | virtual status_t getParameter( |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 66 | node_id node, OMX_INDEXTYPE index, |
| 67 | void *params, size_t size) = 0; |
| 68 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 69 | virtual status_t setParameter( |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 70 | node_id node, OMX_INDEXTYPE index, |
| 71 | const void *params, size_t size) = 0; |
| 72 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 73 | virtual status_t getConfig( |
Andreas Huber | be06d26 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 74 | node_id node, OMX_INDEXTYPE index, |
| 75 | void *params, size_t size) = 0; |
| 76 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 77 | virtual status_t setConfig( |
Andreas Huber | be06d26 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 78 | node_id node, OMX_INDEXTYPE index, |
| 79 | const void *params, size_t size) = 0; |
| 80 | |
Jamie Gennis | 6607b39 | 2011-10-19 21:14:13 -0700 | [diff] [blame] | 81 | virtual status_t getState( |
| 82 | node_id node, OMX_STATETYPE* state) = 0; |
| 83 | |
James Dong | 387e38d | 2010-10-20 17:38:41 -0700 | [diff] [blame] | 84 | virtual status_t storeMetaDataInBuffers( |
| 85 | node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0; |
| 86 | |
Jamie Gennis | 33a7814 | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 87 | virtual status_t enableGraphicBuffers( |
| 88 | node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0; |
| 89 | |
Jamie Gennis | e6befb8 | 2011-02-23 19:01:28 -0800 | [diff] [blame] | 90 | virtual status_t getGraphicBufferUsage( |
| 91 | node_id node, OMX_U32 port_index, OMX_U32* usage) = 0; |
| 92 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 93 | virtual status_t useBuffer( |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 94 | node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, |
| 95 | buffer_id *buffer) = 0; |
| 96 | |
Jamie Gennis | 33a7814 | 2010-08-30 16:48:38 -0700 | [diff] [blame] | 97 | virtual status_t useGraphicBuffer( |
| 98 | node_id node, OMX_U32 port_index, |
| 99 | const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0; |
| 100 | |
Andreas Huber | c712b9f | 2010-01-20 15:05:46 -0800 | [diff] [blame] | 101 | // This API clearly only makes sense if the caller lives in the |
| 102 | // same process as the callee, i.e. is the media_server, as the |
| 103 | // returned "buffer_data" pointer is just that, a pointer into local |
| 104 | // address space. |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 105 | virtual status_t allocateBuffer( |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 106 | node_id node, OMX_U32 port_index, size_t size, |
Andreas Huber | c712b9f | 2010-01-20 15:05:46 -0800 | [diff] [blame] | 107 | buffer_id *buffer, void **buffer_data) = 0; |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 108 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 109 | virtual status_t allocateBufferWithBackup( |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 110 | node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, |
| 111 | buffer_id *buffer) = 0; |
| 112 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 113 | virtual status_t freeBuffer( |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 114 | node_id node, OMX_U32 port_index, buffer_id buffer) = 0; |
| 115 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 116 | virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0; |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 117 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 118 | virtual status_t emptyBuffer( |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 119 | node_id node, |
| 120 | buffer_id buffer, |
| 121 | OMX_U32 range_offset, OMX_U32 range_length, |
| 122 | OMX_U32 flags, OMX_TICKS timestamp) = 0; |
Andreas Huber | 1de1316 | 2009-07-31 11:52:50 -0700 | [diff] [blame] | 123 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 124 | virtual status_t getExtensionIndex( |
Andreas Huber | be06d26 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 125 | node_id node, |
| 126 | const char *parameter_name, |
| 127 | OMX_INDEXTYPE *index) = 0; |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | struct omx_message { |
| 131 | enum { |
| 132 | EVENT, |
| 133 | EMPTY_BUFFER_DONE, |
| 134 | FILL_BUFFER_DONE, |
| 135 | |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 136 | } type; |
| 137 | |
Andreas Huber | be06d26 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 138 | IOMX::node_id node; |
| 139 | |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 140 | union { |
| 141 | // if type == EVENT |
| 142 | struct { |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 143 | OMX_EVENTTYPE event; |
| 144 | OMX_U32 data1; |
| 145 | OMX_U32 data2; |
| 146 | } event_data; |
| 147 | |
Andreas Huber | 329577a | 2009-08-27 14:50:58 -0700 | [diff] [blame] | 148 | // if type == EMPTY_BUFFER_DONE |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 149 | struct { |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 150 | IOMX::buffer_id buffer; |
| 151 | } buffer_data; |
| 152 | |
Andreas Huber | 329577a | 2009-08-27 14:50:58 -0700 | [diff] [blame] | 153 | // if type == FILL_BUFFER_DONE |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 154 | struct { |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 155 | IOMX::buffer_id buffer; |
| 156 | OMX_U32 range_offset; |
| 157 | OMX_U32 range_length; |
| 158 | OMX_U32 flags; |
| 159 | OMX_TICKS timestamp; |
Andreas Huber | 329577a | 2009-08-27 14:50:58 -0700 | [diff] [blame] | 160 | OMX_PTR platform_private; |
Andreas Huber | 52733b8 | 2010-01-25 10:41:35 -0800 | [diff] [blame] | 161 | OMX_PTR data_ptr; |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 162 | } extended_buffer_data; |
| 163 | |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 164 | } u; |
| 165 | }; |
| 166 | |
| 167 | class IOMXObserver : public IInterface { |
| 168 | public: |
| 169 | DECLARE_META_INTERFACE(OMXObserver); |
| 170 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 171 | virtual void onMessage(const omx_message &msg) = 0; |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | //////////////////////////////////////////////////////////////////////////////// |
| 175 | |
| 176 | class BnOMX : public BnInterface<IOMX> { |
| 177 | public: |
| 178 | virtual status_t onTransact( |
| 179 | uint32_t code, const Parcel &data, Parcel *reply, |
| 180 | uint32_t flags = 0); |
| 181 | }; |
| 182 | |
| 183 | class BnOMXObserver : public BnInterface<IOMXObserver> { |
| 184 | public: |
| 185 | virtual status_t onTransact( |
| 186 | uint32_t code, const Parcel &data, Parcel *reply, |
| 187 | uint32_t flags = 0); |
| 188 | }; |
| 189 | |
James Dong | fbb170c | 2011-07-11 12:29:10 -0700 | [diff] [blame] | 190 | struct CodecProfileLevel { |
| 191 | OMX_U32 mProfile; |
| 192 | OMX_U32 mLevel; |
| 193 | }; |
| 194 | |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 195 | } // namespace android |
| 196 | |
| 197 | #endif // ANDROID_IOMX_H_ |