sit_section.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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_SIT_SECTION_H
  22. #define _UCSI_DVB_SIT_SECTION_H 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/section.h>
  28. /**
  29. * dvb_sit_section structure.
  30. */
  31. struct dvb_sit_section {
  32. struct section_ext head;
  33. EBIT2(uint16_t reserved : 4; ,
  34. uint16_t transmission_info_loop_length :12; );
  35. /* struct descriptor descriptors[] */
  36. /* struct dvb_sit_service services[] */
  37. };
  38. /**
  39. * An entry in the services field of a dvb_sit_section.
  40. */
  41. struct dvb_sit_service {
  42. uint16_t service_id;
  43. EBIT3(uint16_t reserved : 1; ,
  44. uint16_t running_status : 3; ,
  45. uint16_t service_loop_length :12; );
  46. /* struct descriptor descriptors[] */
  47. };
  48. /**
  49. * Process a dvb_sit_section.
  50. *
  51. * @param section Generic section_ext structure.
  52. * @return dvb_sit_section pointer, or NULL on error.
  53. */
  54. struct dvb_sit_section * dvb_sit_section_codec(struct section_ext *section);
  55. /**
  56. * Iterator for descriptors field in a dvb_sit_section.
  57. *
  58. * @param sit dvb_sit_section Pointer.
  59. * @param pos Variable holding pointer to current descriptor.
  60. */
  61. #define dvb_sit_section_descriptors_for_each(sit, pos) \
  62. for ((pos) = dvb_sit_section_descriptors_first(sit); \
  63. (pos); \
  64. (pos) = dvb_sit_section_descriptors_first(sit))
  65. /**
  66. * Iterator for services field in a dvb_sit_section.
  67. *
  68. * @param sit dvb_sit_section Pointer.
  69. * @param pos Variable holding pointer to current dvb_sit_service.
  70. */
  71. #define dvb_sit_section_services_for_each(sit, pos) \
  72. for ((pos) = dvb_sit_section_services_first(sit); \
  73. (pos); \
  74. (pos) = dvb_sit_section_services_next(sit, pos))
  75. /**
  76. * Iterator for descriptors field in a dvb_sit_service.
  77. *
  78. * @param service dvb_sit_service Pointer.
  79. * @param pos Variable holding pointer to current descriptor.
  80. */
  81. #define dvb_sit_service_descriptors_for_each(service, pos) \
  82. for ((pos) = dvb_sit_service_descriptors_first(service); \
  83. (pos); \
  84. (pos) = dvb_sit_service_descriptors_next(service, pos))
  85. /******************************** PRIVATE CODE ********************************/
  86. static inline struct descriptor *
  87. dvb_sit_section_descriptors_first(struct dvb_sit_section *sit)
  88. {
  89. if (sit->transmission_info_loop_length == 0)
  90. return NULL;
  91. return (struct descriptor *)
  92. ((uint8_t *) sit + sizeof(struct dvb_sit_section));
  93. }
  94. static inline struct descriptor *
  95. dvb_sit_section_descriptors_next(struct dvb_sit_section *sit,
  96. struct descriptor* pos)
  97. {
  98. return next_descriptor((uint8_t*) sit + sizeof(struct dvb_sit_section),
  99. sit->transmission_info_loop_length,
  100. pos);
  101. }
  102. static inline struct dvb_sit_service *
  103. dvb_sit_section_services_first(struct dvb_sit_section *sit)
  104. {
  105. size_t pos = sizeof(struct dvb_sit_section) + sit->transmission_info_loop_length;
  106. if (pos >= section_ext_length(&sit->head))
  107. return NULL;
  108. return (struct dvb_sit_service*) ((uint8_t *) sit + pos);
  109. }
  110. static inline struct dvb_sit_service *
  111. dvb_sit_section_services_next(struct dvb_sit_section *sit,
  112. struct dvb_sit_service *pos)
  113. {
  114. uint8_t *end = (uint8_t*) sit + section_ext_length(&sit->head);
  115. uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_sit_service) +
  116. pos->service_loop_length;
  117. if (next >= end)
  118. return NULL;
  119. return (struct dvb_sit_service *) next;
  120. }
  121. static inline struct descriptor *
  122. dvb_sit_service_descriptors_first(struct dvb_sit_service * t)
  123. {
  124. if (t->service_loop_length == 0)
  125. return NULL;
  126. return (struct descriptor *)
  127. ((uint8_t *) t + sizeof(struct dvb_sit_service));
  128. }
  129. static inline struct descriptor *
  130. dvb_sit_service_descriptors_next(struct dvb_sit_service *t,
  131. struct descriptor* pos)
  132. {
  133. return next_descriptor((uint8_t*) t + sizeof(struct dvb_sit_service),
  134. t->service_loop_length,
  135. pos);
  136. }
  137. #ifdef __cplusplus
  138. }
  139. #endif
  140. #endif