omx_base_clock_port.c

Go to the documentation of this file.
00001 
00029 #include <stdlib.h>
00030 #include <string.h>
00031 #include <unistd.h>
00032 #include <omxcore.h>
00033 #include <OMX_Core.h>
00034 #include <OMX_Component.h>
00035 #include "omx_base_component.h"
00036 #include "omx_base_clock_port.h"
00037 
00054 OMX_ERRORTYPE base_clock_port_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,omx_base_PortType **openmaxStandPort,OMX_U32 nPortIndex, OMX_BOOL isInput) {
00055   
00056   omx_base_clock_PortType *omx_base_clock_Port;
00057 
00058   if (!(*openmaxStandPort)) {
00059     *openmaxStandPort = calloc(1,sizeof (omx_base_clock_PortType));
00060   }
00061 
00062   if (!(*openmaxStandPort)) {
00063     return OMX_ErrorInsufficientResources;
00064   }
00065 
00066   base_port_Constructor(openmaxStandComp,openmaxStandPort,nPortIndex, isInput);
00067 
00068   omx_base_clock_Port = (omx_base_clock_PortType *)*openmaxStandPort;
00069 
00070   setHeader(&omx_base_clock_Port->sOtherParam, sizeof(OMX_OTHER_PARAM_PORTFORMATTYPE));
00071   omx_base_clock_Port->sOtherParam.nPortIndex = nPortIndex;
00072   omx_base_clock_Port->sOtherParam.nIndex = 0;
00073   omx_base_clock_Port->sOtherParam.eFormat = OMX_OTHER_FormatTime;
00074   
00075   omx_base_clock_Port->sPortParam.eDomain              = OMX_PortDomainOther;
00076   omx_base_clock_Port->sPortParam.format.other.eFormat = OMX_OTHER_FormatTime;
00077   omx_base_clock_Port->sPortParam.nBufferSize          = sizeof(OMX_TIME_MEDIATIMETYPE) ;
00078   omx_base_clock_Port->sPortParam.nBufferCountActual   = 1;
00079   omx_base_clock_Port->sPortParam.nBufferCountMin      = 1;
00080   omx_base_clock_Port->sPortParam.format.other.eFormat = OMX_OTHER_FormatTime;
00081 
00082   setHeader(&omx_base_clock_Port->sTimeStamp, sizeof(OMX_TIME_CONFIG_TIMESTAMPTYPE));
00083   omx_base_clock_Port->sTimeStamp.nPortIndex = nPortIndex;
00084   omx_base_clock_Port->sTimeStamp.nTimestamp = 0x00;
00085   
00086 
00087   setHeader(&omx_base_clock_Port->sMediaTime, sizeof(OMX_TIME_MEDIATIMETYPE));
00088   omx_base_clock_Port->sMediaTime.nClientPrivate = 0;
00089   omx_base_clock_Port->sMediaTime.nOffset = 0x0; 
00090   omx_base_clock_Port->sMediaTime.xScale = 1; 
00091 
00092   setHeader(&omx_base_clock_Port->sMediaTimeRequest, sizeof(OMX_TIME_MEDIATIMETYPE));
00093   omx_base_clock_Port->sMediaTimeRequest.nPortIndex = nPortIndex;
00094   omx_base_clock_Port->sMediaTimeRequest.pClientPrivate = NULL; 
00095   omx_base_clock_Port->sMediaTimeRequest.nOffset = 0x0; 
00096 
00097   omx_base_clock_Port->Port_SendBufferFunction = &base_clock_port_SendBufferFunction;
00098   omx_base_clock_Port->PortDestructor = &base_clock_port_Destructor;
00099 
00100   return OMX_ErrorNone;
00101 }
00102 
00115 OMX_ERRORTYPE base_clock_port_Destructor(omx_base_PortType *openmaxStandPort){
00116 
00117   base_port_Destructor(openmaxStandPort);
00118 
00119   return OMX_ErrorNone;
00120 }
00121 
00127 OMX_ERRORTYPE base_clock_port_SendBufferFunction(
00128   omx_base_PortType *openmaxStandPort,
00129   OMX_BUFFERHEADERTYPE* pBuffer) {
00130 
00131   OMX_ERRORTYPE err;
00132   OMX_U32 portIndex;
00133   OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
00134   omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
00135 #if NO_GST_OMX_PATCH
00136   unsigned int i;
00137 #endif
00138   portIndex = (openmaxStandPort->sPortParam.eDir == OMX_DirInput)?pBuffer->nInputPortIndex:pBuffer->nOutputPortIndex;
00139   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s portIndex %lu\n", __func__, portIndex);
00140 
00141   if (portIndex != openmaxStandPort->sPortParam.nPortIndex) {
00142     DEBUG(DEB_LEV_ERR, "In %s: wrong port for this operation portIndex=%d port->portIndex=%d\n", __func__, (int)portIndex, (int)openmaxStandPort->sPortParam.nPortIndex);
00143     return OMX_ErrorBadPortIndex;
00144   }
00145 
00146   if(omx_base_component_Private->state == OMX_StateInvalid) {
00147     DEBUG(DEB_LEV_ERR, "In %s: we are in OMX_StateInvalid\n", __func__);
00148     return OMX_ErrorInvalidState;
00149   }
00150 
00151   if(omx_base_component_Private->state != OMX_StateExecuting &&
00152     omx_base_component_Private->state != OMX_StatePause &&
00153     omx_base_component_Private->state != OMX_StateIdle) {
00154     DEBUG(DEB_LEV_ERR, "In %s: we are not in executing/paused/idle state, but in %d\n", __func__, omx_base_component_Private->state);
00155     return OMX_ErrorIncorrectStateOperation;
00156   }
00157   if (!PORT_IS_ENABLED(openmaxStandPort) || (PORT_IS_BEING_DISABLED(openmaxStandPort) && !PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) ||
00158       (omx_base_component_Private->transientState == OMX_TransStateExecutingToIdle && 
00159       (PORT_IS_TUNNELED(openmaxStandPort) && !PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)))) {
00160     DEBUG(DEB_LEV_ERR, "In %s: Port %d is disabled comp = %s \n", __func__, (int)portIndex,omx_base_component_Private->name);
00161     return OMX_ErrorIncorrectStateOperation;
00162   }
00163 
00164   /* Temporarily disable this check for gst-openmax */
00165 #if NO_GST_OMX_PATCH
00166   {
00167   OMX_BOOL foundBuffer = OMX_FALSE;
00168   if(pBuffer!=NULL && pBuffer->pBuffer!=NULL) {
00169     for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
00170     if (pBuffer->pBuffer == openmaxStandPort->pInternalBufferStorage[i]->pBuffer) {
00171       foundBuffer = OMX_TRUE;
00172       break;
00173     }
00174     }
00175   }
00176   if (!foundBuffer) {
00177     return OMX_ErrorBadParameter;
00178   }
00179   }
00180 #endif
00181 
00182   if ((err = checkHeader(pBuffer, sizeof(OMX_BUFFERHEADERTYPE))) != OMX_ErrorNone) {
00183     DEBUG(DEB_LEV_ERR, "In %s: received wrong buffer header on input port\n", __func__);
00184     return err;
00185   }
00186   /*If port is not tunneled then simply return the buffer except paused state*/
00187   if (!PORT_IS_TUNNELED(openmaxStandPort) && (omx_base_component_Private->state != OMX_StatePause)) {
00188     openmaxStandPort->ReturnBufferFunction(openmaxStandPort,pBuffer);
00189     return OMX_ErrorNone;
00190   }
00191   
00192   /* And notify the buffer management thread we have a fresh new buffer to manage */
00193   if(!PORT_IS_BEING_FLUSHED(openmaxStandPort) && !(PORT_IS_BEING_DISABLED(openmaxStandPort) && PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort))){
00194     queue(openmaxStandPort->pBufferQueue, pBuffer);
00195     tsem_up(openmaxStandPort->pBufferSem);
00196     DEBUG(DEB_LEV_PARAMS, "In %s Signalling bMgmtSem Port Index=%d\n",__func__, (int)portIndex);
00197     tsem_up(omx_base_component_Private->bMgmtSem);
00198   }else if(PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)){
00199     DEBUG(DEB_LEV_FULL_SEQ, "In %s: Comp %s received io:%d buffer\n", 
00200         __func__,omx_base_component_Private->name,(int)openmaxStandPort->sPortParam.nPortIndex);
00201     queue(openmaxStandPort->pBufferQueue, pBuffer);
00202     tsem_up(openmaxStandPort->pBufferSem);
00203   }
00204   else { // If port being flushed and not tunneled then return error
00205     DEBUG(DEB_LEV_FULL_SEQ, "In %s \n", __func__);
00206     return OMX_ErrorIncorrectStateOperation;
00207   }
00208   return OMX_ErrorNone;
00209 }

Generated for OpenMAX Bellagio rel. 0.9.0 by  doxygen 1.5.1
SourceForge.net Logo