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_OMX_H_ 18 #define ANDROID_OMX_H_ 19 20 #include <media/IOMX.h> 21 #include <utils/threads.h> 22 #include <utils/KeyedVector.h> 23 24 namespace android { 25 26 struct OMXMaster; 27 class OMXNodeInstance; 28 29 class OMX : public BnOMX, 30 public IBinder::DeathRecipient { 31 public: 32 OMX(); 33 34 virtual bool livesLocally(node_id node, pid_t pid); 35 36 virtual status_t listNodes(List<ComponentInfo> *list); 37 38 virtual status_t allocateNode( 39 const char *name, const sp<IOMXObserver> &observer, node_id *node); 40 41 virtual status_t freeNode(node_id node); 42 43 virtual status_t sendCommand( 44 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param); 45 46 virtual status_t getParameter( 47 node_id node, OMX_INDEXTYPE index, 48 void *params, size_t size); 49 50 virtual status_t setParameter( 51 node_id node, OMX_INDEXTYPE index, 52 const void *params, size_t size); 53 54 virtual status_t getConfig( 55 node_id node, OMX_INDEXTYPE index, 56 void *params, size_t size); 57 58 virtual status_t setConfig( 59 node_id node, OMX_INDEXTYPE index, 60 const void *params, size_t size); 61 62 virtual status_t getState( 63 node_id node, OMX_STATETYPE* state); 64 65 virtual status_t enableGraphicBuffers( 66 node_id node, OMX_U32 port_index, OMX_BOOL enable); 67 68 virtual status_t getGraphicBufferUsage( 69 node_id node, OMX_U32 port_index, OMX_U32* usage); 70 71 virtual status_t storeMetaDataInBuffers( 72 node_id node, OMX_U32 port_index, OMX_BOOL enable); 73 74 virtual status_t prepareForAdaptivePlayback( 75 node_id node, OMX_U32 portIndex, OMX_BOOL enable, 76 OMX_U32 max_frame_width, OMX_U32 max_frame_height); 77 78 virtual status_t useBuffer( 79 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 80 buffer_id *buffer); 81 82 virtual status_t useGraphicBuffer( 83 node_id node, OMX_U32 port_index, 84 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer); 85 86 virtual status_t updateGraphicBufferInMeta( 87 node_id node, OMX_U32 port_index, 88 const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer); 89 90 virtual status_t createInputSurface( 91 node_id node, OMX_U32 port_index, 92 sp<IGraphicBufferProducer> *bufferProducer); 93 94 virtual status_t signalEndOfInputStream(node_id node); 95 96 virtual status_t allocateBuffer( 97 node_id node, OMX_U32 port_index, size_t size, 98 buffer_id *buffer, void **buffer_data); 99 100 virtual status_t allocateBufferWithBackup( 101 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 102 buffer_id *buffer); 103 104 virtual status_t freeBuffer( 105 node_id node, OMX_U32 port_index, buffer_id buffer); 106 107 virtual status_t fillBuffer(node_id node, buffer_id buffer); 108 109 virtual status_t emptyBuffer( 110 node_id node, 111 buffer_id buffer, 112 OMX_U32 range_offset, OMX_U32 range_length, 113 OMX_U32 flags, OMX_TICKS timestamp); 114 115 virtual status_t getExtensionIndex( 116 node_id node, 117 const char *parameter_name, 118 OMX_INDEXTYPE *index); 119 120 virtual status_t setInternalOption( 121 node_id node, 122 OMX_U32 port_index, 123 InternalOptionType type, 124 const void *data, 125 size_t size); 126 127 virtual void binderDied(const wp<IBinder> &the_late_who); 128 129 OMX_ERRORTYPE OnEvent( 130 node_id node, 131 OMX_IN OMX_EVENTTYPE eEvent, 132 OMX_IN OMX_U32 nData1, 133 OMX_IN OMX_U32 nData2, 134 OMX_IN OMX_PTR pEventData); 135 136 OMX_ERRORTYPE OnEmptyBufferDone( 137 node_id node, OMX_IN OMX_BUFFERHEADERTYPE *pBuffer); 138 139 OMX_ERRORTYPE OnFillBufferDone( 140 node_id node, OMX_IN OMX_BUFFERHEADERTYPE *pBuffer); 141 142 void invalidateNodeID(node_id node); 143 144 protected: 145 virtual ~OMX(); 146 147 private: 148 struct CallbackDispatcherThread; 149 struct CallbackDispatcher; 150 151 Mutex mLock; 152 OMXMaster *mMaster; 153 int32_t mNodeCounter; 154 155 KeyedVector<wp<IBinder>, OMXNodeInstance *> mLiveNodes; 156 KeyedVector<node_id, OMXNodeInstance *> mNodeIDToInstance; 157 KeyedVector<node_id, sp<CallbackDispatcher> > mDispatchers; 158 159 node_id makeNodeID(OMXNodeInstance *instance); 160 OMXNodeInstance *findInstance(node_id node); 161 sp<CallbackDispatcher> findDispatcher(node_id node); 162 163 void invalidateNodeID_l(node_id node); 164 165 OMX(const OMX &); 166 OMX &operator=(const OMX &); 167 }; 168 169 } // namespace android 170 171 #endif // ANDROID_OMX_H_ 172