pat.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 pat.h
  23. * @ingroup dvb_table
  24. * @brief Provides the descriptors for PAT 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/pat.aspx
  34. *
  35. * @par Bug Report
  36. * Please submit bug reports and patches to linux-media@vger.kernel.org
  37. */
  38. #ifndef _PAT_H
  39. #define _PAT_H
  40. #include <stdint.h>
  41. #include <unistd.h> /* ssize_t */
  42. #include <libdvbv5/header.h>
  43. /**
  44. * @def DVB_TABLE_PAT
  45. * @brief PAT table ID
  46. * @ingroup dvb_table
  47. * @def DVB_TABLE_PAT_PID
  48. * @brief PAT Program ID
  49. * @ingroup dvb_table
  50. */
  51. #define DVB_TABLE_PAT 0x00
  52. #define DVB_TABLE_PAT_PID 0x0000
  53. /**
  54. * @struct dvb_table_pat_program
  55. * @brief MPEG-TS PAT program table
  56. * @ingroup dvb_table
  57. *
  58. * @param service_id service id
  59. * @param pid pid
  60. * @param next pointer to struct dvb_table_pat_program
  61. *
  62. * This structure is used to store the original PAT program table,
  63. * converting the integer fields to the CPU endianness.
  64. *
  65. * The undocumented parameters are used only internally by the API and/or
  66. * are fields that are reserved. They shouldn't be used, as they may change
  67. * on future API releases.
  68. *
  69. * Everything after dvb_table_pat_program::next (including it) won't be bit-mapped
  70. * to the data parsed from the MPEG TS. So, metadata are added there.
  71. */
  72. struct dvb_table_pat_program {
  73. uint16_t service_id;
  74. union {
  75. uint16_t bitfield;
  76. struct {
  77. uint16_t pid:13;
  78. uint8_t reserved:3;
  79. } __attribute__((packed));
  80. } __attribute__((packed));
  81. struct dvb_table_pat_program *next;
  82. } __attribute__((packed));
  83. /**
  84. * @struct dvb_table_pat
  85. * @brief MPEG-TS PAT table
  86. * @ingroup dvb_table
  87. *
  88. * @param header struct dvb_table_header content
  89. * @param programs number of programs
  90. * @param program pointer to struct dvb_table_pat_program
  91. * This structure is used to store the original PAT table,
  92. * converting the integer fields to the CPU endianness.
  93. *
  94. * The undocumented parameters are used only internally by the API and/or
  95. * are fields that are reserved. They shouldn't be used, as they may change
  96. * on future API releases.
  97. *
  98. * Everything after dvb_table_pat_program::program (including it) won't be bit-mapped
  99. * to the data parsed from the MPEG TS. So, metadata are added there.
  100. */
  101. struct dvb_table_pat {
  102. struct dvb_table_header header;
  103. uint16_t programs;
  104. struct dvb_table_pat_program *program;
  105. } __attribute__((packed));
  106. /**
  107. * @brief Macro used to find programs on a PAT table
  108. * @ingroup dvb_table
  109. *
  110. * @param _pgm program to seek
  111. * @param _pat pointer to struct dvb_table_pat_program
  112. */
  113. #define dvb_pat_program_foreach(_pgm, _pat) \
  114. for (struct dvb_table_pat_program *_pgm = _pat->program; _pgm; _pgm = _pgm->next) \
  115. struct dvb_v5_fe_parms;
  116. #ifdef __cplusplus
  117. extern "C" {
  118. #endif
  119. /**
  120. * @brief Initializes and parses PAT table
  121. * @ingroup dvb_table
  122. *
  123. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  124. * @param buf buffer containing the PAT raw data
  125. * @param buflen length of the buffer
  126. * @param table pointer to struct dvb_table_pat to be allocated and filled
  127. *
  128. * This function allocates a PAT table and fills the fields inside
  129. * the struct. It also makes sure that all fields will follow the CPU
  130. * endianness. Due to that, the content of the buffer may change.
  131. *
  132. * @return On success, it returns the size of the allocated struct.
  133. * A negative value indicates an error.
  134. */
  135. ssize_t dvb_table_pat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf,
  136. ssize_t buflen, struct dvb_table_pat **table);
  137. /**
  138. * @brief Frees all data allocated by the PAT table parser
  139. * @ingroup dvb_table
  140. *
  141. * @param table pointer to struct dvb_table_pat to be freed
  142. */
  143. void dvb_table_pat_free(struct dvb_table_pat *table);
  144. /**
  145. * @brief Prints the content of the PAT table
  146. * @ingroup dvb_table
  147. *
  148. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  149. * @param table pointer to struct dvb_table_pat
  150. */
  151. void dvb_table_pat_print(struct dvb_v5_fe_parms *parms,
  152. struct dvb_table_pat *table);
  153. #ifdef __cplusplus
  154. }
  155. #endif
  156. #endif