dcct_section.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. * section and descriptor parser
  3. *
  4. * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
  5. * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  20. */
  21. #ifndef _UCSI_ATSC_DCCT_SECTION_H
  22. #define _UCSI_ATSC_DCCT_SECTION_H 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/atsc/section.h>
  28. #include <libucsi/atsc/types.h>
  29. enum atsc_dcc_context {
  30. ATSC_DCC_CONTEXT_TEMPORARY_RETUNE = 0,
  31. ATSC_DCC_CONTEXT_CHANNEL_REDIRECT = 1,
  32. };
  33. enum atsc_dcc_selection_type {
  34. ATSC_DCC_SELECTION_UNCONDITIONAL_CHANNEL_CHANGE = 0x00,
  35. ATSC_DCC_SELECTION_NUMERIC_POSTAL_CODE_INCLUSION = 0x01,
  36. ATSC_DCC_SELECTION_ALPHANUMERIC_POSTAL_CODE_INCLUSION = 0x02,
  37. ATSC_DCC_SELECTION_DEMOGRAPHIC_CATEGORY_ONE_OR_MORE = 0x05,
  38. ATSC_DCC_SELECTION_DEMOGRAPHIC_CATEGORY_ALL = 0x06,
  39. ATSC_DCC_SELECTION_GENRE_CATEGORY_ONE_OR_MORE = 0x07,
  40. ATSC_DCC_SELECTION_GENRE_CATEGORY_ALL = 0x08,
  41. ATSC_DCC_SELECTION_CANNOT_BE_AUTHORIZED = 0x09,
  42. ATSC_DCC_SELECTION_GEOGRAPHIC_LOCATION_INCLUSION = 0x0c,
  43. ATSC_DCC_SELECTION_RATING_BLOCKED = 0x0d,
  44. ATSC_DCC_SELECTION_RETURN_TO_ORIGINAL_CHANNEL = 0x0f,
  45. ATSC_DCC_SELECTION_NUMERIC_POSTAL_CODE_EXCLUSION = 0x11,
  46. ATSC_DCC_SELECTION_ALPHANUMERIC_POSTAL_CODE_EXCLUSION = 0x12,
  47. ATSC_DCC_SELECTION_DEMOGRAPHIC_CATEGORY_NOT_ONE_OR_MORE = 0x15,
  48. ATSC_DCC_SELECTION_DEMOGRAPHIC_CATEGORY_NOT_ALL = 0x16,
  49. ATSC_DCC_SELECTION_GENRE_CATEGORY_NOT_ONE_OR_MORE = 0x17,
  50. ATSC_DCC_SELECTION_GENRE_CATEGORY_NOT_ALL = 0x18,
  51. ATSC_DCC_SELECTION_GEOGRAPHIC_LOCATION_EXCLUSION = 0x1c,
  52. ATSC_DCC_SELECTION_VIEWER_DIRECT_SELECT_A = 0x20,
  53. ATSC_DCC_SELECTION_VIEWER_DIRECT_SELECT_B = 0x21,
  54. ATSC_DCC_SELECTION_VIEWER_DIRECT_SELECT_C = 0x22,
  55. ATSC_DCC_SELECTION_VIEWER_DIRECT_SELECT_D = 0x23,
  56. };
  57. /**
  58. * atsc_dcct_section structure.
  59. */
  60. struct atsc_dcct_section {
  61. struct atsc_section_psip head;
  62. uint8_t dcc_test_count;
  63. /* struct atsc_dcct_test tests */
  64. /* struct atsc_dcct_section_part2 part2 */
  65. } __ucsi_packed;
  66. struct atsc_dcct_test {
  67. EBIT4(uint32_t dcc_context : 1; ,
  68. uint32_t reserved : 3; ,
  69. uint32_t dcc_from_major_channel_number :10; ,
  70. uint32_t dcc_from_minor_channel_number :10; );
  71. EBIT3(uint32_t reserved1 : 4; ,
  72. uint32_t dcc_to_major_channel_number :10; ,
  73. uint32_t dcc_to_minor_channel_number :10; );
  74. atsctime_t start_time;
  75. atsctime_t end_time;
  76. uint8_t dcc_term_count;
  77. /* struct atsc_dcct_term terms */
  78. /* struct atsc_dcct_test_part2 part2 */
  79. } __ucsi_packed;
  80. struct atsc_dcct_term {
  81. uint8_t dcc_selection_type;
  82. uint64_t dcc_selection_id;
  83. EBIT2(uint16_t reserved : 6; ,
  84. uint16_t descriptors_length :10; );
  85. /* struct descriptor descriptors[] */
  86. } __ucsi_packed;
  87. struct atsc_dcct_test_part2 {
  88. EBIT2(uint16_t reserved : 6; ,
  89. uint16_t descriptors_length :10; );
  90. /* struct descriptor descriptors[] */
  91. } __ucsi_packed;
  92. struct atsc_dcct_section_part2 {
  93. EBIT2(uint16_t reserved : 6; ,
  94. uint16_t descriptors_length :10; );
  95. /* struct descriptor descriptors[] */
  96. } __ucsi_packed;
  97. static inline struct atsc_dcct_test *
  98. atsc_dcct_section_tests_first(struct atsc_dcct_section *dcct);
  99. static inline struct atsc_dcct_test *
  100. atsc_dcct_section_tests_next(struct atsc_dcct_section *dcct,
  101. struct atsc_dcct_test *pos,
  102. int idx);
  103. static inline struct atsc_dcct_term *
  104. atsc_dcct_test_terms_first(struct atsc_dcct_test *test);
  105. static inline struct atsc_dcct_term *
  106. atsc_dcct_test_terms_next(struct atsc_dcct_test *test,
  107. struct atsc_dcct_term *pos,
  108. int idx);
  109. /**
  110. * Process an atsc_dcct_section.
  111. *
  112. * @param section Pointer to an atsc_section_psip structure.
  113. * @return atsc_dcct_section pointer, or NULL on error.
  114. */
  115. struct atsc_dcct_section *atsc_dcct_section_codec(struct atsc_section_psip *section);
  116. /**
  117. * Accessor for the dcc_subtype field of a dcct.
  118. *
  119. * @param dcct dcct pointer.
  120. * @return The dcc_subtype.
  121. */
  122. static inline uint8_t atsc_dcct_section_dcc_subtype(struct atsc_dcct_section *dcct)
  123. {
  124. return dcct->head.ext_head.table_id_ext >> 8;
  125. }
  126. /**
  127. * Accessor for the dcc_id field of a dcct.
  128. *
  129. * @param dcct dcct pointer.
  130. * @return The dcc_id.
  131. */
  132. static inline uint8_t atsc_dcct_section_dcc_id(struct atsc_dcct_section *dcct)
  133. {
  134. return dcct->head.ext_head.table_id_ext & 0xff;
  135. }
  136. /**
  137. * Iterator for the tests field in an atsc_dcct_section.
  138. *
  139. * @param dcct atsc_dcct_section pointer.
  140. * @param pos Variable containing a pointer to the current atsc_dcct_test.
  141. * @param idx Integer used to count which test we are in.
  142. */
  143. #define atsc_dcct_section_tests_for_each(dcct, pos, idx) \
  144. for ((pos) = atsc_dcct_section_tests_first(dcct), idx=0; \
  145. (pos); \
  146. (pos) = atsc_dcct_section_tests_next(dcct, pos, ++idx))
  147. /**
  148. * Iterator for the terms field in an atsc_dcct_test.
  149. *
  150. * @param test atsc_dcct_test pointer.
  151. * @param pos Variable containing a pointer to the current atsc_dcct_term.
  152. * @param idx Integer used to count which test we are in.
  153. */
  154. #define atsc_dcct_test_terms_for_each(test, pos, idx) \
  155. for ((pos) = atsc_dcct_test_terms_first(test), idx=0; \
  156. (pos); \
  157. (pos) = atsc_dcct_test_terms_next(test, pos, ++idx))
  158. /**
  159. * Iterator for the descriptors field in a atsc_dcct_term structure.
  160. *
  161. * @param term atsc_dcct_term pointer.
  162. * @param pos Variable containing a pointer to the current descriptor.
  163. */
  164. #define atsc_dcct_term_descriptors_for_each(term, pos) \
  165. for ((pos) = atsc_dcct_term_descriptors_first(term); \
  166. (pos); \
  167. (pos) = atsc_dcct_term_descriptors_next(term, pos))
  168. /**
  169. * Accessor for the part2 field of an atsc_dcct_test.
  170. *
  171. * @param test atsc_dcct_test pointer.
  172. * @return struct atsc_dcct_test_part2 pointer.
  173. */
  174. static inline struct atsc_dcct_test_part2 *atsc_dcct_test_part2(struct atsc_dcct_test *test)
  175. {
  176. int pos = sizeof(struct atsc_dcct_test);
  177. struct atsc_dcct_term *cur_term;
  178. int idx;
  179. atsc_dcct_test_terms_for_each(test, cur_term, idx) {
  180. pos += sizeof(struct atsc_dcct_term);
  181. pos += cur_term->descriptors_length;
  182. }
  183. return (struct atsc_dcct_test_part2 *) (((uint8_t*) test) + pos);
  184. }
  185. /**
  186. * Iterator for the descriptors field in a atsc_dcct_test_part2 structure.
  187. *
  188. * @param term atsc_dcct_test_part2 pointer.
  189. * @param pos Variable containing a pointer to the current descriptor.
  190. */
  191. #define atsc_dcct_test_part2_descriptors_for_each(part2, pos) \
  192. for ((pos) = atsc_dcct_test_part2_descriptors_first(part2); \
  193. (pos); \
  194. (pos) = atsc_dcct_test_part2_descriptors_next(part2, pos))
  195. /**
  196. * Accessor for the part2 field of an atsc_dcct_section.
  197. *
  198. * @param dcct atsc_dcct_section pointer.
  199. * @return struct atsc_dcct_section_part2 pointer.
  200. */
  201. static inline struct atsc_dcct_section_part2 *atsc_dcct_section_part2(struct atsc_dcct_section *dcct)
  202. {
  203. int pos = sizeof(struct atsc_dcct_section);
  204. struct atsc_dcct_test *cur_test;
  205. int testidx;
  206. atsc_dcct_section_tests_for_each(dcct, cur_test, testidx) {
  207. struct atsc_dcct_test_part2 *part2 = atsc_dcct_test_part2(cur_test);
  208. pos += ((uint8_t*) part2 - (uint8_t*) cur_test);
  209. pos += sizeof(struct atsc_dcct_test_part2);
  210. pos += part2->descriptors_length;
  211. }
  212. return (struct atsc_dcct_section_part2 *) (((uint8_t*) dcct) + pos);
  213. }
  214. /**
  215. * Iterator for the descriptors field in a atsc_dcct_section_part2 structure.
  216. *
  217. * @param part2 atsc_dcct_section_part2 pointer.
  218. * @param pos Variable containing a pointer to the current descriptor.
  219. */
  220. #define atsc_dcct_section_part2_descriptors_for_each(part2, pos) \
  221. for ((pos) = atsc_dcct_section_part2_descriptors_first(part2); \
  222. (pos); \
  223. (pos) = atsc_dcct_section_part2_descriptors_next(part2, pos))
  224. /******************************** PRIVATE CODE ********************************/
  225. static inline struct atsc_dcct_test *
  226. atsc_dcct_section_tests_first(struct atsc_dcct_section *dcct)
  227. {
  228. size_t pos = sizeof(struct atsc_dcct_section);
  229. if (dcct->dcc_test_count == 0)
  230. return NULL;
  231. return (struct atsc_dcct_test*) (((uint8_t *) dcct) + pos);
  232. }
  233. static inline struct atsc_dcct_test *
  234. atsc_dcct_section_tests_next(struct atsc_dcct_section *dcct,
  235. struct atsc_dcct_test *pos,
  236. int idx)
  237. {
  238. if (idx >= dcct->dcc_test_count)
  239. return NULL;
  240. struct atsc_dcct_test_part2 *part2 = atsc_dcct_test_part2(pos);
  241. int len = sizeof(struct atsc_dcct_test_part2);
  242. len += part2->descriptors_length;
  243. return (struct atsc_dcct_test *) (((uint8_t*) part2) + len);
  244. }
  245. static inline struct atsc_dcct_term *
  246. atsc_dcct_test_terms_first(struct atsc_dcct_test *test)
  247. {
  248. size_t pos = sizeof(struct atsc_dcct_test);
  249. if (test->dcc_term_count == 0)
  250. return NULL;
  251. return (struct atsc_dcct_term*) (((uint8_t *) test) + pos);
  252. }
  253. static inline struct atsc_dcct_term *
  254. atsc_dcct_test_terms_next(struct atsc_dcct_test *test,
  255. struct atsc_dcct_term *pos,
  256. int idx)
  257. {
  258. if (idx >= test->dcc_term_count)
  259. return NULL;
  260. int len = sizeof(struct atsc_dcct_term);
  261. len += pos->descriptors_length;
  262. return (struct atsc_dcct_term *) (((uint8_t*) pos) + len);
  263. }
  264. static inline struct descriptor *
  265. atsc_dcct_term_descriptors_first(struct atsc_dcct_term *term)
  266. {
  267. size_t pos = sizeof(struct atsc_dcct_term);
  268. if (term->descriptors_length == 0)
  269. return NULL;
  270. return (struct descriptor*) (((uint8_t *) term) + pos);
  271. }
  272. static inline struct descriptor *
  273. atsc_dcct_term_descriptors_next(struct atsc_dcct_term *term,
  274. struct descriptor *pos)
  275. {
  276. return next_descriptor((uint8_t*) term + sizeof(struct atsc_dcct_term),
  277. term->descriptors_length,
  278. pos);
  279. }
  280. static inline struct descriptor *
  281. atsc_dcct_test_part2_descriptors_first(struct atsc_dcct_test_part2 *part2)
  282. {
  283. size_t pos = sizeof(struct atsc_dcct_test_part2);
  284. if (part2->descriptors_length == 0)
  285. return NULL;
  286. return (struct descriptor*) (((uint8_t *) part2) + pos);
  287. }
  288. static inline struct descriptor *
  289. atsc_dcct_test_part2_descriptors_next(struct atsc_dcct_test_part2 *part2,
  290. struct descriptor *pos)
  291. {
  292. return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_dcct_test_part2),
  293. part2->descriptors_length,
  294. pos);
  295. }
  296. static inline struct descriptor *
  297. atsc_dcct_section_part2_descriptors_first(struct atsc_dcct_section_part2 *part2)
  298. {
  299. size_t pos = sizeof(struct atsc_dcct_section_part2);
  300. if (part2->descriptors_length == 0)
  301. return NULL;
  302. return (struct descriptor*) (((uint8_t *) part2) + pos);
  303. }
  304. static inline struct descriptor *
  305. atsc_dcct_section_part2_descriptors_next(struct atsc_dcct_section_part2 *part2,
  306. struct descriptor *pos)
  307. {
  308. return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_dcct_section_part2),
  309. part2->descriptors_length,
  310. pos);
  311. }
  312. #ifdef __cplusplus
  313. }
  314. #endif
  315. #endif