portbase.h revision 30bd6062e4b295f5f7bcaeb98165065310d29269
1/* 2 * Copyright (c) 2009 Wind River Systems, Inc. 3 * 4 * The right to copy, distribute, modify, or otherwise make use 5 * of this software may be licensed only pursuant to the terms 6 * of an applicable Wind River license agreement. 7 */ 8 9#ifndef __PORTBASE_H 10#define __PORTBASE_H 11 12#include <pthread.h> 13 14#include <OMX_Core.h> 15#include <OMX_Component.h> 16 17#include <list.h> 18#include <queue.h> 19 20class PortBase 21{ 22public: 23 /* 24 * constructor & destructor 25 */ 26 PortBase(); 27 PortBase(const OMX_PARAM_PORTDEFINITIONTYPE *portdefinition); 28 virtual ~PortBase(); 29 30 /* end of constructor & destructor */ 31 32 /* 33 * accessor 34 */ 35 /* owner */ 36 void SetOwner(OMX_COMPONENTTYPE *handle); 37 OMX_COMPONENTTYPE *GetOwner(void); 38 39 /* for ReturnThisBuffer() */ 40 OMX_ERRORTYPE SetCallbacks(OMX_HANDLETYPE hComponent, 41 OMX_CALLBACKTYPE *pCallbacks, 42 OMX_PTR pAppData); 43 /* end of accessor */ 44 45 /* 46 * component methods & helpers 47 */ 48 /* Get/SetParameter */ 49 OMX_ERRORTYPE SetPortDefinition(const OMX_PARAM_PORTDEFINITIONTYPE *p, 50 bool overwrite_readonly); 51 const OMX_PARAM_PORTDEFINITIONTYPE *GetPortDefinition(void); 52 53 /* Use/Allocate/FreeBuffer */ 54 OMX_ERRORTYPE UseBuffer(OMX_BUFFERHEADERTYPE **ppBufferHdr, 55 OMX_U32 nPortIndex, 56 OMX_PTR pAppPrivate, 57 OMX_U32 nSizeBytes, 58 OMX_U8 *pBuffer); 59 OMX_ERRORTYPE AllocateBuffer(OMX_BUFFERHEADERTYPE **ppBuffer, 60 OMX_U32 nPortIndex, 61 OMX_PTR pAppPrivate, 62 OMX_U32 nSizeBytes); 63 OMX_ERRORTYPE FreeBuffer(OMX_U32 nPortIndex, 64 OMX_BUFFERHEADERTYPE *pBuffer); 65 66 /* 67 * called in ComponentBase::TransStateToLoaded(OMX_StateIdle) or 68 * in ComponentBase::TransStateToIdle(OMX_StateLoaded) 69 * wokeup by Use/Allocate/FreeBuffer 70 */ 71 void WaitPortBufferCompletion(void); 72 73 /* Empty/FillThisBuffer */ 74 OMX_ERRORTYPE PushThisBuffer(OMX_BUFFERHEADERTYPE *pBuffer); 75 /* push buffer at head */ 76 OMX_ERRORTYPE RetainThisBuffer(OMX_BUFFERHEADERTYPE *pBuffer); 77 OMX_BUFFERHEADERTYPE *PopBuffer(void); 78 OMX_U32 BufferQueueLength(void); 79 80 /* Empty/FillBufferDone */ 81 OMX_ERRORTYPE ReturnThisBuffer(OMX_BUFFERHEADERTYPE *pBuffer); 82 83 /* flush all buffers not under processing */ 84 OMX_ERRORTYPE FlushPort(void); 85 86 bool IsEnabled(void); 87 88 OMX_DIRTYPE GetPortDirection(void); 89 90 OMX_ERRORTYPE PushMark(OMX_MARKTYPE *mark); 91 OMX_MARKTYPE *PopMark(void); 92 93 /* SendCommand(OMX_CommandPortDisable/Enable) */ 94 OMX_ERRORTYPE TransState(OMX_U8 state); 95 96 /* end of component methods & helpers */ 97 98 /* TransState, state */ 99 static const OMX_U8 OMX_PortDisabled = 0; 100 static const OMX_U8 OMX_PortEnabled = 1; 101 102private: 103 /* common routines for constructor */ 104 void __PortBase(void); 105 106 /* 107 * component methods & helpers 108 */ 109 OMX_STATETYPE GetOwnerState(void); 110 111 /* end of component methods & helpers */ 112 113 /* buffer headers */ 114 struct list *buffer_hdrs; 115 OMX_U32 nr_buffer_hdrs; 116 bool buffer_hdrs_completion; /* Use/Allocate/FreeBuffer completion flag */ 117 pthread_mutex_t hdrs_lock; 118 pthread_cond_t hdrs_wait; 119 120 struct queue bufferq; 121 pthread_mutex_t bufferq_lock; 122 123 struct queue markq; 124 pthread_mutex_t markq_lock; 125 126 /* state */ 127 OMX_U8 state; 128 pthread_mutex_t state_lock; 129 130 /* parameter */ 131 OMX_PARAM_PORTDEFINITIONTYPE portdefinition; 132 /* room for portdefinition.format.*.cMIMEType */ 133 char definition_format_mimetype[OMX_MAX_STRINGNAME_SIZE]; 134 135 OMX_AUDIO_PARAM_PORTFORMATTYPE audioparam; 136 137 /* owner handle */ 138 OMX_COMPONENTTYPE *owner; 139 140 /* omx standard callbacks */ 141 OMX_PTR appdata; 142 OMX_CALLBACKTYPE *callbacks; 143}; 144 145/* end of PortBase */ 146 147#endif /* __PORTBASE_H */ 148