bat_section.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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_DVB_BAT_SECTION_H
  22. #define _UCSI_DVB_BAT_SECTION_H 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/section.h>
  28. /**
  29. * dvb_bat_section structure.
  30. */
  31. struct dvb_bat_section {
  32. struct section_ext head;
  33. EBIT2(uint16_t reserved_1 : 4; ,
  34. uint16_t bouquet_descriptors_length :12; );
  35. /* struct descriptor descriptors[] */
  36. /* struct dvb_bat_section_part2 part2 */
  37. };
  38. /**
  39. * Second part of a dvb_bat_section, following the variable length descriptors field.
  40. */
  41. struct dvb_bat_section_part2 {
  42. EBIT2(uint16_t reserved_2 : 4; ,
  43. uint16_t transport_stream_loop_length :12; );
  44. /* struct dvb_bat_transport transports[] */
  45. } __ucsi_packed;
  46. /**
  47. * An entry in the transports field of a dvb_bat_section_part2.
  48. */
  49. struct dvb_bat_transport {
  50. uint16_t transport_stream_id;
  51. uint16_t original_network_id;
  52. EBIT2(uint16_t reserved : 4; ,
  53. uint16_t transport_descriptors_length :12; );
  54. /* struct descriptor descriptors[] */
  55. };
  56. /**
  57. * Process a dvb_bat_section.
  58. *
  59. * @param section Generic section pointer.
  60. * @return dvb_bat_section pointer, or NULL on error.
  61. */
  62. struct dvb_bat_section *dvb_bat_section_codec(struct section_ext *section);
  63. /**
  64. * Accessor for the bouquet_id field of a BAT.
  65. *
  66. * @param bat BAT pointer.
  67. * @return The bouquet_id.
  68. */
  69. static inline uint16_t dvb_bat_section_bouquet_id(struct dvb_bat_section *bat)
  70. {
  71. return bat->head.table_id_ext;
  72. }
  73. /**
  74. * Iterator for the descriptors field in a dvb_bat_section.
  75. *
  76. * @param bat dvb_bat_section pointer.
  77. * @param pos Variable containing a pointer to the current descriptor.
  78. */
  79. #define dvb_bat_section_descriptors_for_each(bat, pos) \
  80. for ((pos) = dvb_bat_section_descriptors_first(bat); \
  81. (pos); \
  82. (pos) = dvb_bat_section_descriptors_next(bat, pos))
  83. /**
  84. * Accessor for the second part of a dvb_bat_section.
  85. *
  86. * @param bat dvb_bat_section pointer.
  87. * @return dvb_bat_section_part2 pointer.
  88. */
  89. static inline struct dvb_bat_section_part2 *
  90. dvb_bat_section_part2(struct dvb_bat_section *bat)
  91. {
  92. return (struct dvb_bat_section_part2 *)
  93. ((uint8_t*) bat +
  94. sizeof(struct dvb_bat_section) +
  95. bat->bouquet_descriptors_length);
  96. }
  97. /**
  98. * Iterator for the transports field of a dvb_bat_section_part2.
  99. *
  100. * @param part2 dvb_bat_section_part2 pointer.
  101. * @param pos Variable containing a pointer to the current dvb_bat_transport.
  102. */
  103. #define dvb_bat_section_transports_for_each(part2, pos) \
  104. for ((pos) = dvb_bat_section_transports_first(part2); \
  105. (pos); \
  106. (pos) = dvb_bat_section_transports_next(part2, pos))
  107. /**
  108. * Iterator for the descriptors field of a dvb_bat_transport.
  109. *
  110. * @param transport dvb_bat_transport pointer.
  111. * @param pos Variable containing a pointer to the current descriptor.
  112. */
  113. #define dvb_bat_transport_descriptors_for_each(transport, pos) \
  114. for ((pos) = dvb_bat_transport_descriptors_first(transport); \
  115. (pos); \
  116. (pos) = dvb_bat_transport_descriptors_next(transport, pos))
  117. /******************************** PRIVATE CODE ********************************/
  118. static inline struct descriptor *
  119. dvb_bat_section_descriptors_first(struct dvb_bat_section *bat)
  120. {
  121. if (bat->bouquet_descriptors_length == 0)
  122. return NULL;
  123. return (struct descriptor *)
  124. ((uint8_t *) bat + sizeof(struct dvb_bat_section));
  125. }
  126. static inline struct descriptor *
  127. dvb_bat_section_descriptors_next(struct dvb_bat_section *bat,
  128. struct descriptor* pos)
  129. {
  130. return next_descriptor((uint8_t*) bat + sizeof(struct dvb_bat_section),
  131. bat->bouquet_descriptors_length,
  132. pos);
  133. }
  134. static inline struct dvb_bat_transport *
  135. dvb_bat_section_transports_first(struct dvb_bat_section_part2 *part2)
  136. {
  137. if (part2->transport_stream_loop_length == 0)
  138. return NULL;
  139. return (struct dvb_bat_transport *)
  140. ((uint8_t *) part2 + sizeof(struct dvb_bat_section_part2));
  141. }
  142. static inline struct dvb_bat_transport *
  143. dvb_bat_section_transports_next(struct dvb_bat_section_part2 *part2,
  144. struct dvb_bat_transport *pos)
  145. {
  146. uint8_t *end = (uint8_t*) part2 + sizeof(struct dvb_bat_section_part2) +
  147. part2->transport_stream_loop_length;
  148. uint8_t *next = (uint8_t*) pos + sizeof(struct dvb_bat_transport) +
  149. pos->transport_descriptors_length;
  150. if (next >= end)
  151. return NULL;
  152. return (struct dvb_bat_transport *) next;
  153. }
  154. static inline struct descriptor *
  155. dvb_bat_transport_descriptors_first(struct dvb_bat_transport *t)
  156. {
  157. if (t->transport_descriptors_length == 0)
  158. return NULL;
  159. return (struct descriptor *)
  160. ((uint8_t*)t + sizeof(struct dvb_bat_transport));
  161. }
  162. static inline struct descriptor *
  163. dvb_bat_transport_descriptors_next(struct dvb_bat_transport *t,
  164. struct descriptor* pos)
  165. {
  166. return next_descriptor((uint8_t*) t + sizeof(struct dvb_bat_transport),
  167. t->transport_descriptors_length,
  168. pos);
  169. }
  170. #ifdef __cplusplus
  171. }
  172. #endif
  173. #endif