sdt.h 5.5 KB

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