vct.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright (c) 2013 - Mauro Carvalho Chehab <m.chehab@samsung.com>
  3. * Copyright (c) 2013 - 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 vct.h
  23. * @ingroup dvb_table
  24. * @brief Provides the descriptors for TVCT and CVCT tables
  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. * - ATSC A/65:2009
  32. *
  33. * @see http://www.etherguidesystems.com/help/sdos/atsc/syntax/tablesections/TVCT.aspx
  34. * @see http://www.etherguidesystems.com/help/sdos/atsc/syntax/tablesections/CVCT.aspx
  35. *
  36. * @par Bug Report
  37. * Please submit bug reports and patches to linux-media@vger.kernel.org
  38. */
  39. #ifndef _VCT_H
  40. #define _VCT_H
  41. #include <stdint.h>
  42. #include <unistd.h> /* ssize_t */
  43. #include <libdvbv5/atsc_header.h>
  44. /**
  45. * @def ATSC_TABLE_TVCT
  46. * @brief TVCT table ID
  47. * @ingroup dvb_table
  48. * @def ATSC_TABLE_CVCT
  49. * @brief CVCT table ID
  50. * @ingroup dvb_table
  51. * @def ATSC_TABLE_VCT_PID
  52. * @brief Program ID with the VCT tables on it
  53. * @ingroup dvb_table
  54. */
  55. #define ATSC_TABLE_TVCT 0xc8
  56. #define ATSC_TABLE_CVCT 0xc9
  57. #define ATSC_TABLE_VCT_PID 0x1ffb
  58. /**
  59. * @struct atsc_table_vct_channel
  60. * @brief ATSC VCT channel table (covers both CVCT and TVCT)
  61. * @ingroup dvb_table
  62. *
  63. * @param modulation_mode modulation mode
  64. * @param minor_channel_number minor channel number
  65. * @param major_channel_number major channel number
  66. * @param carrier_frequency carrier frequency
  67. * @param channel_tsid channel tsid
  68. * @param program_number program number
  69. * @param service_type service type
  70. * @param hide_guide hide guide
  71. * @param out_of_band out of band (CVCT only)
  72. * @param path_select path select (CVCT only)
  73. * @param hidden hidden
  74. * @param access_controlled access controlled
  75. * @param ETM_location ETM location
  76. * @param source_id source ID
  77. * @param descriptors_length length of the descriptors
  78. *
  79. * @param descriptor pointer to struct dvb_desc
  80. * @param next pointer to another struct atsc_table_vct_channel
  81. * @param descriptors_length length of the descriptors
  82. * @param short_name short name. The __short_name is converted
  83. * from UTF-16 to locale charset when parsed
  84. *
  85. * This structure is used to store the original VCT channel table,
  86. * converting the integer fields to the CPU endianness.
  87. *
  88. * The undocumented parameters are used only internally by the API and/or
  89. * are fields that are reserved. They shouldn't be used, as they may change
  90. * on future API releases.
  91. *
  92. * Everything after atsc_table_vct_channel::descriptor (including it) won't
  93. * be bit-mapped * to the data parsed from the MPEG TS. So, metadata are
  94. * added there.
  95. */
  96. struct atsc_table_vct_channel {
  97. uint16_t __short_name[7];
  98. union {
  99. uint32_t bitfield1;
  100. struct {
  101. uint32_t modulation_mode:8;
  102. uint32_t minor_channel_number:10;
  103. uint32_t major_channel_number:10;
  104. uint32_t reserved1:4;
  105. } __attribute__((packed));
  106. } __attribute__((packed));
  107. uint32_t carrier_frequency;
  108. uint16_t channel_tsid;
  109. uint16_t program_number;
  110. union {
  111. uint16_t bitfield2;
  112. struct {
  113. uint16_t service_type:6;
  114. uint16_t reserved2:3;
  115. uint16_t hide_guide:1;
  116. uint16_t out_of_band:1; /* CVCT only */
  117. uint16_t path_select:1; /* CVCT only */
  118. uint16_t hidden:1;
  119. uint16_t access_controlled:1;
  120. uint16_t ETM_location:2;
  121. } __attribute__((packed));
  122. } __attribute__((packed));
  123. uint16_t source_id;
  124. union {
  125. uint16_t bitfield3;
  126. struct {
  127. uint16_t descriptors_length:10;
  128. uint16_t reserved3:6;
  129. } __attribute__((packed));
  130. } __attribute__((packed));
  131. /*
  132. * Everything after atsc_table_vct_channel::descriptor (including it)
  133. * won't be bit-mapped to the data parsed from the MPEG TS. So,
  134. * metadata are added there
  135. */
  136. struct dvb_desc *descriptor;
  137. struct atsc_table_vct_channel *next;
  138. /* The channel_short_name is converted to locale charset by vct.c */
  139. char short_name[32];
  140. } __attribute__((packed));
  141. /**
  142. * @struct atsc_table_vct
  143. * @brief ATSC VCT table (covers both CVCT and TVCT)
  144. * @ingroup dvb_table
  145. *
  146. * @param header struct dvb_table_header content
  147. * @param protocol_version protocol version
  148. * @param num_channels_in_section num channels in section
  149. * @param channel pointer to struct channel
  150. * @param descriptor pointer to struct descriptor
  151. *
  152. * Everything after atsc_table_vct::channel (including it) won't be bit-mapped
  153. * to the data parsed from the MPEG TS. So, metadata are added there
  154. */
  155. struct atsc_table_vct {
  156. struct dvb_table_header header;
  157. uint8_t protocol_version;
  158. uint8_t num_channels_in_section;
  159. struct atsc_table_vct_channel *channel;
  160. struct dvb_desc *descriptor;
  161. } __attribute__((packed));
  162. /**
  163. * @union atsc_table_vct_descriptor_length
  164. * @brief ATSC VCT descriptor length
  165. * @ingroup dvb_table
  166. *
  167. * @param descriptor_length descriptor length
  168. *
  169. * Used internally by the library to parse the descriptor length endianness.
  170. */
  171. union atsc_table_vct_descriptor_length {
  172. uint16_t bitfield;
  173. struct {
  174. uint16_t descriptor_length:10;
  175. uint16_t reserved:6;
  176. } __attribute__((packed));
  177. } __attribute__((packed));
  178. /**
  179. * @brief Macro used to find channels on a VCT table
  180. * @ingroup dvb_table
  181. *
  182. * @param _channel channel to seek
  183. * @param _vct pointer to struct atsc_table_vct_channel
  184. */
  185. #define atsc_vct_channel_foreach(_channel, _vct) \
  186. for (struct atsc_table_vct_channel *_channel = _vct->channel; _channel; _channel = _channel->next) \
  187. struct dvb_v5_fe_parms;
  188. #ifdef __cplusplus
  189. extern "C" {
  190. #endif
  191. /**
  192. * @brief Initializes and parses VCT table
  193. * @ingroup dvb_table
  194. *
  195. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  196. * @param buf buffer containing the VCT raw data
  197. * @param buflen length of the buffer
  198. * @param table pointer to struct atsc_table_vct to be allocated and filled
  199. *
  200. * This function allocates an ATSC VCT table and fills the fields inside
  201. * the struct. It also makes sure that all fields will follow the CPU
  202. * endianness. Due to that, the content of the buffer may change.
  203. *
  204. * @return On success, it returns the size of the allocated struct.
  205. * A negative value indicates an error.
  206. */
  207. ssize_t atsc_table_vct_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
  208. ssize_t buflen, struct atsc_table_vct **table);
  209. /**
  210. * @brief Frees all data allocated by the VCT table parser
  211. * @ingroup dvb_table
  212. *
  213. * @param table pointer to struct atsc_table_vct to be freed
  214. */
  215. void atsc_table_vct_free(struct atsc_table_vct *table);
  216. /**
  217. * @brief Prints the content of the VCT table
  218. * @ingroup dvb_table
  219. *
  220. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  221. * @param table pointer to struct atsc_table_vct
  222. */
  223. void atsc_table_vct_print(struct dvb_v5_fe_parms *parms,
  224. struct atsc_table_vct *table);
  225. #ifdef __cplusplus
  226. }
  227. #endif
  228. #endif