dccsct_section.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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_DCCSCT_SECTION_H
  22. #define _UCSI_ATSC_DCCSCT_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_dccst_update_types {
  30. ATSC_DCCST_UPDATE_NEW_GENRE = 0x01,
  31. ATSC_DCCST_UPDATE_NEW_STATE = 0x02,
  32. ATSC_DCCST_UPDATE_NEW_COUNTY = 0x03,
  33. };
  34. /**
  35. * atsc_dccsct_section structure.
  36. */
  37. struct atsc_dccsct_section {
  38. struct atsc_section_psip head;
  39. uint8_t updates_defined;
  40. /* struct atsc_dccsct_update updates */
  41. /* struct atsc_dccsct_section_part2 part2 */
  42. } __ucsi_packed;
  43. struct atsc_dccsct_update {
  44. uint8_t update_type;
  45. uint8_t update_data_length;
  46. /* struct atsc_dccsct_update_XXX data -- depends on update_type */
  47. /* struct atsc_dccsct_update_part2 part2 */
  48. } __ucsi_packed;
  49. struct atsc_dccsct_update_new_genre {
  50. uint8_t genre_category_code;
  51. /* atsc_text name */
  52. } __ucsi_packed;
  53. struct atsc_dccsct_update_new_state {
  54. uint8_t dcc_state_location_code;
  55. /* atsc_text name */
  56. } __ucsi_packed;
  57. struct atsc_dccsct_update_new_county {
  58. uint8_t state_code;
  59. EBIT2(uint16_t reserved : 6; ,
  60. uint16_t dcc_county_location_code :10; );
  61. /* atsc_text name */
  62. } __ucsi_packed;
  63. struct atsc_dccsct_update_part2 {
  64. EBIT2(uint16_t reserved : 6; ,
  65. uint16_t descriptors_length :10; );
  66. /* struct descriptor descriptors[] */
  67. } __ucsi_packed;
  68. struct atsc_dccsct_section_part2 {
  69. EBIT2(uint16_t reserved : 6; ,
  70. uint16_t descriptors_length :10; );
  71. /* struct descriptor descriptors[] */
  72. } __ucsi_packed;
  73. /**
  74. * Process an atsc_dccsct_section.
  75. *
  76. * @param section Pointer to an atsc_section_psip structure.
  77. * @return atsc_dccsct_section pointer, or NULL on error.
  78. */
  79. struct atsc_dccsct_section *atsc_dccsct_section_codec(struct atsc_section_psip *section);
  80. /**
  81. * Accessor for the dccsct_type field of a dccsct.
  82. *
  83. * @param dccsct dccsct pointer.
  84. * @return The dccsct_type.
  85. */
  86. static inline uint16_t atsc_dccsct_section_dccsct_type(struct atsc_dccsct_section *dccsct)
  87. {
  88. return dccsct->head.ext_head.table_id_ext;
  89. }
  90. /**
  91. * Iterator for the updates field in an atsc_dccsct_section.
  92. *
  93. * @param dccsct atsc_dccsct_section pointer.
  94. * @param pos Variable containing a pointer to the current atsc_dccsct_update.
  95. * @param idx Integer used to count which test we are in.
  96. */
  97. #define atsc_dccsct_section_updates_for_each(dccsct, pos, idx) \
  98. for ((pos) = atsc_dccsct_section_updates_first(dccsct), idx=0; \
  99. (pos); \
  100. (pos) = atsc_dccsct_section_updates_next(dccsct, pos, ++idx))
  101. /**
  102. * Accessor for the data field of a new genre atsc_dccsct_update.
  103. *
  104. * @param update atsc_dccsct_update pointer.
  105. * @return struct atsc_dccsct_update_new_genre pointer.
  106. */
  107. static inline struct atsc_dccsct_update_new_genre *atsc_dccsct_update_new_genre(struct atsc_dccsct_update *update)
  108. {
  109. if (update->update_type != ATSC_DCCST_UPDATE_NEW_GENRE)
  110. return NULL;
  111. return (struct atsc_dccsct_update_new_genre *)
  112. (((uint8_t*) update) + sizeof(struct atsc_dccsct_update));
  113. }
  114. /**
  115. * Accessor for the name field of an atsc_dccsct_update_new_genre.
  116. *
  117. * @param update atsc_dccsct_update_new_genre pointer.
  118. * @return text pointer.
  119. */
  120. static inline struct atsc_text *atsc_dccsct_update_new_genre_name(struct atsc_dccsct_update *update)
  121. {
  122. if ((update->update_data_length - 1) == 0)
  123. return NULL;
  124. return (struct atsc_text *)
  125. (((uint8_t*) update) + sizeof(struct atsc_dccsct_update_new_genre));
  126. }
  127. /**
  128. * Accessor for the data field of a new state atsc_dccsct_update.
  129. *
  130. * @param update atsc_dccsct_update pointer.
  131. * @return struct atsc_dccsct_update_new_state pointer.
  132. */
  133. static inline struct atsc_dccsct_update_new_state *
  134. atsc_dccsct_update_new_state(struct atsc_dccsct_update *update)
  135. {
  136. if (update->update_type != ATSC_DCCST_UPDATE_NEW_STATE)
  137. return NULL;
  138. return (struct atsc_dccsct_update_new_state *)
  139. (((uint8_t*) update) + sizeof(struct atsc_dccsct_update));
  140. }
  141. /**
  142. * Accessor for the name field of an atsc_dccsct_update_new_state.
  143. *
  144. * @param update atsc_dccsct_update_new_state pointer.
  145. * @return text pointer.
  146. */
  147. static inline struct atsc_text *atsc_dccsct_update_new_state_name(struct atsc_dccsct_update *update)
  148. {
  149. if ((update->update_data_length - 1) == 0)
  150. return NULL;
  151. return (struct atsc_text *)
  152. (((uint8_t*) update) + sizeof(struct atsc_dccsct_update_new_state));
  153. }
  154. /**
  155. * Accessor for the data field of a new county atsc_dccsct_update.
  156. *
  157. * @param update atsc_dccsct_update pointer.
  158. * @return struct atsc_dccsct_update_new_county pointer.
  159. */
  160. static inline struct atsc_dccsct_update_new_county *
  161. atsc_dccsct_update_new_county(struct atsc_dccsct_update *update)
  162. {
  163. if (update->update_type != ATSC_DCCST_UPDATE_NEW_COUNTY)
  164. return NULL;
  165. return (struct atsc_dccsct_update_new_county *)
  166. (((uint8_t*) update) + sizeof(struct atsc_dccsct_update));
  167. }
  168. /**
  169. * Accessor for the name field of an atsc_dccsct_update_new_county.
  170. *
  171. * @param update atsc_dccsct_update_new_county pointer.
  172. * @return text pointer.
  173. */
  174. static inline struct atsc_text *atsc_dccsct_update_new_county_name(struct atsc_dccsct_update *update)
  175. {
  176. if ((update->update_data_length - 3) == 0)
  177. return NULL;
  178. return (struct atsc_text*)
  179. (((uint8_t*) update) + sizeof(struct atsc_dccsct_update_new_county));
  180. }
  181. /**
  182. * Accessor for the part2 field of an atsc_dccsct_update.
  183. *
  184. * @param update atsc_dccsct_update pointer.
  185. * @return struct atsc_dccsct_test_part2 pointer.
  186. */
  187. static inline struct atsc_dccsct_update_part2 *atsc_dccsct_update_part2(struct atsc_dccsct_update *update)
  188. {
  189. int pos = sizeof(struct atsc_dccsct_update);
  190. pos += update->update_data_length;
  191. return (struct atsc_dccsct_update_part2 *) (((uint8_t*) update) + pos);
  192. }
  193. /**
  194. * Iterator for the descriptors field in an atsc_dccsct_update_part2 structure.
  195. *
  196. * @param part2 atsc_dccsct_update_part2 pointer.
  197. * @param pos Variable containing a pointer to the current descriptor.
  198. */
  199. #define atsc_dccsct_update_part2_descriptors_for_each(part2, pos) \
  200. for ((pos) = atsc_dccsct_update_part2_descriptors_first(part2); \
  201. (pos); \
  202. (pos) = atsc_dccsct_update_part2_descriptors_next(part2, pos))
  203. /**
  204. * Iterator for the descriptors field in a atsc_dccsct_section_part2 structure.
  205. *
  206. * @param part2 atsc_dccsct_section_part2 pointer.
  207. * @param pos Variable containing a pointer to the current descriptor.
  208. */
  209. #define atsc_dccsct_section_part2_descriptors_for_each(part2, pos) \
  210. for ((pos) = atsc_dccsct_section_part2_descriptors_first(part2); \
  211. (pos); \
  212. (pos) = atsc_dccsct_section_part2_descriptors_next(part2, pos))
  213. /******************************** PRIVATE CODE ********************************/
  214. static inline struct atsc_dccsct_update *
  215. atsc_dccsct_section_updates_first(struct atsc_dccsct_section *dccsct)
  216. {
  217. size_t pos = sizeof(struct atsc_dccsct_section);
  218. if (dccsct->updates_defined == 0)
  219. return NULL;
  220. return (struct atsc_dccsct_update*) (((uint8_t *) dccsct) + pos);
  221. }
  222. static inline struct atsc_dccsct_update*
  223. atsc_dccsct_section_updates_next(struct atsc_dccsct_section *dccsct,
  224. struct atsc_dccsct_update *pos,
  225. int idx)
  226. {
  227. if (idx >= dccsct->updates_defined)
  228. return NULL;
  229. struct atsc_dccsct_update_part2 *part2 = atsc_dccsct_update_part2(pos);
  230. int len = sizeof(struct atsc_dccsct_update_part2);
  231. len += part2->descriptors_length;
  232. return (struct atsc_dccsct_update *) (((uint8_t*) part2) + len);
  233. }
  234. static inline struct descriptor *
  235. atsc_dccsct_update_part2_descriptors_first(struct atsc_dccsct_update_part2 *part2)
  236. {
  237. size_t pos = sizeof(struct atsc_dccsct_update_part2);
  238. if (part2->descriptors_length == 0)
  239. return NULL;
  240. return (struct descriptor*) (((uint8_t *) part2) + pos);
  241. }
  242. static inline struct descriptor *
  243. atsc_dccsct_update_part2_descriptors_next(struct atsc_dccsct_update_part2 *part2,
  244. struct descriptor *pos)
  245. {
  246. return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_dccsct_update_part2),
  247. part2->descriptors_length,
  248. pos);
  249. }
  250. static inline struct descriptor *
  251. atsc_dccsct_section_part2_descriptors_first(struct atsc_dccsct_section_part2 *part2)
  252. {
  253. size_t pos = sizeof(struct atsc_dccsct_section_part2);
  254. if (part2->descriptors_length == 0)
  255. return NULL;
  256. return (struct descriptor*) (((uint8_t *) part2) + pos);
  257. }
  258. static inline struct descriptor *
  259. atsc_dccsct_section_part2_descriptors_next(struct atsc_dccsct_section_part2 *part2,
  260. struct descriptor *pos)
  261. {
  262. return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_dccsct_section_part2),
  263. part2->descriptors_length,
  264. pos);
  265. }
  266. #ifdef __cplusplus
  267. }
  268. #endif
  269. #endif