cvct_section.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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_CVCT_SECTION_H
  22. #define _UCSI_ATSC_CVCT_SECTION_H 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/atsc/section.h>
  28. /**
  29. * atsc_cvct_section structure.
  30. */
  31. struct atsc_cvct_section {
  32. struct atsc_section_psip head;
  33. uint8_t num_channels_in_section;
  34. /* struct atsc_cvct_channel channels[] */
  35. /* struct atsc_cvct_channel_part2 part2 */
  36. } __ucsi_packed;
  37. struct atsc_cvct_channel {
  38. uint16_t short_name[7]; // UTF-16 network ordered
  39. EBIT4(uint32_t reserved : 4; ,
  40. uint32_t major_channel_number :10; ,
  41. uint32_t minor_channel_number :10; ,
  42. uint32_t modulation_mode : 8; );
  43. uint32_t carrier_frequency;
  44. uint16_t channel_TSID;
  45. uint16_t program_number;
  46. EBIT8(uint16_t ETM_location : 2; ,
  47. uint16_t access_controlled : 1; ,
  48. uint16_t hidden : 1; ,
  49. uint16_t path_select : 1; ,
  50. uint16_t out_of_band : 1; ,
  51. uint16_t hide_guide : 1; ,
  52. uint16_t reserved2 : 3; ,
  53. uint16_t service_type : 6; );
  54. uint16_t source_id;
  55. EBIT2(uint16_t reserved3 : 6; ,
  56. uint16_t descriptors_length :10; );
  57. /* struct descriptor descriptors[] */
  58. } __ucsi_packed;
  59. struct atsc_cvct_section_part2 {
  60. EBIT2(uint16_t reserved : 6; ,
  61. uint16_t descriptors_length :10; );
  62. /* struct descriptor descriptors[] */
  63. } __ucsi_packed;
  64. static inline struct atsc_cvct_channel *atsc_cvct_section_channels_first(struct atsc_cvct_section *cvct);
  65. static inline struct atsc_cvct_channel *
  66. atsc_cvct_section_channels_next(struct atsc_cvct_section *cvct, struct atsc_cvct_channel *pos, int idx);
  67. /**
  68. * Process a atsc_cvct_section.
  69. *
  70. * @param section Pointer to anj atsc_section_psip structure.
  71. * @return atsc_cvct_section pointer, or NULL on error.
  72. */
  73. struct atsc_cvct_section *atsc_cvct_section_codec(struct atsc_section_psip *section);
  74. /**
  75. * Accessor for the transport_stream_id field of a CVCT.
  76. *
  77. * @param cvdt CVDT pointer.
  78. * @return The transport_stream_id.
  79. */
  80. static inline uint16_t atsc_cvct_section_transport_stream_id(struct atsc_cvct_section *cvct)
  81. {
  82. return cvct->head.ext_head.table_id_ext;
  83. }
  84. /**
  85. * Iterator for the tables field in an atsc_cvct_section.
  86. *
  87. * @param mgt atsc_cvct_section pointer.
  88. * @param pos Variable containing a pointer to the current atsc_cvct_channel.
  89. * @param idx Integer used to count which table we in.
  90. */
  91. #define atsc_cvct_section_channels_for_each(mgt, pos, idx) \
  92. for ((pos) = atsc_cvct_section_channels_first(mgt), idx=0; \
  93. (pos); \
  94. (pos) = atsc_cvct_section_channels_next(mgt, pos, ++idx))
  95. /**
  96. * Iterator for the descriptors field in a atsc_cvct_channel structure.
  97. *
  98. * @param table atsc_cvct_channel pointer.
  99. * @param pos Variable containing a pointer to the current descriptor.
  100. */
  101. #define atsc_cvct_channel_descriptors_for_each(table, pos) \
  102. for ((pos) = atsc_cvct_channel_descriptors_first(table); \
  103. (pos); \
  104. (pos) = atsc_cvct_channel_descriptors_next(table, pos))
  105. /**
  106. * Accessor for the second part of an atsc_cvct_section.
  107. *
  108. * @param mgt atsc_cvct_section pointer.
  109. * @return atsc_cvct_section_part2 pointer.
  110. */
  111. static inline struct atsc_cvct_section_part2 *
  112. atsc_cvct_section_part2(struct atsc_cvct_section *mgt)
  113. {
  114. int pos = sizeof(struct atsc_cvct_section);
  115. struct atsc_cvct_channel *cur_table;
  116. int idx;
  117. atsc_cvct_section_channels_for_each(mgt, cur_table, idx) {
  118. pos += sizeof(struct atsc_cvct_channel);
  119. pos += cur_table->descriptors_length;
  120. }
  121. return (struct atsc_cvct_section_part2 *) (((uint8_t*) mgt) + pos);
  122. }
  123. /**
  124. * Iterator for the descriptors field in a atsc_cvct_section structure.
  125. *
  126. * @param part2 atsc_cvct_section_part2 pointer.
  127. * @param pos Variable containing a pointer to the current descriptor.
  128. */
  129. #define atsc_cvct_section_part2_descriptors_for_each(part2, pos) \
  130. for ((pos) = atsc_cvct_section_part2_descriptors_first(part2); \
  131. (pos); \
  132. (pos) = atsc_cvct_section_part2_descriptors_next(part2, pos))
  133. /******************************** PRIVATE CODE ********************************/
  134. static inline struct atsc_cvct_channel *
  135. atsc_cvct_section_channels_first(struct atsc_cvct_section *cvct)
  136. {
  137. size_t pos = sizeof(struct atsc_cvct_section);
  138. if (cvct->num_channels_in_section == 0)
  139. return NULL;
  140. return (struct atsc_cvct_channel*) (((uint8_t *) cvct) + pos);
  141. }
  142. static inline struct atsc_cvct_channel *
  143. atsc_cvct_section_channels_next(struct atsc_cvct_section *cvct,
  144. struct atsc_cvct_channel *pos,
  145. int idx)
  146. {
  147. if (idx >= cvct->num_channels_in_section)
  148. return NULL;
  149. return (struct atsc_cvct_channel *)
  150. (((uint8_t*) pos) + sizeof(struct atsc_cvct_channel) + pos->descriptors_length);
  151. }
  152. static inline struct descriptor *
  153. atsc_cvct_channel_descriptors_first(struct atsc_cvct_channel *table)
  154. {
  155. size_t pos = sizeof(struct atsc_cvct_channel);
  156. if (table->descriptors_length == 0)
  157. return NULL;
  158. return (struct descriptor*) (((uint8_t *) table) + pos);
  159. }
  160. static inline struct descriptor *
  161. atsc_cvct_channel_descriptors_next(struct atsc_cvct_channel *table,
  162. struct descriptor *pos)
  163. {
  164. return next_descriptor((uint8_t*) table + sizeof(struct atsc_cvct_channel),
  165. table->descriptors_length,
  166. pos);
  167. }
  168. static inline struct descriptor *
  169. atsc_cvct_section_part2_descriptors_first(struct atsc_cvct_section_part2 *part2)
  170. {
  171. size_t pos = sizeof(struct atsc_cvct_section_part2);
  172. if (part2->descriptors_length == 0)
  173. return NULL;
  174. return (struct descriptor*) (((uint8_t *) part2) + pos);
  175. }
  176. static inline struct descriptor *
  177. atsc_cvct_section_part2_descriptors_next(struct atsc_cvct_section_part2 *part2,
  178. struct descriptor *pos)
  179. {
  180. return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_cvct_section_part2),
  181. part2->descriptors_length,
  182. pos);
  183. }
  184. #ifdef __cplusplus
  185. }
  186. #endif
  187. #endif