sdt_section.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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_SDT_SECTION_H
  22. #define _UCSI_DVB_SDT_SECTION_H 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/section.h>
  28. /**
  29. * dvb_sdt_section structure.
  30. */
  31. struct dvb_sdt_section {
  32. struct section_ext head;
  33. uint16_t original_network_id;
  34. uint8_t reserved;
  35. /* struct dvb_sdt_service services[] */
  36. } __ucsi_packed;
  37. /**
  38. * An entry in the services field of a dvb_sdt_section.
  39. */
  40. struct dvb_sdt_service {
  41. uint16_t service_id;
  42. EBIT3(uint8_t reserved : 6; ,
  43. uint8_t eit_schedule_flag : 1; ,
  44. uint8_t eit_present_following_flag : 1; );
  45. EBIT3(uint16_t running_status : 3; ,
  46. uint16_t free_ca_mode : 1; ,
  47. uint16_t descriptors_loop_length :12; );
  48. /* struct descriptor descriptors[] */
  49. } __ucsi_packed;
  50. /**
  51. * Process a dvb_sdt_section.
  52. *
  53. * @param section Pointer to a generic section_ext structure.
  54. * @return dvb_sdt_section pointer, or NULL on error.
  55. */
  56. struct dvb_sdt_section * dvb_sdt_section_codec(struct section_ext *section);
  57. /**
  58. * Accessor for the transport_stream_id field of an SDT.
  59. *
  60. * @param sdt SDT pointer.
  61. * @return The transport_stream_id.
  62. */
  63. static inline uint16_t dvb_sdt_section_transport_stream_id(struct dvb_sdt_section *sdt)
  64. {
  65. return sdt->head.table_id_ext;
  66. }
  67. /**
  68. * Iterator for the services field in a dvb_sdt_section.
  69. *
  70. * @param sdt dvb_sdt_section pointer.
  71. * @param pos Variable containing a pointer to the current dvb_sdt_service.
  72. */
  73. #define dvb_sdt_section_services_for_each(sdt, pos) \
  74. for ((pos) = dvb_sdt_section_services_first(sdt); \
  75. (pos); \
  76. (pos) = dvb_sdt_section_services_next(sdt, pos))
  77. /**
  78. * Iterator for the descriptors field in a dvb_sdt_service.
  79. *
  80. * @param service dvb_sdt_service pointer.
  81. * @param pos Variable containing a pointer to the current descriptor.
  82. */
  83. #define dvb_sdt_service_descriptors_for_each(service, pos) \
  84. for ((pos) = dvb_sdt_service_descriptors_first(service); \
  85. (pos); \
  86. (pos) = dvb_sdt_service_descriptors_next(service, pos))
  87. /******************************** PRIVATE CODE ********************************/
  88. static inline struct dvb_sdt_service *
  89. dvb_sdt_section_services_first(struct dvb_sdt_section * sdt)
  90. {
  91. size_t pos = sizeof(struct dvb_sdt_section);
  92. if (pos >= section_ext_length(&sdt->head))
  93. return NULL;
  94. return (struct dvb_sdt_service*) ((uint8_t *) sdt + pos);
  95. }
  96. static inline struct dvb_sdt_service *
  97. dvb_sdt_section_services_next(struct dvb_sdt_section * sdt,
  98. struct dvb_sdt_service * pos)
  99. {
  100. uint8_t *end = (uint8_t*) sdt + section_ext_length(&sdt->head);
  101. uint8_t *next = (uint8_t*) pos + sizeof(struct dvb_sdt_service) +
  102. pos->descriptors_loop_length;
  103. if (next >= end)
  104. return NULL;
  105. return (struct dvb_sdt_service *) next;
  106. }
  107. static inline struct descriptor *
  108. dvb_sdt_service_descriptors_first(struct dvb_sdt_service *svc)
  109. {
  110. if (svc->descriptors_loop_length == 0)
  111. return NULL;
  112. return (struct descriptor *)
  113. ((uint8_t*) svc + sizeof(struct dvb_sdt_service));
  114. }
  115. static inline struct descriptor *
  116. dvb_sdt_service_descriptors_next(struct dvb_sdt_service *svc,
  117. struct descriptor* pos)
  118. {
  119. return next_descriptor((uint8_t*) svc + sizeof(struct dvb_sdt_service),
  120. svc->descriptors_loop_length,
  121. pos);
  122. }
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #endif