📄 dvb_pvr.c
字号:
u8 u8FlushCnt = 0;
u32 u32WaitTime = 1;
/*Dynamic StreamRate*/
u32 u32DiffStreamRate = 0;
u32 u32DeviceRecBufferRatio = 0;
u32 u32DeviceTempTick = 0;
while(1)
{
/* wait message to switch task status */
if ( PVR_Record_GetStatus()!= EN_PVR_RECORD_FILE
&& !( PVR_Play_GetStatus()== EN_PVR_TIME_SHIFT || PVR_Play_GetStatus() == EN_PVR_PLAY_FILE)
)
{
CT_OS_MS_Delay(100);
}
// Device Speed Checking
// Time Shift
#if 0
if(PVR_Play_GetStatus()== EN_PVR_TIME_SHIFT)
{
if(_b8DeviceTimeShiftCheck == FALSE)
{
CT_OS_MS_GetClock(&_u32DeviceTimeShiftLastTick);
_b8DeviceTimeShiftCheck = TRUE;
}
if(_b8DeviceTimeShiftCheck == TRUE)
{
CT_OS_MS_GetClock(&u32DeviceTempTick);
if(CT_OS_TimerMinus(u32DeviceTempTick, _u32DeviceTimeShiftLastTick) > DVB_PVR_DEVICE_TIME_SHIFT_CHECK_TICK)
{
u32DeviceRecBufferRatio = PVR_GetRecBufferFullnessRatio();
// DVBPVR_MSG((">> Record Buffer Ratio=%ld\n", u32DeviceRecBufferRatio));
//DVBPVR_MSG((">> MCU_VIDEO_BS_BUF_REMAINDER=%lu\n", ((*(volatile unsigned int*)(0x80000F30)) & 0x00FFFFFF) << 2);//MCU_VIDEO_BS_BUF_REMAINDER));
if(u32DeviceRecBufferRatio > DVB_PVR_DEVICE_TIME_SHIFT_REC_BUF_RATIO_THRESHOLD)
{
if(_u32DeviceEventLastTick == 0)
{
_dvb_pvr_send_cb_event(EN_PVR_EVENT_DEVICE_READ_WRITE_TOO_SLOW);
CT_OS_MS_GetClock(&_u32DeviceEventLastTick);
}
else
{
CT_OS_MS_GetClock(&u32DeviceTempTick);
if(CT_OS_TimerMinus(u32DeviceTempTick, _u32DeviceEventLastTick) > DVB_PVR_DEVICE_EVENT_CHECK_TICK)
{
_dvb_pvr_send_cb_event(EN_PVR_EVENT_DEVICE_READ_WRITE_TOO_SLOW);
CT_OS_MS_GetClock(&_u32DeviceEventLastTick);
}
}
}
CT_OS_MS_GetClock(&_u32DeviceTimeShiftLastTick);
}
}
}
#endif
// Record
/*else*/ if(PVR_Record_GetStatus() == EN_PVR_RECORD_FILE)
{
if(_b8DeviceRecordCheck == FALSE)
{
_u32DeviceRecordFilterLastCount = PVR_GetFilterCallbackCount();
PVR_ResetWriteCount();
CT_OS_MS_GetClock(&_u32DeviceRecordWriteLastTick);
_b8DeviceRecordCheck = TRUE;
}
if(_b8DeviceRecordCheck == TRUE)
{
CT_OS_MS_GetClock(&u32DeviceTempTick);
if(CT_OS_TimerMinus(u32DeviceTempTick, _u32DeviceRecordWriteLastTick) > DVB_PVR_DEVICE_RECORD_CHECK_TICK)
{
u32 u32FilterSize = 0;
u32 u23FileSize = 0;
s32 s32Temp = 0;
u32DeviceRecBufferRatio = PVR_GetRecBufferFullnessRatio();
// DVBPVR_MSG((">> Record Buffer Ratio=%ld\n", u32DeviceRecBufferRatio));
if(u32DeviceRecBufferRatio > DVB_PVR_DEVICE_RECORD_REC_BUF_RATIO_THRESHOLD)
{
if(_u32DeviceEventLastTick == 0)
{
#if 0
_dvb_pvr_send_cb_event(EN_PVR_EVENT_DEVICE_WRITE_TOO_SLOW);
#else
DVBPVR_DBG(("#$"));
#endif
}
else
{
CT_OS_MS_GetClock(&u32DeviceTempTick);
if(CT_OS_TimerMinus(u32DeviceTempTick, _u32DeviceEventLastTick) > DVB_PVR_DEVICE_EVENT_CHECK_TICK)
{
#if 0
_dvb_pvr_send_cb_event(EN_PVR_EVENT_DEVICE_WRITE_TOO_SLOW);
#else
DVBPVR_DBG(("#$"));
#endif
}
}
}
_u32DeviceRecordFilterCurCount = PVR_GetFilterCallbackCount();
u32FilterSize = (_u32DeviceRecordFilterCurCount - _u32DeviceRecordFilterLastCount) * TS_INPUT_SIZE;
u23FileSize = PVR_GetWriteCount() * PVR_RECORD_UNIT_SIZE;
s32Temp = u32FilterSize - u23FileSize;
// DVBPVR_MSG((">> Filter Size = %ld, Write Size=%ld, s32Temp=%ld\n", u32FilterSize, u23FileSize, s32Temp));
// data is too large
if((s32Temp / PVR_RECORD_UNIT_SIZE) >= DVB_PVR_DEVICE_RECORD_THRESHOLD)
{
// DVBPVR_MSG((">> Filter Size = %ld, Write Size=%ld, s32Temp=%ld, (s32Temp / PVR_RECORD_UNIT_SIZE)=%ld\n", u32FilterSize, u23FileSize, s32Temp, (s32Temp / PVR_RECORD_UNIT_SIZE)));
_u32DeviceRecordWriteErrorCount++;
if(_u32DeviceRecordWriteErrorCount > 1)
{
if(_u32DeviceEventLastTick == 0)
{
#if 0
_dvb_pvr_send_cb_event(EN_PVR_EVENT_DEVICE_WRITE_TOO_SLOW);
#else
DVBPVR_DBG(("#$"));
#endif
}
else
{
CT_OS_MS_GetClock(&u32DeviceTempTick);
if(CT_OS_TimerMinus(u32DeviceTempTick, _u32DeviceEventLastTick) > DVB_PVR_DEVICE_EVENT_CHECK_TICK)
{
#if 0
_dvb_pvr_send_cb_event(EN_PVR_EVENT_DEVICE_WRITE_TOO_SLOW);
#else
DVBPVR_DBG(("#$"));
#endif
}
}
}
}
else
{
_u32DeviceRecordWriteErrorCount = 0;
}
// Reset
_u32DeviceRecordFilterLastCount = _u32DeviceRecordFilterCurCount;
PVR_ResetWriteCount();
CT_OS_MS_GetClock(&_u32DeviceRecordWriteLastTick);
}
}
}
// Playback
#if 0
else if(PVR_Play_GetStatus()== EN_PVR_PLAY_FILE)
{
}
#endif
if( PVR_Record_GetStatus() == EN_PVR_RECORD_FILE )
{
if(u32WaitTime == 1 )
{
if( PVR_GetRecBufferFullnessRatio() > DVB_PVR_RECODR_BUFFER_RATION_UPPER )
{
DVBPVR_DBG(("#!"));
u32WaitTime = 0;
}
}
else
{
if ( PVR_GetRecBufferFullnessRatio() < DVB_PVR_RECODR_BUFFER_RATION_LOWER )
{
DVBPVR_DBG(("#*"));
u32WaitTime = 1;
}
}
}
//Wilson: need more fine tune
if( PVR_Play_GetStatus() == EN_PVR_PLAY_FILE && PVR_GetPreviewStauts() == FALSE )
{
if(PVR_Play_GetSpeed() == EN_PVR_SPEED_NORMAL)
{
if(u32WaitTime == 1 )
{
if( PVR_GetPlayBufferFullnessRatio() < DVB_PVR_PLAY_BUFFER_RATION_LOWER )
{
DVBPVR_DBG(("#!!"));
u32WaitTime = 0;
}
}
else
{
if( PVR_GetPlayBufferFullnessRatio() >= DVB_PVR_PLAY_BUFFER_RATION_LOWER )
{
DVBPVR_DBG(("#**"));
u32WaitTime = 1;
}
}
}
else
{
u32WaitTime = 1;
}
}
enOsStatus = CT_OS_GetMsg(&stPvrQueue, &stPvrRecvMsg, &u32PvrRecvMsgLen,u32WaitTime/*CTOS_WAIT*/);
// pvr_play_proc();
// pvr_record_hdd_write_proc();
if (enOsStatus == EN_CTOS_SUCCESS)
{
enPvrTaskState = stPvrRecvMsg.u8Cmd;
// printf("\n\r CMD %d",enPvrTaskState);
}
else
{
enPvrTaskState = EN_PVR_TASK_IDLE;
}
switch(enPvrTaskState)
{
case EN_PVR_TASK_IDLE:
u8Count ++;
PVR_RECORD_BUFFER_PROC();
/*
if(DVB_DetectKey() == TRUE)
*/
if( _pstFnExternDvb->pfnDvbDetectKey()==TRUE )
{
CT_OS_MS_Delay(10);
}
PVR_PLAY_BUFFER_PROC();
/*
if(DVB_DetectKey() == TRUE)
*/
if( _pstFnExternDvb->pfnDvbDetectKey()==TRUE )
{
CT_OS_MS_Delay(10);
}
if(u8Count == 25)
{
#if 0 //For test av buffer overflow issue
static u32 u32MaxSize = 0;
u32 u32TSFullness,u32VideoRemainder,u32AudioRemainder;
u32TSFullness = PVR_AV_Get_TSBufferFullness();
if(u32TSFullness > u32MaxSize)
{
u32MaxSize = u32TSFullness;
}
CT_MPG_GetVideoBufferRemainder(&u32VideoRemainder);
CT_MPG_GetAudioBufferRemainder(&u32AudioRemainder);
DVBPVR_MSG(("\n\r u32TSFullness %ld Max %ld V %ld A %ld R %ld S %ld ",u32TSFullness,u32MaxSize,u32VideoRemainder,u32AudioRemainder,DISP_GetRepeatCnt(), DISP_GetSkipCnt()));
#endif
enRecStatus = PVR_Record_GetStatus();
u8Count = 0;
if(enRecStatus == EN_PVR_RECORD_FILE)
{
PVR_Update_RecTime();
if(u8FlushCnt == 5*4)
{
PVR_SetFlushEnabled(TRUE);
u8FlushCnt = 0;
}
u8FlushCnt++;
DVB_PVR_CalcRecordingTicks();
/*Calc stream rate*/
_u32CurrentRecordingTicks = DVB_PVR_GetCurrentRecordingDuration();
if(_u32CurrentRecordingTicks < _u32LastRecordingTicks)
{
_u32LastRecordingTicks = _u32CurrentRecordingTicks;
}
if((_u32CurrentRecordingTicks - _u32LastRecordingTicks) >= (2*1000) )
{
//_u32CurrentStreamRate = PVR_GetRecBufferInputSize()/(_u32CurrentRecordingTicks/1000);
_u32CurrentStreamRate = PVR_GetStreamRateOfByte();
if(_u32LastStreamRate > _u32CurrentStreamRate)
{
u32DiffStreamRate = _u32LastStreamRate - _u32CurrentStreamRate;
}
else
{
u32DiffStreamRate = _u32CurrentStreamRate - _u32LastStreamRate;
}
if( u32DiffStreamRate > (_u32LastStreamRate/10) )
{
PVR_SetCurStreamRate(_u32CurrentStreamRate/DVB_PVR_GetSectorSize());
_dvb_pvr_send_cb_event(EN_PVR_EVENT_GET_BITRATE);
DVBPVR_MSG((">>>New StreamRate = [%ld]\n", _u32CurrentStreamRate));
if( _u32FilterCallbackInitSpeed == 0 && _u32FilterCallbackInitSpeedTemp !=0
&& _b8GotFirstFilterCallbackSpeed == FALSE )
{
_u32FilterCallbackInitSpeed = _u32FilterCallbackInitSpeedTemp;
_b8GotFirstFilterCallbackSpeed = TRUE;
DVBPVR_MSG((">>>First Filter Callback Init Speed = [%ld]\n", _u32FilterCallbackInitSpeed));
}
else
{
DVB_PVR_ResetFilterCallbackSpeedCalc(TRUE);
}
}
if( _u32FilterCallbackInitSpeed == 0 && _u32FilterCallbackInitSpeedTemp !=0
&& _b8GotFirstFilterCallbackSpeed == TRUE )
{
_u32FilterCallbackInitSpeed = _u32FilterCallbackInitSpeedTemp;
DVBPVR_MSG((">>>New Filter Callback Init Speed = [%ld]\n", _u32FilterCallbackInitSpeed));
}
_u32LastStreamRate = _u32CurrentStreamRate;
_u32LastRecordingTicks = _u32CurrentRecordingTicks;
}
}
}
break;
case EN_PVR_TASK_PLAY_SKIP:
PVR_PlaybackSkip(stPvrRecvMsg.unData.u32MsgData);
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_PLAY_PAUSE:
PVR_PlaybackPause();
DVBPVR_MSG(("\n\r TASK EN_PVR_TASK_PLAY_PAUSE"));
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_PLAY_UNPAUSE:
PVR_PlaybackUnPause();
DVBPVR_MSG(("\n\r TASK EN_PVR_TASK_PLAY_UNPAUSE"));
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_PLAY_NORMAL:
PVR_PlaybackNormal();
DVBPVR_MSG(("\n\r TASK EN_PVR_TASK_PLAY_NORMAL"));
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_FAST_FORWARD:
PVR_PlaybackFastForward(stPvrRecvMsg.u8Reserve);
// It should finish before free semaphore in PVR Task
CT_MPG_ParserSetAudioPID(0);
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_FAST_BACKWARD:
PVR_PlaybackFastBackward(stPvrRecvMsg.u8Reserve);
// It should finish before free semaphore in PVR Task
CT_MPG_ParserSetAudioPID(0);
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_SLOW_FORWARD:
PVR_PlaybackSlowForward(stPvrRecvMsg.u8Reserve);
DVBPVR_MSG(("\n\r TASK EN_PVR_TASK_SLOW_FORWWARD"));
// It should finish before free semaphore in PVR Task
CT_MPG_ParserSetAudioPID(0);
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_FILE_PLAY_START: //File Play : File Start Play
PVR_PlaybackStart(stPvrRecvMsg.unData.pMsgData);
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_FILE_PLAY_STOP: //File Play : Stop File replay mode
PVR_PlaybackStop();
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_FILE_DELETE: //Delete File Command
break;
case EN_PVR_TASK_FILE_RECORD_START: //File Record : File record start
PVR_RecordStart(stPvrRecvMsg.unData.pMsgData);
DVB_PVR_ResetRecordingTime();
DVB_PVR_ResetFilterCallbackSpeedCalc(FALSE);
DVB_PVR_ResetStreamRateCalc();
PVR_CleanRecBufferInputSize();
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_FILE_RECORD_STOP: //File Record : File record stop
if(PVR_RecordStop() != TRUE)
{
DVBPVR_MSG(("\n\r EN_PVR_TASK_FILE_RECORD_STOP Fail"));
}
else
{
//u8DetectCnt = 0;
DVBPVR_MSG(("\n\r TASK EN_PVR_TASK_FILE_RECORD_STOP"));
}
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_FILE_RECORD_STOP_ALL: //File Record : File record stop
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_FILE_CHECK: //File Record : File record stop
break;
/*
case EN_PVR_TASK_CALLBACK:
DVBPVR_MSG(("\n\r Task Callback"));
if(_fpNotify != NULL)
{
_fpNotify(stPvrRecvMsg.u8Reserve);
}
// CT_OS_FreeSemaphore(&PVR_API_Semaphore);
//To do, Call the register callback
break;
*/
case EN_PVR_TASK_PLAY_RECORDING_START: //File Record : File record start
DVBPVR_MSG(("\n\r ==========EN_PVR_TASK_PLAY_RECORDING_START============"));
PVR_PlaybackRecording();
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_PLAY_RECORDING_STOP: //File Record : File record stop
DVBPVR_MSG(("\n\r ==========EN_PVR_TASK_PLAY_RECORDING_STOP============"));
#if 0
_b8DeviceTimeShiftCheck = FALSE;
_u32DeviceEventLastTick = 0;
#endif
PVR_TimeShiftStop();
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_PLAY_LIVEBACK:
DVBPVR_MSG(("\n\r ==========EN_PVR_TASK_PLAY_LIVEBACK============"));
PVR_TimeShiftLiveFastBackward(stPvrRecvMsg.u8Reserve);
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_TIME_SHIFT_READ_TO_WRITE:
DVBPVR_MSG(("\n\r ==========EN_PVR_TASK_TIME_SHIFT_READ_TO_WRITE============"));
PVR_SetTimeShiftReadToWrite();
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_SCAN_PREVIEW:
DVBPVR_MSG(("\n\r==========EN_PVR_TASK_SCAN_PREVIEW==========="));
PVR_ScanPreview((ST_PVR_PLAY_PARAMETER *)stPvrRecvMsg.unData.u32MsgData);
// It should finish before free semaphore in PVR Task
CT_MPG_ParserSetAudioPID(0);
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_SCAN_PREVIEW_STOP:
DVBPVR_MSG(("\n\r==========EN_PVR_TASK_SCAN_PREVIEW_STOP======="));
PVR_ScanPreviewStop();
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
case EN_PVR_TASK_PLAYBACK_JUMP:
PVR_PlaybackJump(stPvrRecvMsg.unData.pMsgData);
CT_OS_FreeSemaphore(&PVR_API_Semaphore);
break;
default:
break;
}
}
}
/***********************************************************************/
EN_PVR_STATUS DVB_PVR_CallBack_Initial(void)
{
EN_CTOS_STATUS enOsStatusCB;
static bool8 b8CBInitFlag = FALSE;
_enCBStatus = EN_PVR_STATUS_SUCCESS;
if (TRUE == b8CBInitFlag)
{
return _enCBStatus;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -