nit.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 _NIT_H
  22. #define _NIT_H
  23. #include <stdint.h>
  24. #include <unistd.h> /* ssize_t */
  25. #include <libdvbv5/header.h>
  26. #include <libdvbv5/descriptors.h>
  27. /**
  28. * @file nit.h
  29. * @ingroup dvb_table
  30. * @brief Provides the descriptors for NIT MPEG-TS table
  31. * @copyright GNU General Public License version 2 (GPLv2)
  32. * @author Mauro Carvalho Chehab
  33. * @author Andre Roth
  34. *
  35. * @par Bug Report
  36. * Please submit bug report and patches to linux-media@vger.kernel.org
  37. *
  38. * @par Relevant specs
  39. * The table described herein is defined at:
  40. * - ISO/IEC 13818-1
  41. * - ETSI EN 300 468
  42. *
  43. * @par Bug Report
  44. * Please submit bug reports and patches to linux-media@vger.kernel.org
  45. */
  46. /**
  47. * @def DVB_TABLE_NIT
  48. * @brief NIT table ID
  49. * @ingroup dvb_table
  50. * @def DVB_TABLE_NIT2
  51. * @brief NIT table ID (alternative table ID)
  52. * @ingroup dvb_table
  53. * @def DVB_TABLE_NIT_PID
  54. * @brief NIT Program ID
  55. * @ingroup dvb_table
  56. */
  57. #define DVB_TABLE_NIT 0x40
  58. #define DVB_TABLE_NIT2 0x41
  59. #define DVB_TABLE_NIT_PID 0x10
  60. /**
  61. * @union dvb_table_nit_transport_header
  62. * @brief MPEG-TS NIT transport header
  63. * @ingroup dvb_table
  64. *
  65. * @param transport_length transport length
  66. *
  67. * This structure is used to store the original NIT transport header,
  68. * converting the integer fields to the CPU endianness.
  69. *
  70. * The undocumented parameters are used only internally by the API and/or
  71. * are fields that are reserved. They shouldn't be used, as they may change
  72. * on future API releases.
  73. */
  74. union dvb_table_nit_transport_header {
  75. uint16_t bitfield;
  76. struct {
  77. uint16_t transport_length:12;
  78. uint16_t reserved:4;
  79. } __attribute__((packed));
  80. } __attribute__((packed));
  81. /**
  82. * @struct dvb_table_nit_transport
  83. * @brief MPEG-TS NIT transport table
  84. * @ingroup dvb_table
  85. *
  86. * @param transport_id transport id
  87. * @param network_id network id
  88. * @param desc_length desc length
  89. * @param descriptor pointer to struct dvb_desc
  90. * @param next pointer to struct dvb_table_nit_transport
  91. *
  92. * This structure is used to store the original NIT transport table,
  93. * converting the integer fields to the CPU endianness.
  94. *
  95. * The undocumented parameters are used only internally by the API and/or
  96. * are fields that are reserved. They shouldn't be used, as they may change
  97. * on future API releases.
  98. *
  99. * Everything after dvb_table_nit_transport::descriptor (including it) won't
  100. * be bit-mapped to the data parsed from the MPEG TS. So, metadata are added
  101. * there.
  102. */
  103. struct dvb_table_nit_transport {
  104. uint16_t transport_id;
  105. uint16_t network_id;
  106. union {
  107. uint16_t bitfield;
  108. struct {
  109. uint16_t desc_length:12;
  110. uint16_t reserved:4;
  111. } __attribute__((packed));
  112. } __attribute__((packed));
  113. struct dvb_desc *descriptor;
  114. struct dvb_table_nit_transport *next;
  115. } __attribute__((packed));
  116. /**
  117. * @struct dvb_table_nit
  118. * @brief MPEG-TS NIT table
  119. * @ingroup dvb_table
  120. *
  121. * @param header struct dvb_table_header content
  122. * @param desc_length descriptor length
  123. * @param descriptor pointer to struct dvb_desc
  124. * @param transport pointer to struct dvb_table_nit_transport
  125. *
  126. * This structure is used to store the original NIT table,
  127. * converting the integer fields to the CPU endianness.
  128. *
  129. * The undocumented parameters are used only internally by the API and/or
  130. * are fields that are reserved. They shouldn't be used, as they may change
  131. * on future API releases.
  132. *
  133. * Everything after dvb_table_nit::descriptor (including it) won't be bit-mapped
  134. * to the data parsed from the MPEG TS. So, metadata are added there.
  135. */
  136. struct dvb_table_nit {
  137. struct dvb_table_header header;
  138. union {
  139. uint16_t bitfield;
  140. struct {
  141. uint16_t desc_length:12;
  142. uint16_t reserved:4;
  143. } __attribute__((packed));
  144. } __attribute__((packed));
  145. struct dvb_desc *descriptor;
  146. struct dvb_table_nit_transport *transport;
  147. } __attribute__((packed));
  148. /**
  149. * @brief typedef for a callback used when a NIT table entry is found
  150. * @ingroup dvb_table
  151. *
  152. * @param nit a struct dvb_table_nit pointer
  153. * @param desc a struct dvb_desc pointer
  154. * @param priv an opaque optional pointer
  155. */
  156. typedef void nit_handler_callback_t(struct dvb_table_nit *nit,
  157. struct dvb_desc *desc,
  158. void *priv);
  159. /**
  160. * @brief typedef for a callback used when a NIT transport table entry is found
  161. * @ingroup dvb_table
  162. *
  163. * @param nit a struct dvb_table_nit pointer
  164. * @param tran a struct dvb_table_nit_transport pointer
  165. * @param desc a struct dvb_desc pointer
  166. * @param priv an opaque optional pointer
  167. */
  168. typedef void nit_tran_handler_callback_t(struct dvb_table_nit *nit,
  169. struct dvb_table_nit_transport *tran,
  170. struct dvb_desc *desc,
  171. void *priv);
  172. /**
  173. * @brief Macro used to find a transport inside a NIT table
  174. * @ingroup dvb_table
  175. *
  176. * @param _tran transport to seek
  177. * @param _nit pointer to struct dvb_table_nit_transport
  178. */
  179. #define dvb_nit_transport_foreach( _tran, _nit ) \
  180. for (struct dvb_table_nit_transport *_tran = _nit->transport; _tran; _tran = _tran->next) \
  181. struct dvb_v5_fe_parms;
  182. #ifdef __cplusplus
  183. extern "C" {
  184. #endif
  185. /**
  186. * @brief Initializes and parses NIT table
  187. * @ingroup dvb_table
  188. *
  189. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  190. * @param buf buffer containing the NIT raw data
  191. * @param buflen length of the buffer
  192. * @param table pointer to struct dvb_table_nit to be allocated and filled
  193. *
  194. * This function allocates a NIT table and fills the fields inside
  195. * the struct. It also makes sure that all fields will follow the CPU
  196. * endianness. Due to that, the content of the buffer may change.
  197. *
  198. * @return On success, it returns the size of the allocated struct.
  199. * A negative value indicates an error.
  200. */
  201. ssize_t dvb_table_nit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf,
  202. ssize_t buflen, struct dvb_table_nit **table);
  203. /**
  204. * @brief Frees all data allocated by the NIT table parser
  205. * @ingroup dvb_table
  206. *
  207. * @param table pointer to struct dvb_table_nit to be freed
  208. */
  209. void dvb_table_nit_free(struct dvb_table_nit *table);
  210. /**
  211. * @brief Prints the content of the NIT table
  212. * @ingroup dvb_table
  213. *
  214. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  215. * @param table pointer to struct dvb_table_nit
  216. */
  217. void dvb_table_nit_print(struct dvb_v5_fe_parms *parms, struct dvb_table_nit *table);
  218. /**
  219. * @brief For each entry at NIT and NIT transport tables, call a callback
  220. * @ingroup dvb_table
  221. *
  222. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  223. * @param table pointer to struct dvb_table_nit
  224. * @param descriptor indicates the NIT table descriptor to seek
  225. * @param call_nit a nit_handler_callback_t function to be called when a
  226. * new entry at the NIT table is found (or NULL).
  227. * @param call_tran a nit_tran_handler_callback_t function to be called
  228. * when a new entry at the NIT transport table is found
  229. * (or NULL).
  230. * @param priv an opaque pointer to be optionally used by the
  231. * callbacks. The function won't touch on it, just use
  232. * as an argument for the callback functions.
  233. *
  234. * When parsing a NIT entry, we need to call some code to properly handle
  235. * when a given descriptor in the table is found. This is used, for example,
  236. * to create newer transponders to seek during scan.
  237. *
  238. * For example, to seek for the CATV delivery system descriptor and call a
  239. * function that would add a new transponder to a scan procedure:
  240. * @code
  241. * dvb_table_nit_descriptor_handler(
  242. * &parms->p, dvb_scan_handler->nit,
  243. * cable_delivery_system_descriptor,
  244. * NULL, add_update_nit_dvbc, &tr);
  245. * @endcode
  246. */
  247. void dvb_table_nit_descriptor_handler(
  248. struct dvb_v5_fe_parms *parms,
  249. struct dvb_table_nit *table,
  250. enum descriptors descriptor,
  251. nit_handler_callback_t *call_nit,
  252. nit_tran_handler_callback_t *call_tran,
  253. void *priv);
  254. #ifdef __cplusplus
  255. }
  256. #endif
  257. #endif