eit.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. /**
  22. * @file eit.h
  23. * @ingroup dvb_table
  24. * @brief Provides the table parser for the DVB EIT (Event Information Table)
  25. * @copyright GNU General Public License version 2 (GPLv2)
  26. * @author Mauro Carvalho Chehab
  27. * @author Andre Roth
  28. *
  29. * @par Relevant specs
  30. * The table described herein is defined at:
  31. * - ETSI EN 300 468
  32. *
  33. * @see
  34. * http://www.etherguidesystems.com/Help/SDOs/dvb/syntax/tablesections/EIT.aspx
  35. *
  36. * @par Bug Report
  37. * Please submit bug reports and patches to linux-media@vger.kernel.org
  38. */
  39. #ifndef _EIT_H
  40. #define _EIT_H
  41. #include <stdint.h>
  42. #include <unistd.h> /* ssize_t */
  43. #include <time.h>
  44. #include <libdvbv5/header.h>
  45. /**
  46. * @def DVB_TABLE_EIT
  47. * @brief DVB EIT table ID for the actual TS
  48. * @ingroup dvb_table
  49. * @def DVB_TABLE_EIT_OTHER
  50. * @brief DVB EIT table ID for other TS
  51. * @ingroup dvb_table
  52. * @def DVB_TABLE_EIT_PID
  53. * @brief DVB EIT Program ID
  54. * @ingroup dvb_table
  55. * @def DVB_TABLE_EIT_SCHEDULE
  56. * @brief Start table ID for the DVB EIT schedule data on the actual TS
  57. * @ingroup dvb_table
  58. * @def DVB_TABLE_EIT_SCHEDULE_OTHER
  59. * @brief Start table ID for the DVB EIT schedule data on other TS
  60. * @ingroup dvb_table
  61. */
  62. #define DVB_TABLE_EIT 0x4E
  63. #define DVB_TABLE_EIT_OTHER 0x4F
  64. #define DVB_TABLE_EIT_PID 0x12
  65. #define DVB_TABLE_EIT_SCHEDULE 0x50 /* - 0x5F */
  66. #define DVB_TABLE_EIT_SCHEDULE_OTHER 0x60 /* - 0x6F */
  67. /**
  68. * @struct dvb_table_eit_event
  69. * @brief DVB EIT event table
  70. * @ingroup dvb_table
  71. *
  72. * @param event_id an uniquelly (inside a service ID) event ID
  73. * @param desc_length descriptor's length
  74. * @param free_CA_mode free CA mode. 0 indicates that the event
  75. * is not scrambled
  76. * @param running_status running status of the event. The status can
  77. * be translated to string via
  78. * dvb_eit_running_status_name string table.
  79. * @param descriptor pointer to struct dvb_desc
  80. * @param next pointer to struct dvb_table_eit_event
  81. * @param tm_start event start (in struct tm format)
  82. * @param duration duration in seconds
  83. * @param service_id service ID
  84. *
  85. * This structure is used to store the original EIT event table,
  86. * converting the integer fields to the CPU endianness, and converting the
  87. * timestamps to a way that it is better handled on Linux.
  88. *
  89. * The undocumented parameters are used only internally by the API and/or
  90. * are fields that are reserved. They shouldn't be used, as they may change
  91. * on future API releases.
  92. *
  93. * Everything after dvb_table_eit_event::descriptor (including it) won't
  94. * be bit-mapped to the data parsed from the MPEG TS. So, metadata are added
  95. * there.
  96. */
  97. struct dvb_table_eit_event {
  98. uint16_t event_id;
  99. union {
  100. uint16_t bitfield1; /* first 2 bytes are MJD, they need to be bswapped */
  101. uint8_t dvbstart[5];
  102. } __attribute__((packed));
  103. uint8_t dvbduration[3];
  104. union {
  105. uint16_t bitfield2;
  106. struct {
  107. uint16_t desc_length:12;
  108. uint16_t free_CA_mode:1;
  109. uint16_t running_status:3;
  110. } __attribute__((packed));
  111. } __attribute__((packed));
  112. struct dvb_desc *descriptor;
  113. struct dvb_table_eit_event *next;
  114. struct tm start;
  115. uint32_t duration;
  116. uint16_t service_id;
  117. } __attribute__((packed));
  118. /**
  119. * @struct dvb_table_eit
  120. * @brief DVB EIT table
  121. * @ingroup dvb_table
  122. *
  123. * @param header struct dvb_table_header content
  124. * @param transport_id transport id
  125. * @param network_id network id
  126. * @param last_segment last segment
  127. * @param last_table_id last table id
  128. * @param event pointer to struct dvb_table_eit_event
  129. *
  130. * This structure is used to store the original EIT table,
  131. * converting the integer fields to the CPU endianness.
  132. *
  133. * Everything after dvb_table_eit::event (including it) won't
  134. * be bit-mapped to the data parsed from the MPEG TS. So, metadata are added
  135. * there.
  136. */
  137. struct dvb_table_eit {
  138. struct dvb_table_header header;
  139. uint16_t transport_id;
  140. uint16_t network_id;
  141. uint8_t last_segment;
  142. uint8_t last_table_id;
  143. struct dvb_table_eit_event *event;
  144. } __attribute__((packed));
  145. /**
  146. * @brief Macro used to find event on a DVB EIT table
  147. * @ingroup dvb_table
  148. *
  149. * @param _event event to seek
  150. * @param _eit pointer to struct dvb_table_eit_event
  151. */
  152. #define dvb_eit_event_foreach(_event, _eit) \
  153. for( struct dvb_table_eit_event *_event = _eit->event; _event; _event = _event->next ) \
  154. struct dvb_v5_fe_parms;
  155. /** @brief Converts a running_status field into string */
  156. extern const char *dvb_eit_running_status_name[8];
  157. #ifdef __cplusplus
  158. extern "C" {
  159. #endif
  160. /**
  161. * @brief Initializes and parses EIT table
  162. * @ingroup dvb_table
  163. *
  164. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  165. * @param buf buffer containing the EIT raw data
  166. * @param buflen length of the buffer
  167. * @param table pointer to struct dvb_table_eit to be allocated and filled
  168. *
  169. * This function allocates an EIT table and fills the fields inside
  170. * the struct. It also makes sure that all fields will follow the CPU
  171. * endianness. Due to that, the content of the buffer may change.
  172. *
  173. * @return On success, it returns the size of the allocated struct.
  174. * A negative value indicates an error.
  175. */
  176. ssize_t dvb_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf,
  177. ssize_t buflen, struct dvb_table_eit **table);
  178. /**
  179. * @brief Frees all data allocated by the DVB EIT table parser
  180. * @ingroup dvb_table
  181. *
  182. * @param table pointer to struct dvb_table_eit to be freed
  183. */
  184. void dvb_table_eit_free(struct dvb_table_eit *table);
  185. /**
  186. * @brief Prints the content of the DVB EIT table
  187. * @ingroup dvb_table
  188. *
  189. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  190. * @param table pointer to struct dvb_table_eit
  191. */
  192. void dvb_table_eit_print(struct dvb_v5_fe_parms *parms,
  193. struct dvb_table_eit *table);
  194. /**
  195. * @brief Converts a DVB EIT formatted timestamp into struct tm
  196. * @ingroup dvb_table
  197. *
  198. * @param data event on DVB EIT time format
  199. * @param tm pointer to struct tm where the converted timestamp will
  200. * be stored.
  201. */
  202. void dvb_time(const uint8_t data[5], struct tm *tm);
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #endif