portbase.h revision b2b1b8e0c1425cde2025791cfb74d9053170845c
1/* 2 * Copyright (C) 2009 Wind River Systems. 3 */ 4 5#ifndef __PORTBASE_H 6#define __PORTBASE_H 7 8#include <pthread.h> 9 10#include <OMX_Core.h> 11#include <OMX_Component.h> 12 13#include <list.h> 14#include <queue.h> 15 16class PortBase 17{ 18public: 19 /* 20 * constructor & destructor 21 */ 22 PortBase(); 23 PortBase(const OMX_PARAM_PORTDEFINITIONTYPE *param); 24 virtual ~PortBase(); 25 26 /* end of constructor & destructor */ 27 28 /* 29 * accessor 30 */ 31 /* owner */ 32 void SetOwner(OMX_COMPONENTTYPE *handle); 33 OMX_COMPONENTTYPE *GetOwner(void); 34 35 /* for ReturnThisBuffer() */ 36 OMX_ERRORTYPE SetCallbacks(OMX_HANDLETYPE hComponent, 37 OMX_CALLBACKTYPE *pCallbacks, 38 OMX_PTR pAppData); 39 /* end of accessor */ 40 41 /* 42 * component methods & helpers 43 */ 44 /* Get/SetParameter */ 45 void SetPortParam( 46 const OMX_PARAM_PORTDEFINITIONTYPE *pComponentParameterStructure); 47 const OMX_PARAM_PORTDEFINITIONTYPE *GetPortParam(void); 48 /* audio parameter */ 49 void SetAudioPortParam( 50 const OMX_AUDIO_PARAM_PORTFORMATTYPE *pComponentParameterStructure); 51 const OMX_AUDIO_PARAM_PORTFORMATTYPE *GetAudioPortParam(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 OMX_BUFFERHEADERTYPE *PopBuffer(void); 76 OMX_U32 BufferQueueLength(void); 77 78 /* Empty/FillBufferDone */ 79 OMX_ERRORTYPE ReturnThisBuffer(OMX_BUFFERHEADERTYPE *pBuffer); 80 81 /* flush all buffers not under processing */ 82 OMX_ERRORTYPE FlushPort(void); 83 84 bool IsEnabled(void); 85 86 /* end of component methods & helpers */ 87 88private: 89 /* common routines for constructor */ 90 void __PortBase(void); 91 92 /* 93 * component methods & helpers 94 */ 95 OMX_STATETYPE GetOwnerState(void); 96 97 /* end of component methods & helpers */ 98 99 /* buffer headers */ 100 struct list *buffer_hdrs; 101 OMX_U32 nr_buffer_hdrs; 102 bool buffer_hdrs_completion; /* Use/Allocate/FreeBuffer completion flag */ 103 pthread_mutex_t hdrs_lock; 104 pthread_cond_t hdrs_wait; 105 106 struct queue bufferq; 107 pthread_mutex_t bufferq_lock; 108 109 /* parameter */ 110 OMX_PARAM_PORTDEFINITIONTYPE portparam; 111 OMX_AUDIO_PARAM_PORTFORMATTYPE audioparam; 112 113 /* owner handle */ 114 OMX_COMPONENTTYPE *owner; 115 116 /* omx standard callbacks */ 117 OMX_PTR appdata; 118 OMX_CALLBACKTYPE *callbacks; 119}; 120 121#endif /* __PORTBASE_H */ 122