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 26namespace android { 27 28class IOMXObserver; 29struct OMXMaster; 30 31struct OMXNodeInstance { 32 OMXNodeInstance( 33 OMX *owner, const sp<IOMXObserver> &observer); 34 35 void setHandle(OMX::node_id node_id, OMX_HANDLETYPE handle); 36 37 OMX *owner(); 38 sp<IOMXObserver> observer(); 39 OMX::node_id nodeID(); 40 41 status_t freeNode(OMXMaster *master); 42 43 status_t sendCommand(OMX_COMMANDTYPE cmd, OMX_S32 param); 44 status_t getParameter(OMX_INDEXTYPE index, void *params, size_t size); 45 46 status_t setParameter( 47 OMX_INDEXTYPE index, const void *params, size_t size); 48 49 status_t getConfig(OMX_INDEXTYPE index, void *params, size_t size); 50 status_t setConfig(OMX_INDEXTYPE index, const void *params, size_t size); 51 52 status_t getState(OMX_STATETYPE* state); 53 54 status_t enableGraphicBuffers(OMX_U32 portIndex, OMX_BOOL enable); 55 56 status_t getGraphicBufferUsage(OMX_U32 portIndex, OMX_U32* usage); 57 58 status_t storeMetaDataInBuffers(OMX_U32 portIndex, OMX_BOOL enable); 59 60 status_t useBuffer( 61 OMX_U32 portIndex, const sp<IMemory> ¶ms, 62 OMX::buffer_id *buffer); 63 64 status_t useGraphicBuffer( 65 OMX_U32 portIndex, const sp<GraphicBuffer> &graphicBuffer, 66 OMX::buffer_id *buffer); 67 68 status_t allocateBuffer( 69 OMX_U32 portIndex, size_t size, OMX::buffer_id *buffer, 70 void **buffer_data); 71 72 status_t allocateBufferWithBackup( 73 OMX_U32 portIndex, const sp<IMemory> ¶ms, 74 OMX::buffer_id *buffer); 75 76 status_t freeBuffer(OMX_U32 portIndex, OMX::buffer_id buffer); 77 78 status_t fillBuffer(OMX::buffer_id buffer); 79 80 status_t emptyBuffer( 81 OMX::buffer_id buffer, 82 OMX_U32 rangeOffset, OMX_U32 rangeLength, 83 OMX_U32 flags, OMX_TICKS timestamp); 84 85 status_t getExtensionIndex( 86 const char *parameterName, OMX_INDEXTYPE *index); 87 88 void onMessage(const omx_message &msg); 89 void onObserverDied(OMXMaster *master); 90 void onGetHandleFailed(); 91 92 static OMX_CALLBACKTYPE kCallbacks; 93 94private: 95 Mutex mLock; 96 97 OMX *mOwner; 98 OMX::node_id mNodeID; 99 OMX_HANDLETYPE mHandle; 100 sp<IOMXObserver> mObserver; 101 bool mDying; 102 103 struct ActiveBuffer { 104 OMX_U32 mPortIndex; 105 OMX::buffer_id mID; 106 }; 107 Vector<ActiveBuffer> mActiveBuffers; 108 109 ~OMXNodeInstance(); 110 111 void addActiveBuffer(OMX_U32 portIndex, OMX::buffer_id id); 112 void removeActiveBuffer(OMX_U32 portIndex, OMX::buffer_id id); 113 void freeActiveBuffers(); 114 status_t useGraphicBuffer2_l( 115 OMX_U32 portIndex, const sp<GraphicBuffer> &graphicBuffer, 116 OMX::buffer_id *buffer); 117 static OMX_ERRORTYPE OnEvent( 118 OMX_IN OMX_HANDLETYPE hComponent, 119 OMX_IN OMX_PTR pAppData, 120 OMX_IN OMX_EVENTTYPE eEvent, 121 OMX_IN OMX_U32 nData1, 122 OMX_IN OMX_U32 nData2, 123 OMX_IN OMX_PTR pEventData); 124 125 static OMX_ERRORTYPE OnEmptyBufferDone( 126 OMX_IN OMX_HANDLETYPE hComponent, 127 OMX_IN OMX_PTR pAppData, 128 OMX_IN OMX_BUFFERHEADERTYPE *pBuffer); 129 130 static OMX_ERRORTYPE OnFillBufferDone( 131 OMX_IN OMX_HANDLETYPE hComponent, 132 OMX_IN OMX_PTR pAppData, 133 OMX_IN OMX_BUFFERHEADERTYPE *pBuffer); 134 135 OMXNodeInstance(const OMXNodeInstance &); 136 OMXNodeInstance &operator=(const OMXNodeInstance &); 137}; 138 139} // namespace android 140 141#endif // OMX_NODE_INSTANCE_H_ 142