portbase.h revision ecc877a1dd44921dff3f300bc5559841f0c44ac6
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 OMX_ERRORTYPE RetainAndReturnBuffer(OMX_BUFFERHEADERTYPE *pRetain, OMX_BUFFERHEADERTYPE *pReturn); 92 93 /* retain buffer */ 94 OMX_ERRORTYPE RetainThisBuffer(OMX_BUFFERHEADERTYPE *pBuffer, 95 bool accumulate); 96 /* 97 * components have responsibilty of calling this function to return all 98 * accumulated buffers to omx-il clients. 99 */ 100 void ReturnAllRetainedBuffers(void); 101 102 /* flush all buffers not under processing */ 103 OMX_ERRORTYPE FlushPort(void); 104 105 bool IsEnabled(void); 106 107 OMX_DIRTYPE GetPortDirection(void); 108 OMX_U32 GetPortBufferCount(void); 109 110 OMX_ERRORTYPE PushMark(OMX_MARKTYPE *mark); 111 OMX_MARKTYPE *PopMark(void); 112 113 /* SendCommand(OMX_CommandPortDisable/Enable) */ 114 OMX_ERRORTYPE TransState(OMX_U8 state); 115 116 /* EventHandler(OMX_EventPortSettingChanged) */ 117 OMX_ERRORTYPE ReportPortSettingsChanged(void); 118 OMX_ERRORTYPE ReportOutputCrop(void); 119 /* get frame size */ 120 OMX_U32 getFrameBufSize(OMX_COLOR_FORMATTYPE colorFormat, OMX_U32 width, OMX_U32 height); 121 122 /* end of component methods & helpers */ 123 124 /* TransState, state */ 125 static const OMX_U8 OMX_PortDisabled = 0; 126 static const OMX_U8 OMX_PortEnabled = 1; 127 128private: 129 /* common routines for constructor */ 130 void __PortBase(void); 131 132 /* 133 * component methods & helpers 134 */ 135 OMX_STATETYPE GetOwnerState(void); 136 137 /* end of component methods & helpers */ 138 139 /* buffer headers */ 140 struct list *buffer_hdrs; 141 OMX_U32 nr_buffer_hdrs; 142 bool buffer_hdrs_completion; /* Use/Allocate/FreeBuffer completion flag */ 143 pthread_mutex_t hdrs_lock; 144 pthread_cond_t hdrs_wait; 145 146 struct queue bufferq; 147 pthread_mutex_t bufferq_lock; 148 149 /* retained buffers (only accumulated buffer) */ 150 struct queue retainedbufferq; 151 pthread_mutex_t retainedbufferq_lock; 152 153 struct queue markq; 154 pthread_mutex_t markq_lock; 155 156 /* state */ 157 OMX_U8 state; 158 pthread_mutex_t state_lock; 159 160 /* parameter */ 161 OMX_PARAM_PORTDEFINITIONTYPE portdefinition; 162 /* room for portdefinition.format.*.cMIMEType */ 163 char definition_format_mimetype[OMX_MAX_STRINGNAME_SIZE]; 164 165 OMX_AUDIO_PARAM_PORTFORMATTYPE audioparam; 166 167 /* owner handle */ 168 OMX_COMPONENTTYPE *owner; 169 170 /* omx standard callbacks */ 171 OMX_PTR appdata; 172 OMX_CALLBACKTYPE *callbacks; 173 174 /* wrs component handle */ 175 class ComponentBase *cbase; 176}; 177 178/* end of PortBase */ 179 180#endif /* __PORTBASE_H */ 181