kb_dc_filterdata.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:8k
源码类别:

DVD

开发平台:

C/C++

  1. /*****************************************************************************
  2. File name  : kb_dc_filterdata.c
  3. Description: Private Section filter for download.
  4. COPYRIGHT (C) STMicroelectronics 2004.
  5. *****************************************************************************/
  6. //-----------------------------------------------------------------------------
  7. // Project include files:
  8. //-----------------------------------------------------------------------------
  9. #include "kb_dc_pub.h"
  10. KB_DC_FILTER_STATUS filter_status = FILTER_READY;
  11. UINT32   DCchannelID;
  12. UINT32  DCfilterID;
  13. static unsigned char DCSectionHardMask[8];
  14. static unsigned char  DCSectionHardValue[8];
  15. unsigned char byFilterBuf[PSI_SECTION_SIZE];
  16.  int KB_DC_DmxInit(void)
  17. {
  18. signed long  nReturn;
  19. #define FILTER_DEPTH      (8)
  20. nReturn = KB_DmxAllocateChnnl(DMX_CHANNEL_SECTION, 5 * 1024, TRUE, &DCchannelID);
  21. if(nReturn != 0)
  22. {
  23. DCDebug1("KD_DmxAllocateChnnl fail = %ldn",nReturn);
  24. return -1;
  25. }
  26. KB_DmxRegNotice(DCchannelID, DCGetSectionCallback);
  27. nReturn = KB_DmxAllocateFilter(DMX_SECTION_FILTER, FILTER_DEPTH, &DCfilterID);
  28. if(nReturn != 0)
  29. {
  30. DCDebug1("KD_DmxAllocateFilter fail = %ldn",nReturn);
  31. return -1;
  32. }
  33. DCDebug4("n DCchannelID=%ld",DCchannelID);
  34. DCDebug4("n DCfilterID=%ld",DCfilterID);
  35. nReturn = KB_DmxAssociateFilter(DCchannelID, DCfilterID);  
  36. if(nReturn != 0)
  37. {
  38. DCDebug1("KD_DmxAssociateFilter fail = %ldn",nReturn);
  39. return -1;
  40. }
  41.    
  42. return 0;
  43. }
  44. int KB_DC_FilterStop(void)
  45. {
  46. int   ErrorCode = RETFIAL1;
  47.  ErrorCode = KB_DmxControlChnnl(DCchannelID, KB_DMX_STOP);   
  48. if(RETOK != ErrorCode)
  49. {
  50. return -1;
  51. }
  52. return 0;
  53. }
  54. int KB_DC_FilterStart(void)
  55. {
  56. int   ErrorCode = RETFIAL1;
  57.  ErrorCode = KB_DmxControlChnnl(DCchannelID, KB_DMX_START);   
  58. if(RETOK != ErrorCode)
  59. {
  60. return -1;
  61. }
  62. return 0;
  63. }
  64. static signed long Kb_Filter_Setup(unsigned long lFilterId, unsigned short lPid, 
  65. unsigned short lTableId, unsigned short lTableIdExt, 
  66. unsigned short lVersion, unsigned short lSectionNumber)
  67. {
  68. unsigned char  byte1, byte2;
  69. INT32 sErr = Err_OK;
  70. KB_DmxControlChnnl(DCchannelID,KB_DMX_STOP);
  71. KB_DmxDisassociateFilter(DCchannelID, lFilterId);
  72. sErr = KB_DmxFreeFilter(lFilterId);
  73. if(Err_OK != sErr )
  74. {
  75. DCDebug1("[LOADER]:KD_DmxFreeFilter error[0x%x].nr ",sErr);
  76. return sErr;
  77. }
  78.    
  79. KBDcMemset(DCSectionHardMask, 0, 8);
  80. if(lTableId != UNSET_PARAM)
  81. {
  82. DCSectionHardMask[0]  = 0xff;
  83. DCSectionHardValue[0] = (unsigned char)lTableId;
  84. }
  85. if(lTableIdExt != UNSET_PARAM)
  86. {
  87. byte1 = (unsigned char)((lTableIdExt >> 8) & 0xff);
  88. byte2 = (unsigned char)(lTableIdExt & 0xff);
  89. DCSectionHardMask[3]  = 0xff;
  90. DCSectionHardMask[4]  = 0xff;
  91. DCSectionHardValue[3] = byte1;
  92. DCSectionHardValue[4] = byte2;
  93. if(lTableId == 0xfe && byte2 == 0xff)
  94. {
  95. DCSectionHardMask[2]  = 0x00;
  96. }
  97. }
  98. if(lVersion != UNSET_PARAM)
  99. {
  100. DCSectionHardMask[5]  = 0x02;
  101. DCSectionHardValue[5] = (unsigned char)(~lVersion);
  102. }
  103. if(lSectionNumber != UNSET_PARAM)
  104. {
  105. DCSectionHardMask[6]  = 0xff;
  106. DCSectionHardValue[6] = (unsigned char)lSectionNumber;
  107. }
  108. #if 0
  109.        DCDebug4("nvalue[8]={%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x}", DCSectionHardValue[0], DCSectionHardValue[1],DCSectionHardValue[2], DCSectionHardValue[3],
  110. DCSectionHardValue[4], DCSectionHardValue[5],DCSectionHardValue[6], DCSectionHardValue[1]);
  111. DCDebug4("nmask[8]= {%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x}", DCSectionHardMask[0], DCSectionHardMask[1],DCSectionHardMask[2], DCSectionHardMask[3],
  112. DCSectionHardMask[4], DCSectionHardMask[5],DCSectionHardMask[6], DCSectionHardMask[1]);
  113. #endif
  114. sErr = KB_DmxAllocateFilter(DMX_SECTION_FILTER, 8, &DCfilterID);
  115. if(sErr != 0)
  116. {
  117. DCDebug1("DDB_FilterSet KD_DmxAllocateFilter fail = %ldn",sErr);
  118. return -1;
  119. }
  120. sErr = KB_DmxAssociateFilter(DCchannelID, DCfilterID);  
  121. if(sErr != 0)
  122. {
  123. DCDebug1("DDB_FilterSet KB_DmxAssociateFilter fail = %ldn",sErr);
  124. return -1;
  125. }
  126. KB_DmxSetChnnlPID(DCchannelID, lPid);
  127. sErr = KB_DmxSetFilter(DCfilterID, DCSectionHardValue, DCSectionHardMask, 0);
  128. if(Err_OK != sErr)
  129. {
  130. DCDebug1("DDB_FilterSet KB_DmxSetFilter fail = %ldn",sErr);
  131. return sErr;
  132. }
  133.    
  134.        return (sErr);
  135. }
  136. unsigned long KB_DC_FilterReSet(unsigned short lPid, unsigned short lTableId, unsigned short lTableIdExt, unsigned short lVersion, unsigned short lSectionNumber)
  137. {
  138. unsigned long ErrCode =Err_OK;
  139. DCDebug3("n KB_DC_FilterReSet: lPid=%x, lTableId=%x, lTableIdExt=%x, lSectionNumber=%x", lPid, lTableId, lTableIdExt, lSectionNumber);
  140. ErrCode = Kb_Filter_Setup(DCfilterID, lPid, lTableId, lTableIdExt, UNSET_PARAM, lSectionNumber);
  141. if(Err_OK != ErrCode)
  142. {
  143. return ErrCode;
  144. }
  145. Section_Pool_Reset();
  146. return Err_OK;
  147. }
  148. KB_DC_FILTER_STATUS KB_DC_FilterStatGet(void)
  149. {
  150. return filter_status;
  151. }
  152. void KB_DC_FilterStatSet(KB_DC_FILTER_STATUS status)
  153. {
  154.  filter_status = status;
  155. }
  156. int DTV_SectionGet(unsigned char *buf, unsigned char *ptr, int *sec_len, PSI_MALLOC_OPT flag)
  157. {
  158.        unsigned char       *read_ptr=NULL;
  159.        unsigned char *dest,cur_sec,last_sec;
  160.        if( buf==NULL)
  161. {
  162. DCDebug1("rnSection found null.");
  163. return -1;
  164.   
  165.        //第一个字节是 TABLE ID
  166.        read_ptr = buf;
  167. *sec_len=(((read_ptr[1] << 8) | read_ptr[2]) & 0x0FFF);
  168. cur_sec = read_ptr[6];
  169. last_sec = read_ptr[7];
  170.        DCDebug4("n PSI_SectionGet Section : %1x  Len=%d, cur=%x, flag %d",read_ptr[0],*sec_len,cur_sec,flag);
  171. switch(flag)
  172. {
  173. case PSI_S_ALLOC_NONE:
  174. dest = (unsigned char *)ptr;
  175. break;
  176. case PSI_S_ALLOC_SECTION:
  177. if((dest=(unsigned char *)KBDcMalloc(PSI_SECTION_SIZE))==NULL)
  178. {
  179. DCDebug1("PSI_get_sction: Out of memory!rn");
  180. return DC_NOT_OK;
  181. }
  182. *((unsigned char **)ptr) = dest;
  183. break;
  184. case PSI_S_ALLOC_TABLE:
  185. if((dest=(unsigned char *)KBDcMalloc(((UINT32)PSI_SECTION_SIZE*((UINT32)last_sec+1))))==NULL)
  186. {
  187. DCDebug1("PSI_get_sction: Out of memory!!! size = %drn", PSI_SECTION_SIZE*(last_sec+1));
  188. return DC_NOT_OK;
  189. }
  190. *((unsigned char **)ptr) = dest;
  191. break;
  192. default:
  193. break;
  194. }
  195. KBDcMemcpy(dest, read_ptr,(*sec_len)+3 );
  196. return DC_OK;
  197. }
  198. int KB_DC_GetTable(unsigned short pid, 
  199.                           unsigned char tableId, 
  200.      unsigned int extId, 
  201.      unsigned char ** table_info, 
  202.      int style)
  203. {
  204. ST_ErrorCode_t ErrCode;
  205. unsigned short  Pid;
  206. unsigned char Tableid;
  207. U8 Instance=0;
  208. U32 Section = 0;
  209. int sec_len=0;
  210. unsigned short iDataSize =0;
  211. int  total_sec_len=0;
  212. unsigned char       *dest_ptr=NULL;
  213. Tableid   = tableId;
  214. Pid     = pid;
  215. KBDcMemset(byFilterBuf, 0, PSI_SECTION_SIZE);
  216. do
  217. {
  218. ErrCode = KB_DC_FilterReSet( Pid, Tableid, extId, UNSET_PARAM, Section);
  219. if ( ErrCode != Err_OK )
  220. break;
  221. ErrCode  = KB_DC_GetSection(byFilterBuf, &iDataSize);
  222. if(Err_OK != ErrCode)
  223. {
  224. DCDebug1("nr Get section error[%d].rn",ErrCode );
  225. return ErrCode;
  226. }
  227. if(Section==0)
  228. {
  229. *table_info = NULL;
  230. if(DTV_SectionGet(byFilterBuf, (unsigned char *)table_info,&sec_len, PSI_S_ALLOC_TABLE)!=DC_OK)
  231. {
  232. ErrCode = -1;
  233. DCDebug1("rnGet PSI Section Error 0!");
  234. break;
  235. }
  236.        
  237. DCDebug4("n DTV_GetTable:sec_len=%d",sec_len);
  238. dest_ptr = *table_info;
  239. dest_ptr += sec_len + 3;
  240.  
  241. }
  242. else
  243. {
  244. if(DTV_SectionGet(byFilterBuf, (unsigned char *)dest_ptr,&sec_len, PSI_S_ALLOC_NONE)!=DC_OK)
  245. {
  246. ErrCode = -2;
  247. DCDebug1("==no table id=%xrn", tableId);
  248. break;
  249. }
  250. dest_ptr += sec_len + 3;
  251. }
  252. total_sec_len+=sec_len+3;
  253. DCDebug3(" n -------cursec=%d  -have received %d byte data",byFilterBuf[6],total_sec_len);   
  254. if(ErrCode!=0 && *table_info  )
  255. {
  256. KBDcFree(*table_info);
  257. *table_info=0;
  258. }
  259. }while ( Section++ < byFilterBuf[LASTSECT_IDX]);
  260. return total_sec_len;
  261. }
  262. /* EOF --------------------------------------------------------------------- */