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 OMX_NODE_INSTANCE_H_ 18 19 #define OMX_NODE_INSTANCE_H_ 20 21 #include "OMX.h" 22 23 #include <utils/RefBase.h> 24 #include <utils/threads.h> 25 26 namespace android { 27 28 class IOMXObserver; 29 struct OMXMaster; 30 struct GraphicBufferSource; 31 32 struct OMXNodeInstance { 33 OMXNodeInstance( 34 OMX *owner, const sp<IOMXObserver> &observer); 35 36 void setHandle(OMX::node_id node_id, OMX_HANDLETYPE handle); 37 38 OMX *owner(); 39 sp<IOMXObserver> observer(); 40 OMX::node_id nodeID(); 41 42 status_t freeNode(OMXMaster *master); 43 44 status_t sendCommand(OMX_COMMANDTYPE cmd, OMX_S32 param); 45 status_t getParameter(OMX_INDEXTYPE index, void *params, size_t size); 46 47 status_t setParameter( 48 OMX_INDEXTYPE index, const void *params, size_t size); 49 50 status_t getConfig(OMX_INDEXTYPE index, void *params, size_t size); 51 status_t setConfig(OMX_INDEXTYPE index, const void *params, size_t size); 52 53 status_t getState(OMX_STATETYPE* state); 54 55 status_t enableGraphicBuffers(OMX_U32 portIndex, OMX_BOOL enable); 56 57 status_t getGraphicBufferUsage(OMX_U32 portIndex, OMX_U32* usage); 58 59 status_t storeMetaDataInBuffers(OMX_U32 portIndex, OMX_BOOL enable); 60 61 status_t useBuffer( 62 OMX_U32 portIndex, const sp<IMemory> ¶ms, 63 OMX::buffer_id *buffer); 64 65 status_t useGraphicBuffer( 66 OMX_U32 portIndex, const sp<GraphicBuffer> &graphicBuffer, 67 OMX::buffer_id *buffer); 68 69 status_t createInputSurface( 70 OMX_U32 portIndex, sp<IGraphicBufferProducer> *bufferProducer); 71 72 status_t signalEndOfInputStream(); 73 74 status_t allocateBuffer( 75 OMX_U32 portIndex, size_t size, OMX::buffer_id *buffer, 76 void **buffer_data); 77 78 status_t allocateBufferWithBackup( 79 OMX_U32 portIndex, const sp<IMemory> ¶ms, 80 OMX::buffer_id *buffer); 81 82 status_t freeBuffer(OMX_U32 portIndex, OMX::buffer_id buffer); 83 84 status_t fillBuffer(OMX::buffer_id buffer); 85 86 status_t emptyBuffer( 87 OMX::buffer_id buffer, 88 OMX_U32 rangeOffset, OMX_U32 rangeLength, 89 OMX_U32 flags, OMX_TICKS timestamp); 90 91 status_t emptyDirectBuffer( 92 OMX_BUFFERHEADERTYPE *header, 93 OMX_U32 rangeOffset, OMX_U32 rangeLength, 94 OMX_U32 flags, OMX_TICKS timestamp); 95 96 status_t getExtensionIndex( 97 const char *parameterName, OMX_INDEXTYPE *index); 98 99 void onMessage(const omx_message &msg); 100 void onObserverDied(OMXMaster *master); 101 void onGetHandleFailed(); 102 void onEvent(OMX_EVENTTYPE event, OMX_U32 arg1, OMX_U32 arg2); 103 104 static OMX_CALLBACKTYPE kCallbacks; 105 106 private: 107 Mutex mLock; 108 109 OMX *mOwner; 110 OMX::node_id mNodeID; 111 OMX_HANDLETYPE mHandle; 112 sp<IOMXObserver> mObserver; 113 bool mDying; 114 115 // Lock only covers mGraphicBufferSource. We can't always use mLock 116 // because of rare instances where we'd end up locking it recursively. 117 Mutex mGraphicBufferSourceLock; 118 // Access this through getGraphicBufferSource(). 119 sp<GraphicBufferSource> mGraphicBufferSource; 120 121 122 struct ActiveBuffer { 123 OMX_U32 mPortIndex; 124 OMX::buffer_id mID; 125 }; 126 Vector<ActiveBuffer> mActiveBuffers; 127 128 ~OMXNodeInstance(); 129 130 void addActiveBuffer(OMX_U32 portIndex, OMX::buffer_id id); 131 void removeActiveBuffer(OMX_U32 portIndex, OMX::buffer_id id); 132 void freeActiveBuffers(); 133 status_t useGraphicBuffer2_l( 134 OMX_U32 portIndex, const sp<GraphicBuffer> &graphicBuffer, 135 OMX::buffer_id *buffer); 136 static OMX_ERRORTYPE OnEvent( 137 OMX_IN OMX_HANDLETYPE hComponent, 138 OMX_IN OMX_PTR pAppData, 139 OMX_IN OMX_EVENTTYPE eEvent, 140 OMX_IN OMX_U32 nData1, 141 OMX_IN OMX_U32 nData2, 142 OMX_IN OMX_PTR pEventData); 143 144 static OMX_ERRORTYPE OnEmptyBufferDone( 145 OMX_IN OMX_HANDLETYPE hComponent, 146 OMX_IN OMX_PTR pAppData, 147 OMX_IN OMX_BUFFERHEADERTYPE *pBuffer); 148 149 static OMX_ERRORTYPE OnFillBufferDone( 150 OMX_IN OMX_HANDLETYPE hComponent, 151 OMX_IN OMX_PTR pAppData, 152 OMX_IN OMX_BUFFERHEADERTYPE *pBuffer); 153 154 status_t storeMetaDataInBuffers_l(OMX_U32 portIndex, OMX_BOOL enable); 155 156 sp<GraphicBufferSource> getGraphicBufferSource(); 157 void setGraphicBufferSource(const sp<GraphicBufferSource>& bufferSource); 158 159 OMXNodeInstance(const OMXNodeInstance &); 160 OMXNodeInstance &operator=(const OMXNodeInstance &); 161 }; 162 163 } // namespace android 164 165 #endif // OMX_NODE_INSTANCE_H_ 166