mgt_section.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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_MGT_SECTION_H
  22. #define _UCSI_ATSC_MGT_SECTION_H 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/atsc/section.h>
  28. enum atsc_mgt_section_table_type {
  29. ATSC_MGT_TABLE_TYPE_TVCT_CURRENT = 0,
  30. ATSC_MGT_TABLE_TYPE_TVCT_NEXT = 1,
  31. ATSC_MGT_TABLE_TYPE_CVCT_CURRENT = 2,
  32. ATSC_MGT_TABLE_TYPE_CVCT_NEXT = 3,
  33. ATSC_MGT_TABLE_TYPE_CHANNEL_ETT = 4,
  34. ATSC_MGT_TABLE_TYPE_DCCSCT = 5,
  35. };
  36. /**
  37. * atsc_mgt_section structure.
  38. */
  39. struct atsc_mgt_section {
  40. struct atsc_section_psip head;
  41. uint16_t tables_defined;
  42. /* struct atsc_mgt_table tables[] */
  43. /* struct atsc_mgt_section_part2 part2 */
  44. } __ucsi_packed;
  45. struct atsc_mgt_table {
  46. uint16_t table_type;
  47. EBIT2(uint16_t reserved : 3; ,
  48. uint16_t table_type_PID :13; );
  49. EBIT2(uint8_t reserved1 : 3; ,
  50. uint8_t table_type_version_number : 5; );
  51. uint32_t number_bytes;
  52. EBIT2(uint16_t reserved2 : 4; ,
  53. uint16_t table_type_descriptors_length :12; );
  54. /* struct descriptor descriptors[] */
  55. } __ucsi_packed;
  56. struct atsc_mgt_section_part2 {
  57. EBIT2(uint16_t reserved : 4; ,
  58. uint16_t descriptors_length :12; );
  59. /* struct descriptor descriptors[] */
  60. } __ucsi_packed;
  61. static inline struct atsc_mgt_table * atsc_mgt_section_tables_first(struct atsc_mgt_section *mgt);
  62. static inline struct atsc_mgt_table *
  63. atsc_mgt_section_tables_next(struct atsc_mgt_section *mgt, struct atsc_mgt_table *pos, int idx);
  64. /**
  65. * Process a atsc_mgt_section.
  66. *
  67. * @param section Pointer to an atsc_section_psip structure.
  68. * @return atsc_mgt_section pointer, or NULL on error.
  69. */
  70. struct atsc_mgt_section *atsc_mgt_section_codec(struct atsc_section_psip *section);
  71. /**
  72. * Iterator for the tables field in an atsc_mgt_section.
  73. *
  74. * @param mgt atsc_mgt_section pointer.
  75. * @param pos Variable containing a pointer to the current atsc_mgt_table.
  76. * @param idx Integer used to count which table we in.
  77. */
  78. #define atsc_mgt_section_tables_for_each(mgt, pos, idx) \
  79. for ((pos) = atsc_mgt_section_tables_first(mgt), idx=0; \
  80. (pos); \
  81. (pos) = atsc_mgt_section_tables_next(mgt, pos, ++idx))
  82. /**
  83. * Iterator for the descriptors field in a atsc_mgt_table structure.
  84. *
  85. * @param table atsc_mgt_table pointer.
  86. * @param pos Variable containing a pointer to the current descriptor.
  87. */
  88. #define atsc_mgt_table_descriptors_for_each(table, pos) \
  89. for ((pos) = atsc_mgt_table_descriptors_first(table); \
  90. (pos); \
  91. (pos) = atsc_mgt_table_descriptors_next(table, pos))
  92. /**
  93. * Accessor for the second part of an atsc_mgt_section.
  94. *
  95. * @param mgt atsc_mgt_section pointer.
  96. * @return atsc_mgt_section_part2 pointer.
  97. */
  98. static inline struct atsc_mgt_section_part2 *
  99. atsc_mgt_section_part2(struct atsc_mgt_section *mgt)
  100. {
  101. int pos = sizeof(struct atsc_mgt_section);
  102. struct atsc_mgt_table *cur_table;
  103. int idx;
  104. atsc_mgt_section_tables_for_each(mgt, cur_table, idx) {
  105. pos += sizeof(struct atsc_mgt_table);
  106. pos += cur_table->table_type_descriptors_length;
  107. }
  108. return (struct atsc_mgt_section_part2 *) (((uint8_t*) mgt) + pos);
  109. }
  110. /**
  111. * Iterator for the descriptors field in a atsc_mgt_section structure.
  112. *
  113. * @param part2 atsc_mgt_section_part2 pointer.
  114. * @param pos Variable containing a pointer to the current descriptor.
  115. */
  116. #define atsc_mgt_section_part2_descriptors_for_each(part2, pos) \
  117. for ((pos) = atsc_mgt_section_part2_descriptors_first(part2); \
  118. (pos); \
  119. (pos) = atsc_mgt_section_part2_descriptors_next(part2, pos))
  120. /******************************** PRIVATE CODE ********************************/
  121. static inline struct atsc_mgt_table *
  122. atsc_mgt_section_tables_first(struct atsc_mgt_section *mgt)
  123. {
  124. size_t pos = sizeof(struct atsc_mgt_section);
  125. if (mgt->tables_defined == 0)
  126. return NULL;
  127. return (struct atsc_mgt_table*) (((uint8_t *) mgt) + pos);
  128. }
  129. static inline struct atsc_mgt_table *
  130. atsc_mgt_section_tables_next(struct atsc_mgt_section *mgt,
  131. struct atsc_mgt_table *pos,
  132. int idx)
  133. {
  134. if (idx >= mgt->tables_defined)
  135. return NULL;
  136. return (struct atsc_mgt_table *)
  137. (((uint8_t*) pos) + sizeof(struct atsc_mgt_table) + pos->table_type_descriptors_length);
  138. }
  139. static inline struct descriptor *
  140. atsc_mgt_table_descriptors_first(struct atsc_mgt_table *table)
  141. {
  142. size_t pos = sizeof(struct atsc_mgt_table);
  143. if (table->table_type_descriptors_length == 0)
  144. return NULL;
  145. return (struct descriptor*) (((uint8_t *) table) + pos);
  146. }
  147. static inline struct descriptor *
  148. atsc_mgt_table_descriptors_next(struct atsc_mgt_table *table,
  149. struct descriptor *pos)
  150. {
  151. return next_descriptor((uint8_t*) table + sizeof(struct atsc_mgt_table),
  152. table->table_type_descriptors_length,
  153. pos);
  154. }
  155. static inline struct descriptor *
  156. atsc_mgt_section_part2_descriptors_first(struct atsc_mgt_section_part2 *part2)
  157. {
  158. size_t pos = sizeof(struct atsc_mgt_section_part2);
  159. if (part2->descriptors_length == 0)
  160. return NULL;
  161. return (struct descriptor*) (((uint8_t *) part2) + pos);
  162. }
  163. static inline struct descriptor *
  164. atsc_mgt_section_part2_descriptors_next(struct atsc_mgt_section_part2 *part2,
  165. struct descriptor *pos)
  166. {
  167. return next_descriptor((uint8_t*) part2 + sizeof(struct atsc_mgt_section_part2),
  168. part2->descriptors_length,
  169. pos);
  170. }
  171. #ifdef __cplusplus
  172. }
  173. #endif
  174. #endif