eit_section.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_EIT_SECTION_H
  22. #define _UCSI_DVB_EIT_SECTION_H 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/section.h>
  28. #include <libucsi/dvb/types.h>
  29. /**
  30. * dvb_eit_section structure.
  31. */
  32. struct dvb_eit_section {
  33. struct section_ext head;
  34. uint16_t transport_stream_id;
  35. uint16_t original_network_id;
  36. uint8_t segment_last_section_number;
  37. uint8_t last_table_id;
  38. /* struct eit_event events[] */
  39. } __ucsi_packed;
  40. /**
  41. * An entry in the events field of a dvb_eit_section.
  42. */
  43. struct dvb_eit_event {
  44. uint16_t event_id;
  45. dvbdate_t start_time;
  46. dvbduration_t duration;
  47. EBIT3(uint16_t running_status : 3; ,
  48. uint16_t free_ca_mode : 1; ,
  49. uint16_t descriptors_loop_length:12; );
  50. /* struct descriptor descriptors[] */
  51. } __ucsi_packed;
  52. /**
  53. * Process a dvb_eit_section.
  54. *
  55. * @param section Pointer to a generic section_ext structure.
  56. * @return Pointer to a dvb_eit_section, or NULL on error.
  57. */
  58. struct dvb_eit_section *dvb_eit_section_codec(struct section_ext *section);
  59. /**
  60. * Accessor for the service_id field of an EIT.
  61. *
  62. * @param eit EIT pointer.
  63. * @return The service_id.
  64. */
  65. static inline uint16_t dvb_eit_section_service_id(struct dvb_eit_section *eit)
  66. {
  67. return eit->head.table_id_ext;
  68. }
  69. /**
  70. * Iterator for the events field of a dvb_eit_section.
  71. *
  72. * @param eit dvb_eit_section pointer.
  73. * @param pos Variable containing a pointer to the current dvb_eit_event.
  74. */
  75. #define dvb_eit_section_events_for_each(eit, pos) \
  76. for ((pos) = dvb_eit_section_events_first(eit); \
  77. (pos); \
  78. (pos) = dvb_eit_section_events_next(eit, pos))
  79. /**
  80. * Iterator for the descriptors field of a dvb_eit_event.
  81. *
  82. * @param eit dvb_eit_event pointer.
  83. * @param pos Variable containing a pointer to the current descriptor.
  84. */
  85. #define dvb_eit_event_descriptors_for_each(event, pos) \
  86. for ((pos) = dvb_eit_event_descriptors_first(event); \
  87. (pos); \
  88. (pos) = dvb_eit_event_descriptors_next(event, pos))
  89. /******************************** PRIVATE CODE ********************************/
  90. static inline struct dvb_eit_event *
  91. dvb_eit_section_events_first(struct dvb_eit_section *eit)
  92. {
  93. size_t pos = sizeof(struct dvb_eit_section);
  94. if (pos >= section_ext_length(&eit->head))
  95. return NULL;
  96. return (struct dvb_eit_event*) ((uint8_t *) eit + pos);
  97. }
  98. static inline struct dvb_eit_event *
  99. dvb_eit_section_events_next(struct dvb_eit_section *eit,
  100. struct dvb_eit_event *pos)
  101. {
  102. uint8_t *end = (uint8_t*) eit + section_ext_length(&eit->head);
  103. uint8_t *next = (uint8_t *) pos +
  104. sizeof(struct dvb_eit_event) +
  105. pos->descriptors_loop_length;
  106. if (next >= end)
  107. return NULL;
  108. return (struct dvb_eit_event *) next;
  109. }
  110. static inline struct descriptor *
  111. dvb_eit_event_descriptors_first(struct dvb_eit_event * t)
  112. {
  113. if (t->descriptors_loop_length == 0)
  114. return NULL;
  115. return (struct descriptor *)
  116. ((uint8_t *) t + sizeof(struct dvb_eit_event));
  117. }
  118. static inline struct descriptor *
  119. dvb_eit_event_descriptors_next(struct dvb_eit_event * t,
  120. struct descriptor* pos)
  121. {
  122. return next_descriptor((uint8_t*) t + sizeof(struct dvb_eit_event),
  123. t->descriptors_loop_length,
  124. pos);
  125. }
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif