tvct_section.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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_TVCT_SECTION_H
  22. #define _UCSI_ATSC_TVCT_SECTION_H 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/atsc/section.h>
  28. /**
  29. * atsc_tvct_section structure.
  30. */
  31. struct atsc_tvct_section {
  32. struct atsc_section_psip head;
  33. uint8_t num_channels_in_section;
  34. /* struct atsc_tvct_channel channels[] */
  35. /* struct atsc_tvct_channel_part2 part2 */
  36. } __ucsi_packed;
  37. struct atsc_tvct_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. EBIT7(uint16_t ETM_location : 2; ,
  47. uint16_t access_controlled : 1; ,
  48. uint16_t hidden : 1; ,
  49. uint16_t reserved1 : 2; ,
  50. uint16_t hide_guide : 1; ,
  51. uint16_t reserved2 : 3; ,
  52. uint16_t service_type : 6; );
  53. uint16_t source_id;
  54. EBIT2(uint16_t reserved3 : 6; ,
  55. uint16_t descriptors_length :10; );
  56. /* struct descriptor descriptors[] */
  57. } __ucsi_packed;
  58. struct atsc_tvct_section_part2 {
  59. EBIT2(uint16_t reserved : 6; ,
  60. uint16_t descriptors_length :10; );
  61. /* struct descriptor descriptors[] */
  62. } __ucsi_packed;
  63. static inline struct atsc_tvct_channel *atsc_tvct_section_channels_first(struct atsc_tvct_section *tvct);
  64. static inline struct atsc_tvct_channel *
  65. atsc_tvct_section_channels_next(struct atsc_tvct_section *tvct, struct atsc_tvct_channel *pos, int idx);
  66. /**
  67. * Process a atsc_tvct_section.
  68. *
  69. * @param section Pointer to an atsc_section_psip structure.
  70. * @return atsc_tvct_section pointer, or NULL on error.
  71. */
  72. struct atsc_tvct_section *atsc_tvct_section_codec(struct atsc_section_psip *section);
  73. /**
  74. * Accessor for the transport_stream_id field of a TVCT.
  75. *
  76. * @param tvct TVCT pointer.
  77. * @return The transport_stream_id.
  78. */
  79. static inline uint16_t atsc_tvct_section_transport_stream_id(struct atsc_tvct_section *tvct)
  80. {
  81. return tvct->head.ext_head.table_id_ext;
  82. }
  83. /**
  84. * Iterator for the channels field in an atsc_tvct_section.
  85. *
  86. * @param mgt atsc_tvct_section pointer.
  87. * @param pos Variable containing a pointer to the current atsc_tvct_channel.
  88. * @param idx Integer used to count which channel we in.
  89. */
  90. #define atsc_tvct_section_channels_for_each(mgt, pos, idx) \
  91. for ((pos) = atsc_tvct_section_channels_first(mgt), idx=0; \
  92. (pos); \
  93. (pos) = atsc_tvct_section_channels_next(mgt, pos, ++idx))
  94. /**
  95. * Iterator for the descriptors field in a atsc_tvct_channel structure.
  96. *
  97. * @param channel atsc_tvct_channel pointer.
  98. * @param pos Variable containing a pointer to the current descriptor.
  99. */
  100. #define atsc_tvct_channel_descriptors_for_each(channel, pos) \
  101. for ((pos) = atsc_tvct_channel_descriptors_first(channel); \
  102. (pos); \
  103. (pos) = atsc_tvct_channel_descriptors_next(channel, pos))
  104. /**
  105. * Accessor for the second part of an atsc_tvct_section.
  106. *
  107. * @param mgt atsc_tvct_section pointer.
  108. * @return atsc_tvct_section_part2 pointer.
  109. */
  110. static inline struct atsc_tvct_section_part2 *
  111. atsc_tvct_section_part2(struct atsc_tvct_section *mgt)
  112. {
  113. int pos = sizeof(struct atsc_tvct_section);
  114. struct atsc_tvct_channel *cur_channel;
  115. int idx;
  116. atsc_tvct_section_channels_for_each(mgt, cur_channel, idx) {
  117. pos += sizeof(struct atsc_tvct_channel);
  118. pos += cur_channel->descriptors_length;
  119. }
  120. return (struct atsc_tvct_section_part2 *) (((uint8_t*) mgt) + pos);
  121. }
  122. /**
  123. * Iterator for the descriptors field in a atsc_tvct_section structure.
  124. *
  125. * @param part2 atsc_tvct_section_part2 pointer.
  126. * @param pos Variable containing a pointer to the current descriptor.
  127. */
  128. #define atsc_tvct_section_part2_descriptors_for_each(part2, pos) \
  129. for ((pos) = atsc_tvct_section_part2_descriptors_first(part2); \
  130. (pos); \
  131. (pos) = atsc_tvct_section_part2_descriptors_next(part2, pos))
  132. /******************************** PRIVATE CODE ********************************/
  133. static inline struct atsc_tvct_channel *
  134. atsc_tvct_section_channels_first(struct atsc_tvct_section *tvct)
  135. {
  136. size_t pos = sizeof(struct atsc_tvct_section);
  137. if (tvct->num_channels_in_section == 0)
  138. return NULL;
  139. return (struct atsc_tvct_channel*) (((uint8_t *) tvct) + pos);
  140. }
  141. static inline struct atsc_tvct_channel *
  142. atsc_tvct_section_channels_next(struct atsc_tvct_section *tvct,
  143. struct atsc_tvct_channel *pos,
  144. int idx)
  145. {
  146. if (idx >= tvct->num_channels_in_section)
  147. return NULL;
  148. return (struct atsc_tvct_channel *)
  149. (((uint8_t*) pos) + sizeof(struct atsc_tvct_channel) + pos->descriptors_length);
  150. }
  151. static inline struct descriptor *
  152. atsc_tvct_channel_descriptors_first(struct atsc_tvct_channel *channel)
  153. {
  154. size_t pos = sizeof(struct atsc_tvct_channel);
  155. if (channel->descriptors_length == 0)
  156. return NULL;
  157. return (struct descriptor*) (((uint8_t *) channel) + pos);
  158. }
  159. static inline struct descriptor *
  160. atsc_tvct_channel_descriptors_next(struct atsc_tvct_channel *channel,
  161. struct descriptor *pos)
  162. {
  163. return next_descriptor((uint8_t*) channel + sizeof(struct atsc_tvct_channel),
  164. channel->descriptors_length,
  165. pos);
  166. }
  167. static inline struct descriptor *
  168. atsc_tvct_section_part2_descriptors_first(struct atsc_tvct_section_part2 *part2)
  169. {
  170. size_t pos = sizeof(struct atsc_tvct_section_part2);
  171. if (part2->descriptors_length == 0)
  172. return NULL;
  173. return (struct descriptor*) (((uint8_t *) part2) + pos);
  174. }
  175. static inline struct descriptor *
  176. atsc_tvct_section_part2_descriptors_next(struct atsc_tvct_section_part2 *part2,
  177. struct descriptor *pos)
  178. {
  179. return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_tvct_section_part2),
  180. part2->descriptors_length,
  181. pos);
  182. }
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #endif