st_pti.c
来自「ST5100 driver files for ST chipset」· C语言 代码 · 共 1,961 行 · 第 1/5 页
C
1,961 行
memcpy(&(InitParams.EventHandlerName),
EVT_GET_DEVICENAME(PTI_GET_EVTDEVICEID(DeviceId)),
sizeof(ST_DeviceName_t));
#if defined(TSMERGE_BYPASS)
InitParams.StreamID = STPTI_STREAM_ID_NOTAGS;
InitParams.PacketArrivalTimeSource = STPTI_ARRIVAL_TIME_SOURCE_PTI;
#else
InitParams.StreamID = PTI_GET_STREAMID(DeviceId);
InitParams.PacketArrivalTimeSource = STPTI_ARRIVAL_TIME_SOURCE_TSMERGER;
#endif
ErrCode = SERVICE_PTI_InitParams(SERVICE_Mode, &InitParams, &STPTI_SlotTypes_p);
if (ErrCode != ST_NO_ERROR)
return( ErrCode );
#if 1 // EXT_SHARE
// 48 荤侩 啊瓷..
InitParams.NumberOfSlots = 48;
#else
InitParams.NumberOfSlots = NUM_PTI_SLOTS;
#endif
InitParams.DiscardOnCrcError = FALSE;
InitParams.AlternateOutputLatency = 42;
/* initialises PTI device */
#if defined(TSMERGE_BYPASS)
STTBX_Print(("PTI_Setup(%s, STPTI_STREAM_ID_NOTAGS)\n", PTI_GET_DEVICENAME(DeviceId) ));
#else
STTBX_Print(("PTI_Setup(%s, %s)\n", PTI_GET_DEVICENAME(DeviceId),PTITSmergeInput_ToStr(InitParams.StreamID) ));
#endif
}
/* Call driver */
if (ErrCode == ST_NO_ERROR)
{
ErrCode = STPTI_Init(PTI_GET_DEVICENAME(DeviceId), &InitParams);
}
#if 0 // EXT_SHARE
if (ErrCode == ST_NO_ERROR)
{
STTBX_Report((STTBX_REPORT_LEVEL_INFO, "STPTI_Init(%s, %s)=%s",
PTI_GET_DEVICENAME(DeviceId), PTITSmergeInput_ToStr(InitParams.StreamID), GetErrorText(ErrCode)));
/* Enter Critical section */
PTI_Protect();
/* Set Pti_SlotKeepInfo */
for ( ii = 0 ; ii < PTI_MAXOPEN ; ii++ )
{
for ( jj = 0 ; jj < PTI_SLOT_TYPE_MAXID ; jj++ )
{
ResetSlotParams(DeviceId, ii, jj);
}
} /* for ( ii = 0 ; ii < PTI_MAXOPEN ; ii++ )*/
/* Leave Critical section */
PTI_UnProtect();
/* Clear handles table for current DeviceType */
for ( i = 0 ; i < PTI_MAXOPEN ; i++ )
{
PTI_GET_HANDLE(DeviceId, i) = PTI_HANDLE_NULL;
}
}
else
{
STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "STPTI_Init(%s)=%s",
PTI_GET_DEVICENAME(DeviceId), GetErrorText(ErrCode)));
}
#endif
return (ErrCode);
} /* PTI_Init () */
/* -----------------------------------------------------------------------------
* Name : PTI_Open
* Description : Open a STPTI connection
* Parameters :
* PTI_DeviceId_t DeviceId "Target"
* PTI_HandleId_t HandleId For multi-instance management
* Assumptions :
* Limitations :
* Returns : ErrCode
* ST_ERROR_BAD_PARAMETER Bad param
* ST_ERROR_UNKNOWN_DEVICE PTI Device has not been initialized
* ST_ERROR_NO_MEMORY Unable to allocate memory
* ST_ERROR_FEATURE_NOT_SUPPORTED The device type is not supported
* ST_NO_ERROR Success.
* -------------------------------------------------------------------------- */
ST_ErrorCode_t PTI_Open(PTI_DeviceId_t DeviceId, PTI_HandleId_t HandleId)
{
ST_ErrorCode_t ErrCode;
STPTI_OpenParams_t OpenParams;
STTBX_ReportLevel_t ReportLevel;
ErrCode = ST_NO_ERROR;
ReportLevel = STTBX_REPORT_LEVEL_INFO;
/* Test input parameters */
if ( DeviceId >= PTI_MAXDEVICE || HandleId >= PTI_MAXOPEN )
{
ErrCode = ST_ERROR_BAD_PARAMETER;
}
if ( PTI_GET_HANDLE(DeviceId,HandleId) != PTI_HANDLE_NULL )
{
ErrCode = ST_ERROR_BAD_PARAMETER;
}
if (ErrCode == ST_NO_ERROR)
{
/* Set OpenParams */
memset((void *)&OpenParams, 0, sizeof(STPTI_OpenParams_t));
OpenParams.DriverPartition_p = DriverPartition;
OpenParams.NonCachedPartition_p = NcachePartition;
/* Call driver */
ErrCode = STPTI_Open(PTI_GET_DEVICENAME(DeviceId), &OpenParams,
&(PTI_GET_HANDLE(DeviceId,HandleId)));
if (ErrCode != ST_NO_ERROR)
{
ReportLevel = STTBX_REPORT_LEVEL_ERROR;
}
}
STTBX_Report((ReportLevel, "STPTI_Open(%s,%d)=%s",
PTI_GET_DEVICENAME(DeviceId), HandleId,
GetErrorText(ErrCode) ));
return ( ErrCode );
} /* PTI_Open () */
/* -----------------------------------------------------------------------------
* Name : PTI_Close
* Description : Close a STPTI connection
* Parameters :
* PTI_DeviceId_t DeviceId "Target"
* PTI_HandleId_t HandleId For multi-instance management
* Assumptions :
* Limitations :
* Returns : ErrCode
* ST_ERROR_BAD_PARAMETER Bad param or the specified pti wasn't open
* ST_ERROR_INVALID_HANDLE The specified handle is invalid.
* ST_ERROR_FEATURE_NOT_SUPPORTED The device type is not supported
* ST_NO_ERROR Success.
* -------------------------------------------------------------------------- */
ST_ErrorCode_t PTI_Close ( PTI_DeviceId_t DeviceId, PTI_HandleId_t HandleId)
{
ST_ErrorCode_t ErrCode;
STTBX_ReportLevel_t ReportLevel;
ErrCode = ST_NO_ERROR;
ReportLevel = STTBX_REPORT_LEVEL_INFO;
/* Test input parameters */
if ( DeviceId >= PTI_MAXDEVICE || HandleId >= PTI_MAXOPEN )
{
ErrCode = ST_ERROR_BAD_PARAMETER;
}
if ( PTI_GET_HANDLE(DeviceId,HandleId) == PTI_HANDLE_NULL )
{
ErrCode = ST_ERROR_BAD_PARAMETER;
}
if (ErrCode == ST_NO_ERROR)
{
/* Call driver */
ErrCode = STPTI_Close(PTI_GET_HANDLE(DeviceId,HandleId));
if (ErrCode != ST_NO_ERROR)
{
ReportLevel = STTBX_REPORT_LEVEL_ERROR;
}
else
{
PTI_GET_HANDLE(DeviceId,HandleId) = PTI_HANDLE_NULL;
}
}
STTBX_Report((ReportLevel, "STPTI_Close()=%s",GetErrorText(ErrCode)));
return ( ErrCode );
} /* PTI_Close () */
/* -----------------------------------------------------------------------------
* Name : PTI_Term
* Description : Close a STPTI DeviceId
* Parameters :
* PTI_DeviceId_t DeviceId "Target"
* BOOL ForceTerminate Force terminate
* Assumptions :
* Limitations :
* Returns : ErrCode
* ST_ERROR_UNKNOWN_DEVICE PTI Device has not been initialized
* ST_ERROR_BAD_PARAMETER Term-parameters were invalid
* ST_ERROR_DEVICE_BUSY Unforced termination has been requested and
* connections are still active
* ST_ERROR_FEATURE_NOT_SUPPORTED The device type is not supported
* ST_NO_ERROR Success.
* -------------------------------------------------------------------------- */
ST_ErrorCode_t PTI_Term ( PTI_DeviceId_t DeviceId, BOOL ForceTerminate )
{
ST_ErrorCode_t ErrCode;
STPTI_TermParams_t TermParams;
ErrCode = ST_NO_ERROR;
/* Test input parameters */
if ( DeviceId >= PTI_MAXDEVICE )
{
ErrCode = ST_ERROR_BAD_PARAMETER;
}
if (ErrCode == ST_NO_ERROR)
{
/* Initialize struct TermParams */
memset((void *)&TermParams, 0, sizeof(STPTI_TermParams_t));
TermParams.ForceTermination = ForceTerminate;
/* Call driver */
ErrCode = STPTI_Term(PTI_GET_DEVICENAME(DeviceId), &TermParams );
}
if ( ErrCode != ST_NO_ERROR)
{
STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "STPTI_Term()=%s",
GetErrorText(ErrCode)));
}
else
{
STTBX_Report((STTBX_REPORT_LEVEL_INFO, "STPTI_Term()=%s",
GetErrorText(ErrCode)));
}
return (ErrCode);
} /* PTI_Term () */
/* -----------------------------------------------------------------------------
* Name : PTI_AudioStart
* Description : Start PTI transferring Audio
* Parameters :
* PTI_DeviceId_t DeviceId "Target"
* PTI_HandleId_t HandleId For multi-instance management
* STPTI_Pid_t AudioPid
* Assumptions :
* Limitations :
* Returns :
* ST_NO_ERROR Success.
* -------------------------------------------------------------------------- */
ST_ErrorCode_t PTI_AudioStart( PTI_DeviceId_t DeviceId, PTI_HandleId_t HandleId,
STPTI_Pid_t AudioPid )
{
ST_ErrorCode_t ErrCode, KeepErrCode;
STPTI_SlotData_t SlotData;
STPTI_DMAParams_t DMAParams;
Pti_SlotKeepInfo_t *Pti_SlotKeepInfo_p;
/* Enter Critical section */
PTI_Protect();
Pti_SlotKeepInfo_p = &(Pti_SlotKeepInfo[DeviceId][HandleId][PTI_SLOT_TYPE_AUDIO]);
ErrCode = ST_NO_ERROR;
KeepErrCode = ErrCode;
memset((void*)&DMAParams, 0, sizeof(STPTI_DMAParams_t));
if ( Pti_SlotKeepInfo_p->InUse )
{
STTBX_Report((STTBX_REPORT_LEVEL_ERROR,
"PTI(%s,Id=%d) already in use, stop audiopid before",
PTI_GET_DEVICENAME(DeviceId),HandleId));
ErrCode = KeepErrCode = ST_ERROR_BAD_PARAMETER;
}
/* Get UserBuffer */
if (ErrCode == ST_NO_ERROR)
{
if ( (Pti_SlotKeepInfo_p->UserBuffer_p) == NULL )
{
Pti_SlotKeepInfo_p->UserBufferSize = PTI_AUDIO_BUFFER_SIZE;
Pti_SlotKeepInfo_p->UserBuffer_p = memory_allocate(SystemPartition, PTI_AUDIO_BUFFER_SIZE);
if (Pti_SlotKeepInfo_p->UserBuffer_p == NULL)
{
STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "memory_allocate failure"));
KeepErrCode = ErrCode = ST_ERROR_NO_MEMORY;
}
}
}
if (ErrCode == ST_NO_ERROR)
{
memset((void *)&SlotData, 0, sizeof(STPTI_SlotData_t));
/* Get Slot and set PID */
SlotData.SlotType = STPTI_SLOT_TYPE_PES;
SlotData.SlotFlags.SignalOnEveryTransportPacket = FALSE;
SlotData.SlotFlags.CollectForAlternateOutputOnly = FALSE;
SlotData.SlotFlags.AlternateOutputInjectCarouselPacket = FALSE;
SlotData.SlotFlags.StoreLastTSHeader = FALSE;
SlotData.SlotFlags.InsertSequenceError = FALSE;
SlotData.SlotFlags.OutPesWithoutMetadata = FALSE; /* Only PTI3 archi */
SlotData.SlotFlags.ForcePesLengthToZero = FALSE; /* Only PTI3 archi */
SlotData.SlotFlags.AppendSyncBytePrefixToRawData = FALSE;
SlotData.SlotFlags.SoftwareCDFifo = FALSE;
ErrCode = STPTI_SlotAllocate(PTI_GET_HANDLE(DeviceId, HandleId),
&(Pti_SlotKeepInfo_p->SlotHandle),
&SlotData);
if ( ErrCode != ST_NO_ERROR)
{
STTBX_Report((STTBX_REPORT_LEVEL_ERROR,
"PTI_AudioStart : STPTI_SlotAllocate %s",
GetErrorText(ErrCode)));
KeepErrCode = ErrCode;
}
}
if (ErrCode == ST_NO_ERROR)
{
ErrCode = STPTI_SlotClearPid(Pti_SlotKeepInfo_p->SlotHandle);
if ( ErrCode != ST_NO_ERROR)
{
STTBX_Report((STTBX_REPORT_LEVEL_ERROR,
"PTI_AudioStart : STPTI_SlotClearPid %s", GetErrorText(ErrCode)));
KeepErrCode = ErrCode;
}
}
if ((AudioPid) && (ErrCode == ST_NO_ERROR))
{
ErrCode = STPTI_SlotSetPid(Pti_SlotKeepInfo_p->SlotHandle, AudioPid);
if ( ErrCode != ST_NO_ERROR)
{
STTBX_Report((STTBX_REPORT_LEVEL_ERROR,
"PTI_AudioStart : STPTI_SlotSetPid %s",
GetErrorText(ErrCode)));
KeepErrCode = ErrCode;
}
else
{
STTBX_Print(("PTI_AudioSlotPid=%d\n", AudioPid));
}
}
#if (PTI_IS_IN_BACK_BUFFERED_MODE == FALSE)
if (ErrCode == ST_NO_ERROR)
{
/* Link Slot/Buffer to CD Fifo */
if ( PTI_USE_AUDIO_CDFIFO(DeviceId, HandleId) )
{
U32 DMAUsed;
Pti_SlotKeepInfo_p->BufferSize = 0; /* No buffer used */
Pti_SlotKeepInfo_p->Pid = AudioPid;
/* Link audio slot to the CD-FIFO */
DMAParams.Destination = AUDIO_CD_FIFO;
DMAParams.Holdoff = 31;
DMAParams.WriteLength = 1;
DMAParams.CDReqLine = STPTI_CDREQ_AUDIO;
DMAParams.BurstSize = STPTI_DMA_BURST_MODE_ONE_BYTE;
DMAParams.DMAUsed = &DMAUsed;
ErrCode = STPTI_SlotLinkToCdFifo(Pti_SlotKeepInfo_p->SlotHandle,
&DMAParams);
if ( ErrCode != ST_NO_ERROR)
{
STTBX_Report((STTBX_REPORT_LEVEL_ERROR,
"PTI_AudioStart : STPTI_SlotLinkToCdFifo %s", GetErrorText(ErrCode)));
KeepErrCode = ErrCode;
}
}
else
{
STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "CDFIFO are not enabled"));
ErrCode = ST_ERROR_BAD_PARAMETER;
} /* if ( PTI_USE_AUDIO_CDFIFO(DeviceId, HandleId) ) */
}
#else /* (PTI_IS_IN_BACK_BUFFERED_MODE == FALSE) */
/* Back buffered mode */
if (ErrCode == ST_NO_ERROR)
{
/* Link Slot to Buffer */
if ( PTI_GET_AUDIO_BUFFERSIZE(DeviceId, HandleId) != 0 )
{
Pti_SlotKeepInfo_p->BufferSize = PTI_GET_AUDIO_BUFFERSIZE(DeviceId,
HandleId)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?