nit_section.h 5.6 KB

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