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