mid_siutil.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /*! \addtogroup SIUTIL
  2. * @{
  3. */
  4. /******************************************************************************/
  5. /**
  6. * \file mid_siutil.h
  7. *
  8. * \brief header for all SI
  9. *
  10. * \note Copyright (C) 2006 SunMedia Co, chengdu
  11. * Author anlzhao@sunmedia.com.cn
  12. *
  13. * \author
  14. *
  15. * The source code in this file is written by anlzhao referring to
  16. * ETSI EN 300 468 and owned by SunMedia Coporation. The header defines all
  17. * the macro and common struct. You should include it in all file.
  18. *
  19. * BUGS:
  20. *
  21. ******************************************************************************/
  22. #ifndef _MID_SIUTIL_H_20080327
  23. #define _MID_SIUTIL_H_20080327
  24. #include <string.h>
  25. #include <types.h>
  26. #include <drv_debug.h>
  27. #include "mid_common.h"
  28. extern unsigned int sisdbgconf1;
  29. extern unsigned int sisdbgconf2;
  30. #ifndef CONFIG_SUPPORT_DEBUG_MESSAGE
  31. #define SI_DEBUG(level, fmt, args...)
  32. #define SI_DEBUG2(level, fmt, args...)
  33. #else
  34. #define SIDEBUG
  35. #ifdef SIDEBUG
  36. #define SI_DEBUG(level, fmt, args...) do {if (sisdbgconf1 & DBGCFG_PSI) fprintf(stderr, "[SIPSI] " fmt, ## args);}while(0)
  37. #define SI_DEBUG2(level, fmt, args...) do {if (sisdbgconf2 & DBGCFG_PSI) fprintf(stderr, "[SIPSI] " fmt, ## args);}while(0)
  38. #else
  39. #define SI_DEBUG(level, fmt, args...)
  40. #define SI_DEBUG2(level, fmt, args...)
  41. #endif
  42. #endif
  43. #define SAFR_FREE_FUNC(func_free, p) {if(p){ func_free(p); p = NULL;}}
  44. /* Max section size */
  45. #define MAX_SECTION_SIZE_D4 4096 /**<\brief default section max size 12bits = 4096bytes */
  46. /* Timeout */
  47. #undef DEFAULT_TIMEOUT
  48. #define DEFAULT_TIMEOUT 500
  49. typedef INT16 CHAN_INDEX;
  50. #define SERVICE_NAME_DEFAULT "NONAME"
  51. #define CARRIER_NAME_DEFAULT "TPS"
  52. #define INVALID_INDEX (-1)
  53. #define MID_SIUTIL_CHANNELS_PER_UNIT 16
  54. #define MID_SIUTIL_TOTAL_CHANNELS MID_SIUTIL_CHANNELS_PER_UNIT*DEMUX_TOTAL_UNITS
  55. #define CRC_LEN 4
  56. #define SAFE_DELETE_QUEUE(p) {if(p){GL_QueueDelete(p); p = NULL;}}
  57. #define HILO(x) (x##_hi << 8 | x##_lo)
  58. #define MID_SIUTIL_IS_CHANIDX_VALID(n) (n >= 0 && n < MID_SIUTIL_TOTAL_CHANNELS)
  59. #define INVALID_HANDLE (0xffff)
  60. /**
  61. * \brief PSI crc check option
  62. */
  63. typedef enum
  64. {
  65. CRC_CHECK_AUTO = 0, ///< only calculate CRC when section_syntax_indicator
  66. CRC_CHECK_NONE, ///< do not check CRC
  67. CRC_CHECK_FORCE, ///< do check CRC
  68. #ifdef DRV_DEMUX_SUPPORT_SUB_CHANNEL
  69. // for demux sub1 PVR channel
  70. CRC_CHECK_AUTO_SUB1 = 100,
  71. CRC_CHECK_NONE_SUB1,
  72. CRC_CHECK_FORCE_SUB1,
  73. // for demux sub2 PVR channel
  74. CRC_CHECK_AUTO_SUB2 = 200,
  75. CRC_CHECK_NONE_SUB2,
  76. CRC_CHECK_FORCE_SUB2,
  77. #endif // #ifdef DRV_DEMUX_SUPPORT_SUB_CHANNEL
  78. }MID_SIUTIL_CRC_CHECK;
  79. // ================ Common SI related ======================= //
  80. /**
  81. * \brief SI structure
  82. */
  83. typedef struct _mid_siutil_si_table_header_t
  84. {
  85. UINT8 table_id :8; /**<\brief table_id */
  86. UINT8 section_length_hi :4; /**<\brief section_length high bit */
  87. UINT8 :3;
  88. UINT8 section_syntax_indicator :1; /**<\brief section_syntax_indicator */
  89. UINT8 section_length_lo :8; /**<\brief section_length low bit */
  90. UINT8 id_hi :8; /**<\brief extend id high bit */
  91. UINT8 id_lo :8; /**<\brief extend id low bit */
  92. UINT8 current_next_indicator :1; /**<\brief current_next_indicator */
  93. UINT8 version_number :5; /**<\brief version_number */
  94. UINT8 :2;
  95. UINT8 section_number :8; /**<\brief section_number */
  96. UINT8 last_section_number :8; /**<\brief last_section_number */
  97. }MID_SiutilSiTableHeader_t, *LP_MID_SiutilSiTableHeader_t;
  98. /**
  99. * \brief SI descriptor structure
  100. */
  101. typedef struct _mid_siutil_si_descriptor
  102. {
  103. UINT8 tag; ///<\brief descriptor tag
  104. UINT8 len; ///<\brief descriptor length
  105. UINT8 content[1]; ///<\brief pointer to descriptor content
  106. }MID_SiutilSiDescr_t, *LP_MID_SiutilSiDescr_t;
  107. #define MAX_BUF_LEN 256
  108. /**
  109. * \brief SI singlge section storing struct
  110. */
  111. typedef struct _mid_si_section_t
  112. {
  113. UINT16 iSecNo; ///<\brief section_number
  114. UINT16 iSecLen; ///<\brief section length
  115. UINT8 *pSec; ///<\brief pointer to section content
  116. }MID_SiutilSiSection_t, *LP_MID_SiutilSiSection_t;
  117. typedef struct _mid_si_section_cb_param_t
  118. {
  119. volatile UINT8 bSignaled; /* for all section collected */
  120. UINT8 iTotalSecNum; /* total sections */
  121. UINT8 iCollectSecNum; /* currently collected sections */
  122. UINT8 version;
  123. MID_SiutilSiSection_t stSections[MAX_BUF_LEN];
  124. }MID_SiutilSectionCbParam_t, *LPMID_SiutilSectionCbParam_t;
  125. #define PRIVATE_LEN 9
  126. typedef struct
  127. {
  128. UINT8 section_num;
  129. UINT16 version_num;
  130. UINT16 tbl_id_ext;
  131. UINT16 len;
  132. UINT8 *pPayload;
  133. }MID_SiutilPrivateSection_t;
  134. /**
  135. * \brief channels structure
  136. */
  137. typedef struct _mid_siutil_channels_t
  138. {
  139. UINT16 pid; ///>\brief PID
  140. INT16 table_id_ext; ///>\brief extend_id
  141. INT8 table_id; ///>\brief table_id
  142. bool bIsMultiSection; ///>\brief Is multi section or not
  143. int hChanHdl;
  144. UINT16 filter_id;
  145. GL_Queue_t hChanEQHdl; ///>\brief event queue handle for the specific opened demux channel
  146. MID_SiutilSectionCbParam_t sections;
  147. }MID_SiutilChannels_t, *LP_MID_SiutilChannels_t;
  148. /*
  149. * siutil.c
  150. */
  151. /*************************************************************************************
  152. * Definition of SIUTIL module interfaces
  153. *************************************************************************************/
  154. /** \addtogroup Initialize
  155. * \brief initialize and uninitialize
  156. * @{ */
  157. /************************************************************************************/
  158. /**
  159. * \fn INT32 MID_SIUTIL_Init(void)
  160. *
  161. * \param none.
  162. *
  163. * \return 1 for successful, 0 for failed.
  164. *
  165. * \note Description :
  166. * Initialize SIUTIL engine for collect SI/PSI information.
  167. *
  168. ************************************************************************************/
  169. INT32 MID_SIUTIL_Init(void);
  170. /************************************************************************************/
  171. /**
  172. * \fn INT32 MID_SIUTIL_Uninit(void)
  173. *
  174. * \param none.
  175. *
  176. * \return none.
  177. *
  178. * \note Description :
  179. * Uninitialize SIUTIL engine.
  180. *
  181. ************************************************************************************/
  182. void MID_SIUTIL_Uninit(void);
  183. /** @} end of addtogroup Initialize */
  184. /** \addtogroup Section_operation Section Operation
  185. * \brief sections operations
  186. *
  187. * collect all sections corresponding to the same demux event queue
  188. * return the received section corresponding channel index maintained by siutil module
  189. *
  190. * @{ */
  191. /************************************************************************************/
  192. /**
  193. * \fn CHAN_INDEX MID_SIUTIL_CollectAllSections(GL_Queue_t hDmxEventQueueHdl, INT32 iTimeout)
  194. *
  195. * \param hDmxEventQueueHdl : event queue handle
  196. * \param iTimeout : time of time out
  197. *
  198. * \return index of channel handle which section is collected completely
  199. *
  200. * \note Description :
  201. * give some ids and get the index of channel array.
  202. *
  203. ************************************************************************************/
  204. CHAN_INDEX MID_SIUTIL_CollectAllSections(GL_Queue_t hDmxEventQueueHdl, INT32 iTimeout);
  205. /************************************************************************************/
  206. /**
  207. * \fn INT32 MID_SIUTIL_CollectSections(CHAN_INDEX index, INT32 iTimeout)
  208. *
  209. * \param index : indicate which channel we want to collect
  210. * \param iTimeout : time of time out
  211. *
  212. * \return 0 for success. -1 for failed
  213. *
  214. * \note Description :
  215. * collect the specific demux channel sections, other dmx channel use the same demux event queue handle will be released.
  216. *
  217. ************************************************************************************/
  218. INT32 MID_SIUTIL_CollectSections(CHAN_INDEX index, INT32 iTimeout);
  219. /************************************************************************************/
  220. /**
  221. * \fn INT32 MID_SIUTIL_CollectSectionsNonBlock(CHAN_INDEX index)
  222. *
  223. * \param index : indicate which channel we want to collect
  224. *
  225. * \return 0 for success. -1 for failed
  226. *
  227. * \note Description :
  228. * collect the specific demux channel sections without time out.
  229. *
  230. ************************************************************************************/
  231. INT32 MID_SIUTIL_CollectSectionsNonBlock(CHAN_INDEX index);
  232. /************************************************************************************/
  233. /**
  234. * \fn INT32 MID_SIUTIL_CollectSingleSection(CHAN_INDEX index, INT32 iTimeout, UINT8 **ppSec)
  235. *
  236. * \param index : indicate which channel we want to collect
  237. * \param iTimeout : time of time out
  238. * \param ppSec : pointer to collected section data
  239. *
  240. * \return 0 for success. -1 for failed
  241. *
  242. * \note Description :
  243. * only collect the specific demux channel "singal section", other dmx channel use the same demux event queue handle will be released.
  244. *
  245. ************************************************************************************/
  246. INT32 MID_SIUTIL_CollectSingleSection(CHAN_INDEX index, INT32 iTimeout, UINT8 **ppSec);
  247. /************************************************************************************/
  248. /**
  249. * \fn void MID_SIUTIL_FreeSections(CHAN_INDEX *pindex)
  250. *
  251. * \param pindex : point to which channel we want to collect
  252. *
  253. * \return none
  254. *
  255. * \note Description :
  256. * free the section buffer in channel array
  257. *
  258. ************************************************************************************/
  259. void MID_SIUTIL_FreeSections(CHAN_INDEX *pindex);
  260. /** @} end of addtogroup Section Operation */
  261. /** \addtogroup Get_channel_information Get Channel Information
  262. * \brief index and channel handle transformation
  263. * @{ */
  264. /************************************************************************************/
  265. /**
  266. * \fn CHAN_INDEX MID_SIUTIL_GetChannelIndexEx( LIVE_INPUT_UNIT InputUnit, UINT16 pid, INT8 table_id, INT16 ext_id)
  267. *
  268. * \param InputUnit : primary or secondary demux
  269. * \param pid : pid of TS packet
  270. * \param table_id : table_id
  271. * \param ext_id:it indicates program_number, if table is PMT.
  272. * it indicates transport_stream_id, if table is PAT, SDT, NIT.
  273. *
  274. * \return index of channel handle array
  275. *
  276. * \note Description :
  277. * give some ids and get the index of channel array.
  278. *
  279. ************************************************************************************/
  280. CHAN_INDEX MID_SIUTIL_GetChannelIndexEx(LIVE_INPUT_UNIT InputUnit, UINT16 pid, INT8 table_id, INT16 ext_id);
  281. /************************************************************************************/
  282. /**
  283. * \fn CHAN_INDEX MID_SIUTIL_GetChannelIndex( UINT16 pid, INT8 table_id, INT16 ext_id)
  284. *
  285. * \param pid : pid of TS packet
  286. * \param table_id : table_id
  287. * \param ext_id:it indicates program_number, if table is PMT.
  288. * it indicates transport_stream_id, if table is PAT, SDT, NIT.
  289. *
  290. * \return index of channel handle array
  291. *
  292. * \note Description :
  293. * give some ids and get the index of channel array.
  294. *
  295. ************************************************************************************/
  296. CHAN_INDEX MID_SIUTIL_GetChannelIndex(UINT16 pid, INT8 table_id, INT16 ext_id);
  297. /************************************************************************************/
  298. /**
  299. * \fn LP_MID_SiutilChannels_t MID_SIUTIL_TurnIndexToChannel(CHAN_INDEX index)
  300. *
  301. * \param index : channel index
  302. *
  303. * \return channel handle
  304. *
  305. * \note Description :
  306. * give a index and get the channel handle of array
  307. *
  308. ************************************************************************************/
  309. LP_MID_SiutilChannels_t MID_SIUTIL_TurnIndexToChannel(CHAN_INDEX index);
  310. /** @} end of addtogroup Get Channel information */
  311. /** \addtogroup Open_channels Open Channels
  312. * \brief open channels to map all tables in
  313. * @{ */
  314. /************************************************************************************/
  315. /**
  316. * \fn MID_SIUTIL_OpenChannelEx(LIVE_INPUT_UNIT InputUnit,
  317. * UINT16 pid,
  318. * INT8 table_id,
  319. * INT16 ext_id,
  320. * GL_Queue_t hChanEventQueueHdl,
  321. * MID_SIUTIL_CRC_CHECK eCrcCheck,
  322. * bool bIsMultiSection);
  323. *
  324. * \param InputUnit : primary or secondary demux
  325. * \param pid : pid of TS packet
  326. * \param table_id : table_id
  327. * \param ext_id:it indicates program_number, if table is PMT.
  328. * it indicates transport_stream_id, if table is PAT, SDT, NIT.
  329. * \param hChanEventQueueHdl : event queue handle
  330. * \param eCrcCheck : it indicate whether check CRC32 or not
  331. *
  332. * \return index of channel handle array
  333. *
  334. * \note Description : give some pids whick we want to map in.
  335. *
  336. ************************************************************************************/
  337. CHAN_INDEX MID_SIUTIL_OpenChannelEx(LIVE_INPUT_UNIT InputUnit,
  338. UINT16 pid,
  339. INT8 table_id,
  340. INT16 ext_id,
  341. GL_Queue_t hChanEventQueueHdl,
  342. MID_SIUTIL_CRC_CHECK eCrcCheck,
  343. bool bIsMultiSection); //[kiwi 20090223] Add for TOT TDT
  344. /************************************************************************************/
  345. /**
  346. * \fn MID_SIUTIL_OpenChannel(UINT16 pid,
  347. * INT8 table_id,
  348. * INT16 ext_id,
  349. * GL_Queue_t hChanEventQueueHdl,
  350. * MID_SIUTIL_CRC_CHECK eCrcCheck,
  351. * bool bIsMultiSection);
  352. *
  353. * \param pid : pid of TS packet
  354. * \param table_id : table_id
  355. * \param ext_id:it indicates program_number, if table is PMT.
  356. * it indicates transport_stream_id, if table is PAT, SDT, NIT.
  357. * \param hChanEventQueueHdl : event queue handle
  358. * \param eCrcCheck : it indicate whether check CRC32 or not
  359. *
  360. * \return index of channel handle array
  361. *
  362. * \note Description : give some pids whick we want to map in.
  363. *
  364. ************************************************************************************/
  365. CHAN_INDEX MID_SIUTIL_OpenChannel( UINT16 pid,
  366. INT8 table_id,
  367. INT16 ext_id,
  368. GL_Queue_t hChanEventQueueHdl,
  369. MID_SIUTIL_CRC_CHECK eCrcCheck,
  370. bool bIsMultiSection); //[kiwi 20090223] Add for TOT TDT
  371. /************************************************************************************/
  372. /**
  373. * \fn void MID_SIUTIL_CloseChannel(INT16 *pindex)
  374. *
  375. * \param pindex : point to which channel we want to close
  376. *
  377. * \return none
  378. *
  379. ************************************************************************************/
  380. void MID_SIUTIL_CloseChannel(INT16 *pindex);
  381. /** \addtogroup Get_service_or_descriptor Get service or descriptor
  382. * @{
  383. */
  384. /************************************************************************************/
  385. /**
  386. * \fn INT32 MID_SIUTIL_ServiceInArray(UINT16 *p_service, INT16 serLen, UINT16 serNum)
  387. *
  388. * \brief check whether the value serNum is in array p_service
  389. *
  390. * \param p_service : point to head of array
  391. * \param serLen : length of array
  392. * \param serNum : the value we want to check
  393. *
  394. * \return 0 for success, -1 for failed
  395. *
  396. ************************************************************************************/
  397. INT32 MID_SIUTIL_ServiceInArray(UINT16 *p_service, INT16 serLen, UINT16 serNum);
  398. /* Add by anzhao, 2006/05/26 */
  399. /************************************************************************************/
  400. /**
  401. * \fn INT32 MID_SIUTIL_TagsInDescriptorArray(UINT8 *p_desc,
  402. * INT16 descLen,
  403. * UINT8 *pBytes,
  404. * UINT16 sDescrLoopLen)
  405. *
  406. * \brief Count the number of descriptors we want
  407. *
  408. * \param p_desc : Defined array of descriptor we want
  409. * \param descLen : Number of unit in descriptor array
  410. * \param pBytes : Source data of descriptor
  411. * \param sDescrLoopLen : Length of descriptor source
  412. *
  413. * \return number of descriptors we want in source data
  414. *
  415. ************************************************************************************/
  416. INT32 MID_SIUTIL_TagsInDescriptorArray(UINT8 *p_desc,
  417. INT16 descLen,
  418. UINT8 *pBytes,
  419. UINT16 sDescrLoopLen);
  420. /************************************************************************************/
  421. /**
  422. * \fn UINT8* MID_SIUTIL_CreateDescriptorArray(UINT8 *p_desc,
  423. * INT16 descLen,
  424. * UINT8 *pBytes,
  425. * UINT16 sDescrLoopLen,
  426. * UINT16 *bufLen)
  427. *
  428. * \brief Extract descriptors we want into a new array
  429. *
  430. * \param p_desc : Defined array of descriptor we want
  431. * \param descLen : Number of unit in descriptor array
  432. * \param pBytes : Source data of descriptor
  433. * \param sDescrLoopLen : Length of descriptor source
  434. * \param bufLen : It indicate that received length of new array
  435. *
  436. * \return Length(bytes) of new array
  437. *
  438. ************************************************************************************/
  439. UINT8* MID_SIUTIL_CreateDescriptorArray(UINT8 *p_desc,
  440. INT16 descLen,
  441. UINT8 *pBytes,
  442. UINT16 sDescrLoopLen,
  443. UINT16 *bufLen);
  444. /** @} end of addtogroup Get service or descriptor */
  445. /** \addtogroup Change_channel_value Change Channel Value
  446. * @{
  447. */
  448. /************************************************************************************/
  449. /**
  450. * \fn INT32 MID_SIUTIL_ChangePsiChnFilter(CHAN_INDEX ChnIndex,
  451. * UINT8 FilterLen,
  452. * UINT8* Match,
  453. * UINT8* Mask,
  454. * UINT8* Negate)
  455. *
  456. * \brief Change filter of channel with this index
  457. *
  458. * \param ChnIndex : The index of channel array we want to change
  459. * \param FilterLen : total length of the filter we want to change
  460. * \param Match : indicate the value we want to match
  461. * \param Mask : indicate which bit we want to match
  462. * \param Negate : indicate the value we want to match using excusive or.
  463. *
  464. * \return 0 for success, -1 for failed
  465. *
  466. ************************************************************************************/
  467. INT32 MID_SIUTIL_ChangePsiChnFilter(CHAN_INDEX ChnIndex, UINT8 FilterLen, UINT8 * Match, UINT8 * Mask, UINT8 * Negate, UINT8 * crc32, UINT8 bskip_conti_crc);
  468. /************************************************************************************/
  469. /**
  470. * \fn CHAN_INDEX MID_SIUTIL_ChangePsiChnPID(CHAN_INDEX ChnIndex,
  471. * UINT8 FilterLen,
  472. * UINT16 prog_id,
  473. * UINT16 pid,
  474. * UINT8* Match,
  475. * UINT8* Mask,
  476. * UINT8* Negate,
  477. * MID_SIUTIL_CRC_CHECK eCrcCheck)
  478. *
  479. * \brief close the old channel and open a new one
  480. *
  481. * \param ChnIndex : The index of channel array we want to change
  482. * \param FilterLen : total length of the filter we want to change
  483. * \param prog_id : program_number
  484. * \param pid : PID
  485. * \param Match : indicate the value we want to match
  486. * \param Mask : indicate which bit we want to match
  487. * \param Negate : indicate the value we want to match using excusive or.
  488. * \param eCrcCheck : it indicate whether check CRC32 or not
  489. *
  490. * \return index of new channel handle
  491. *
  492. ************************************************************************************/
  493. CHAN_INDEX MID_SIUTIL_ChangePsiChnPID(CHAN_INDEX ChnIndex,
  494. UINT8 FilterLen, UINT16 prog_id, UINT16 pid, MID_SIUTIL_CRC_CHECK eCrcCheck);
  495. /** @} end of addtogroup Change Channel Value */
  496. /** \addtogroup Dump_buffer Dump Buffer
  497. * @{
  498. */
  499. /************************************************************************************/
  500. /**
  501. * \fn void MID_SIUTIL_DumpBuffer(UINT8 *bBuffer, INT32 len)
  502. *
  503. * \brief dump buffer value
  504. *
  505. * \param bBuffer : pointer to head of buffer we want to dump
  506. * \param len : length of data we want to dump
  507. *
  508. * \return none
  509. *
  510. ************************************************************************************/
  511. void MID_SIUTIL_DumpBuffer(UINT8 *bBuffer, INT32 len);
  512. MID_Status_t MID_SIUTIL_ReleaseDataInQueue(GL_Queue_t queueHdl);
  513. /** @} end of addtogroup Dump Buffer*/
  514. #endif /* #ifndef _MID_SIUTIL_H_20080327 */