portbase.h revision 2f6e87e64736666857c1bbe2cb0692c1f4e56508
1/* 2 * portbase.h, port base class 3 * 4 * Copyright (c) 2009-2010 Wind River Systems, Inc. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19#ifndef __PORTBASE_H 20#define __PORTBASE_H 21 22#include <pthread.h> 23 24#include <OMX_Core.h> 25#include <OMX_Component.h> 26 27#include <list.h> 28#include <queue.h> 29 30class PortBase 31{ 32public: 33 /* 34 * constructor & destructor 35 */ 36 PortBase(); 37 PortBase(const OMX_PARAM_PORTDEFINITIONTYPE *portdefinition); 38 virtual ~PortBase(); 39 40 /* end of constructor & destructor */ 41 42 /* 43 * accessor 44 */ 45 /* owner */ 46 void SetOwner(OMX_COMPONENTTYPE *handle); 47 OMX_COMPONENTTYPE *GetOwner(void); 48 49 /* for ReturnThisBuffer() */ 50 OMX_ERRORTYPE SetCallbacks(OMX_HANDLETYPE hComponent, 51 OMX_CALLBACKTYPE *pCallbacks, 52 OMX_PTR pAppData); 53 /* end of accessor */ 54 55 /* 56 * component methods & helpers 57 */ 58 /* Get/SetParameter */ 59 OMX_ERRORTYPE SetPortDefinition(const OMX_PARAM_PORTDEFINITIONTYPE *p, 60 bool overwrite_readonly); 61 const OMX_PARAM_PORTDEFINITIONTYPE *GetPortDefinition(void); 62 63 /* Use/Allocate/FreeBuffer */ 64 OMX_ERRORTYPE UseBuffer(OMX_BUFFERHEADERTYPE **ppBufferHdr, 65 OMX_U32 nPortIndex, 66 OMX_PTR pAppPrivate, 67 OMX_U32 nSizeBytes, 68 OMX_U8 *pBuffer); 69 OMX_ERRORTYPE AllocateBuffer(OMX_BUFFERHEADERTYPE **ppBuffer, 70 OMX_U32 nPortIndex, 71 OMX_PTR pAppPrivate, 72 OMX_U32 nSizeBytes); 73 OMX_ERRORTYPE FreeBuffer(OMX_U32 nPortIndex, 74 OMX_BUFFERHEADERTYPE *pBuffer); 75 76 /* 77 * called in ComponentBase::TransStateToLoaded(OMX_StateIdle) or 78 * in ComponentBase::TransStateToIdle(OMX_StateLoaded) 79 * wokeup by Use/Allocate/FreeBuffer 80 */ 81 void WaitPortBufferCompletion(void); 82 83 /* Empty/FillThisBuffer */ 84 OMX_ERRORTYPE PushThisBuffer(OMX_BUFFERHEADERTYPE *pBuffer); 85 OMX_BUFFERHEADERTYPE *PopBuffer(void); 86 OMX_U32 BufferQueueLength(void); 87 88 /* Empty/FillBufferDone */ 89 OMX_ERRORTYPE ReturnThisBuffer(OMX_BUFFERHEADERTYPE *pBuffer); 90 91 /* retain buffer */ 92 OMX_ERRORTYPE RetainThisBuffer(OMX_BUFFERHEADERTYPE *pBuffer, 93 bool accumulate); 94 /* 95 * components have responsibilty of calling this function to return all 96 * accumulated buffers to omx-il clients. 97 */ 98 void ReturnAllRetainedBuffers(void); 99 100 /* flush all buffers not under processing */ 101 OMX_ERRORTYPE FlushPort(void); 102 103 bool IsEnabled(void); 104 105 OMX_DIRTYPE GetPortDirection(void); 106 OMX_U32 GetPortBufferCount(void); 107 108 OMX_ERRORTYPE PushMark(OMX_MARKTYPE *mark); 109 OMX_MARKTYPE *PopMark(void); 110 111 /* SendCommand(OMX_CommandPortDisable/Enable) */ 112 OMX_ERRORTYPE TransState(OMX_U8 state); 113 114 /* EventHandler(OMX_EventPortSettingChanged) */ 115 OMX_ERRORTYPE ReportPortSettingsChanged(void); 116 117 /* end of component methods & helpers */ 118 119 /* TransState, state */ 120 static const OMX_U8 OMX_PortDisabled = 0; 121 static const OMX_U8 OMX_PortEnabled = 1; 122 123private: 124 /* common routines for constructor */ 125 void __PortBase(void); 126 127 /* 128 * component methods & helpers 129 */ 130 OMX_STATETYPE GetOwnerState(void); 131 132 /* end of component methods & helpers */ 133 134 /* buffer headers */ 135 struct list *buffer_hdrs; 136 OMX_U32 nr_buffer_hdrs; 137 bool buffer_hdrs_completion; /* Use/Allocate/FreeBuffer completion flag */ 138 pthread_mutex_t hdrs_lock; 139 pthread_cond_t hdrs_wait; 140 141 struct queue bufferq; 142 pthread_mutex_t bufferq_lock; 143 144 /* retained buffers (only accumulated buffer) */ 145 struct queue retainedbufferq; 146 pthread_mutex_t retainedbufferq_lock; 147 148 struct queue markq; 149 pthread_mutex_t markq_lock; 150 151 /* state */ 152 OMX_U8 state; 153 pthread_mutex_t state_lock; 154 155 /* parameter */ 156 OMX_PARAM_PORTDEFINITIONTYPE portdefinition; 157 /* room for portdefinition.format.*.cMIMEType */ 158 char definition_format_mimetype[OMX_MAX_STRINGNAME_SIZE]; 159 160 OMX_AUDIO_PARAM_PORTFORMATTYPE audioparam; 161 162 /* owner handle */ 163 OMX_COMPONENTTYPE *owner; 164 165 /* omx standard callbacks */ 166 OMX_PTR appdata; 167 OMX_CALLBACKTYPE *callbacks; 168 169 /* wrs component handle */ 170 class ComponentBase *cbase; 171}; 172 173/* end of PortBase */ 174 175#endif /* __PORTBASE_H */ 176