pmt.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 pmt.h
  23. * @ingroup dvb_table
  24. * @brief Provides the descriptors for PMT MPEG-TS 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. * - ISO/IEC 13818-1
  32. *
  33. * @see http://www.etherguidesystems.com/help/sdos/mpeg/syntax/tablesections/pmts.aspx
  34. *
  35. * @par Bug Report
  36. * Please submit bug reports and patches to linux-media@vger.kernel.org
  37. */
  38. #ifndef _PMT_H
  39. #define _PMT_H
  40. #include <stdint.h>
  41. #include <unistd.h> /* ssize_t */
  42. #include <libdvbv5/header.h>
  43. /**
  44. * @def DVB_TABLE_PMT
  45. * @brief PMT table ID
  46. * @ingroup dvb_table
  47. */
  48. #define DVB_TABLE_PMT 0x02
  49. /**
  50. * @enum dvb_streams
  51. * @brief Add support for MPEG-TS Stream types
  52. * @ingroup dvb_table
  53. *
  54. * @var stream_reserved0
  55. * @brief ITU-T | ISO/IEC Reserved
  56. * @var stream_video
  57. * @brief ISO/IEC 11172 Video
  58. * @var stream_video_h262
  59. * @brief ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or ISO/IEC 11172-2 constrained parameter video stream
  60. * @var stream_audio
  61. * @brief ISO/IEC 11172 Audio
  62. * @var stream_audio_13818_3
  63. * @brief ISO/IEC 13818-3 Audio
  64. * @var stream_private_sections
  65. * @brief ITU-T Rec. H.222.0 | ISO/IEC 13818-1 private_sections
  66. * @var stream_private_data
  67. * @brief ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES packets containing private data
  68. * @var stream_mheg
  69. * @brief ISO/IEC 13522 MHEG
  70. * @var stream_h222
  71. * @brief ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A DSM-CC
  72. * @var stream_h222_1
  73. * @brief ITU-T Rec. H.222.1
  74. * @var stream_13818_6_A
  75. * @brief ISO/IEC 13818-6 type A
  76. * @var stream_13818_6_B
  77. * @brief ISO/IEC 13818-6 type B
  78. * @var stream_13818_6_C
  79. * @brief ISO/IEC 13818-6 type C
  80. * @var stream_13818_6_D
  81. * @brief ISO/IEC 13818-6 type D
  82. * @var stream_h222_aux
  83. * @brief ITU-T Rec. H.222.0 | ISO/IEC 13818-1 auxiliary
  84. * @var stream_audio_adts
  85. * @brief ISO/IEC 13818-7 Audio with ADTS transport syntax
  86. * @var stream_video_14496_2
  87. * @brief ISO/IEC 14496-2 Visual
  88. * @var stream_audio_latm
  89. * @brief ISO/IEC 14496-3 Audio with the LATM transport syntax as defined in ISO/IEC 14496-3 / AMD 1
  90. * @var stream_14496_1_pes
  91. * @brief ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in PES packets
  92. * @var stream_14496_1_iso
  93. * @brief ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in ISO/IEC14496_sections.
  94. * @var stream_download
  95. * @brief ISO/IEC 13818-6 Synchronized Download Protocol
  96. * @var stream_reserved
  97. * @brief ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved (from 0x15 to 0x7f)
  98. * @var stream_private
  99. * @brief User Private (from 0x80 to 0xff)
  100. */
  101. enum dvb_streams {
  102. stream_reserved0 = 0x00,
  103. stream_video = 0x01,
  104. stream_video_h262 = 0x02,
  105. stream_audio = 0x03,
  106. stream_audio_13818_3 = 0x04,
  107. stream_private_sections = 0x05,
  108. stream_private_data = 0x06,
  109. stream_mheg = 0x07,
  110. stream_h222 = 0x08,
  111. stream_h222_1 = 0x09,
  112. stream_13818_6_A = 0x0A,
  113. stream_13818_6_B = 0x0B,
  114. stream_13818_6_C = 0x0C,
  115. stream_13818_6_D = 0x0D,
  116. stream_h222_aux = 0x0E,
  117. stream_audio_adts = 0x0F,
  118. stream_video_14496_2 = 0x10,
  119. stream_audio_latm = 0x11,
  120. stream_14496_1_pes = 0x12,
  121. stream_14496_1_iso = 0x13,
  122. stream_download = 0x14,
  123. stream_reserved = 0x15,
  124. stream_private = 0x80
  125. };
  126. /**
  127. * @brief Converts from enum dvb_streams into a string
  128. * @ingroup dvb_table
  129. */
  130. extern const char *pmt_stream_name[];
  131. /**
  132. * @struct dvb_table_pmt_stream
  133. * @brief MPEG-TS PMT stream table
  134. * @ingroup dvb_table
  135. *
  136. * @param type stream type
  137. * @param elementary_pid elementary pid
  138. * @param desc_length descriptor length
  139. * @param zero zero
  140. * @param descriptor pointer to struct dvb_desc
  141. * @param next pointer to struct dvb_table_pmt_stream
  142. *
  143. * This structure is used to store the original PMT stream table,
  144. * converting the integer fields to the CPU endianness.
  145. *
  146. * The undocumented parameters are used only internally by the API and/or
  147. * are fields that are reserved. They shouldn't be used, as they may change
  148. * on future API releases.
  149. *
  150. * Everything after dvb_table_pmt_stream::descriptor (including it) won't be
  151. * bit-mapped to the data parsed from the MPEG TS. So, metadata are added there.
  152. */
  153. struct dvb_table_pmt_stream {
  154. uint8_t type;
  155. union {
  156. uint16_t bitfield;
  157. struct {
  158. uint16_t elementary_pid:13;
  159. uint16_t reserved:3;
  160. } __attribute__((packed));
  161. } __attribute__((packed));
  162. union {
  163. uint16_t bitfield2;
  164. struct {
  165. uint16_t desc_length:10;
  166. uint16_t zero:2;
  167. uint16_t reserved2:4;
  168. } __attribute__((packed));
  169. } __attribute__((packed));
  170. struct dvb_desc *descriptor;
  171. struct dvb_table_pmt_stream *next;
  172. } __attribute__((packed));
  173. /**
  174. * @struct dvb_table_pmt
  175. * @brief MPEG-TS PMT table
  176. * @ingroup dvb_table
  177. *
  178. * @param header struct dvb_table_header content
  179. * @param pcr_pid PCR PID
  180. * @param desc_length descriptor length
  181. * @param descriptor pointer to struct dvb_desc
  182. * @param stream pointer to struct dvb_table_pmt_stream
  183. *
  184. * This structure is used to store the original PMT stream table,
  185. * converting the integer fields to the CPU endianness.
  186. *
  187. * The undocumented parameters are used only internally by the API and/or
  188. * are fields that are reserved. They shouldn't be used, as they may change
  189. * on future API releases.
  190. *
  191. * Everything after dvb_table_pmt::descriptor (including it) won't be
  192. * bit-mapped to the data parsed from the MPEG TS. So, metadata are added there.
  193. */
  194. struct dvb_table_pmt {
  195. struct dvb_table_header header;
  196. union {
  197. uint16_t bitfield;
  198. struct {
  199. uint16_t pcr_pid:13;
  200. uint16_t reserved2:3;
  201. } __attribute__((packed));
  202. } __attribute__((packed));
  203. union {
  204. uint16_t bitfield2;
  205. struct {
  206. uint16_t desc_length:10;
  207. uint16_t zero3:2;
  208. uint16_t reserved3:4;
  209. } __attribute__((packed));
  210. } __attribute__((packed));
  211. struct dvb_desc *descriptor;
  212. struct dvb_table_pmt_stream *stream;
  213. } __attribute__((packed));
  214. /** @brief First field at the struct */
  215. #define dvb_pmt_field_first header
  216. /** @brief First field that are not part of the received data */
  217. #define dvb_pmt_field_last descriptor
  218. /**
  219. * @brief Macro used to find streams on a PMT table
  220. * @ingroup dvb_table
  221. *
  222. * @param _stream stream to seek
  223. * @param _pmt pointer to struct dvb_table_pmt_stream
  224. */
  225. #define dvb_pmt_stream_foreach(_stream, _pmt) \
  226. for (struct dvb_table_pmt_stream *_stream = _pmt->stream; _stream; _stream = _stream->next) \
  227. struct dvb_v5_fe_parms;
  228. #ifdef __cplusplus
  229. extern "C" {
  230. #endif
  231. /**
  232. * @brief Initializes and parses PMT table
  233. * @ingroup dvb_table
  234. *
  235. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  236. * @param buf buffer containing the PMT raw data
  237. * @param buflen length of the buffer
  238. * @param table pointer to struct dvb_table_pmt to be allocated and filled
  239. *
  240. * This function allocates a PMT table and fills the fields inside
  241. * the struct. It also makes sure that all fields will follow the CPU
  242. * endianness. Due to that, the content of the buffer may change.
  243. *
  244. * @return On success, it returns the size of the allocated struct.
  245. * A negative value indicates an error.
  246. */
  247. ssize_t dvb_table_pmt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf,
  248. ssize_t buflen, struct dvb_table_pmt **table);
  249. /**
  250. * @brief Frees all data allocated by the PMT table parser
  251. * @ingroup dvb_table
  252. *
  253. * @param table pointer to struct dvb_table_pmt to be freed
  254. */
  255. void dvb_table_pmt_free(struct dvb_table_pmt *table);
  256. /**
  257. * @brief Prints the content of the PAT table
  258. * @ingroup dvb_table
  259. *
  260. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  261. * @param table pointer to struct dvb_table_pmt
  262. */
  263. void dvb_table_pmt_print(struct dvb_v5_fe_parms *parms,
  264. const struct dvb_table_pmt *table);
  265. #ifdef __cplusplus
  266. }
  267. #endif
  268. #endif