avplay.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:30k
- #include <string.h>
- #include "avplay.h"
- #include "db.h"
- #include "dmd.h"
- #include "db.h"
- #include "appltype.h"
- #include "av.h"
- #include "epg.h"
- #include "timeclk.h"
- #include "ca_user.h"
- #include <string.h>
- #include "sipsi.h"
- #include "timer.h"
- #include "KB_MenuData.h"
- #include "kb_machblue_client_task.h"
- #define J_PLAY_USE_PID FALSE
- //#define J_PLAY_USE_PID TRUE
- typedef enum
- {
- PLAY_START,
- PLAY_STOP,
- PLAY_PAUSE,
- PLAY_RESUME,
- PLAY_START_IFRAME,
- PLAY_STOP_IFRAME
- }PlayRequest;
- typedef struct
- {
- INT32 nTsId;
- INT32 nPgmNum;
- INT32 nPmtPid;
- INT32 nVideoPid;
- INT32 nAudioPid;
- INT32 nPcrPid;
- INT32 nCaFlag;
- }DTV_AVINFO;
- static UINT32 gDtvTaskID;
- static UINT32 gDtvQueID;
- static KB_SIPatStruct gDtvPat;
- static KB_SIPmtStruct gDtvPmt;
- static KB_SICatStruct gDtvCat;
- static KB_SIPmtStruct gDtvPrePmt;
- static KB_SICatStruct gDtvPreCat;
- static DTV_AVINFO gCurPrg;
- static KB_DTVRunCallback gDtvCallBack;
- static UINT32 gDtvPmtTimer = 0xffffffff;
- static UINT32 gDtvCatTimer = 0xffffffff;
- static KB_DTVPrgAVInfo gPrePrgInfo;
- static KB_DTVPrgAVInfo gCurPrgInfo;
- static KB_DTVStatus gPlayStatus;
- time_t g_avTime;
- static KB_DBPrgNode gtPgmNode;
- static KB_DBPRGPID gPgmPid;
- static UINT8 gCurTrace;
- static UINT8 gCurVolume = 20;
- static INT32 gMuteFlag;
- static INT32 gPrgClass[2];
- static void DTV_HandleTuner(KB_OSPMsgNode *pInMsg);
- static void DTV_HandleSI_AV(KB_OSPMsgNode *pInMsg);
- static void DTV_HandleTuner_AV(KB_OSPMsgNode *pInMsg);
- static void DTV_HandleMsg_2(KB_OSPMsgNode *pInMsg);
- //static void DTV_ChangeType(INT32 nOldType, INT32 nNewType);
- static void DTV_AVCallbackHandle(int intype);
- static void DTV_Task(void);
- static INT32 DTV_HandleMsg_1(KB_OSPMsgNode *pInMsg);
- static INT32 DTV_HandleSI(KB_OSPMsgNode *pInMsg);
- static INT32 DTV_HandlePmt(KB_OSPMsgNode *pInMsg);
- static INT32 DTV_GetPmtPid(INT32 nSvcNO);
- static void DTV_CallbackHandle(INT32 nSuccess,
- INT32 nHours,
- INT32 nMinutes,
- INT32 nSeconds);
- static void DTV_PmtTimer(void);
- static void DTV_CatTimer(void);
- static INT32 DTV_HandleCat(KB_OSPMsgNode *pInMsg);
- static KB_DTVSinglePrgInfo gPrePrg;
- static KB_DTVSinglePrgInfo gRetPrg;
- extern void KB_MENUTranslateMsg(KB_OSPMsgNode* pInMsg);
- extern void kb_mb_service_context_evaluation(int serviceIndex,int service_type);
- extern INT32 STB_StateSwitch(INT32 nApplet);
- extern void LED_ShowString(char *str);
- INT32 KB_DTVInit(void)
- {
- memset(&gPrePrgInfo, 0, sizeof(KB_DTVPrgAVInfo));
- memset(&gCurPrgInfo,0, sizeof(KB_DTVPrgAVInfo));
-
- gMuteFlag = FALSE;
- gPrePrg.prgType = 0xFFFFFFFF;
- gPrePrg.ndtvNO = 0xFFFFFFFF;
- gPrePrg.nradNO = 0xFFFFFFFF;
-
- gRetPrg.prgType = 0xFFFFFFFF;
- gRetPrg.ndtvNO = 0xFFFFFFFF;
- gRetPrg.nradNO = 0xFFFFFFFF;
-
- KB_DTVMute(FALSE);
- KB_OSPQueInit("PLAY", 64, &gDtvQueID);
- KB_OSPTaskInit("PLAY",
- 1024 * 32,
- (void (*)(void*))DTV_Task,
- PLAY_PRIORITY,
- NULL,
- &gDtvTaskID);
- gDtvPmtTimer = KB_TimerCreate(KB_TIMER_REPEAT,
- (KB_TIMER_FUNC_POINTER)DTV_PmtTimer,
- NULL);
- gDtvCatTimer = KB_TimerCreate(KB_TIMER_REPEAT,
- (KB_TIMER_FUNC_POINTER)DTV_CatTimer,
- NULL);
-
- memset(&gCurPrg, 0, sizeof(DTV_AVINFO));
- gDtvCallBack = NULL;
- KB_AVHandlePlayState(DTV_CallbackHandle);
-
- return RETOK;
- }
- INT32 KB_DTVCreate(void)
- {
- KB_EpgCallBack(DTV_HandleTuner_AV);
- KB_DTVCallBack(DTV_AVCallbackHandle);
-
- KB_SIGetTime(&g_avTime);
- if (gCurPrgInfo.prgNO == 0xFFFFFFFF)
- {
- KB_DTVSetPreChnnl();
- }
-
- KB_DTVRun();
- KB_DTVGetEitPF();
-
- return RETOK;
- }
- INT32 KB_DTVDestroy(void)
- {
- KB_DTVStopAV();
- return RETOK;
- }
- INT32 KB_DTVAVHandleMsg(KB_OSPMsgNode *pInMsg)
- {
- switch (pInMsg->Word1)
- {
- case MOD_TUNER:
- DTV_HandleTuner(pInMsg);
- break;
- case MOD_SIPSI:
- DTV_HandleSI_AV(pInMsg);
- KB_DTVHandleMsg(pInMsg);
- break;
- case J_EPG_MODULE:
- DTV_HandleTuner_AV(pInMsg);
- break;
- case J_AVAPPLET_MODULE:
- DTV_HandleMsg_2(pInMsg);
- break;
-
- default:
- break;
- }
- return RETOK;
- }
- INT32 KB_DTVSetPreChnnl(void)
- {
- INT32 prgType, nProgram, nTotalProgram;
-
- prgType = KB_DTVGetPrePrgType();
- switch (prgType)
- {
- case DTVPRG:
- nProgram = KB_DTVGetPreDtvNO();
- break;
- case RADIOPRG:
- nProgram = KB_DTVGetPreRadNO();
- break;
- default:
- prgType = DTVPRG;
- nProgram = 1;
- break;
- }
-
- nTotalProgram = KB_DBGetPrgTotal((UINT8)prgType);
- if (nProgram > nTotalProgram || nProgram <= 0)
- {
- nProgram = 1;
- }
-
- KB_DTVSetPrg((int)prgType, (int)nProgram);
-
- return RETOK;
- }
- static void KB_ProcDtvrunCheck(int PrgType, int PrgNO)
- {
- INT32 nTotal = 0;
-
- if (PrgType != DTVPRG && PrgType != RADIOPRG)
- {
- printf("nKB_ProcDtvrunCheck::input prgType(%d) error!", PrgType);
-
- PrgType = DTVPRG;
- PrgNO = 1;
- nTotal = KB_DBGetPrgTotal(PrgType);
- if (nTotal > KB_DB_MAX_DTV || 0 == nTotal)
- {
- printf("nKB_ProcDtvrunCheck::There is no way now, dtv total(%d)!", nTotal);
- return;
- }
- KB_DTVSetPrg(PrgType, PrgNO);
- return;
- }
- nTotal = KB_DBGetPrgTotal(PrgType);
- if (DTVPRG == PrgType)
- {
- if (nTotal > KB_DB_MAX_DTV || 0 == nTotal)
- {
- printf("nKB_ProcDtvrunCheck::dtv nTotal(%d) error!", nTotal);
- return;
- }
- }
- else if (RADIOPRG == PrgType)
- {
- if (nTotal > KB_DB_MAX_RAD || 0 == nTotal)
- {
- printf("nKB_ProcDtvrunCheck::rad nTotal(%d) error!", nTotal);
- return;
- }
- }
- else
- {
- printf("nKB_ProcDtvrunCheck::PrgType(%d) error", PrgType);
- return;
- }
- if (PrgNO > nTotal)
- {
- PrgNO = 1;
- KB_DTVSetPrg(PrgType, PrgNO);
- }
- return;
- }
- INT32 KB_DTVSetPrg(int prgType, int prgNO)
- {
- if (prgType != DTVPRG && prgType != RADIOPRG)
- {
- return RETFAIL3;
- }
- if (gPrePrgInfo.prgType == prgType
- && gPrePrgInfo.prgNO == prgNO)
- {
- return RETOK;
- }
-
- gPrePrgInfo.prgType = prgType;
- gPrePrgInfo.prgNO = prgNO;
- gRetPrg.prgType = gPrePrg.prgType;
- gPrePrg.prgType = prgType;
-
- if (prgType == DTVPRG)
- {
- if (gRetPrg.ndtvNO != gPrePrg.ndtvNO)
- {
- gRetPrg.ndtvNO = gPrePrg.ndtvNO;
- }
- gPrePrg.ndtvNO = prgNO;
- }
- else
- {
- if (gRetPrg.nradNO != gPrePrg.nradNO)
- {
- gRetPrg.nradNO = gPrePrg.nradNO;
- }
- gPrePrg.nradNO = prgNO;
- }
- return RETOK;
- }
- INT32 KB_DTVGetPrg(int *pPrgType, int *pPrgNO)
- {
- *pPrgType = gPrePrgInfo.prgType;
- *pPrgNO = gPrePrgInfo.prgNO;
- return RETOK;
- }
- INT32 KB_DTVGetPreDtvNO(void)
- {
- return gPrePrg.ndtvNO;
- }
- INT32 KB_DTVGetPreRadNO(void)
- {
- return gPrePrg.nradNO;
- }
- void PlayCurrectProgram(void)
- {
- KB_DTVStart(gtPgmNode.Video_Pid, gtPgmNode.Audio_Pid, gtPgmNode.PCR_Pid);
-
- }
- INT32 KB_DTVGetPrePrgType(void)
- {
- return gPrePrg.prgType;
- }
- static void DTV_HandleTuner(KB_OSPMsgNode *pInMsg)
- {
- switch (pInMsg->Word2)
- {
- case DMD_CALLBACK_SIGNAL_CONNECTED:
- gPlayStatus = KB_DTVRUN;
- #if (J_PLAY_USE_PID == TRUE)
- {
- KB_DTVStart(gPgmPid.Video_Pid, gPgmPid.Audio_Pid, gPgmPid.PCR_Pid);
- }
- #else
- {
- KB_DTVStartCA(0, gCurPrgInfo.nSvcID);
- }
- #endif
- KB_MENUTranslateMsg(pInMsg);
- break;
- case DMD_CALLBACK_SIGNAL_LOST:
- {
- KB_MENUTranslateMsg(pInMsg);
- }
- break;
-
- default:
- break;
- }
- return;
- }
- INT32 KB_DTVRun(void)
- {
- KB_DMDTunerParameters tTs;
- //INT32 nSvcID;
- UINT16 ndbTIMER_Mode;
- KB_OSPMsgNode msg;
- KB_ProcDtvrunCheck(gPrePrgInfo.prgType, gPrePrgInfo.prgNO);
-
- ndbTIMER_Mode = KB_DBGetChnlInfoByPrgNO(gPrePrgInfo.prgType, gPrePrgInfo.prgNO,
- &gPrePrgInfo.nFrequency, &gPrePrgInfo.nSymbol,
- &gPrePrgInfo.nQamTyep);
- gPrePrgInfo.nSvcID = KB_DBGetSvcIDByNO(gPrePrgInfo.prgType,
- gPrePrgInfo.prgNO - 1);
- if (gPrePrgInfo.prgType == gCurPrgInfo.prgType
- && gPrePrgInfo.prgNO == gCurPrgInfo.prgNO
- && gPrePrgInfo.nSvcID== gCurPrgInfo.nSvcID
- && gPlayStatus == KB_DTVRUN)
- {
- return RETOK;
- }
- KB_CAService(KB_CA_CLOSE,0);
- KB_DTVStop();
- if ((KB_AVGetIFrameFlag() == FALSE)
- && gPrePrgInfo.prgType == RADIOPRG)
- {
- //KB_DTVStop();
- KB_AVPlayIFrame((UINT8 *)IFrmae_Logo_Data,
- IFrmae_Logo_Data_length);
- }
- if ((KB_AVGetIFrameFlag() == TRUE)
- && gPrePrgInfo.prgType == DTVPRG)
- {
- //KB_DTVStop();
- KB_AVStopIFrame();
- }
-
- KB_DBSaveCurPrgInfo(gPrePrgInfo.prgNO,
- gPrePrgInfo.prgType);
-
- gCurPrgInfo.prgType = gPrePrgInfo.prgType;
- gCurPrgInfo.prgNO = gPrePrgInfo.prgNO;
- gCurPrgInfo.nSvcID = gPrePrgInfo.nSvcID;
- //added by whale 07/06/03
- //KB_DBGetVolumeByPrgNo(&gCurVolume, gPrePrgInfo.prgType,gPrePrgInfo.prgNO);
- //added by yyj 2007.6.14
- KB_DBGetPgmCurVol(&gCurVolume);
- KB_DTVSetVolume(gCurVolume);
- //printf("n[KB_DTVRun]:gCurVolume=%dn",gCurVolume);
- gCurTrace = KB_DTVGetTrack();
- KB_AVSetPrgTrack(gCurTrace);
-
- KB_DBGetPrgAvInfoByPrgNo(gPrePrgInfo.prgType,gPrePrgInfo.prgNO,&gPgmPid);
-
- gPlayStatus = KB_DTVSTOP;
- //KB_DTVStop();
- KB_EPGStopAllEITPF();
-
- if (gPrePrgInfo.nFrequency == gCurPrgInfo.nFrequency
- && gPrePrgInfo.nSymbol == gCurPrgInfo.nSymbol
- && gPrePrgInfo.nQamTyep == gCurPrgInfo.nQamTyep)
- {
- KB_DMDGetSignalParameters(&tTs);
- if (KB_DMDQuerySignalStatus() == TRUE
- && tTs.frequency == gCurPrgInfo.nFrequency / 1000
- && tTs.details.qam.symbolRatekSs == gCurPrgInfo.nSymbol / 1000
- && tTs.details.qam.modulation == gCurPrgInfo.nQamTyep)
- {
- gPlayStatus = KB_DTVRUN;
- #if (J_PLAY_USE_PID == TRUE)
- {
- KB_DTVStart(gPgmPid.Video_Pid, gPgmPid.Audio_Pid, gPgmPid.PCR_Pid);
- }
- #else
- {
- KB_DTVStartCA(0, gCurPrgInfo.nSvcID);
- }
- #endif
- }
- else
- {
- tTs.type = DMD_TYPE_QAM;
- tTs.inversion = INVERSION_AUTO;
- tTs.frequency = gCurPrgInfo.nFrequency / 1000;
- tTs.details.qam.symbolRatekSs = gCurPrgInfo.nSymbol / 1000;
- tTs.details.qam.modulation = gCurPrgInfo.nQamTyep;
- KB_DMDDropSignal();
- KB_DMDConnectSignal(&tTs);
- //msg to movie client
- msg.Word1=KB_CLIENT_FRE_SWITCH;
- msg.Word2=gCurPrgInfo.nFrequency;
- msg.Word3=gCurPrgInfo.nSymbol;
- msg.Word4=gCurPrgInfo.nQamTyep;
- kb_machblue_task_post(&msg);
- }
- }
- else
- {
- tTs.type = DMD_TYPE_QAM;
- tTs.inversion = INVERSION_AUTO;
- tTs.frequency = gPrePrgInfo.nFrequency / 1000;
- tTs.details.qam.symbolRatekSs = gPrePrgInfo.nSymbol / 1000;
- tTs.details.qam.modulation = gPrePrgInfo.nQamTyep;
- gCurPrgInfo.nFrequency = gPrePrgInfo.nFrequency;
- gCurPrgInfo.nSymbol = gPrePrgInfo.nSymbol;
- gCurPrgInfo.nQamTyep = gPrePrgInfo.nQamTyep;
-
- KB_DMDDropSignal();
- KB_DMDConnectSignal(&tTs);
- //msg to movie client
- msg.Word1=KB_CLIENT_FRE_SWITCH;
- msg.Word2=gCurPrgInfo.nFrequency;
- msg.Word3=gCurPrgInfo.nSymbol;
- msg.Word4=gCurPrgInfo.nQamTyep;
- kb_machblue_task_post(&msg);
- }
- //add by steven
- //led show
- {
- char pLED[4];
- if((gCurPrgInfo.prgNO>0)&&(gCurPrgInfo.prgNO<10))
- sprintf(pLED,"%s%d","C00",gCurPrgInfo.prgNO);
- else if((gCurPrgInfo.prgNO>=10)&&(gCurPrgInfo.prgNO<100))
- sprintf(pLED,"%s%d","C0",gCurPrgInfo.prgNO);
- else if((gCurPrgInfo.prgNO>=100)&&(gCurPrgInfo.prgNO<1000))
- sprintf(pLED,"%s%d","C",gCurPrgInfo.prgNO);
-
- LED_ShowString(pLED);
- }
- //end add by steven
-
- kb_mb_service_context_evaluation(gCurPrgInfo.prgNO,gCurPrgInfo.prgType);
-
- return RETOK;
- }
- INT32 KB_DTVStopAV(void)
- {
- gPlayStatus = KB_DTVSTOP;
- KB_DTVStop();
- KB_EPGStopAllEITPF();
-
- if (gCurPrgInfo.prgType == RADIOPRG)
- {
- KB_DTVStopIFrame();
- }
-
- gCurPrgInfo.prgNO = 0xFFFFFFFF;
-
- return RETOK;
- }
- void KB_DTVPlayPrg(int prgType, int prgNO)
- {
- KB_DTVSetPrg(prgType, prgNO);
- KB_DTVRun();
- }
- INT32 KB_DTVRunNextPrg(KB_DBPRGType prgType)
- {
- KB_DTVSetNextPrg(prgType);
- KB_DTVRun();
-
- return RETOK;
- }
- INT32 KB_DTVRunPrePrg(KB_DBPRGType prgType)
- {
- KB_DTVSetPrePrg(prgType);
- KB_DTVRun();
-
- return RETOK;
- }
- KB_DTVStatus KB_DTVGetRunFlag(void)
- {
- return gPlayStatus;
- }
- INT32 KB_DTVSetVolume(UINT8 nVolume)
- {
- if (nVolume < 0 || nVolume > KB_AV_MAX_VOLUME - 1)
- {
- return RETFAIL3;
- }
-
- gCurVolume = nVolume;
- KB_AVSetVolume(nVolume);
- //added by yyj 2007.6.14
- KB_DBSavePgmCurVol(gCurVolume);
- return RETOK;
- }
- INT32 KB_DTVGetVolume(void)
- {
- return gCurVolume;
- }
- INT32 KB_DTVMute(BOOL nMute)
- {
- if (nMute != TRUE && nMute != FALSE)
- {
- return RETFAIL3;
- }
-
- if (gMuteFlag != nMute)
- {
- gMuteFlag = nMute;
- KB_AVSetMute(nMute);
- }
- return RETOK;
- }
- INT32 KB_DTVGetMuteFlag(void)
- {
- return gMuteFlag;
- }
- INT32 KB_DTVGetEitPF(void)
- {
- KB_EPGStopAllEITPF();
-
- KB_EPGGetEITPF(gCurPrgInfo.nSvcID);
-
- return RETOK;
- }
- static void DTV_HandleSI_AV(KB_OSPMsgNode *pInMsg)
- {
- switch (pInMsg->Word2)
- {
- case KB_SI_MSG_TDT_DONE:
- KB_TimeSetCurTime(*((time_t*)pInMsg->Word3));
- KB_MENUTranslateMsg(pInMsg);
- break;
- case KB_SI_MSG_NIT_CHANGE:
- KB_MENUTranslateMsg(pInMsg);
- break;
- case KB_SI_MSG_SDT_CHANGE:
- KB_MENUTranslateMsg(pInMsg);
- break;
-
- default:
- break;
- }
- return;
- }
- static void DTV_HandleTuner_AV(KB_OSPMsgNode *pInMsg)
- {
- KB_SIEitPF *ptEitPf;
-
- switch (pInMsg->Word2)
- {
- case EPG_MSG_PF_DONE:
- ptEitPf = (KB_SIEitPF*)pInMsg->Word3;
- if (ptEitPf != NULL)
- {
- if (gCurPrgInfo.nSvcID == ptEitPf->service_id)
- {
- KB_MENUTranslateMsg(pInMsg);
- }
- }
-
- break;
- case EPG_MSG_PF_TIMEOUT:
- break;
-
- default:
- break;
- }
- return;
- }
- static void DTV_HandleMsg_2(KB_OSPMsgNode *pInMsg)
- {
- switch (pInMsg->Word2)
- {
- case KB_DTVOK:
- KB_MENUTranslateMsg(pInMsg);
- break;
- case KB_DTVFAIL:
- KB_MENUTranslateMsg(pInMsg);
- break;
-
- default:
- break;
- }
- return;
- }
- INT32 KB_DTVGetClass(INT32 nPrgType)
- {
- return gPrgClass[nPrgType];
- }
- void KB_DTVSetClass(INT32 nPrgType, INT32 iPlayClass)
- {
-
- gPrgClass[nPrgType] = iPlayClass;
- }
- #if 0
- static void DTV_ChangeType(INT32 nOldType, INT32 nNewType)
- {
- if (nOldType == DTVPRG)
- {
- KB_DTVStop();
- //DTV_StartIFrame(gatPlayIframeData, J_PLAY_IFRAME_DATA_SIZE);
- }
- else
- {
- //DTV_StopIFrame();
- }
- }
- #endif
- INT32 KB_DTVSetTrack(KB_DBTRACK nTrackType)
- {
-
- //UINT8 bTrackAndVol = 0;
- if (nTrackType != gCurTrace)
- {
- gCurTrace = nTrackType;
- KB_AVSetPrgTrack(gCurTrace);
- //modified by yyj 2007.6.27
- KB_DBSavePgmCurTrack(gCurTrace);
- //bTrackAndVol = ((gCurTrace & 0x03) << 5) | (gCurVolume & 0x1F);
- //KB_DBSaveTrace(gCurPrgInfo.prgType, gCurPrgInfo.prgNO,
- // bTrackAndVol);
- }
- return RETOK;
- }
- INT32 KB_DTVSetPrePrg(KB_DBPRGType prgType)
- {
- int channelNo, totalChannels;
-
- channelNo = gPrePrgInfo.prgNO;
- totalChannels = KB_DBGetPrgTotal(prgType);
- if((channelNo <= 1) || (channelNo > totalChannels))
- {
- channelNo = (totalChannels + 1);
- }
- channelNo --;
- if(channelNo == 0)
- {
- channelNo = 1;
- }
- KB_DTVSetPrg(prgType, channelNo);
- return RETOK;
- }
- KB_DBTRACK KB_DTVGetTrack(void)
- {
- // UINT8 bTrack;
-
- //KB_DBGetPgmCurTrack(&bTrack);
- // bTrack = KB_DBGetPrgTrace(gCurPrgInfo.prgType,
- // gCurPrgInfo.prgNO);
- //return bTrack;
- //modified by yyj 2007.6.27
- return gCurTrace;
- }
- INT32 KB_DTVSaveCurVolume(void)
- {
-
- UINT8 bTrackAndVol = 0;
- bTrackAndVol = ((gCurTrace & 0x03) << 5) | (gCurVolume & 0x1F);
- KB_DBSaveTrace(gCurPrgInfo.prgType, gCurPrgInfo.prgNO,
- bTrackAndVol);
- return RETOK;
- }
- INT32 KB_DTVSetNextPrg(KB_DBPRGType prgType)
- {
- int channelNo, totalChannels;
-
- channelNo = gPrePrgInfo.prgNO;
- totalChannels = KB_DBGetPrgTotal(prgType);
- channelNo ++;
- if(channelNo > totalChannels)
- channelNo = 1;
- KB_DTVSetPrg(prgType, channelNo);
- return RETOK;
- }
- INT32 KB_DTVSetRetPrg(KB_DBPRGType nCurPrg)
- {
- INT32 prgType, nProgram, nTotalProgram;
-
- prgType = KB_DTVGetPrePrgType();
- if (prgType == 0xFFFFFFFF)
- {
- nProgram = 0xFFFFFFFF;
- }
- else
- {
- if (nCurPrg == prgType)
- {
- switch (prgType)
- {
- case DTVPRG:
- nProgram = KB_DTVGetPreDtvNO();
- break;
- case RADIOPRG:
- nProgram = KB_DTVGetPreRadNO();
- break;
- default:
- prgType = DTVPRG;
- nProgram = 1;
- break;
- }
- }
- else
- {
- switch (prgType)
- {
- case DTVPRG:
- nProgram = KB_DTVGetPreDtvNO();
- break;
- case RADIOPRG:
- nProgram = KB_DTVGetPreRadNO();
- break;
- default:
- prgType = DTVPRG;
- nProgram = 1;
- break;
- }
- }
- }
-
- nTotalProgram = KB_DBGetPrgTotal((UINT8)prgType);
- if (nProgram < nTotalProgram && nProgram > 0)
- {
- KB_DTVSetPrg((int)prgType, (int)nProgram);
- }
-
- return RETOK;
- }
- INT32 DTV_GetRetChnnl(KB_DBPRGType nCurPrg)
- {
- INT32 prgType, nProgram, nTotalProgram;
-
- prgType = KB_DTVGetPrePrgType();
- if (nCurPrg == prgType)
- {
- switch (prgType)
- {
- case DTVPRG:
- nProgram = KB_DTVGetPreDtvNO();
- break;
- case RADIOPRG:
- nProgram = KB_DTVGetPreRadNO();
- break;
- default:
- prgType = DTVPRG;
- nProgram = 1;
- break;
- }
- }
- else
- {
- switch (prgType)
- {
- case DTVPRG:
- nProgram = KB_DTVGetPreDtvNO();
- break;
- case RADIOPRG:
- nProgram = KB_DTVGetPreRadNO();
- break;
- default:
- prgType = DTVPRG;
- nProgram = 1;
- break;
- }
- }
-
- nTotalProgram = KB_DBGetPrgTotal((UINT8)prgType);
- if (nProgram > nTotalProgram || nProgram <= 0)
- {
- nProgram = 1;
- }
- KB_DTVSetPrg((int)prgType, (int)nProgram);
-
- return RETOK;
- }
- INT32 KB_DTVGetRetDtvNO(void)
- {
- return gRetPrg.ndtvNO;
- }
- INT32 KB_DTVGetRetRadNO(void)
- {
- return gRetPrg.nradNO;
- }
- INT32 KB_DTVGetRetPrgType(void)
- {
- return gRetPrg.prgType;
- }
- INT32 KB_DTVStart(UINT32 nVideoPid, UINT32 nAudioPid, UINT32 nPcrPid)
- {
- KB_OSPMsgNode msgNode;
- msgNode.Word1 = PLAY_START;
- msgNode.Word2 = nVideoPid;
- msgNode.Word3 = nAudioPid;
- msgNode.Word4 = nPcrPid;
- KB_OSPMsgSend(gDtvQueID, &msgNode);
- return RETOK;
- }
- INT32 KB_DTVStop(void)
- {
- KB_OSPMsgNode msgNode;
- msgNode.Word1 = PLAY_STOP;
-
- KB_OSPMsgSend(gDtvQueID, &msgNode);
- KB_TimerDisable(gDtvPmtTimer);
-
- return RETOK;
- }
- INT32 KB_DTVStartIFrame(UINT8 *pInData, INT32 nDataSize)
- {
- KB_OSPMsgNode msgNode;
- msgNode.Word1 = PLAY_START_IFRAME;
- msgNode.Word2 = (UINT32)pInData;
- msgNode.Word3 = (UINT32)nDataSize;
- KB_OSPMsgSend(gDtvQueID, &msgNode);
-
- return RETOK;
- }
- INT32 KB_DTVStopIFrame(void)
- {
- KB_OSPMsgNode msgNode;
- msgNode.Word1 = PLAY_STOP_IFRAME;
-
- KB_OSPMsgSend(gDtvQueID, &msgNode);
- return RETOK;
- }
- static void DTV_Task(void)
- {
- int i, nReturn;
- KB_OSPMsgNode msgNode;
-
- i = 1;
- while (i)
- {
- nReturn = KB_OSPMsgGet(gDtvQueID, KB_Wait, 0, &msgNode);
- if (nReturn != Ret_OK)
- {
- continue;
- }
- DTV_HandleMsg_1(&msgNode);
- }
-
- return;
- }
- INT32 KB_DTVHandleMsg(KB_OSPMsgNode *pInMsg)
- {
- switch (pInMsg->Word1)
- {
- case MOD_SIPSI:
- DTV_HandleSI(pInMsg);
- break;
- default:
- break;
- }
- return RETOK;
- }
- static INT32 DTV_HandleMsg_1(KB_OSPMsgNode *pInMsg)
- {
- switch (pInMsg->Word1)
- {
- case PLAY_START:
- KB_AVPlay(pInMsg->Word2, pInMsg->Word3, pInMsg->Word4);
- break;
- case PLAY_STOP:
- KB_AVStop();
- break;
- case PLAY_START_IFRAME:
- KB_AVPlayIFrame((UINT8*)pInMsg->Word2, pInMsg->Word3);
- break;
- case PLAY_STOP_IFRAME:
- KB_AVStopIFrame();
-
- default:
- break;
- }
- return RETOK;
- }
- INT32 KB_DTVStartCA(INT32 nTsId, INT32 nSvcID)
- {
- gCurPrg.nPgmNum = nSvcID;
- gCurPrg.nVideoPid = 0;
- gCurPrg.nAudioPid = 0;
- gCurPrg.nPcrPid = 0;
-
- memset(&gDtvPrePmt, 0, sizeof(KB_SIPmtStruct));
- KB_SIStopPat();
- KB_SIGetPat(&gDtvPat, KB_SI_RECEIVE_ONCE, -1);
- KB_SIStopCat();
- KB_SIGetCat(&gDtvCat, KB_SI_RECEIVE_ONCE, -1);
-
- KB_TimerEnable(gDtvPmtTimer, 5000);
- memset(&gDtvPreCat, 0, sizeof(KB_SICatStruct));
- KB_TimerEnable(gDtvCatTimer, 5000);
-
- return RETOK;
- }
- static INT32 DTV_HandleSI(KB_OSPMsgNode *pInMsg)
- {
- switch (pInMsg->Word2)
- {
- case KB_SI_MSG_PAT_DONE:
- gCurPrg.nPmtPid = DTV_GetPmtPid(gCurPrg.nPgmNum);
- if (gCurPrg.nPmtPid)
- {
- KB_SIStopPmt(-1);
- KB_SIGetPmt(gCurPrg.nPmtPid, gCurPrg.nPgmNum, &gDtvPmt, KB_SI_RECEIVE_ONCE, -1);
- KB_TimerEnable(gDtvPmtTimer, 5000);
- }
- break;
- case KB_SI_MSG_PAT_TIMEOUT:
- break;
- case KB_SI_MSG_PMT_DONE:
- DTV_HandlePmt(pInMsg);
- break;
- case KB_SI_MSG_PMT_TIMEOUT:
- break;
- case KB_SI_MSG_CAT_DONE:
- DTV_HandleCat(pInMsg);
- break;
- case KB_SI_MSG_CAT_TIMEOUT:
- break;
- case KB_SI_MSG_NIT_DONE:
- break;
-
- case KB_SI_MSG_NIT_TIMEOUT:
- break;
-
- default:
- break;
- }
- return RETOK;
- }
- static INT32 DTV_GetPmtPid(INT32 nSvcNO)
- {
- int i;
- int num;
- num = gDtvPat.num;
- for(i = 0; i < num; i ++)
- {
- if( gDtvPat.program[i].program_number == nSvcNO)
- {
- return (INT32)gDtvPat.program[i].program_map_PID;
- }
- }
-
- return 0;
- }
- static INT32 DTV_HandlePmt(KB_OSPMsgNode *pInMsg)
- {
- INT32 i;
- KB_SIPmtStruct *ptPmt;
- //static KB_SIPmtStruct thePre_pmt;
- INT32 nVideoPid, nAudioPid, nPcrPid;
-
- ptPmt = (KB_SIPmtStruct*)pInMsg->Word3;
- nVideoPid = nAudioPid = nPcrPid = 0;
- if (memcmp(&gDtvPrePmt, ptPmt, sizeof(KB_SIPmtStruct)) != 0)
- {
- for(i = 0;i< ptPmt->num;i++)
- {
- if ((ptPmt->stream[i].stream_type == 0x01)
- || (ptPmt->stream[i].stream_type == 0x02))
- {
- nVideoPid = ptPmt->stream[i].elementary_PID;
- }
- if ((ptPmt->stream[i].stream_type == 0x03)
- || (ptPmt->stream[i].stream_type == 0x04))
- {
- nAudioPid = ptPmt->stream[i].elementary_PID;
- }
- if (nVideoPid != 0 && nAudioPid != 0)
- {
- break;
- }
- }
- nPcrPid = ptPmt->PCR_PID;
- //printf("nChannel switch gCurPrg.nVideoPid[%d]nVideoPid[%d] gCurPrg.nAudioPid[%d]nAudioPid[%d] gCurPrg.nPcrPid [%d]nPcrPid[%d]",gCurPrg.nVideoPid,nVideoPid,gCurPrg.nAudioPid,nAudioPid,gCurPrg.nPcrPid,nPcrPid);
- if ( gCurPrg.nVideoPid != nVideoPid
- || gCurPrg.nAudioPid != nAudioPid
- || gCurPrg.nPcrPid != nPcrPid)
- {
- gCurPrg.nVideoPid = nVideoPid;
- gCurPrg.nAudioPid = nAudioPid;
- gCurPrg.nPcrPid = nPcrPid;
- KB_TimerDisable(gDtvPmtTimer);
- KB_TimerDisable(gDtvCatTimer);
-
- KB_DTVStart(nVideoPid, nAudioPid, nPcrPid);
- }
-
- memcpy(&gDtvPrePmt, ptPmt, sizeof(KB_SIPmtStruct));
- KB_CAService(KB_CA_PMTUPDATE, (void *)ptPmt);
-
-
- }
- return RETOK;
- }
- static void DTV_CallbackHandle(INT32 nSuccess,
- INT32 nHours,
- INT32 nMinutes,
- INT32 nSeconds)
- {
- INT32 nPlay;
-
- if(nSuccess)
- {
- nPlay = 0;
- }
- else
- {
- nPlay = 1;
- }
- if (gDtvCallBack)
- {
- gDtvCallBack((int)nPlay);
- }
- }
- KB_DTVRunCallback KB_DTVCallBack(KB_DTVRunCallback ptCallback)
- {
- KB_DTVRunCallback ptPreCallback;
- ptPreCallback = gDtvCallBack;
- gDtvCallBack = ptCallback;
- return ptPreCallback;
- }
- static void DTV_PmtTimer(void)
- {
- KB_SIStopPat();
- KB_SIGetPat(&gDtvPat, KB_SI_RECEIVE_ONCE, -1);
- }
- static void DTV_CatTimer(void)
- {
- KB_SIStopCat();
- KB_SIGetCat(&gDtvCat, KB_SI_RECEIVE_ONCE, -1);
- }
- static INT32 DTV_HandleCat(KB_OSPMsgNode *pInMsg)
- {
- KB_SICatStruct *ptCat;
- ptCat = (KB_SICatStruct*)pInMsg->Word3;
- if (memcmp(&gDtvPreCat, ptCat, sizeof(KB_SICatStruct)) != 0)
- {
- memcpy(&gDtvPreCat, ptCat, sizeof(KB_SICatStruct));
- KB_CAService(KB_CA_CATUPDATE, (void *)ptCat);//播放第一个加密节目时,调用这个函数有问题。
- }
- return RETOK;
- }
- static void DTV_AVCallbackHandle(int intype)
- {
- KB_OSPMsgNode pInMsg;
- pInMsg.Word1 = J_AVAPPLET_MODULE;
- pInMsg.Word2 = 0;
- pInMsg.Word3 = 0;
- pInMsg.Word4 = 0;
- switch (intype)
- {
- case 0:
- pInMsg.Word2 = KB_DTVOK;
- break;
- case 1:
- pInMsg.Word2 = KB_DTVFAIL;
- break;
- default:
- break;
- }
- DTV_HandleMsg_2(&pInMsg);
-
- }
- //播放当前节目
- void KB_DTVPlayCurPrg(void)
- {
- UINT8 prgType;
- unsigned short prgNO;
- KB_DBGetCurPrgInfo(&prgNO,&prgType);
- KB_DTVSetPrg(prgType, prgNO);
- KB_DTVRun();
- KB_DTVGetEitPF();
- }
- //播放上一节目
- void KB_DTVPlayPrePrg(void)
- {
- KB_DTVSetPrePrg(KB_DTVGetPrePrgType());
- KB_OSPTaskDelay(500);
- STB_StateSwitch(State_AV);
- }
- //播放下一节目
- void KB_DTVPlayNexPrg(void)
- {
- KB_DTVSetNextPrg(KB_DTVGetPrePrgType());
- KB_OSPTaskDelay(500);
- STB_StateSwitch(State_AV);
- }
- int KB_DTVGetCurrentProgramNo(void)
- {
- return gCurPrgInfo.prgNO;
- }
- //切换节目类型
- INT32 KB_DTVPrgSwitch(KB_DBPRGType type)
- {
- if(KB_DBGetPrgTotal(type)==0)
- {
- return RETFIAL1;
- }
-
- KB_DTVSetPrg(type,1);
- KB_OSPTaskDelay(500);
- STB_StateSwitch(State_AV);
- return RETOK;
- }
- void KB_DTVVolumeAdd(void)
- {
- UINT8 vol;
- vol=(UINT8)KB_DTVGetVolume();
- printf("n[Han]:Volume add [%d]",vol);
- if(vol<KB_AV_MAX_VOLUME)
- {
- vol+=1;
- KB_DTVSetVolume(vol);
- }
- }
- void KB_DTVVolumeReduce(void)
- {
- UINT8 vol;
- vol=(UINT8)KB_DTVGetVolume();
- printf("n[Han]:Volume reduce [%d]",vol);
- if(vol>0)
- {
- vol-=1;
- KB_DTVSetVolume(vol);
- }
- }
- void KB_DTVDisplayCurPrgInfo(void)
- {
- printf("nn--------KB_DTVDisplayCurPrgInfo---------");
- printf("nprgType: %d", gCurPrgInfo.prgType);
- printf("nprgNO: %d", gCurPrgInfo.prgNO);
- printf("nnSvcID: %d", gCurPrgInfo.nSvcID);
- printf("nnFrequency: %d", gCurPrgInfo.nFrequency);
- printf("nnSymbol: %d", gCurPrgInfo.nSymbol);
- printf("nnQamTyep: %d", gCurPrgInfo.nQamTyep);
- return;
- }
- BOOL KB_DTVGetCurPrgInfo(unsigned short *pTsID, unsigned short *pServID)
- {
- BOOL ret;
- unsigned long fre=gCurPrgInfo.nFrequency/100000;
- if (!KB_DBGetTsIDByFre(pTsID,fre))
- {
- *pServID = gCurPrgInfo.nSvcID;
- ret = TRUE;
- }
- else
- {
- ret = FALSE;
- }
- return ret;
- }
- //将VEDIO的编码状态设置为VIDEO_STATUS_STOPPED
- void KB_DTVRunForNvod(void)
- {
- KB_CAService(KB_CA_CLOSE, 0);
- KB_DTVSetVolume(gCurVolume);
- gCurTrace = KB_DTVGetTrack();
- KB_AVSetPrgTrack(gCurTrace);
-
- gPlayStatus = KB_DTVSTOP;
- KB_DTVStop();
- KB_DTVStopIFrame();
- }
- void KB_DTVStartCurCAProg(void)
- {
- KB_DTVStartCA(0, gCurPrgInfo.nSvcID);
- }
- /* EOF */