atsc_eit.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 atsc_eit.h
  22. * @ingroup dvb_table
  23. * @brief Provides the table parser for the ATSC EIT (Event Information Table)
  24. * @copyright GNU General Public License version 2 (GPLv2)
  25. * @author Mauro Carvalho Chehab
  26. * @author Andre Roth
  27. *
  28. * @par Relevant specs
  29. * The table described herein is defined at:
  30. * - ATSC A/65:2009
  31. *
  32. * @see
  33. * http://www.etherguidesystems.com/help/sdos/atsc/syntax/tablesections/eitks.aspx
  34. *
  35. * @par Bug Report
  36. * Please submit bug reports and patches to linux-media@vger.kernel.org
  37. */
  38. #ifndef _ATSC_EIT_H
  39. #define _ATSC_EIT_H
  40. #include <stdint.h>
  41. #include <unistd.h> /* ssize_t */
  42. #include <time.h>
  43. #include <libdvbv5/atsc_header.h>
  44. /**
  45. * @def ATSC_TABLE_EIT
  46. * @brief ATSC EIT table ID
  47. * @ingroup dvb_table
  48. */
  49. #define ATSC_TABLE_EIT 0xCB
  50. /**
  51. * @struct atsc_table_eit_event
  52. * @brief ATSC EIT event table
  53. * @ingroup dvb_table
  54. *
  55. * @param event_id an uniquelly (inside a service ID) event ID
  56. * @param title_length title length. Zero means no title
  57. * @param duration duration in seconds
  58. * @param etm Extended Text Message location
  59. * @param descriptor pointer to struct dvb_desc
  60. * @param next pointer to struct atsc_table_eit_event
  61. * @param start event start (in struct tm format)
  62. * @param source_id source id (obtained from ATSC header)
  63. *
  64. * This structure is used to store the original ATSC EIT event table,
  65. * converting the integer fields to the CPU endianness, and converting the
  66. * timestamps to a way that it is better handled on Linux.
  67. *
  68. * The undocumented parameters are used only internally by the API and/or
  69. * are fields that are reserved. They shouldn't be used, as they may change
  70. * on future API releases.
  71. *
  72. * Everything after atsc_table_eit_event::descriptor (including it) won't
  73. * be bit-mapped to the data parsed from the MPEG TS. So, metadata are added
  74. * there.
  75. */
  76. struct atsc_table_eit_event {
  77. union {
  78. uint16_t bitfield;
  79. struct {
  80. uint16_t event_id:14;
  81. uint16_t one:2;
  82. } __attribute__((packed));
  83. } __attribute__((packed));
  84. uint32_t start_time;
  85. union {
  86. uint32_t bitfield2;
  87. struct {
  88. uint32_t title_length:8;
  89. uint32_t duration:20;
  90. uint32_t etm:2;
  91. uint32_t one2:2;
  92. uint32_t :2;
  93. } __attribute__((packed));
  94. } __attribute__((packed));
  95. struct dvb_desc *descriptor;
  96. struct atsc_table_eit_event *next;
  97. struct tm start;
  98. uint16_t source_id;
  99. } __attribute__((packed));
  100. /**
  101. * @union atsc_table_eit_desc_length
  102. * @brief ATSC EIT descriptor length
  103. * @ingroup dvb_table
  104. *
  105. * @param desc_length descriptor length
  106. *
  107. * This structure is used to store the original ATSC EIT event table,
  108. * converting the integer fields to the CPU endianness, and converting the
  109. * timestamps to a way that it is better handled on Linux.
  110. *
  111. * The undocumented parameters are used only internally by the API and/or
  112. * are fields that are reserved. They shouldn't be used, as they may change
  113. * on future API releases.
  114. */
  115. union atsc_table_eit_desc_length {
  116. uint16_t bitfield;
  117. struct {
  118. uint16_t desc_length:12;
  119. uint16_t reserved:4;
  120. } __attribute__((packed));
  121. } __attribute__((packed));
  122. /**
  123. * @struct atsc_table_eit
  124. * @brief ATSC EIT table
  125. * @ingroup dvb_table
  126. *
  127. * @param header struct dvb_table_header content
  128. * @param protocol_version protocol version
  129. * @param events events
  130. * @param event pointer to struct atsc_table_eit_event
  131. *
  132. * This structure is used to store the original ATSC EIT table,
  133. * converting the integer fields to the CPU endianness.
  134. *
  135. * Everything after atsc_table_eit::event (including it) won't
  136. * be bit-mapped to the data parsed from the MPEG TS. So, metadata are added
  137. * there.
  138. */
  139. struct atsc_table_eit {
  140. struct dvb_table_header header;
  141. uint8_t protocol_version;
  142. uint8_t events;
  143. struct atsc_table_eit_event *event;
  144. } __attribute__((packed));
  145. /**
  146. * @brief Macro used to find event on an ATSC EIT table
  147. * @ingroup dvb_table
  148. *
  149. * @param _event event to seek
  150. * @param _eit pointer to struct atsc_table_eit_event
  151. */
  152. #define atsc_eit_event_foreach(_event, _eit) \
  153. for( struct atsc_table_eit_event *_event = _eit->event; _event; _event = _event->next ) \
  154. struct dvb_v5_fe_parms;
  155. #ifdef __cplusplus
  156. extern "C" {
  157. #endif
  158. /**
  159. * @brief Initializes and parses ATSC EIT table
  160. * @ingroup dvb_table
  161. *
  162. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  163. * @param buf buffer containing the EIT raw data
  164. * @param buflen length of the buffer
  165. * @param table pointer to struct atsc_table_eit to be allocated and filled
  166. *
  167. * This function allocates an ATSC EIT table and fills the fields inside
  168. * the struct. It also makes sure that all fields will follow the CPU
  169. * endianness. Due to that, the content of the buffer may change.
  170. *
  171. * @return On success, it returns the size of the allocated struct.
  172. * A negative value indicates an error.
  173. */
  174. ssize_t atsc_table_eit_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
  175. ssize_t buflen, struct atsc_table_eit **table);
  176. /**
  177. * @brief Frees all data allocated by the ATSC EIT table parser
  178. * @ingroup dvb_table
  179. *
  180. * @param table pointer to struct atsc_table_eit to be freed
  181. */
  182. void atsc_table_eit_free(struct atsc_table_eit *table);
  183. /**
  184. * @brief Prints the content of the ATSC EIT table
  185. * @ingroup dvb_table
  186. *
  187. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  188. * @param table pointer to struct atsc_table_eit
  189. */
  190. void atsc_table_eit_print(struct dvb_v5_fe_parms *parms,
  191. struct atsc_table_eit *table);
  192. /**
  193. * @brief Converts an ATSC EIT formatted timestamp into struct tm
  194. * @ingroup ancillary
  195. *
  196. * @param start_time event on ATSC EIT time format
  197. * @param tm pointer to struct tm where the converted timestamp will
  198. * be stored.
  199. */
  200. void atsc_time(const uint32_t start_time, struct tm *tm);
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. #endif