kb_dc_task.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:12k
- #include "kb_dc_pub.h"
- #include "kb_dc_task.h"
- #include "kb_dc.h"
- #include "kb_machblue_client.h"
- #include "kb_machblue_client_task.h"
- #include "swf.h"
- static UINT32 kb_dc_queueID;
- static UINT32 _realtime_adver_timer = 0xffffffff;
- static unsigned short curCfgTsID = 0x1fff;
- extern mb_error_t kb_machblue_movie_close(BOOL Menu_Exit);
- void AdverTimerCallback(void);
- void movieInfoPrint(KB_MovieInfoNode *Info)
- {
- DCDebug2("n movieInfoPrint:Infoaddr=%x", Info);
- DCDebug2("n InfoPrint]: pid=[%d], fMid=[%d], name=[%s], size=[%d]...n", Info->st_MovieInfo.m_nPid, Info->st_MovieInfo.m_nFirstModuleId, Info->st_MovieInfo.m_strName, Info->st_MovieInfo.m_nSize);
- }
- BOOL KB_DcDataGet(KB_MovieInfoNode *pInfo)
- {
- pInfo->st_MovieInfo.m_pData=KBDcMalloc((mb_size_t)pInfo->st_MovieInfo.m_nSize);
- if(pInfo->st_MovieInfo.m_pData==NULL)
- {
- if(pInfo->st_MovieInfo.m_dataGet==kb_dc_data_searching)
- pInfo->st_MovieInfo.m_dataGet=kb_dc_data_no;
-
- return FALSE;
- }
-
- if(kb_dc_getMovie(pInfo)==FALSE)
- {
- if(pInfo->st_MovieInfo.m_dataGet==kb_dc_data_searching)
- pInfo->st_MovieInfo.m_dataGet=kb_dc_data_no;
- mb_free(pInfo->st_MovieInfo.m_pData);
-
- DCDebug1("n[Machblue]:Client get movie adver data error.");
- return FALSE;
- }
- KB_XmlParse((char*)pInfo->st_MovieInfo.m_pData, pInfo->st_MovieInfo.m_nSize);
- mb_free(pInfo->st_MovieInfo.m_pData);
- pInfo->st_MovieInfo.m_dataGet=kb_dc_data_searched;
- return TRUE;
- }
- BOOL KB_DcMovieGet(KB_MovieInfoNode *pInfo)
- {
- pInfo->st_MovieInfo.m_pData=mb_malloc((mb_size_t)pInfo->st_MovieInfo.m_nSize);
- if(kb_dc_getMovie(pInfo)==FALSE)
- {
- if(pInfo->st_MovieInfo.m_dataGet==kb_dc_data_searching)
- pInfo->st_MovieInfo.m_dataGet=kb_dc_data_no;
- mb_free(pInfo->st_MovieInfo.m_pData);
-
- DCDebug1("n[Machblue]:Client get movie adver data error.");
- return FALSE;
- }
- pInfo->st_MovieInfo.m_dataGet=kb_dc_data_searched;
- return TRUE;
- }
- void KB_DcMsgSend(KB_OSPMsgNode *msg)
- {
- KB_OSPRet ret;
-
- ret=KB_OSPMsgSend(kb_dc_queueID,msg);
- if(ret!=RET_OK)
- DCDebug1("nKB_DcMsgSend error.");
- }
- void KB_DcTask(void)
- {
- time_t curTime, end_time, last_check_time=0;
- KB_OSPRet status;
- KB_OSPMsgNode msg;
- KB_MovieInfoNode *movieInfo=NULL;
- unsigned short curTSID,curServiceID;
- BOOL playret;
- static bool updateInfo=false,update=false;
- unsigned char verSTB=0,verDC=0;
- unsigned long year,month,day,hour,minter,second;
- int testCnt =0;
- int x;
- _realtime_adver_timer = KB_TimerCreate(KB_TIMER_REPEAT, (KB_TIMER_FUNC_POINTER)AdverTimerCallback, NULL);
- KB_TimeGetCurTime(&curTime);
- last_check_time = curTime;
- while(1)
- {
- KB_OSPTaskDelay(2000);
- KB_TimeGetCurTime(&curTime);
- #if 0
- ConvertTimeStampToDate(curTime,&year,&month,&day);
- ConvertTimeStampToTime(curTime,&hour,&minter,&second);
- DCDebug2("n KB_DcTask:current time[%d],year[%d],month[%d],day[%d],hour[%d],minter[%d],second[%d]",curTime,year,month,day,hour,minter,second);
- #endif
- //定时去激活版本的监测
- if(curTime-last_check_time > 60)
- {
- DCDebug2("nnn*******it is time to check configure file version!*****nnn");
- last_check_time = curTime;
-
- #ifdef KB_DC_TEST_2
- {
- if((++testCnt)%4==0)
- kb_dc_CfgVerSaveTest();
- }
- #endif
-
- msg.Word1=kb_dc_version_check;
- goto SWITCH;
- }
- status=KB_OSPMsgGet(kb_dc_queueID, KD_NoWait,0, &msg);
- if(status!=Ret_OK) KBDcMemset(&msg, 0x00, sizeof(KB_OSPMsgNode));
-
- movieInfo=KB_GetXmlMovieInfoHead();
- while(movieInfo!=NULL)
- {
- DCDebug3("n m_dataGet=%d m_cfgType=%d name=%s", movieInfo->st_MovieInfo.m_dataGet, movieInfo->st_MovieInfo.m_cfgType, movieInfo->st_MovieInfo.m_strName);
- //数据广播数据文件
- if(((movieInfo->st_MovieInfo.m_cfgType==kb_dc_data_broadcast)||
- (movieInfo->st_MovieInfo.m_cfgType==kb_dc_data_vote))&&
- (movieInfo->st_MovieInfo.m_dataGet==kb_dc_data_no))
- {
- movieInfo->st_MovieInfo.m_dataGet=kb_dc_data_searching;
- msg.Word1=kb_db_data_get;
- msg.Word2=(UINT32)movieInfo;
- break;
- }
- //交互广告影片文件
- else if((movieInfo->st_MovieInfo.m_cfgType==kb_dc_adv_alter)&&
- (movieInfo->st_MovieInfo.m_dataGet==kb_dc_data_no))
- {
- movieInfo->st_MovieInfo.m_dataGet=kb_dc_data_searching;
- msg.Word1=kb_dc_movie_get;
- msg.Word2=(UINT32)movieInfo;
- break;
- }
- //界面更新影片文件
- else if((movieInfo->st_MovieInfo.m_cfgType==kb_dc_swf_update)&&
- (movieInfo->st_MovieInfo.m_dataGet==kb_dc_data_no))
- {
- verDC=movieInfo->st_MovieInfo.m_reserve2;
- //下发的版本号无效
- if((verDC==0)||(verDC==255))
- {
- movieInfo->st_MovieInfo.m_dataGet=kb_dc_data_searched;
- }
- else
- {
- if(movieInfo->st_MovieInfo.m_reserve1==kb_movie_adve_logo)
- verSTB=KB_SWF_VersionGet(0);
- else
- verSTB=KB_SWF_VersionGet(1);
- //if(((verSTB>=250)&&(verSTB!=verDC))||(verSTB<verDC))
- if(verSTB!=verDC)
- {
- update=true;
- movieInfo->st_MovieInfo.m_dataGet=kb_dc_data_searching;
- msg.Word1=kb_dc_movie_get;
- msg.Word2=(UINT32)movieInfo;
- break;
- }
- else
- {
- DCDebug2("n 无效版本: verSTB=%d verDC=%d", verSTB, verDC);
- movieInfo->st_MovieInfo.m_dataGet=kb_dc_data_searched;
- }
- }
- }
- //插播广告
- else if(movieInfo->st_MovieInfo.m_cfgType==kb_dc_adv_rt)
- {
- if(KB_DTVGetCurPrgInfo(&curTSID,&curServiceID)==FALSE)
- {
- DCDebug1("nKB_DcTask get current program information error.");
- }
- else
- {
- DCDebug2("n curTSID=%x curServiceID=%x m_serviceID=%x m_tsID=%x", curTSID,curServiceID, movieInfo->st_MovieInfo.m_serviceID, movieInfo->st_MovieInfo.m_tsID);
- //if((movieInfo->st_MovieInfo.m_tsID==curTSID)&&(movieInfo->st_MovieInfo.m_serviceID==curServiceID))
- if(movieInfo->st_MovieInfo.m_serviceID==curServiceID&&movieInfo->st_MovieInfo.m_tsID==curTSID)
- {
- end_time = movieInfo->st_MovieInfo.m_nStartTime + (movieInfo->st_MovieInfo.m_nTimeStep*(movieInfo->st_MovieInfo.m_nTimesPlayed-1) + 10);
- DCDebug2("n curTime[%d] vs [%d]st_MovieInfo.m_nStartTime----end_time[%d]", curTime, movieInfo->st_MovieInfo.m_nStartTime, end_time);
- if( (curTime>movieInfo->st_MovieInfo.m_nStartTime)&&(curTime<=end_time) )
- {
- x = (curTime - movieInfo->st_MovieInfo.m_nStartTime)%(movieInfo->st_MovieInfo.m_nTimeStep);
- DCDebug2("n x=%d",x);
- if((x>=0)&&(x<=10))
- {
- msg.Word1 = kb_dc_movie_play;
- msg.Word2=(UINT32)movieInfo;
- break;
- }
- }
- }
- }
- }
-
- movieInfo=movieInfo->m_pNext;
- }
- SWITCH:
- if(KB_DC_FilterStatGet()==FILTER_COLSED)
- {
- DCDebug2("n FilterStat is FILTER_COLSED, continue!!!");
- continue;
- }
-
- switch(msg.Word1)
- {
- //搜索业务配置文件
- case kb_dc_servcfg_get:
- DCDebug2("n ---kb_dc_servcfg_get recieved----");
- KB_DC_FilterStatSet(FILTER_RUNNING);
- if(kb_dc_getMainFreqCfg()==0)
- {
- DCDebug1("n kb_dc_getMainFreqCfg failure!");
- break;
- }
- KB_DC_FilterStatSet(FILTER_READY);
- break;
-
- case kb_dc_version_check:
- DCDebug2("n -----kb_dc_version_check received!-----");
- {
- unsigned char *xmlBuf=NULL;
- unsigned long xmlLen=0;
- KB_DC_FilterStatSet(FILTER_RUNNING);
- if(kb_dc_CfgDiiCheck()<=0)
- {
- DCDebug2("n dii version not changed , break!");
- break;
- }
- updateInfo=false;
- update=false;
- ResetXmlStbInfo(); /*先清空*/
- xmlBuf = kb_dc_getCfgXml(&xmlLen);
- if(xmlBuf!=NULL)
- {
- KB_XmlParse((char*)xmlBuf, xmlLen);
- KBDcFree(xmlBuf);
- xmlBuf=NULL;
- }
- }
- break;
- case kb_dc_movie_play:
- DCDebug2("n -----kb_dc_movie_play received!-----");
- if(kb_movie_playStatusGet()==kb_movie_closed)
- {
- playret =kb_machblue_TSMovie2((KB_MovieInfoNode*)msg.Word2);
- if(playret)
- {
- KB_MovieInfoNode *pInfo=NULL;
- int duration;
-
- pInfo = (KB_MovieInfoNode *)msg.Word2;
- duration = pInfo->st_MovieInfo.m_nDuration;
- DCDebug4("nr -----duration=%d", duration);
- KB_TimerEnable(_realtime_adver_timer, duration*1000);
- }
- }
- break;
- case kb_dc_movie_get:
- DCDebug2("n -----kb_dc_movie_get received!-----");
- KB_DcMovieGet((KB_MovieInfoNode*)msg.Word2);
- break;
-
- case kb_db_data_get:
- DCDebug2("n #####kb_db_data_get received!msg.Word2=%x#####", msg.Word2);
- KB_DcDataGet((KB_MovieInfoNode*)msg.Word2);
- break;
-
- case kb_dc_filter_close:
- KB_DC_FilterStop();
- KB_DC_FilterStatSet(FILTER_COLSED);
- break;
-
- case kb_dc_filter_start:
- KB_DC_FilterStart();
- break;
- }
- if((!updateInfo)&&update)
- {
- movieInfo=KB_GetXmlMovieInfoHead();
- if(movieInfo!=NULL)
- updateInfo=true;
-
- while(movieInfo!=NULL)
- {
- if((movieInfo->st_MovieInfo.m_cfgType==kb_dc_swf_update)&&
- (movieInfo->st_MovieInfo.m_dataGet!=kb_dc_data_searched))
- {
- updateInfo=false;
- break;
- }
- movieInfo=movieInfo->m_pNext;
- }
- if(updateInfo)
- {
- KB_MovieInfoNode *tmpInfo=NULL,*p1=tmpInfo,*p2;
- KB_DBRET updateRet;
-
- movieInfo=KB_GetXmlMovieInfoHead();
- while(movieInfo!=NULL)
- {
- //生成链表
- if((movieInfo->st_MovieInfo.m_cfgType==kb_dc_swf_update)&&
- (movieInfo->st_MovieInfo.m_pData!=NULL))
- {
- p2 = (KB_MovieInfoNode*)KBDcMalloc(sizeof(KB_MovieInfoNode));
- KBDcMemcpy(p2, movieInfo, sizeof(KB_MovieInfoNode));
- //p2->st_MovieInfo.m_pData=(unsigned char*)mb_malloc(p2->st_MovieInfo.m_nSize);
- //mb_memcpy(p2->st_MovieInfo.m_pData,movieInfo->st_MovieInfo.m_pData,p2->st_MovieInfo.m_nSize);
- if(tmpInfo==NULL)
- {
- tmpInfo=p2;
- p1=tmpInfo;
- p1->m_pNext=NULL;
- }
- else
- {
- p1->m_pNext=p2;
- p1=p2;
- p1->m_pNext=NULL;
- }
- }
-
- movieInfo=movieInfo->m_pNext;
- }
- kb_machblue_updatePlay();
- updateRet=KB_SWF_Update(tmpInfo);
- if(kb_movie_playStatusGet()==kb_movie_playing)
- {
- if(updateRet==RET_OK)
- KB_MB_lc_2_movie_word_Post_Task(1);
- else
- KB_MB_lc_2_movie_word_Post_Task(0);
- }
- while(tmpInfo!=NULL)
- {
- KBDcFree(tmpInfo->st_MovieInfo.m_pData);
- tmpInfo->st_MovieInfo.m_pData = NULL;
- p1=tmpInfo;
- tmpInfo=tmpInfo->m_pNext;
- KBDcFree(p1);
- }
- }
- }
- }
-
- }
- void KB_DcTaskInit(void)
- {
- UINT32 TaskId;
-
- KB_OSPTaskInit("KB_DcTask", 8*1024,
- (void(*)(void *))KB_DcTask, 1*16,
- NULL, &TaskId);
- KB_OSPQueInit("kb_dc_queueID", 128, &kb_dc_queueID);
- }
- void AdverTimerCallback(void)
- {
- DCDebug4("rnn ----------------_realtime_adver_timer expired-------------------n");
- KB_TimerDisable(_realtime_adver_timer );
- kb_machblue_movie_close(TRUE);
- }
- void Kb_clearAderTimer(void)
- {
- KB_TimerDisable(_realtime_adver_timer );
- }
- void KB_DCStop_Service(void)
- {
- KB_DC_FilterStop();
- KB_DC_FilterStatSet(FILTER_COLSED);
- }
- void KB_DCStart_Service(void)
- {
- KB_DC_FilterStart();
- KB_DC_FilterStatSet(FILTER_RUNNING);
-
- }
- void kb_dc_LoadCurTs(void)
- {
- unsigned short curTSID,curServiceID;
-
- KB_DTVGetCurPrgInfo(&curTSID,&curServiceID);
- curCfgTsID=curTSID;
- }
- unsigned short kb_dc_GetCurTS(void)
- {
- return curCfgTsID;
- }
- BOOL kb_dc_FreqIsChanged(void)
- {
- unsigned short curTSID,curServiceID;
-
- KB_DTVGetCurPrgInfo(&curTSID,&curServiceID);
- if(curCfgTsID!=curTSID)
- return TRUE;
- else
- return FALSE;
- }
- //activate service configure xml info
- void kb_dc_ServCfgGetActivate(void)
- {
- KB_OSPMsgNode msg;
-
- msg.Word1=kb_dc_servcfg_get;
- KB_DcMsgSend(&msg);
- }