mgt.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation version 2
  7. * of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  18. *
  19. */
  20. /**
  21. * @file mgt.h
  22. * @ingroup dvb_table
  23. * @brief Provides the table parser for the ATSC MGT (Master Guide Table)
  24. * @copyright GNU General Public License version 2 (GPLv2)
  25. * @author Andre Roth
  26. *
  27. * @par Relevant specs
  28. * The table described herein is defined at:
  29. * - ATSC A/65:2009
  30. *
  31. * @see
  32. * http://www.etherguidesystems.com/help/sdos/atsc/syntax/tablesections/MGT.aspx
  33. *
  34. * @par Bug Report
  35. * Please submit bug reports and patches to linux-media@vger.kernel.org
  36. */
  37. #ifndef _MGT_H
  38. #define _MGT_H
  39. #include <stdint.h>
  40. #include <unistd.h> /* ssize_t */
  41. #include <libdvbv5/atsc_header.h>
  42. /**
  43. * @def ATSC_TABLE_MGT
  44. * @brief ATSC MGT table ID
  45. * @ingroup dvb_table
  46. */
  47. #define ATSC_TABLE_MGT 0xC7
  48. /**
  49. * @struct atsc_table_mgt_table
  50. * @brief ATSC tables descrition at MGT table
  51. * @ingroup dvb_table
  52. *
  53. * @param type table type
  54. * @param pid table type pid
  55. * @param type_version type type version number
  56. * @param size number of bytes for the table entry
  57. * @param desc_length table type descriptors length
  58. * @param descriptor pointer to struct dvb_desc
  59. * @param next pointer to struct atsc_table_mgt_table
  60. *
  61. * This structure is used to store the original VCT channel table,
  62. * converting the integer fields to the CPU endianness.
  63. *
  64. * The undocumented parameters are used only internally by the API and/or
  65. * are fields that are reserved. They shouldn't be used, as they may change
  66. * on future API releases.
  67. *
  68. * Everything after atsc_table_mgt_table::descriptor (including it) won't
  69. * be bit-mapped * to the data parsed from the MPEG TS. So, metadata are
  70. * added there.
  71. */
  72. struct atsc_table_mgt_table {
  73. uint16_t type;
  74. union {
  75. uint16_t bitfield;
  76. struct {
  77. uint16_t pid:13;
  78. uint16_t one:3;
  79. } __attribute__((packed));
  80. } __attribute__((packed));
  81. uint8_t type_version:5;
  82. uint8_t one2:3;
  83. uint32_t size;
  84. union {
  85. uint16_t bitfield2;
  86. struct {
  87. uint16_t desc_length:12;
  88. uint16_t one3:4;
  89. } __attribute__((packed));
  90. } __attribute__((packed));
  91. struct dvb_desc *descriptor;
  92. struct atsc_table_mgt_table *next;
  93. } __attribute__((packed));
  94. /**
  95. * @struct atsc_table_mgt
  96. * @brief ATSC MGT table
  97. * @ingroup dvb_table
  98. *
  99. * @param header struct dvb_table_header content
  100. * @param protocol_version protocol version
  101. * @param tables tables_defined Number of tables defined
  102. * @param table pointer to struct atsc_table_mgt_table
  103. * @param descriptor pointer to struct dvb_desc
  104. *
  105. * This structure is used to store the original MGT channel table,
  106. * converting the integer fields to the CPU endianness.
  107. *
  108. * The undocumented parameters are used only internally by the API and/or
  109. * are fields that are reserved. They shouldn't be used, as they may change
  110. * on future API releases.
  111. *
  112. * Everything after atsc_table_mgt::table (including it) won't
  113. * be bit-mapped * to the data parsed from the MPEG TS. So, metadata are
  114. * added there.
  115. */
  116. struct atsc_table_mgt {
  117. struct dvb_table_header header;
  118. uint8_t protocol_version;
  119. uint16_t tables;
  120. struct atsc_table_mgt_table *table;
  121. struct dvb_desc *descriptor;
  122. } __attribute__((packed));
  123. /**
  124. * @brief Macro used to find a table inside a MGT table
  125. *
  126. * @param _table channel to seek
  127. * @param _mgt pointer to struct atsc_table_mgt_table
  128. */
  129. #define atsc_mgt_table_foreach( _table, _mgt ) \
  130. for( struct atsc_table_mgt_table *_table = _mgt->table; _table; _table = _table->next ) \
  131. struct dvb_v5_fe_parms;
  132. #ifdef __cplusplus
  133. extern "C" {
  134. #endif
  135. /**
  136. * @brief Initializes and parses MGT table
  137. * @ingroup dvb_table
  138. *
  139. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  140. * @param buf buffer containing the MGT raw data
  141. * @param buflen length of the buffer
  142. * @param table pointer to struct atsc_table_mgt to be allocated and filled
  143. *
  144. * This function allocates an ATSC MGT table and fills the fields inside
  145. * the struct. It also makes sure that all fields will follow the CPU
  146. * endianness. Due to that, the content of the buffer may change.
  147. *
  148. * @return On success, it returns the size of the allocated struct.
  149. * A negative value indicates an error.
  150. */
  151. ssize_t atsc_table_mgt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
  152. ssize_t buflen, struct atsc_table_mgt **table);
  153. /**
  154. * @brief Frees all data allocated by the MGT table parser
  155. * @ingroup dvb_table
  156. *
  157. * @param table pointer to struct atsc_table_mgt to be freed
  158. */
  159. void atsc_table_mgt_free(struct atsc_table_mgt *table);
  160. /**
  161. * @brief Prints the content of the MGT table
  162. * @ingroup dvb_table
  163. *
  164. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  165. * @param table pointer to struct atsc_table_mgt
  166. */
  167. void atsc_table_mgt_print(struct dvb_v5_fe_parms *parms,
  168. struct atsc_table_mgt *table);
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif