eit_section.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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_ATSC_EIT_SECTION_H
  22. #define _UCSI_ATSC_EIT_SECTION_H 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/atsc/section.h>
  28. #include <libucsi/atsc/types.h>
  29. /**
  30. * atsc_eit_section structure.
  31. */
  32. struct atsc_eit_section {
  33. struct atsc_section_psip head;
  34. uint8_t num_events_in_section;
  35. /* struct atsc_eit_event events[] */
  36. } __ucsi_packed;
  37. struct atsc_eit_event {
  38. EBIT2(uint16_t reserved : 2; ,
  39. uint16_t event_id :14; );
  40. atsctime_t start_time;
  41. EBIT4(uint32_t reserved1 : 2; ,
  42. uint32_t ETM_location : 2; ,
  43. uint32_t length_in_seconds :20; ,
  44. uint32_t title_length : 8; );
  45. /* struct atsc_text title_text */
  46. /* struct atsc_eit_event_part2 part2 */
  47. } __ucsi_packed;
  48. struct atsc_eit_event_part2 {
  49. EBIT2(uint16_t reserved : 4; ,
  50. uint16_t descriptors_length :12; );
  51. /* struct descriptor descriptors[] */
  52. } __ucsi_packed;
  53. /**
  54. * Process a atsc_eit_section.
  55. *
  56. * @param section Pointer to an atsc_section_psip structure.
  57. * @return atsc_eit_section pointer, or NULL on error.
  58. */
  59. struct atsc_eit_section *atsc_eit_section_codec(struct atsc_section_psip *section);
  60. /**
  61. * Accessor for the source_id field of an EIT.
  62. *
  63. * @param eit EIT pointer.
  64. * @return The source_id .
  65. */
  66. static inline uint16_t atsc_eit_section_source_id(struct atsc_eit_section *eit)
  67. {
  68. return eit->head.ext_head.table_id_ext;
  69. }
  70. /**
  71. * Iterator for the events field in an atsc_eit_section.
  72. *
  73. * @param eit atsc_eit_section pointer.
  74. * @param pos Variable containing a pointer to the current atsc_eit_event.
  75. * @param idx Integer used to count which event we are in.
  76. */
  77. #define atsc_eit_section_events_for_each(eit, pos, idx) \
  78. for ((pos) = atsc_eit_section_events_first(eit), idx=0; \
  79. (pos); \
  80. (pos) = atsc_eit_section_events_next(eit, pos, ++idx))
  81. /**
  82. * Accessor for the title_text field of an atsc_eit_event.
  83. *
  84. * @param event atsc_eit_event pointer.
  85. * @return struct atsc_text pointer, or NULL on error.
  86. */
  87. static inline struct atsc_text *atsc_eit_event_name_title_text(struct atsc_eit_event *event)
  88. {
  89. if (event->title_length == 0)
  90. return NULL;
  91. return (struct atsc_text*)(((uint8_t*) event) + sizeof(struct atsc_eit_event));
  92. }
  93. /**
  94. * Accessor for the part2 field of an atsc_eit_event.
  95. *
  96. * @param event atsc_eit_event pointer.
  97. * @return struct atsc_eit_event_part2 pointer.
  98. */
  99. static inline struct atsc_eit_event_part2 *atsc_eit_event_part2(struct atsc_eit_event *event)
  100. {
  101. return (struct atsc_eit_event_part2 *)
  102. (((uint8_t*) event) + sizeof(struct atsc_eit_event) + event->title_length);
  103. }
  104. /**
  105. * Iterator for the descriptors field in a atsc_eit_section structure.
  106. *
  107. * @param part2 atsc_eit_event_part2 pointer.
  108. * @param pos Variable containing a pointer to the current descriptor.
  109. */
  110. #define atsc_eit_event_part2_descriptors_for_each(part2, pos) \
  111. for ((pos) = atsc_eit_event_part2_descriptors_first(part2); \
  112. (pos); \
  113. (pos) = atsc_eit_event_part2_descriptors_next(part2, pos))
  114. /******************************** PRIVATE CODE ********************************/
  115. static inline struct atsc_eit_event *
  116. atsc_eit_section_events_first(struct atsc_eit_section *eit)
  117. {
  118. size_t pos = sizeof(struct atsc_eit_section);
  119. if (eit->num_events_in_section == 0)
  120. return NULL;
  121. return (struct atsc_eit_event*) (((uint8_t *) eit) + pos);
  122. }
  123. static inline struct atsc_eit_event *
  124. atsc_eit_section_events_next(struct atsc_eit_section *eit,
  125. struct atsc_eit_event *pos,
  126. int idx)
  127. {
  128. if (idx >= eit->num_events_in_section)
  129. return NULL;
  130. struct atsc_eit_event_part2 *part2 = atsc_eit_event_part2(pos);
  131. int len = sizeof(struct atsc_eit_event_part2);
  132. len += part2->descriptors_length;
  133. return (struct atsc_eit_event *) (((uint8_t*) part2) + len);
  134. }
  135. static inline struct descriptor *
  136. atsc_eit_event_part2_descriptors_first(struct atsc_eit_event_part2 *part2)
  137. {
  138. size_t pos = sizeof(struct atsc_eit_event_part2);
  139. if (part2->descriptors_length == 0)
  140. return NULL;
  141. return (struct descriptor*) (((uint8_t *) part2) + pos);
  142. }
  143. static inline struct descriptor *
  144. atsc_eit_event_part2_descriptors_next(struct atsc_eit_event_part2 *part2,
  145. struct descriptor *pos)
  146. {
  147. return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_eit_event_part2),
  148. part2->descriptors_length,
  149. pos);
  150. }
  151. #ifdef __cplusplus
  152. }
  153. #endif
  154. #endif