portbase.h revision 229ae5acfb89e9c1559c0394190e77ca6f23f24b
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 30typedef OMX_U8* CustomMemAlloc(OMX_U32 nSizeBytes, OMX_PTR pUserData); 31typedef void CustomMemFree(OMX_U8 *pBuffer, OMX_PTR pUserData); 32 33class PortBase 34{ 35public: 36 /* 37 * constructor & destructor 38 */ 39 PortBase(); 40 PortBase(const OMX_PARAM_PORTDEFINITIONTYPE *portdefinition); 41 virtual ~PortBase(); 42 43 /* end of constructor & destructor */ 44 45 /* 46 * accessor 47 */ 48 /* owner */ 49 void SetOwner(OMX_COMPONENTTYPE *handle); 50 OMX_COMPONENTTYPE *GetOwner(void); 51 52 /* for ReturnThisBuffer() */ 53 OMX_ERRORTYPE SetCallbacks(OMX_HANDLETYPE hComponent, 54 OMX_CALLBACKTYPE *pCallbacks, 55 OMX_PTR pAppData); 56 /* end of accessor */ 57 58 OMX_ERRORTYPE SetMemAllocator(CustomMemAlloc *pMemAlloc, CustomMemFree *pMemFree, OMX_PTR pUserData); 59 60 /* set port buffer alignment, nAlignment=0 means alignment disabled */ 61 OMX_ERRORTYPE SetMemAlignment(OMX_U32 nAlignment); 62 63 /* 64 * component methods & helpers 65 */ 66 /* Get/SetParameter */ 67 OMX_ERRORTYPE SetPortDefinition(const OMX_PARAM_PORTDEFINITIONTYPE *p, 68 bool overwrite_readonly); 69 const OMX_PARAM_PORTDEFINITIONTYPE *GetPortDefinition(void); 70 71 /* Use/Allocate/FreeBuffer */ 72 OMX_ERRORTYPE UseBuffer(OMX_BUFFERHEADERTYPE **ppBufferHdr, 73 OMX_U32 nPortIndex, 74 OMX_PTR pAppPrivate, 75 OMX_U32 nSizeBytes, 76 OMX_U8 *pBuffer); 77 OMX_ERRORTYPE AllocateBuffer(OMX_BUFFERHEADERTYPE **ppBuffer, 78 OMX_U32 nPortIndex, 79 OMX_PTR pAppPrivate, 80 OMX_U32 nSizeBytes); 81 OMX_ERRORTYPE FreeBuffer(OMX_U32 nPortIndex, 82 OMX_BUFFERHEADERTYPE *pBuffer); 83 84 /* 85 * called in ComponentBase::TransStateToLoaded(OMX_StateIdle) or 86 * in ComponentBase::TransStateToIdle(OMX_StateLoaded) 87 * wokeup by Use/Allocate/FreeBuffer 88 */ 89 void WaitPortBufferCompletion(void); 90 91 /* Empty/FillThisBuffer */ 92 OMX_ERRORTYPE PushThisBuffer(OMX_BUFFERHEADERTYPE *pBuffer); 93 OMX_BUFFERHEADERTYPE *PopBuffer(void); 94 OMX_U32 BufferQueueLength(void); 95 96 /* Empty/FillBufferDone */ 97 OMX_ERRORTYPE ReturnThisBuffer(OMX_BUFFERHEADERTYPE *pBuffer); 98 99 OMX_ERRORTYPE RetainAndReturnBuffer(OMX_BUFFERHEADERTYPE *pRetain, OMX_BUFFERHEADERTYPE *pReturn); 100 101 /* retain buffer */ 102 OMX_ERRORTYPE RetainThisBuffer(OMX_BUFFERHEADERTYPE *pBuffer, 103 bool accumulate); 104 /* 105 * components have responsibilty of calling this function to return all 106 * accumulated buffers to omx-il clients. 107 */ 108 void ReturnAllRetainedBuffers(void); 109 110 /* flush all buffers not under processing */ 111 OMX_ERRORTYPE FlushPort(void); 112 113 bool IsEnabled(void); 114 115 OMX_DIRTYPE GetPortDirection(void); 116 OMX_U32 GetPortBufferCount(void); 117 118 OMX_ERRORTYPE PushMark(OMX_MARKTYPE *mark); 119 OMX_MARKTYPE *PopMark(void); 120 121 /* SendCommand(OMX_CommandPortDisable/Enable) */ 122 OMX_ERRORTYPE TransState(OMX_U8 state); 123 124 /* EventHandler(OMX_EventPortSettingChanged) */ 125 OMX_ERRORTYPE ReportPortSettingsChanged(void); 126 OMX_ERRORTYPE ReportOutputCrop(void); 127 /* get frame size */ 128 OMX_U32 getFrameBufSize(OMX_COLOR_FORMATTYPE colorFormat, OMX_U32 width, OMX_U32 height); 129 130 /* end of component methods & helpers */ 131 132 /* TransState, state */ 133 static const OMX_U8 OMX_PortDisabled = 0; 134 static const OMX_U8 OMX_PortEnabled = 1; 135 136private: 137 /* common routines for constructor */ 138 void __PortBase(void); 139 140 /* 141 * component methods & helpers 142 */ 143 OMX_STATETYPE GetOwnerState(void); 144 145 /* end of component methods & helpers */ 146 147 /* buffer headers */ 148 struct list *buffer_hdrs; 149 OMX_U32 nr_buffer_hdrs; 150 bool buffer_hdrs_completion; /* Use/Allocate/FreeBuffer completion flag */ 151 pthread_mutex_t hdrs_lock; 152 pthread_cond_t hdrs_wait; 153 154 struct queue bufferq; 155 pthread_mutex_t bufferq_lock; 156 157 /* retained buffers (only accumulated buffer) */ 158 struct queue retainedbufferq; 159 pthread_mutex_t retainedbufferq_lock; 160 161 struct queue markq; 162 pthread_mutex_t markq_lock; 163 164 /* state */ 165 OMX_U8 state; 166 pthread_mutex_t state_lock; 167 168 CustomMemAlloc *custom_mem_alloc; 169 CustomMemFree *custom_mem_free; 170 OMX_PTR custom_mem_userdata; 171 172 OMX_U32 mem_alignment; 173 174 /* parameter */ 175 OMX_PARAM_PORTDEFINITIONTYPE portdefinition; 176 /* room for portdefinition.format.*.cMIMEType */ 177 char definition_format_mimetype[OMX_MAX_STRINGNAME_SIZE]; 178 179 OMX_AUDIO_PARAM_PORTFORMATTYPE audioparam; 180 181 /* owner handle */ 182 OMX_COMPONENTTYPE *owner; 183 184 /* omx standard callbacks */ 185 OMX_PTR appdata; 186 OMX_CALLBACKTYPE *callbacks; 187 188 /* wrs component handle */ 189 class ComponentBase *cbase; 190}; 191 192/* end of PortBase */ 193 194#endif /* __PORTBASE_H */ 195