nvod.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:66k
- #include <string.h>
- #include "nvod.h"
- #include "appltype.h"
- #include "epg.h"
- #include "sipsi.h"
- #include "db.h"
- #include "avplay.h"
- #include "av.h"
- #include "Search.h"
- #include "kb_machblue_client_task.h"
- #include "Timer.h"
- #include "Timeclk.h"
- typedef enum
- {
- NVOD_Connect,
- NVOD_Play,
- NVOD_Stop
- }NVOD_Mode;
- KB_SINitStruct g_novdNit;
- static KB_SIRefSvcCell gNvodSvcInfo[KB_NVOD_MAX_REF];
- static UINT8 gNvodRefSvcNum;
- static INT32 gSvcNum;
- static int gArriveNum;
- static int gTimeOutNum;
- //目前仅支持EIT时间表0x50、0x51
- static UINT8 gNvodEitSchTableSwitchFlag = KB_EIT_SCHEDULE_CURRENT_TS_TABLE_DEFAULT;
- //当前正在执行搜索任务的gatNvod数组索引号
- static UINT32 CurrentSearchTsNum = KB_NVOD_MAX_TS_NUM;
- //用来标识搜索当前Ts中的参考事件是否已经完成
- static UINT32 CurrentPFCompleteFlag = 0;
- static KB_NVOD_Info gatNvod[KB_NVOD_MAX_TS_NUM];
- //static KB_DMDTunerParameters NvodCurrentTs;
- static KB_DMDTunerParameters gNvodRefFre[KB_NVOD_MAX_REF];
- static KB_NVODReceive gRecieveState[KB_NVOD_MAX_REF];
- static UINT8 gNvodRefSvcEachFre[KB_NVOD_MAX_REF];
- static UINT8 gFreqInd = 0;
- static UINT8 gFreqNum =0 ;
- static time_t gNvodTime;
- //static struct tm gNvodtmTime;
- //static time_t gSchTime;
- static time_t gPrgEndTime;
- static BOOL gNewFlag = FALSE;
- static INT32 gCurTsID;
- static INT32 gCurSvcID;
- static NVOD_Mode gPrgPlayStatus;
- static KB_NVODPfInfo gNvodPFInfo[KB_SI_MAX_REF_SVC_NUMS];
- static KB_SIEitPF *gNvodPF;
- static KB_SINVODEitPF *gNvodPFEvent;
-
- static KB_NVODSch gNvodSch[KB_NVOD_MAX_ShiftSrv_One_Ts];
- static KB_SIEitSchTimeShiftNode *gNvodSchEvent;
- static UINT32 EitSrhTimer;
- //static void KD_NVODHandleMsg3(KB_OSPMsgNode *pInMsg);
- static BOOL KD_NVODRefSvcReceiveStatus(UINT16 refScvId, BOOL bTimeout);
- static void KD_NVODHandleEitSch(KB_OSPMsgNode *pInMsg);
- static INT32 KD_NVODGetFreePF(void);
- static INT32 KD_NVODGetFreeSch(void);
- static INT32 KD_NVODResetPF(INT32 nNumber);
- static INT32 KD_ResetSCH(INT32 nNumber);
- static void quicksortEit(KB_NVODTime *pbuf,int low,int high);
- static int quickpartEit(KB_NVODTime *pbuf,int i,int j);
- static INT32 KD_NVODHandlePFOver(KB_OSPMsgNode *pInMsg);
- static INT32 KD_NVODHandleSCHOver(KB_OSPMsgNode *pInMsg);
- static void KD_NVODHandleTuner(KB_OSPMsgNode *pInMsg);
- static INT32 KB_NVODGetEitPF(UINT32 TsSequence);
- static void KB_NvodHandleEitSrhTimeOut(void);
- static INT32 KD_NVODInitTask(void);
- static INT32 KD_NVODPlayInit(void);
- static UINT8 KB_NVOD_AllocategatNvodInfo(UINT32 frequency);
- static void KB_NVOD_ResetTsData(UINT32 TsSequence);
- static INT32 KB_NVOD_SetCurrentTsPara(KB_DMDTunerParameters TsPara);
- static INT32 KD_NVODGetPF(INT32 nTsId, INT32 nSvcID, KB_SIEitTs eTs);
- static UINT32 KB_NVOD_GetNullPFTsNum(void);
- static INT32 KB_NVODGetEitSch(UINT32 TsSequence);
- static INT32 KD_NVODGetSchTimeShift(INT32 nTsId, INT32 nSvcID, KB_SIEitTs eTs);
- static void KB_NVOD_DirectInsertSort(KB_NVODTime TimeNode[], UINT16 TimeNum);
- static UINT32 KB_NVOD_GetNullSchTsNum(void);
- extern void KB_MENUTranslateMsg(KB_OSPMsgNode* pInMsg);
- INT32 KB_NVODInit(void)
- {
- KD_NVODInitTask();
- KD_NVODPlayInit();
-
-
- return RETOK;
- }
- INT32 KB_NVODCreate(void)
- {
- KB_SIGetTime(&gNvodTime);
- KB_EPGToNvod(TRUE);
- if (KB_DB_DTV_SUCCESS != KB_NVODInit2())
- {
- printf("nKB_NVODCreate::KB_NVODInit2 failed!n");
- }
-
- if(gNewFlag)
- {
- KB_EPGStopAllSCH();
- KD_NVODStopAllPF();
- KD_NVODStopAllSch();
- KB_TimerDisable(EitSrhTimer);
- printf("nKB_NVODCreate::关闭定时期 EitSrhTimer");
- memset(gNvodSvcInfo, 0, sizeof(gNvodSvcInfo));
- memset(gatNvod, 0, sizeof(gatNvod));
- gNvodRefSvcNum = 0;
- gArriveNum = 0;
- gTimeOutNum = 0;
- gNvodEitSchTableSwitchFlag = KB_EIT_SCHEDULE_CURRENT_TS_TABLE_DEFAULT;
- memset(gNvodRefFre,0,sizeof(gNvodRefFre));
- memset(gNvodRefSvcEachFre,0,sizeof(gNvodRefSvcEachFre));
- gFreqInd = 0;
- gFreqNum = 0;
- //memset(&NvodCurrentTs,0,sizeof(KB_DMDTunerParameters));
- KB_NVODInit();
- }
-
- return RETOK;
- }
- static void KD_NVODHandleTuner(KB_OSPMsgNode *pInMsg)
- {
- switch (pInMsg->Word2)
- {
- case DMD_CALLBACK_SIGNAL_CONNECTED:
- if (gPrgPlayStatus == NVOD_Connect)
- {
- gPrgPlayStatus = NVOD_Play;
- KB_DTVStartCA(gCurTsID, gCurSvcID);
- }
- break;
- case DMD_CALLBACK_SIGNAL_LOST:
- break;
-
- default:
- break;
- }
- }
- void quicksortEit(KB_NVODTime *pbuf,int low,int high)
- {
- int i;
- if(low < high)
- {
- i = quickpartEit(pbuf,low,high);
- quicksortEit(pbuf,low,i-1);
- quicksortEit(pbuf,i + 1,high);
- }
- }
- int quickpartEit(KB_NVODTime *pbuf,int i,int j)
- {
- KB_NVODTime b;
-
- memcpy(&b,&pbuf[i],sizeof(KB_NVODTime));
- while(i<j)
- {
- while(i<j && pbuf[j].startTime >= b.startTime)
- {
- j --;
- }
- if(i< j)
- {
- memcpy(&pbuf[i++],&pbuf[j],sizeof(KB_NVODTime));
- }
- while(i<j && pbuf[i].startTime <= b.startTime)
- {
- i ++;
- }
- if(i<j)
- {
- memcpy(&pbuf[j --],&pbuf[i],sizeof(KB_NVODTime));
- }
- }
-
- memcpy(&pbuf[i],&b,sizeof(KB_NVODTime));
- return i;
- }
- static INT32 KD_NVODPlayInit(void)
- {
- UINT8 i =0;
-
- gCurTsID = 0xFFFFFFFF;
- gCurSvcID = 0xFFFFFFFF;
- gPrgPlayStatus = NVOD_Stop;
-
- memset(gatNvod, 0, sizeof(gatNvod));
- for (i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- gatNvod[i].CurrentTsFlag = FALSE;
- gatNvod[i].SearchStartFlag = FALSE;
- gatNvod[i].SearchCompleteFlag = FALSE;
- }
-
- return RETOK;
- }
- INT32 KD_NVODPlayStop(void)
- {
- gCurTsID = 0xFFFFFFFF;
- gCurSvcID = 0xFFFFFFFF;
- gPrgPlayStatus = NVOD_Stop;
- KB_DTVStop();
- return RETOK;
- }
- INT32 KD_NVODStartPlay(INT32 nTsId, INT32 nSvcID)
- {
- unsigned short pFreq,pSymbl;
- unsigned char qam;
- KB_DMDTunerParameters tReqDmdPara, tCurrDmdPara;
-
- KB_DBGetChnlInfoByTsID((UINT16)nTsId,&pFreq,&pSymbl,&qam);
-
- tReqDmdPara.type = DMD_TYPE_QAM;
- tReqDmdPara.inversion = INVERSION_AUTO;
- tReqDmdPara.frequency = (UINT32)pFreq * 100;
- tReqDmdPara.details.qam.symbolRatekSs = pSymbl;
- tReqDmdPara.details.qam.modulation = qam;
- KB_DMDGetSignalParameters(&tCurrDmdPara);
- //printf("nCur(%d, %d, %d), Play(%d, %d, %d)n",
- // tCurrDmdPara.frequency, tCurrDmdPara.details.qam.symbolRatekSs, tCurrDmdPara.details.qam.modulation,
- // tReqDmdPara.frequency, tReqDmdPara.details.qam.symbolRatekSs, tReqDmdPara.details.qam.modulation);
- //printf("nTsId(%d), nSvcID(%d), gCurSvcID(%d)", nTsId, nSvcID, gCurSvcID);
- if (KB_DMDQuerySignalStatus() == TRUE
- && tCurrDmdPara.frequency == tReqDmdPara.frequency
- && tCurrDmdPara.details.qam.symbolRatekSs == tReqDmdPara.details.qam.symbolRatekSs
- && tCurrDmdPara.details.qam.modulation == tReqDmdPara.details.qam.modulation)
- {
- if (0xFFFFFFFF == gCurSvcID)
- {
- gCurTsID = nTsId;
- gCurSvcID = nSvcID;
- gPrgPlayStatus = NVOD_Play;
- KB_DTVRunForNvod();
- KB_DTVStartCA(nTsId, nSvcID);
- return RETOK;
- }
- else if (gCurSvcID != nSvcID)
- {
- KD_NVODPlayStop();
- gPrgPlayStatus = NVOD_Play;
- KB_DTVRunForNvod();
- KB_DTVStartCA(nTsId, nSvcID);
- }
- }
- else
- {
- KD_NVODPlayStop();
- gPrgPlayStatus = NVOD_Connect;
- KB_DMDConnectSignal(&tReqDmdPara);
- }
- gCurTsID = nTsId;
- gCurSvcID = nSvcID;
-
- return RETOK;
- }
- INT32 KD_NVODSetVolume(INT32 nVolume)
- {
- if (nVolume < 0 || nVolume > KB_AV_MAX_VOLUME)
- {
- return RETFAIL3;
- }
-
- KB_AVSetVolume(nVolume);
- return RETOK;
- }
- INT32 KD_NVODGetVolume(void)
- {
- return KB_AVGetVolume();
- }
- INT32 KD_NVODMute(BOOL nMute)
- {
- INT32 nCurrMute;
-
- if (nMute != TRUE && nMute != FALSE)
- {
- return RETFAIL3;
- }
- nCurrMute = KB_AVGetMuteFlag();
- if (nCurrMute != nMute)
- {
- KB_AVSetMute(nMute);
- }
- return RETOK;
- }
- INT32 KD_NVODDestoryPlay(void)
- {
- gNvodTime = 0;
- gCurTsID = 0xFFFFFFFF;
- gCurSvcID = 0xFFFFFFFF;
- gPrgPlayStatus = NVOD_Stop;
- KD_NVODPlayStop();
-
- return RETOK;
- }
- BOOL KD_NVODGetMute(void)
- {
- return (BOOL)KB_AVGetMuteFlag();
- }
- INT32 KD_NVODSetTrack(KB_DBTRACK nTrackType)
- {
- KB_AVSetPrgTrack(nTrackType);
- return RETOK;
- }
- KB_DBTRACK KD_NVODGetTrack(void)
- {
- return KB_AVGetTrack();
- }
- INT32 KB_NVODDestroy(void)
- {
- KB_EPGToNvod(FALSE);
- KD_NVODStopAllPF();
- KD_NVODStopAllSch();
- KB_TimerDisable(EitSrhTimer);
- printf("nKB_NVODDestroy::关闭定时期 EitSrhTimer");
- KD_NVODDestoryPlay();
-
- return RETOK;
- }
- INT32 NVOD_HandleMsg(KB_OSPMsgNode *pInMsg)
- {
- //UINT32 CurrentTsNum;
- switch (pInMsg->Word1)
- {
- case MOD_SIPSI:
- {
- KB_DTVHandleMsg(pInMsg);
- switch(pInMsg->Word2)
- {
- case KB_SI_MSG_TDT_DONE:
- {
- KB_TimeSetCurTime(*((time_t*)pInMsg->Word3));
- gNvodTime = KB_TimeGetCurGMTTime();
- //KB_TimeGetCurTime(&gNvodTime);
- printf("nNVOD_HandleMsg::get gNvodTime(0x%x) ok",
- gNvodTime);
- }
- break;
- }
- }
- break;
-
- case MOD_TUNER:
- {
- KD_NVODHandleTuner(pInMsg);
- switch (pInMsg->Word2)
- {
- case DMD_CALLBACK_SIGNAL_LOST:
- {
- }
- break;
- case DMD_CALLBACK_SIGNAL_CONNECTED:
- {
- }
- break;
- default:
- break;
- }
- }
- break;
- default:
- break;
- }
- return RETOK;
- }
- int KB_NVODInit2(void)
- {
- UINT8 TsSequence;
- int i,j;
- int rt = KB_DB_DTV_FAILURE;
- //KB_SINitStruct * nit;
- int num;
- int ret;
- UINT16 tsid;
- UINT32 CurrentTsTsSequence;
- unsigned short pFreq,pSymbl;
- unsigned char qam;
- KB_DMDTunerParameters ts;
- #if 1
- //对已初始化过的,不再进行初始化
- CurrentTsTsSequence = KB_NVOD_GetCurrentTsNum();
- if ((UINT32)(-1) != CurrentTsTsSequence
- && gatNvod[CurrentTsTsSequence].TsPara.frequency == CurrentSignal.frequency)
- {
- printf("nKB_NVODInit2::不再重复初始化");
- return KB_DB_DTV_SUCCESS;
- }
- #endif
- memset(gNvodSvcInfo, 0, sizeof(gNvodSvcInfo));
- gNvodRefSvcNum = 0;
- gArriveNum = 0;
- gTimeOutNum = 0;
- gNvodEitSchTableSwitchFlag = KB_EIT_SCHEDULE_CURRENT_TS_TABLE_DEFAULT;
- memset(gRecieveState,0,sizeof(gRecieveState));
- memset(gNvodRefFre,0,sizeof(gNvodRefFre));
- memset(gNvodRefSvcEachFre,0,sizeof(gNvodRefSvcEachFre));
- gFreqInd = 0;
- gFreqNum = 0;
- ret = KB_DBGetNvodInfo(gNvodSvcInfo,&num);
- if(ret != RET_OK)
- {
- gSvcNum = 0;
- return rt;
- }
- gNvodRefSvcNum = num;
- if (0 == gNvodRefSvcNum)
- {
- gSvcNum = 0;
- return KB_DB_DTV_SUCCESS;
- }
- j = 1;
- for(i=1; i<gNvodRefSvcNum; i++)
- {
- if (gNvodSvcInfo[i-1].TsID != gNvodSvcInfo[i].TsID)
- {
- tsid = gNvodSvcInfo[i-1].TsID;
- KB_DBGetChnlInfoByTsID(tsid,&pFreq,&pSymbl,&qam);
-
- ts.type = DMD_TYPE_QAM;
- ts.inversion = INVERSION_AUTO;
- ts.frequency = ((UINT32)pFreq * 100);
- ts.details.qam.symbolRatekSs = pSymbl;
- ts.details.qam.modulation = qam;
- TsSequence = KB_NVOD_AllocategatNvodInfo(ts.frequency);
- if (TsSequence < KB_NVOD_MAX_TS_NUM)
- {
- memcpy(&gatNvod[TsSequence].TsPara, &ts, sizeof(KB_DMDTunerParameters));
- gatNvod[TsSequence].SearchStartFlag = FALSE;
- gatNvod[TsSequence].SearchCompleteFlag = FALSE;
- gatNvod[TsSequence].CurrentTsFlag = FALSE;
- }
- else if (TsSequence == KB_NVOD_ALLOCATE_REPEAT)
- {
- printf("nKB_NVODInit2::KB_NVOD_AllocategatNvodInfo ALLOCATE REPEAT!n");
- }
- else
- {
- printf("nKB_NVODInit2::KB_NVOD_AllocategatNvodInfo error!n");
- return KB_DB_DTV_FAILURE;
- }
-
- gNvodRefFre[gFreqInd] = ts;
- gNvodRefSvcEachFre[gFreqInd] = j;
- gFreqInd++;
- j = 1;
- }
- else
- {
- j++;
- }
- }
- tsid = gNvodSvcInfo[i-1].TsID;
- KB_DBGetChnlInfoByTsID(tsid,&pFreq,&pSymbl,&qam);
-
- ts.type = DMD_TYPE_QAM;
- ts.inversion = INVERSION_AUTO;
- ts.frequency = ((UINT32)pFreq * 100);
- ts.details.qam.symbolRatekSs = pSymbl;
- ts.details.qam.modulation = qam;
- TsSequence = KB_NVOD_AllocategatNvodInfo(ts.frequency);
- if (TsSequence < KB_NVOD_MAX_TS_NUM)
- {
- memcpy(&gatNvod[TsSequence].TsPara, &ts, sizeof(KB_DMDTunerParameters));
- gatNvod[TsSequence].SearchStartFlag = FALSE;
- gatNvod[TsSequence].SearchCompleteFlag = FALSE;
- gatNvod[TsSequence].CurrentTsFlag = FALSE;
- }
- else if (TsSequence == KB_NVOD_ALLOCATE_REPEAT)
- {
- printf("nKB_NVODInit2::KB_NVOD_AllocategatNvodInfo ALLOCATE REPEAT!n");
- }
- else
- {
- printf("nKB_NVODInit2::KB_NVOD_AllocategatNvodInfo error!n");
-
- for (i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- KB_NVOD_ResetTsData(i);
- }
-
- memcpy(&gatNvod[0].TsPara, &ts, sizeof(KB_DMDTunerParameters));
- gatNvod[0].SearchStartFlag = FALSE;
- gatNvod[0].SearchCompleteFlag = FALSE;
- gatNvod[0].CurrentTsFlag = FALSE;
- }
- gNvodRefFre[gFreqInd] = ts;
- gNvodRefSvcEachFre[gFreqInd] = j;
- gFreqInd++;
- gFreqNum = gFreqInd;
- gFreqInd = 0;
- ts = gNvodRefFre[gFreqInd];
- gSvcNum = gNvodRefSvcEachFre[gFreqInd];
- if (0 == CurrentSignal.frequency)
- {
- printf("nKB_NVODInit2::serious error! CurrentSignal is NULL!");
- if (0 != gatNvod[0].TsPara.frequency)
- {
- if (RET_OK != KB_NVOD_SetCurrentTsPara(gatNvod[0].TsPara))
- {
- printf("nKB_NVODInit2::KB_NVOD_SetCurrentTsPara fail!n");
- return KB_DB_DTV_FAILURE;
- }
- KB_DMDDropSignal();
- KB_DMDConnectSignal(&(gatNvod[0].TsPara));
- }
- }
- else
- {
- if (RET_OK != KB_NVOD_SetCurrentTsPara(CurrentSignal))
- {
- printf("nKB_NVODInit2::KB_NVOD_SetCurrentTsPara fail!n");
- return KB_DB_DTV_FAILURE;
- }
- }
-
- //memcpy(&NvodCurrentTs, &ts, sizeof(KB_DMDTunerParameters));
- gArriveNum = 0;
- gTimeOutNum = 0;
- gNvodEitSchTableSwitchFlag = KB_EIT_SCHEDULE_CURRENT_TS_TABLE_DEFAULT;
- gFreqInd++;
- if(ret == RET_OK)
- {
- if(num > KB_SI_MAX_REF_SVC_NUMS)
- {
- num = KB_SI_MAX_REF_SVC_NUMS;
- }
- //先用gRecieveState记录下所有的参考业务ID和它对应的时移业务数
- //以后只需将各参考业务收到的时移业务数(gRecieveState[i].recvSvcNum)清零,
- //并更新该频点中的参考业务数(gSvcNum)即可
- for(i = 0; i < gNvodRefSvcNum; i ++)
- {
- if(gNvodSvcInfo[i].shiftSvcNum > KB_SI_MAX_SHIFT_SVC_NUMS)
- {
- gNvodSvcInfo[i].shiftSvcNum = KB_SI_MAX_SHIFT_SVC_NUMS;
- }
- gRecieveState[i].refScvId = gNvodSvcInfo[i].refScvId;
- gRecieveState[i].shiftSvcNum = gNvodSvcInfo[i].shiftSvcNum;
- gRecieveState[i].recvSvcNum = 0;
- }
- }
-
- return KB_DB_DTV_SUCCESS;
- }
- //NVOD的搜索总入口, 次序所有频点的CurrentTsEitPF-->所有频点的CurrentTsEitSch
- INT32 KB_NVODGetEit(void)
- {
- UINT32 CurrentTsNum;
- INT32 status;
- if (0 ==gNvodRefSvcNum)
- {
- printf("nKB_NVODGetEit::无参考业务!n");
- return RETOK;
- }
-
- CurrentTsNum = KB_NVOD_GetCurrentTsNum();
- if ((UINT32)(-1) == CurrentTsNum)
- {
- printf("nKB_NVODGetEit::serious error! KB_NVOD_GetCurrentTsNum fail!n");
- return RETFIAL1;
- }
-
- printf("nKB_NVODGetEit::启动定时器 EitSrhTimer");
- status = KB_TimerEnable(EitSrhTimer, 90*1000);
- if(status != RETOK)
- {
- printf("nKB_NVODGetEit::EitSrhTimer Enable failed!");
- }
-
- KB_NVODGetEitPF(CurrentTsNum);
- return RET_OK;
- }
- static INT32 KB_NVODGetEitPF(UINT32 TsSequence)
- {
- int i;
- UINT32 NullDataTsNum = (UINT32)(-1);
- UINT32 CurrentTsNum = (UINT32)(-1);
- BOOL StartFlag = FALSE, NeedSrhPFFlag = FALSE;
- KB_SIEitTs eTs;
- KB_OSPMsgNode message;
- KB_DMDTunerParameters *pTsPara = NULL;
- //对搜索过程中,中途被打断的ts流, 先清掉以前的不完整数据
- if (TRUE == gatNvod[TsSequence].SearchStartFlag
- && FALSE ==gatNvod[TsSequence].SearchCompleteFlag)
- {
- KB_NVOD_ResetTsData(TsSequence);
- }
- if (TsSequence == KB_NVOD_GetCurrentTsNum())
- {
- eTs = KB_SI_EIT_CURRENT_TS;
- }
- else
- {
- eTs = KB_SI_EIT_OTHER_TS;
- }
- if (FALSE == gatNvod[TsSequence].SearchStartFlag
- && FALSE == gatNvod[TsSequence].SearchCompleteFlag)
- {
- //该标志的作用是防止本频点无NVOD参考事件, 产生死循环
- NeedSrhPFFlag = TRUE;
- for(i=0; i<gNvodRefSvcNum; i++)
- {
- if (((UINT32)gNvodSvcInfo[i].freq*100) == gatNvod[TsSequence].TsPara.frequency)
- {
- KD_NVODGetPF(gNvodSvcInfo[i].TsID,
- gNvodSvcInfo[i].refScvId,
- eTs);
- ++gatNvod[TsSequence].RefSrvNum; //通常1个RefSrv只含有1一个RefEvent
- StartFlag = TRUE;
- }
- }
- }
- //本频点无NVOD参考事件, 无需继续搜索, 仅将标志设置即可
- if (TRUE == NeedSrhPFFlag && FALSE == StartFlag)
- {
- gatNvod[TsSequence].SearchStartFlag = TRUE;
- gatNvod[TsSequence].SearchCompleteFlag = TRUE;
- printf("nWARNING: KB_NVODGetEitPF::there is no EIT-PF on the fre(%ld)",
- gatNvod[TsSequence].TsPara.frequency);
- }
- if (TRUE == StartFlag)
- {
- gatNvod[TsSequence].SearchStartFlag = TRUE;
- CurrentSearchTsNum = TsSequence;
- CurrentPFCompleteFlag = 0;
- }
- //如果本频点无参考事件需要查找, 则启动下一个未搜索的TS流的数据搜索
- else
- {
- NullDataTsNum = KB_NVOD_GetNullPFTsNum();
- //用户正在播放本频点节目时,不切换频点, 只搜索本频点数据
- if (NVOD_Play != gPrgPlayStatus
- && NullDataTsNum < KB_NVOD_MAX_TS_NUM)
- {
- //启动下一个Ts的参考事件搜索
- printf("nKB_NVODGetEitPF::本频点(%d)无参考事件需要搜索, 启动下一个Ts的参考事件搜索",
- gatNvod[TsSequence].TsPara.frequency);
- KD_NVODStopAllPF();
- KB_DMDDropSignal();
- pTsPara = KB_NVOD_GetTsParaFromTsSequence(NullDataTsNum);
- if (NULL == pTsPara)
- {
- printf("nKB_NVODGetEitSch::KB_NVOD_GetTsParaFromTsSequence error!n");
- return RETFIAL1;
- }
- KB_DMDConnectSignal(pTsPara);
- KB_OSPTaskDelay(50);
- KB_NVODGetEitPF(NullDataTsNum);
- }
- //如果所有的参考事件已经搜索完成, 则启动时移事件搜索
- else
- {
- printf("nKB_NVODGetEitPF::所有的参考事件已经搜索完成, 则启动时移事件搜索");
- KD_NVODStopAllPF();
-
- message.Word1 = MOD_NVOD;
- message.Word2 = KB_NVOD_OVER;
- message.Word3 = 0;
- message.Word4 = 0;
- KB_MENUTranslateMsg(&message);
-
- CurrentTsNum = KB_NVOD_GetCurrentTsNum();
- if ((UINT32)(-1) == CurrentTsNum)
- {
- printf("nKB_NVODGetEitPF::serious error! KB_NVOD_GetCurrentTsNum fail!n");
- return RETFIAL1;
- }
- KB_NVODGetEitSch(CurrentTsNum);
- }
- }
- return RETOK;
- }
- //目前仅搜索当前流SCh的0x50, 0x51表; 若不够用,可按模式添加
- //本函数仅负责0x50表, 其扩展表0x51的搜索在KD_NVODHandleEitSch进行
- static INT32 KB_NVODGetEitSch(UINT32 TsSequence)
- {
- int i, j;
- UINT32 NullDataTsNum = (UINT32)(-1);
- //UINT32 CurrentTsNum = (UINT32)(-1);
- BOOL StartFlag = FALSE;
- KB_SIEitTs eTs;
- //KB_OSPMsgNode message;
- KB_DMDTunerParameters *pTsPara = NULL;
- //搜索总是从PF开始, 所以在这里不再无需再作数据完整性检查
- //这里仅启动0x50的搜索, 0x51的搜索在KD_NVODHandleEitSch启动
- if (TsSequence == KB_NVOD_GetCurrentTsNum())
- {
- eTs = KB_SI_EIT_CURRENT_TS;
- gNvodEitSchTableSwitchFlag = KB_EIT_SCHEDULE_CURRENT_TS_TABLE_DEFAULT;
- //printf("nKB_NVODGetEitSch::eTs = KB_SI_EIT_CURRENT_TSn");
- }
- else
- {
- eTs = KB_SI_EIT_OTHER_TS;
- gNvodEitSchTableSwitchFlag = KB_EIT_SCHEDULE_OTHER_TS_TABLE_DEFAULT;
- //printf("nKB_NVODGetEitSch::eTs = KB_SI_EIT_OTHER_TSn");
- }
-
- if (FALSE == gatNvod[TsSequence].SearchCompleteFlag)
- {
- for(i=0; i<gNvodRefSvcNum; i++)
- {
- if (((UINT32)gNvodSvcInfo[i].freq*100) == gatNvod[TsSequence].TsPara.frequency)
- {
- for (j = 0; j < gNvodSvcInfo[i].shiftSvcNum; j++)
- {
- KD_NVODGetSchTimeShift(gNvodSvcInfo[i].shiftSvc[j].tsId,
- gNvodSvcInfo[i].shiftSvc[j].svcId,
- eTs);
- }
- StartFlag = TRUE;
- }
- }
- }
- if (TRUE == StartFlag)
- {
- CurrentSearchTsNum = TsSequence;
- gSvcNum = gatNvod[TsSequence].RefSrvNum;
- gArriveNum = 0;
- gTimeOutNum = 0;
- //printf("nKB_NVODGetEitSch::gSvcNum(%d), gNvodRefSvcNum(%d)n",
- // gSvcNum, gNvodRefSvcNum);
-
- for(i = 0; i < gNvodRefSvcNum; i ++)
- {
- gRecieveState[i].recvSvcNum = 0;
- }
- }
- //如果本频点无参考事件需要查找, 则启动下一个未搜索频点的数据搜索
- else
- {
- printf("nKB_NVODGetEitSch::本频点无参考事件需要查找, 则启动下一个未搜索频点的数据搜索n");
- NullDataTsNum = KB_NVOD_GetNullSchTsNum();
- //用户正在播放本频点节目时,不切换频点, 只搜索本频点数据
- if (NVOD_Play != gPrgPlayStatus
- && NullDataTsNum < KB_NVOD_MAX_TS_NUM)
- {
- //启动下一个Ts的时移事件搜索
- KD_NVODStopAllPF();
- KD_NVODStopAllSch();
- KB_DMDDropSignal();
- pTsPara = KB_NVOD_GetTsParaFromTsSequence(NullDataTsNum);
- if (NULL == pTsPara)
- {
- printf("nKB_NVODGetEitSch::KB_NVOD_GetTsParaFromTsSequence error!n");
- return RETFIAL1;
- }
- KB_DMDConnectSignal(pTsPara);
- KB_OSPTaskDelay(50);
- KB_NVODGetEitSch(NullDataTsNum);
- }
- //如果所有的时移事件已经搜索完成, 则停止所有搜索,发送刷新消息到MENU
- else
- {
- KB_OSPMsgNode movie_msg;
- KD_NVODStopAllPF();
- KD_NVODStopAllSch();
-
- KB_TimerDisable(EitSrhTimer);
- printf("nKB_NVODGetEitSch::关闭定时期 EitSrhTimer");
- //message.Word1 = MOD_NVOD;
- // message.Word2 = KB_NVOD_OVER;
- // message.Word3 = 0;
- // message.Word4 = 0;
-
-
- movie_msg.Word1 = KB_MOVIE_NVOD_TO_MOVIE;
- kb_machblue_task_post(&movie_msg);
- printf("nKB_NVODGetEitSch::XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
-
- }
- }
- return RETOK;
- }
- int KB_NVODAddTime(UINT16 SerID,UINT16 refSerID,UINT16 evtID,UINT16 refEvtID,time_t start_time)
- {
- int index, ShiftEventNum, i = 0;
- //int add = 0;
- UINT16 TsId = 0;
-
- index = KB_NVODFindEveInd(CurrentSearchTsNum, refSerID, refEvtID);
- if(index == -1)
- {
- return 0;
- }
-
- #if 0
- gSchTime = gNvodTime + 24 * 3600;//AcquireSixTime(pT);
- start_time += 8*3600;
- if((gatNvod[index].refSerID == refSerID) && (gatNvod[index].refEvtID == refEvtID ))
- {
- if( start_time + gatNvod[index].durTime < gNvodTime)
- {
- add = -1;
- }
- else if( start_time + gatNvod[index].durTime > gSchTime )
- {
- add = -2;
- }
- else if((( start_time >= gNvodTime) && (start_time + gatNvod[index].durTime <= gSchTime))
- || (( start_time < gNvodTime) && (start_time + gatNvod[index].durTime >= gNvodTime)))
- {
- add = 1;
- }
- }
- #endif
-
- #if 0
- //抛弃过期的SCH事件
- if (0 == gNvodTime)
- {
- printf("nKB_NVODAddTime::gNvodTime 未获取");
- }
- else
- {
- if (start_time + gatNvod[CurrentSearchTsNum].RefEventData[index].durTime < gNvodTime)
- {
- return 0;
- }
- }
- #endif
- //if(add == 1)
- //{
- //if(gatNvod[index].TimeNum >= 200)
- //{
- // quicksortEit(gatNvod[index].TimeNode,0,gatNvod[index].TimeNum - 1);
- // gatNvod[index].TimeNum = 120;
- //return;
- //}
- //超出最大限制
- ShiftEventNum = gatNvod[CurrentSearchTsNum].RefEventData[index].TimeNum;
- if (ShiftEventNum >= 500)
- {
- printf("nKB_NVODAddTime::ShiftEventNum 超出最大限制 n");
- return 0;
- }
- //防止重复添加
- for (i = 0; i < gatNvod[CurrentSearchTsNum].RefEventData[index].TimeNum; i++)
- {
- if (gatNvod[CurrentSearchTsNum].RefEventData[index].TimeNode[i].EvtID == evtID
- &&gatNvod[CurrentSearchTsNum].RefEventData[index].TimeNode[i].SerID == SerID
- &&gatNvod[CurrentSearchTsNum].RefEventData[index].TimeNode[i].startTime == start_time)
- {
- return 0;
- }
- }
- if (RET_OK != KB_DBGetTsIDByFre(&TsId,
- gatNvod[CurrentSearchTsNum].TsPara.frequency/ 100))
- {
- printf("nKB_NVODAddTime::serious error! KB_DBGetTsIDByFre fail!n");
- return 0;
- }
-
- if (0 != TsId)
- {
- gatNvod[CurrentSearchTsNum].RefEventData[index].TimeNode[ShiftEventNum].tsID = TsId;
- }
- gatNvod[CurrentSearchTsNum].RefEventData[index].TimeNode[ShiftEventNum].EvtID = evtID;
- gatNvod[CurrentSearchTsNum].RefEventData[index].TimeNode[ShiftEventNum].SerID = SerID;
- gatNvod[CurrentSearchTsNum].RefEventData[index].TimeNode[ShiftEventNum].startTime = start_time;
- gatNvod[CurrentSearchTsNum].RefEventData[index].TimeNum ++;
- //}
-
- return 1;
- }
- int KB_NVODFindEveInd(UINT32 TsSequence, UINT16 refSerID,UINT16 refEvtID)
- {
- int i;
- for(i = 0;i<gatNvod[TsSequence].RefEventNum; i++)
- {
- if((gatNvod[TsSequence].RefEventData[i].refEvtID == refEvtID)
- && (gatNvod[TsSequence].RefEventData[i].refSerID == refSerID))
- {
- return i;
- }
- }
- return -1;
- }
- int KB_NVODAddRefSvc(unsigned short tsID,
- unsigned short refEvtID,
- unsigned short refSerID,
- char *PrgName,
- char *PrgTxt,
- UINT16 durTime)
- {
- int i;
- //int index;
- int len;
- UINT8 EventNum;
-
- if((PrgName == NULL) || (PrgTxt == NULL) )
- {
- return -1;
- }
- if(gatNvod[CurrentSearchTsNum].RefEventNum >= KB_NVOD_MAX_RefEvent_One_Ts)
- {
- return -1;
- }
- //目前本ts流的参考事件数目
- EventNum = gatNvod[CurrentSearchTsNum].RefEventNum;
- for( i = 0;i < EventNum;i++)
- {
- if((gatNvod[CurrentSearchTsNum].RefEventData[i].refEvtID ==refEvtID )
- && (gatNvod[CurrentSearchTsNum].RefEventData[i].refSerID ==refSerID ))
- {
- return -1;
- }
- }
- gatNvod[CurrentSearchTsNum].RefEventData[EventNum].durTime = durTime;
- gatNvod[CurrentSearchTsNum].RefEventData[EventNum].refSerID = refSerID;
- gatNvod[CurrentSearchTsNum].RefEventData[EventNum].refEvtID = refEvtID;
- memcpy(gatNvod[CurrentSearchTsNum].RefEventData[EventNum].PrgName,
- PrgName,
- 30);
- gatNvod[CurrentSearchTsNum].RefEventData[EventNum].PrgName[28] = ' ';
- gatNvod[CurrentSearchTsNum].RefEventData[EventNum].PrgName[29] = ' ';
-
- len = strlen(PrgTxt);
- if(len >= 400)
- {
- len = 390;
- }
- memcpy(gatNvod[CurrentSearchTsNum].RefEventData[EventNum].PrgTxt,
- PrgTxt,
- len);
- gatNvod[CurrentSearchTsNum].RefEventNum++;
- return 0;
- }
- //static void KD_NVODHandleMsg3(KB_OSPMsgNode *pInMsg)
- //{
- // int j;
- //
- // for(j = 0;j<nvodEvent;j++)
- // {
- // quicksortEit(gatNvod[j].TimeNode,0,gatNvod[j].TimeNum - 1);
- // }
- //}
- INT32 KB_NVODHandleMsg(KB_OSPMsgNode *pInMsg)
- {
- //UINT32 CurrentTsNum = (UINT32)(-1);
- KB_OSPMsgNode pSendMsg;
- //KB_DMDTunerParameters ts;
-
- switch (pInMsg->Word1)
- {
- case MOD_NVOD:
- {
- switch (pInMsg->Word2)
- {
- case KB_NVOD_PF_OVER:
-
- break;
- case KB_NVOD_PF_TIMEOUT:
- {
- gTimeOutNum++;
- if(KD_NVODRefSvcReceiveStatus((UINT16)pInMsg->Word4, TRUE))
- {
- KD_NVODStopAllSch();
- gNvodEitSchTableSwitchFlag = KB_EIT_SCHEDULE_CURRENT_TS_TABLE_DEFAULT;
- //if (gFreqInd == gFreqNum)
- {
- pSendMsg.Word1 = pInMsg->Word1;
- pSendMsg.Word2 = KB_NVOD_OVER;
- pSendMsg.Word3 = 0;
- pSendMsg.Word4 = 0;
- KB_MENUTranslateMsg(&pSendMsg);
- }
- #if 0
- else
- {
- KB_EPGStopAllSCH();
- KD_NVODStopAllPF();
- KD_NVODStopAllSch();
- KB_DMDDropSignal();
-
- ts = gNvodRefFre[gFreqInd];
- gSvcNum = gNvodRefSvcEachFre[gFreqInd];
- gArriveNum = 0;
- gTimeOutNum = 0;
- gFreqInd++;
- KB_DMDConnectSignal(&ts);
- if (RET_OK != KB_NVOD_SetCurrentTsPara(ts))
- {
- printf("nKB_NVODHandleMsg::KB_NVOD_SetCurrentTsPara fail!n");
- return KB_DB_DTV_FAILURE;
- }
- //memcpy(&NvodCurrentTs, &ts, sizeof(KB_DMDTunerParameters));
- }
- #endif
- }
- }
- break;
- case KB_NVOD_SCH_OVER:
- {
- //KB_NVODHandleMsg(pInMsg);
- KD_NVODHandleEitSch(pInMsg);
- }
- break;
- case KB_NVOD_SCH_TIMEOUT:
- KD_NVODHandleEitSch(pInMsg);
- break;
- default:
- break;
- }
- }
- break;
- default :
- break;
- }
- return 0;
-
- }
- INT32 KB_NVODGetPrgNum(UINT32 TsSequence)
- {
- return gatNvod[TsSequence].RefEventNum;
- }
- char *KB_NVODGetPrgName(UINT32 TsSequence, INT32 RefEventIndex)
- {
- if(RefEventIndex < 0
- || RefEventIndex >= KB_NVOD_MAX_RefEvent_One_Ts
- || TsSequence >= KB_NVOD_MAX_TS_NUM)
- {
- return NULL;
- }
-
- return gatNvod[TsSequence].RefEventData[RefEventIndex].PrgName;
- }
- char *KB_NVODGetPrgContent(UINT32 TsSequence, INT32 RefEventIndex)
- {
- if(RefEventIndex < 0
- || RefEventIndex >= KB_NVOD_MAX_RefEvent_One_Ts
- || TsSequence >= KB_NVOD_MAX_TS_NUM)
- {
- return NULL;
- }
-
- return gatNvod[TsSequence].RefEventData[RefEventIndex].PrgTxt;
- }
- INT32 KB_NVODGetPrgDuring(UINT32 TsSequence, INT32 RefEventIndex)
- {
- if(RefEventIndex < 0
- || RefEventIndex >= KB_NVOD_MAX_RefEvent_One_Ts
- || TsSequence >= KB_NVOD_MAX_TS_NUM)
- {
- return 0;
- }
-
- return (INT32)(gatNvod[TsSequence].RefEventData[RefEventIndex].durTime);
- }
- INT32 KB_NVODGetPrgTimeNum(UINT32 TsSequence, INT32 RefEventIndex)
- {
- if(RefEventIndex < 0
- || RefEventIndex >= KB_NVOD_MAX_RefEvent_One_Ts
- || TsSequence >= KB_NVOD_MAX_TS_NUM)
- {
- return 0;
- }
-
- return (INT32)(gatNvod[TsSequence].RefEventData[RefEventIndex].TimeNum);
- }
- BOOL KB_NVODGetPrgRefSvcFlag(UINT32 TsSequence,
- INT32 RefEventIndex,
- UINT16 nRefSvcID)
- {
- if(RefEventIndex < 0
- || RefEventIndex >= KB_NVOD_MAX_RefEvent_One_Ts
- || TsSequence >= KB_NVOD_MAX_TS_NUM)
- {
- return 0;
- }
-
- return (gatNvod[TsSequence].RefEventData[RefEventIndex].refSerID == nRefSvcID);
- }
- time_t KB_NVODGetPrgStartTime(UINT32 TsSequence,
- INT32 RefEventIndex,
- INT32 ShiftEventIndex)
- {
- if(RefEventIndex < 0
- || RefEventIndex >= KB_NVOD_MAX_RefEvent_One_Ts
- || TsSequence >= KB_NVOD_MAX_TS_NUM)
- {
- return 0;
- }
- if(ShiftEventIndex<0
- || ShiftEventIndex>=(INT32)(gatNvod[TsSequence].RefEventData[RefEventIndex].TimeNum))
- {
- return 0;
- }
- return gatNvod[TsSequence].RefEventData[RefEventIndex].TimeNode[ShiftEventIndex].startTime;
- }
- static BOOL KD_NVODRefSvcReceiveStatus(UINT16 refScvId, BOOL bTimeout)
- {
- int i;
- if(refScvId == (UINT16)(-1))
- {
- gArriveNum++;
- }
- else
- {
- if(!bTimeout)
- {
- for(i=0; i<gSvcNum; i++)
- {
- if(gRecieveState[i].refScvId == refScvId)
- {
- ++gRecieveState[i].recvSvcNum;
- if( gRecieveState[i].recvSvcNum == gRecieveState[i].shiftSvcNum)
- {
- gArriveNum++;
- }
- break;
- }
- }
- }
- }
-
- if((UINT32)gArriveNum+ (UINT32)gTimeOutNum == gSvcNum)
- {
- return TRUE;
- }
-
- return FALSE;
- }
- BOOL KB_NVODGetTimeInfo(UINT32 TsSequence,
- INT32 RefEventIndex,
- INT32 ShiftEventIndex,
- INT32 *nTsId,
- INT32 *nSvcID)
- {
- unsigned short serID,refSerID;
- int i,j;
-
- if(RefEventIndex < 0
- || RefEventIndex >= KB_NVOD_MAX_RefEvent_One_Ts
- || TsSequence >= KB_NVOD_MAX_TS_NUM)
- {
- return FALSE;
- }
- if(ShiftEventIndex<0
- || ShiftEventIndex>=(INT32)(gatNvod[TsSequence].RefEventData[RefEventIndex].TimeNum))
- {
- return FALSE;
- }
- *nSvcID = gatNvod[TsSequence].RefEventData[RefEventIndex].TimeNode[ShiftEventIndex].SerID;
-
- refSerID = gatNvod[TsSequence].RefEventData[RefEventIndex].refSerID;
- serID = gatNvod[TsSequence].RefEventData[RefEventIndex].TimeNode[ShiftEventIndex].SerID;
-
- for(i = 0;i<gSvcNum;i++)
- {
- if(gNvodSvcInfo[i].refScvId == refSerID)
- {
- for(j = 0;j<gNvodSvcInfo[i].shiftSvcNum;j++)
- {
- if(gNvodSvcInfo[i].shiftSvc[j].svcId ==serID)
- {
- *nTsId = gNvodSvcInfo[i].shiftSvc[j].tsId;
- return TRUE;
- }
- }
- }
- }
-
- return FALSE;
- }
- INT32 KB_NVODGetClassNum(void)
- {
- return gNvodRefSvcNum;
- }
- char *KB_NVODGetClassName(INT32 index)
- {
- if(index<0 || index>=gNvodRefSvcNum)
- {
- return NULL;
- }
-
- return (char *)gNvodSvcInfo[index].refScvName;
- }
- UINT16 KB_NVODGetClassRefSvc(INT32 index)
- {
- if(index<0 || index>=gNvodRefSvcNum)
- {
- return (UINT16)-1;
- }
-
- return gNvodSvcInfo[index].refScvId;
- }
- void KB_NVODSetNewFlag(BOOL bFlag)
- {
- gNewFlag = bFlag;
- }
- BOOL KB_NVODGetNewFlag(void)
- {
- return gNewFlag;
- }
- void KB_NVODSetPrgEnd(time_t tTime)
- {
- gPrgEndTime = tTime;
- }
- time_t KB_NVODGetPrgEnd(void)
- {
- return gPrgEndTime;
- }
- static void KD_NVODHandleEitSch(KB_OSPMsgNode *pInMsg)
- {
- UINT16 time_shifted_service_id = 0xffff;
- UINT16 reference_Service_id = 0xffff;
- UINT16 shiftSvcNum;
- UINT32 i,j;
- UINT32 NullDataTsNum = (UINT32)(-1);
- KB_OSPMsgNode message;
- //KB_DMDTunerParameters ts;
- KB_DMDTunerParameters *pTsPara = NULL;
-
- time_shifted_service_id = (UINT16)pInMsg->Word3;
- for(i=0; i<gNvodRefSvcNum; i++)
- {
- shiftSvcNum = gNvodSvcInfo[i].shiftSvcNum;
- for(j=0; j<shiftSvcNum; j++)
- {
- if (time_shifted_service_id == gNvodSvcInfo[i].shiftSvc[j].svcId)
- {
- reference_Service_id = gNvodSvcInfo[i].refScvId;
- break;
- }
- }
- if (reference_Service_id != 0xffff)
- {
- break;
- }
- }
- for(i=0; i<KB_NVOD_MAX_REF; i++)
- {
- if (gRecieveState[i].refScvId == reference_Service_id)
- {
- gRecieveState[i].recvSvcNum++;
- break;
- }
- }
- if( gRecieveState[i].recvSvcNum == gRecieveState[i].shiftSvcNum)
- {
- gArriveNum++;
- //printf("nKD_NVODHandleEitSch::gArriveNum++, gArriveNum(%d), gSvcNum(%d)n",
- // gArriveNum, gSvcNum);
- }
- if((UINT32)gArriveNum+ (UINT32)gTimeOutNum == gSvcNum)
- {
- KD_NVODStopAllSch();
- #if 1
- message.Word1 = MOD_NVOD;
- message.Word2 = KB_NVOD_OVER;
- message.Word3 = 0;
- message.Word4 = 0;
- KB_MENUTranslateMsg(&message);
- #endif
- //printf("nKD_NVODHandleEitSch::gArriveNum == gSvcNumn");
-
- switch(gNvodEitSchTableSwitchFlag)
- {
- //增加对表0x51的处理
- case KB_EIT_SCHEDULE_CURRENT_TS_TABLE_DEFAULT:
- #if 0
- //printf("nKD_NVODHandleEitSch::EIT_SCHEDULE_DONE 0x50n");
- {
- gNvodEitSchTableSwitchFlag = KB_EIT_SCHEDULE_CURRENT_TS_TABLE_0X51;
- gArriveNum = 0;
- gTimeOutNum = 0;
- for(i = 0; i < gNvodRefSvcNum; i ++)
- {
- gRecieveState[i].recvSvcNum = 0;
- }
- if (FALSE == gatNvod[CurrentSearchTsNum].SearchCompleteFlag)
- {
- for(i = 0; i <gNvodRefSvcNum; i++)
- {
- if ((gNvodSvcInfo[i].freq*100) == gatNvod[CurrentSearchTsNum].TsPara.frequency)
- {
- for (j = 0; j < gNvodSvcInfo[i].shiftSvcNum; j++)
- {
- KD_NVODGetSchTimeShift(gNvodSvcInfo[i].shiftSvc[j].tsId,
- gNvodSvcInfo[i].shiftSvc[j].svcId,
- KB_SI_EIT_CURRENT_TS_FOR_0x51_table);
- }
- }
- }
- }
- }
- break;
- //当前流0x50、0x51搜索完成, 首次启动各个其他流的搜索, 先找0x60
- case KB_EIT_SCHEDULE_CURRENT_TS_TABLE_0X51:
- #endif
- //printf("nKD_NVODHandleEitSch::EIT_SCHEDULE_DONE 0x51n");
- {
- gatNvod[CurrentSearchTsNum].SearchCompleteFlag = TRUE;
- #if 0
- message.Word1 = MOD_NVOD;
- message.Word2 = KB_NVOD_OVER;
- message.Word3 = 0;
- message.Word4 = 0;
- KB_MENUTranslateMsg(&message);
- #endif
- NullDataTsNum = KB_NVOD_GetNullSchTsNum();
- //用户正在播放本频点节目时,不切换频点, 只搜索本频点数据
- if (NVOD_Play != gPrgPlayStatus
- && NullDataTsNum < KB_NVOD_MAX_TS_NUM)
- {
- //启动下一个其他流的时移事件搜索
- KD_NVODStopAllPF();
- KB_DMDDropSignal();
- pTsPara = KB_NVOD_GetTsParaFromTsSequence(NullDataTsNum);
- if (NULL == pTsPara)
- {
- printf("nKD_NVODHandleEitSch::KB_NVOD_GetTsParaFromTsSequence error!n");
- return;
- }
- KB_DMDConnectSignal(pTsPara);
- KB_OSPTaskDelay(50);
- KB_NVODGetEitSch(NullDataTsNum);
- }
- else
- {
- KB_OSPMsgNode movie_msg;
-
- movie_msg.Word1 = KB_MOVIE_NVOD_TO_MOVIE;
- kb_machblue_task_post(&movie_msg);
- KB_TimerDisable(EitSrhTimer);
- printf("nKD_NVODHandleEitSch::关闭定时期 EitSrhTimer");
- printf("nKD_NVODHandleEitSch::没有其他流SCHn");
- }
- }
- break;
- //目前流程下面的代码不会执行到
- #if 0
- //启动0x61的搜索
- case KB_EIT_SCHEDULE_OTHER_TS_TABLE_DEFAULT:
- printf("nKD_NVODHandleEitSch::EIT_SCHEDULE_DONE 0x60n");
- {
- gNvodEitSchTableSwitchFlag = KB_EIT_SCHEDULE_OTHER_TS_TABLE_0X61;
- gArriveNum = 0;
- gTimeOutNum = 0;
- for(i = 0; i < gNvodRefSvcNum; i ++)
- {
- gRecieveState[i].recvSvcNum = 0;
- }
-
- for(i = 0; i <gNvodRefSvcNum; i++)
- {
- if ((gNvodSvcInfo[i].freq*100) == gatNvod[CurrentSearchTsNum].TsPara.frequency
- && gatNvod[CurrentSearchTsNum].SearchCompleteFlag == FALSE)
- {
- for (j = 0; j < gNvodSvcInfo[i].shiftSvcNum; j++)
- {
- KD_NVODGetSchTimeShift(gNvodSvcInfo[i].shiftSvc[j].tsId,
- gNvodSvcInfo[i].shiftSvc[j].svcId,
- KB_SI_EIT_OTHER_TS_FOR_0x61_table);
- }
- }
- }
- }
- break;
- //非首次启动其他频点的参考事件搜索
- case KB_EIT_SCHEDULE_OTHER_TS_TABLE_0X61:
- printf("nKD_NVODHandleEitSch::EIT_SCHEDULE_DONE 0x61n");
- {
- gatNvod[CurrentSearchTsNum].SearchCompleteFlag = TRUE;
- NullDataTsNum = KB_NVOD_GetNullSchTsNum();
- //启动下一个其他流的时移事件搜索
- if (NullDataTsNum < KB_NVOD_MAX_TS_NUM)
- {
- KB_NVODGetEitSch(NullDataTsNum);
- }
- }
- break;
- #endif
- default:
- printf("nKD_NVODHandleEitSch::error!");
- break;
- }
- }
- }
- static INT32 KD_NVODInitTask(void)
- {
- int i;
- gNvodPF = KB_OSPMalloc(sizeof(KB_SIEitPF) * KB_SI_MAX_REF_SVC_NUMS);
- gNvodPFEvent = KB_OSPMalloc(sizeof(KB_SINVODEitPF) * KB_SI_MAX_REF_SVC_NUMS * KB_SI_EIT_PF_MAX_NVOD_EVENT_NUMBER);
-
- if (gNvodPF == NULL)
- {
- printf("KD_NVODInitTask gNvodPF == NULLn");
- return RETFAIL2;
- }
- else
- {
- for (i = 0; i < KB_SI_MAX_REF_SVC_NUMS; i++)
- {
- gNvodPFInfo[i].nTsId = 0xFFFFFFFF;
- gNvodPFInfo[i].nEnable = TRUE;
- gNvodPFInfo[i].nState = KB_NVOD_EMPTY;
- gNvodPFInfo[i].nSvcID = 0xFFFFFFFF;
- gNvodPFInfo[i].pPresent = gNvodPF + i;
- gNvodPFInfo[i].pPresent->NVODEvent = gNvodPFEvent + i * KB_SI_EIT_PF_MAX_NVOD_EVENT_NUMBER;
-
- }
- }
-
- //gNvodSchEvent = (KB_SIEitSchTimeShiftNode*)KB_EPGGetMemAddress();
- gNvodSchEvent = (KB_SIEitSchTimeShiftNode*)KB_OSPMalloc(sizeof(KB_SIEitSchTimeShiftNode) * KB_NVOD_MAX_ShiftSrv_One_Ts * KB_SI_MAX_SHIFT_EVENT_NUM_PER_SERVICE);
- for (i = 0; i < KB_NVOD_MAX_ShiftSrv_One_Ts; i++)
- {
- gNvodSch[i].nTsId = 0xFFFFFFFF;
- gNvodSch[i].nEnable = TRUE;
- gNvodSch[i].nState = KB_NVOD_EMPTY;
- gNvodSch[i].nSvcID = 0xFFFFFFFF;
- gNvodSch[i].nSchInfo.ptTimeShift = gNvodSchEvent + i * KB_SI_MAX_SHIFT_EVENT_NUM_PER_SERVICE;
- }
- EitSrhTimer = KB_TimerCreate(KB_TIMER_ONCE,
- (KB_TIMER_FUNC_POINTER)KB_NvodHandleEitSrhTimeOut,
- NULL);
- if (KB_TIMER_INVALID_ID == EitSrhTimer)
- {
- printf("nKD_NVODInitTask::EitSrhTimer create failed!");
- }
-
- return RETOK;
- }
- static void KB_NvodHandleEitSrhTimeOut(void)
- {
- KB_OSPMsgNode movie_msg;
- KD_NVODStopAllPF();
- KD_NVODStopAllSch();
- movie_msg.Word1 = KB_MOVIE_NVOD_TO_MOVIE;
- kb_machblue_task_post(&movie_msg);
- printf("nKB_NVODGetEitSch::XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
- printf("nKB_NvodHandleEitSrhTimeOut::EIT数据搜索超时");
- return;
- }
- void KD_NVODHandleMsg2(KB_OSPMsgNode *pInMsg)
- {
- UINT32 NullDataTsNum = (UINT32)(-1);
- UINT32 CurrentTsNum = (UINT32)(-1);
- KB_OSPMsgNode msgNode;
- //KB_SIEitPF *ptEitPf;
- KB_OSPMsgNode message;
- KB_DMDTunerParameters *pTsPara = NULL;
-
- switch (pInMsg->Word1)
- {
- case MOD_SIPSI:
-
- msgNode.Word1 = J_EPG_MODULE;
- if (pInMsg->Word2 >= KB_SI_MSG_EIT_PF_DONE
- && pInMsg->Word2 <= KB_SI_MSG_EIT_SCHEDULE_TIMEOUT)
- {
- switch (pInMsg->Word2)
- {
- case KB_SI_MSG_EIT_PF_DONE:
- //printf("nKD_NVODHandleMsg2::SrvId(%d)n",
- // ((KB_SIEitPF*)pInMsg->Word3)->service_id);
- KD_NVODHandlePFOver(pInMsg);
- ++CurrentPFCompleteFlag;
- if (CurrentSearchTsNum < KB_NVOD_MAX_TS_NUM
- && CurrentPFCompleteFlag == gatNvod[CurrentSearchTsNum].RefSrvNum)
- {
- KD_NVODStopAllPF();
- NullDataTsNum = KB_NVOD_GetNullPFTsNum();
- //用户正在播放本频点节目时,不切换频点, 只搜索本频点数据
- if (NVOD_Play != gPrgPlayStatus
- && NullDataTsNum < KB_NVOD_MAX_TS_NUM)
- {
- //启动下一个Ts的参考事件搜索
- KD_NVODStopAllPF();
- KB_DMDDropSignal();
- pTsPara = KB_NVOD_GetTsParaFromTsSequence(NullDataTsNum);
- if (NULL == pTsPara)
- {
- printf("nKB_NVODGetEitSch::KB_NVOD_GetTsParaFromTsSequence error!n");
- return;
- }
- KB_DMDConnectSignal(pTsPara);
- KB_OSPTaskDelay(50);
- KB_NVODGetEitPF(NullDataTsNum);
- }
- //如果所有的参考事件已经搜索完成, 则启动时移事件搜索
- else
- {
- //printf("nKD_NVODHandleMsg2::EIT_PF_DONEn");
- message.Word1 = MOD_NVOD;
- message.Word2 = KB_NVOD_OVER;
- message.Word3 = 0;
- message.Word4 = 0;
- KB_MENUTranslateMsg(&message);
-
- CurrentTsNum = KB_NVOD_GetCurrentTsNum();
- if ((UINT32)(-1) == CurrentTsNum)
- {
- printf("nKD_NVODHandleMsg2::serious error! KB_NVOD_GetCurrentTsNum fail!n");
- return;
- }
- KB_NVODGetEitSch(CurrentTsNum);
- }
- }
- break;
- case KB_SI_MSG_EIT_PF_TIMEOUT:
- msgNode.Word1 = MOD_NVOD;
- msgNode.Word2 = KB_NVOD_PF_TIMEOUT;
- msgNode.Word4 = pInMsg->Word4;
- KB_NVODHandleMsg(&msgNode);
- break;
-
- case KB_SI_MSG_EIT_SCHEDULE_EVENT_DONE:
- break;
-
- case KB_SI_MSG_EIT_SCHEDULE_DONE:
- KD_NVODHandleSCHOver(pInMsg);
- break;
- case KB_SI_MSG_EIT_SCHEDULE_TIMEOUT:
- msgNode.Word1 = MOD_NVOD;
- msgNode.Word2 = KB_NVOD_SCH_TIMEOUT;
- msgNode.Word3 = pInMsg->Word4;
- msgNode.Word4 = 0xFFFFFFFF;
- KB_NVODHandleMsg(&msgNode);
- break;
-
- default:
- break;
- }
- }
-
- break;
- default:
- break;
- }
- }
- static INT32 KD_NVODGetPF(INT32 nTsId, INT32 nSvcID, KB_SIEitTs eTs)
- {
- INT32 nReturn, nNumber;
- nNumber = KD_NVODGetFreePF();
- if (nNumber == 0xFFFFFFFF)
- {
- return RETFIAL1;
- }
- nReturn = KB_SIGetEitPF(nSvcID, eTs,
- gNvodPFInfo[nNumber].pPresent,
- gNvodPFInfo[nNumber].pPresent,
- KB_SI_RECEIVE_ONCE,
- -1);
- if (nReturn != 0)
- {
- return RETFIAL1;
- }
- else
- {
- gNvodPFInfo[nNumber].nTsId = nTsId;
- gNvodPFInfo[nNumber].nSvcID = nSvcID;
- gNvodPFInfo[nNumber].nEnable = FALSE;
- gNvodPFInfo[nNumber].nState = KB_NVOD_RECEIVING;
- //printf("nKD_NVODGetPF::RefSrvId(%d), eTs(%d)n", nSvcID, eTs);
- return RETOK;
- }
- }
- static INT32 KD_NVODGetSchTimeShift(INT32 nTsId,
- INT32 nSvcID,
- KB_SIEitTs eTs)
- {
- INT32 nNumber, nReturn;
- nNumber = KD_NVODGetFreeSch();
- if (nNumber == 0xFFFFFFFF)
- {
- return RETFIAL1;
- }
-
- nReturn = KB_SIGetEITSCHShift(nSvcID,
- eTs,
- &gNvodSch[nNumber].nSchInfo);
- if (nReturn != 0)
- {
- return RETFIAL1;
- }
- else
- {
- gNvodSch[nNumber].nTsId = nTsId;
- gNvodSch[nNumber].nSvcID = nSvcID;
- gNvodSch[nNumber].nEnable = FALSE;
- gNvodSch[nNumber].nState = KB_NVOD_RECEIVING;
- return RETOK;
- }
- }
- INT32 KD_NVODStopAllPF(void)
- {
- int i;
- //对于KB_SI_STOP_ALL的情况, 第二个参数是不起作用的
- KB_SIStopEitPF(KB_SI_STOP_ALL, KB_SI_EIT_CURRENT_TS);
-
- for (i = 0; i < KB_SI_MAX_REF_SVC_NUMS; i++)
- {
- KD_NVODResetPF(i);
- }
- return RETOK;
- }
- INT32 KD_NVODStopAllSch(void)
- {
- int i;
- KB_SIStopEitSCHShift(KB_SI_STOP_ALL, KB_SI_EIT_CURRENT_TS);
-
- for (i = 0; i < KB_NVOD_MAX_REF; i++)
- {
- KD_ResetSCH(i);
- }
- return RETOK;
- }
- static INT32 KD_NVODGetFreePF(void)
- {
- INT32 i, nNumber;
- nNumber = 0xFFFFFFFF;
- for (i = 0; i < KB_SI_MAX_REF_SVC_NUMS; i++)
- {
- if (gNvodPFInfo[i].nEnable == TRUE)
- {
- nNumber = i;
- break;
- }
- }
- return nNumber;
- }
- static INT32 KD_NVODGetFreeSch(void)
- {
- INT32 i, nNumber;
- nNumber = 0xFFFFFFFF;
- for (i = 0; i < KB_NVOD_MAX_ShiftSrv_One_Ts; i++)
- {
- if (gNvodSch[i].nEnable == TRUE)
- {
- nNumber = i;
- break;
- }
- }
- return nNumber;
- }
- static INT32 KD_NVODResetPF(INT32 nNumber)
- {
- gNvodPFInfo[nNumber].nTsId = 0xFFFFFFFF;
- gNvodPFInfo[nNumber].nEnable = TRUE;
- gNvodPFInfo[nNumber].nState = KB_NVOD_EMPTY;
- gNvodPFInfo[nNumber].nSvcID = 0xFFFFFFFF;
-
- return RETOK;
- }
- static INT32 KD_ResetSCH(INT32 nNumber)
- {
- gNvodSch[nNumber].nEnable = TRUE;
- gNvodSch[nNumber].nState = KB_NVOD_EMPTY;
- gNvodSch[nNumber].nSvcID = 0xFFFFFFFF;
- gNvodSch[nNumber].nSchInfo.num = 0;
- gNvodSch[nNumber].nSchInfo.service_id = 65535;
- return RETOK;
- }
- static INT32 KD_NVODHandlePFOver(KB_OSPMsgNode *pInMsg)
- {
- KB_SIEitPF *ptEitPf;
- KB_SINVODEitPF *ptNvod;
- KB_OSPMsgNode msgNode;
- int i;
-
- ptEitPf = (KB_SIEitPF*)pInMsg->Word3;
-
- for (i = 0; i < ptEitPf->NVODEventNum; i++)
- {
- ptNvod = ptEitPf->NVODEvent + i;
- KB_NVODAddRefSvc(0,
- ptNvod->event_id,
- ptNvod->service_id,
- (char*)ptNvod->chinese.event_name,
- (char*)ptNvod->chinese.text,
- (UINT16)ptNvod->duration);
- }
- msgNode.Word1 = MOD_NVOD;
- msgNode.Word2 = KB_NVOD_PF_OVER;
- msgNode.Word3 = ptEitPf->service_id;
- KB_NVODHandleMsg(&msgNode);
-
- return RETOK;
- }
- static INT32 KD_NVODHandleSCHOver(KB_OSPMsgNode *pInMsg)
- {
- KB_SIEitSchTimeShift *ptShift;
- KB_SIEitSchTimeShiftNode *ptShiftEvent;
- KB_OSPMsgNode msgNode;
- int i;
-
- ptShift = (KB_SIEitSchTimeShift*)pInMsg->Word3;
- //printf("nKD_NVODHandleSCHOver::SrvId(%d), num(%d), RefSrvId(%d)",
- // ptShift->service_id, ptShift->num, (ptShift->ptTimeShift)->reference_service_id);
-
- for (i = 0; i < ptShift->num; i++)
- {
- ptShiftEvent = ptShift->ptTimeShift + i;
- KB_NVODAddTime(ptShift->service_id,
- ptShiftEvent->reference_service_id,
- ptShiftEvent->event_id,
- ptShiftEvent->reference_event_id,
- ptShiftEvent->start_time);
- }
- msgNode.Word1 = MOD_NVOD;
- msgNode.Word2 = KB_NVOD_SCH_OVER;
- msgNode.Word3 = ptShift->service_id;
- if (ptShift->num == 0)
- {
- msgNode.Word4 = 0xFFFFFFFF;
- }
- else
- {
- msgNode.Word4 = ptShift->ptTimeShift->reference_service_id;
- }
-
- KB_NVODHandleMsg(&msgNode);
-
- return RETOK;
- }
- INT32 KB_NvodGetRefEventNum(UINT32 TsSequence)
- {
- return gatNvod[TsSequence].RefEventNum;
- }
- INT32 KB_NvodGetFreNum(UINT32 TsSequence)
- {
- int i, count = 0;
-
- for (i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (gatNvod[i].TsPara.frequency != 0)
- {
- count++;
- }
- }
-
- return count;
- }
- KB_NVOD_Info *KB_NvodGetRefNodeHead(void)
- {
- return gatNvod;
- }
- #if 0
- UINT16 KB_NvodGetTsIdFromRefsrvIdSrvId(UINT16 refSerID,UINT16 SerID)
- {
- int i = 0, j = 0;
- UINT16 ret = 0;
-
- for (i = 0; i <gNvodRefSvcNum; i++)
- {
- if (gNvodSvcInfo[i].refScvId == refSerID)
- {
- for (j = 0; j < gNvodSvcInfo[i].shiftSvcNum; j++)
- {
- if (gNvodSvcInfo[i].shiftSvc[j].svcId == SerID)
- {
- ret = gNvodSvcInfo[i].shiftSvc[j].tsId;
- break;
- }
- }
- }
- }
- return ret;
- }
- #endif
- KB_NVODStruct *KB_NVOD_GetTsIndexFromCur(int CursorIndex)
- {
- int i, j, count;
- KB_NVOD_Info *pstNvodNodeHead;
- if (CursorIndex < 0)
- {
- printf("nKB_NVOD_GetTsIndexFromCur::input(%d) error!", CursorIndex);
- return NULL;
- }
- count = (int)CursorIndex;
- pstNvodNodeHead = KB_NvodGetRefNodeHead();
-
- for (i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- for(j = 0; j < KB_NvodGetRefEventNum(i); j++)
- {
- if (--count < 0)
- {
- return &(pstNvodNodeHead[i].RefEventData[j]);
- }
- }
- }
- return NULL;
- }
- UINT32 KB_NVOD_GetCurrentTsNum(void)
- {
- int i;
- for(i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (TRUE == gatNvod[i].CurrentTsFlag)
- {
- return i;
- }
- }
- return (UINT32)(-1);
- }
- static UINT32 KB_NVOD_GetNullPFTsNum(void)
- {
- UINT8 i;
- for(i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (0 != gatNvod[i].TsPara.frequency
- && FALSE == gatNvod[i].SearchStartFlag
- && FALSE == gatNvod[i].SearchCompleteFlag)
- {
- return i;
- }
- }
- return (UINT32)(-1);
- }
- static UINT32 KB_NVOD_GetNullSchTsNum(void)
- {
- UINT8 i;
- for(i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (0 != gatNvod[i].TsPara.frequency
- && TRUE == gatNvod[i].SearchStartFlag
- && FALSE == gatNvod[i].SearchCompleteFlag)
- {
- return i;
- }
- }
- return (UINT32)(-1);
- }
- static void KB_NVOD_ResetTsData(UINT32 TsSequence)
- {
- KD_NVODStopAllPF();
- KD_NVODStopAllSch();
- memset(gatNvod[TsSequence].RefEventData,
- 0,
- (sizeof(KB_NVODStruct)*KB_NVOD_MAX_RefEvent_One_Ts));
- gatNvod[TsSequence].RefSrvNum = 0;
- gatNvod[TsSequence].RefEventNum = 0;
- gatNvod[TsSequence].SearchStartFlag = FALSE;
- gatNvod[TsSequence].SearchCompleteFlag = FALSE;
- return;
- }
- UINT32 KB_NVOD_GetTsSequenceFromFrequency(UINT32 frequency)
- {
- int i;
- for(i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (frequency == gatNvod[i].TsPara.frequency)
- {
- return i;
- }
- }
- return (UINT32)(-1);
- }
- KB_DMDTunerParameters *KB_NVOD_GetTsParaFromTsSequence(UINT32 TsSequence)
- {
- if (TsSequence < KB_NVOD_MAX_TS_NUM
- && 0 != gatNvod[TsSequence].TsPara.frequency)
- {
- return &(gatNvod[TsSequence].TsPara);
- }
- return NULL;
- }
- static INT32 KB_NVOD_SetCurrentTsPara(KB_DMDTunerParameters TsPara)
- {
- UINT8 i;
- UINT32 preTsNum, NowTsNum;
- preTsNum = KB_NVOD_GetCurrentTsNum();
-
- //将原当前流标志修改;如果是第一次搜索,当前流还没有设置
- if ((UINT32)(-1) != preTsNum)
- {
- gatNvod[preTsNum].CurrentTsFlag = FALSE;
- }
- for (i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (gatNvod[i].TsPara.frequency == TsPara.frequency)
- {
- //该ts流已经申请了gatNvod,修改当前流标志后return
- gatNvod[i].CurrentTsFlag = TRUE;
- return RET_OK;
- }
- }
- //该ts流未申请gatNvod
- NowTsNum = KB_NVOD_AllocategatNvodInfo(TsPara.frequency);
-
- if (KB_NVOD_ALLOCATE_FAIL == NowTsNum)
- {
- printf("nKB_EPG_SetCurrentTsNum::KB_NVOD_AllocategatNvodInfo fail!n");
- return RET_FAIL;
- }
- //理论上是不可能出现的情况, 因为前面已处理已申请的情况
- else if (KB_NVOD_ALLOCATE_REPEAT == NowTsNum)
- {
- for (i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (gatNvod[i].TsPara.frequency == TsPara.frequency)
- {
- gatNvod[i].CurrentTsFlag = TRUE;
- return RET_OK;
- }
- }
- }
- else
- {
- memcpy(&gatNvod[NowTsNum].TsPara, &TsPara, sizeof(KB_DMDTunerParameters));
- gatNvod[NowTsNum].CurrentTsFlag = TRUE;
- return RET_OK;
- }
-
- return RET_OK;
- }
- static UINT8 KB_NVOD_AllocategatNvodInfo(UINT32 frequency)
- {
- UINT8 i, ret = KB_NVOD_ALLOCATE_FAIL;
- for(i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (frequency == gatNvod[i].TsPara.frequency)
- {
- return KB_NVOD_ALLOCATE_REPEAT;
- }
- }
-
- for (i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (0 == gatNvod[i].TsPara.frequency)
- {
- ret = i;
- break;
- }
- }
- return ret;
- }
- void KB_NVOD_FreegatNvodInfo(UINT32 frequency)
- {
- UINT8 i;
-
- for (i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (frequency == gatNvod[i].TsPara.frequency)
- {
- memset(&gatNvod[i], 0, sizeof(KB_NVOD_Info));
- gatNvod[i].CurrentTsFlag = FALSE;
- gatNvod[i].SearchCompleteFlag = FALSE;
- return;
- }
- }
- return;
- }
- BOOL KB_NVOD_IsThisTsShallSearched(UINT32 frequency)
- {
- UINT8 i;
- for(i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (frequency == gatNvod[i].TsPara.frequency)
- {
- return gatNvod[i].SearchCompleteFlag;
- }
- }
- printf("nKB_NVOD_IsThisTsShallSearch::input frequency error!n");
- return FALSE;
- }
- BOOL KB_NVOD_IsTsShallSearched(void)
- {
- UINT8 i;
- //UINT8 flag = 0xff;
- for(i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (0 != gatNvod[i].TsPara.frequency
- && TRUE == gatNvod[i].SearchStartFlag
- && TRUE == gatNvod[i].SearchCompleteFlag)
- {
-
- }
- else
- {
- return TRUE;
- }
- }
- return FALSE;
- }
- void KB_NVOD_GetValidFreInfo(UINT8 *pNum, KB_NVOD_Info *Address[])
- {
- UINT8 i = 0;
- if (NULL == pNum || NULL == Address)
- {
- printf("nKB_NVOD_GetValidFreInfo::input err!");
- return;
- }
- #if 1
- //刷新播放时间列表,干掉所有过期的ShiftEvent
- if (TRUE != KB_NVOD_RefreshSchEvent())
- {
- printf("nKB_NVOD_GetValidFreInfo::refresh ShiftEvent failed.");
- }
- #endif
- *pNum = 0;
-
- for(i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (0 != gatNvod[i].TsPara.frequency)
- {
- Address[(*pNum)] = gatNvod + i;
- (*pNum)++;
- }
- }
- return;
- }
- BOOL KB_NVOD_PlayForGrap(int nPrgCurRow, int nSchCurRow)
- {
- UINT32 i = 0;
- UINT8 TsIndex = 0xff, RefEventIndex = 0xff;
-
- KB_DMDTunerParameters *pTsPara = NULL;
- //参数自减的原因是: 界面传入的RefEvent条目(即nPrgCurRow)、SchEvent条目(即nSchCurRow)编号从1开始
- nPrgCurRow--;
- nSchCurRow--;
- if (nPrgCurRow < 0 || nSchCurRow < 0)
- {
- printf("nKB_NVOD_PlayForGrap::input error!");
- return FALSE;
- }
- for (i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (0 != gatNvod[i].TsPara.frequency)
- {
- nPrgCurRow -= (int)(KB_NvodGetRefEventNum(i));
- }
- if (nPrgCurRow < 0)
- {
- TsIndex = (UINT8)i;
- RefEventIndex = (UINT8)(nPrgCurRow + KB_NvodGetRefEventNum(i));
- break;
- }
- }
- if (TsIndex >= KB_NVOD_MAX_TS_NUM || RefEventIndex >= KB_NVOD_MAX_RefEvent_One_Ts)
- {
- printf("nKB_NVOD_PlayForGrap::TsIndex or RefEventIndex error!n");
- return FALSE;
- }
-
- if (TsIndex != KB_NVOD_GetCurrentTsNum())
- {
- printf("nKB_NVOD_PlayForGrap::Ts switched!n");
- KD_NVODStopAllPF();
- KD_NVODStopAllSch();
- KB_DMDDropSignal();
- pTsPara = KB_NVOD_GetTsParaFromTsSequence(TsIndex);
- if (NULL == pTsPara)
- {
- printf("nKB_NVOD_PlayForGrap::KB_NVOD_GetTsParaFromTsSequence error!n");
- return FALSE;
- }
- KB_DMDConnectSignal(pTsPara);
- KB_OSPTaskDelay(50);
- KB_NVODGetEit();
- }
- KD_NVODStartPlay((gatNvod[TsIndex].RefEventData[RefEventIndex].TimeNode[nSchCurRow].tsID),
- (gatNvod[TsIndex].RefEventData[RefEventIndex].TimeNode[nSchCurRow].SerID));
- return TRUE;
- }
- const KB_NVODStruct *KB_NVOD_GetCurRefEventInfoForGrap(int nPrgCurRow)
- {
- UINT32 i = 0;
- UINT8 TsIndex = 0xff, RefEventIndex = 0xff;
- //参数自减的原因是: 界面传入的RefEvent条目(即nPrgCurRow)、SchEvent条目(即nSchCurRow)编号从1开始
- nPrgCurRow--;
- if (nPrgCurRow < 0)
- {
- printf("nKB_NVOD_GetCurRefEventInfoForGrap::input error!");
- return NULL;
- }
- for (i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- if (0 != gatNvod[i].TsPara.frequency)
- {
- nPrgCurRow -= (int)(KB_NvodGetRefEventNum(i));
- }
- if (nPrgCurRow < 0)
- {
- TsIndex = (UINT8)i;
- RefEventIndex = (UINT8)(nPrgCurRow + KB_NvodGetRefEventNum(i));
- break;
- }
- }
- if (TsIndex >= KB_NVOD_MAX_TS_NUM || RefEventIndex >= KB_NVOD_MAX_RefEvent_One_Ts)
- {
- printf("nKB_NVOD_GetCurRefEventInfoForGrap::TsIndex or RefEventIndex error!n");
- return NULL;
- }
-
-
- return &(gatNvod[TsIndex].RefEventData[RefEventIndex]);
- }
- //刷新已搜索好的每个NVOD参考时间的ShiftEvent列表, 干掉所有过期的ShiftEvent
- BOOL KB_NVOD_RefreshSchEvent(void)
- {
- UINT16 i = 0; //频点循环参数
- UINT16 j = 0; //参考事件循环参数
- UINT16 k = 0; //ShiftEvent循环参数
- UINT16 count = 0; //计算过期的ShiftEvent个数
-
-
- if (0 == gNvodTime)
- {
- printf("nKB_NVOD_RefreshSchEvent::gNvodTime 未获取");
- return FALSE;
- }
- for(i = 0; i < KB_NVOD_MAX_TS_NUM; i++)
- {
- //该频点没有参考事件,则察看下一频点信息
- if (0 == gatNvod[i].RefEventNum)
- {
- continue;
- }
- for (j = 0; j < gatNvod[i].RefEventNum; j++)
- {
- //本参考事件无时移事件,则察看本频点的下一个参考事件信息
- if (0 == gatNvod[i].RefEventData[j].TimeNum)
- {
- continue;
- }
- //对频点i的第j个参考事件的ShiftEvent列表, 按时间先后进行排序
- KB_NVOD_DirectInsertSort(gatNvod[i].RefEventData[j].TimeNode,
- gatNvod[i].RefEventData[j].TimeNum);
- count = 0;
- //计算目前总共有几个ShiftEvent过期
- for (k = 0; k < gatNvod[i].RefEventData[j].TimeNum; k++)
- {
- if (gatNvod[i].RefEventData[j].TimeNode[k].startTime + gatNvod[i].RefEventData[j].durTime < gNvodTime)
- {
- count++;
- }
- else
- {
- break;
- }
- }
- if (count > 0)
- {
- for (k = 0; (k + count) < gatNvod[i].RefEventData[j].TimeNum; k++)
- {
- gatNvod[i].RefEventData[j].TimeNode[k].tsID = gatNvod[i].RefEventData[j].TimeNode[(k+count)].tsID;
- gatNvod[i].RefEventData[j].TimeNode[k].SerID = gatNvod[i].RefEventData[j].TimeNode[(k+count)].SerID;
- gatNvod[i].RefEventData[j].TimeNode[k].EvtID = gatNvod[i].RefEventData[j].TimeNode[(k+count)].EvtID;
- gatNvod[i].RefEventData[j].TimeNode[k].startTime = gatNvod[i].RefEventData[j].TimeNode[(k+count)].startTime;
- }
- }
- gatNvod[i].RefEventData[j].TimeNum -= count;
- }
- }
- return TRUE;
- }
- //直接插入排序, 在基本有序和SIZE很小时是最好的排序方法
- static void KB_NVOD_DirectInsertSort(KB_NVODTime TimeNode[], UINT16 TimeNum)
- {
- int i = 0, j = 0;
- KB_NVODTime tmp;
- if (0 == TimeNum || TimeNum > 500 || NULL == TimeNode)
- {
- printf("nKB_NVOD_DirectInsertSort::input TimeNum(%d) error.", TimeNum);
- return;
- }
- for (i = 1; i < TimeNum; i++)
- {
- if (TimeNode[i].startTime < TimeNode[i-1].startTime)
- {
- tmp.tsID = TimeNode[i].tsID;
- tmp.SerID = TimeNode[i].SerID;
- tmp.EvtID = TimeNode[i].EvtID;
- tmp.startTime = TimeNode[i].startTime;
- TimeNode[i].tsID = TimeNode[i-1].tsID;
- TimeNode[i].SerID = TimeNode[i-1].SerID;
- TimeNode[i].EvtID = TimeNode[i-1].EvtID;
- TimeNode[i].startTime = TimeNode[i-1].startTime;
-
- for(j = i-2; j >= 0 && tmp.startTime < TimeNode[j].startTime; --j)
- {
- TimeNode[j+1].tsID = TimeNode[j].tsID;
- TimeNode[j+1].SerID = TimeNode[j].SerID;
- TimeNode[j+1].EvtID = TimeNode[j].EvtID;
- TimeNode[j+1].startTime = TimeNode[j].startTime;
- }
- TimeNode[j+1].tsID = tmp.tsID;
- TimeNode[j+1].SerID = tmp.SerID;
- TimeNode[j+1].EvtID = tmp.EvtID;
- TimeNode[j+1].startTime = tmp.startTime;
- }
- }
- return;
- }
- time_t KB_NVOD_GetNvodTime(void)
- {
- return gNvodTime;
- }
- /* EOF */