header.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. * Described at ISO/IEC 13818-1
  21. */
  22. #ifndef _HEADER_H
  23. #define _HEADER_H
  24. #include <stdint.h>
  25. #include <unistd.h> /* ssize_t */
  26. /**
  27. * @file header.h
  28. * @ingroup dvb_table
  29. * @brief Provides the MPEG TS table headers
  30. * @copyright GNU General Public License version 2 (GPLv2)
  31. * @author Mauro Carvalho Chehab
  32. * @author Andre Roth
  33. *
  34. * @par Bug Report
  35. * Please submit bug reports and patches to linux-media@vger.kernel.org
  36. */
  37. /**
  38. * @struct dvb_ts_packet_header
  39. * @brief Header of a MPEG-TS transport packet
  40. * @ingroup dvb_table
  41. *
  42. * @param sync_byte sync byte
  43. * @param pid Program ID
  44. * @param transport_priority transport priority
  45. * @param payload_unit_start_indicator payload unit start indicator
  46. * @param transport_error_indicator transport error indicator
  47. * @param continuity_counter continuity counter
  48. * @param adaptation_field_control adaptation field control
  49. * @param transport_scrambling_control transport scrambling control
  50. * @param adaptation_field_length adaptation field length
  51. *
  52. * @see http://www.etherguidesystems.com/Help/SDOs/MPEG/Semantics/MPEG-2/transport_packet.aspx
  53. */
  54. struct dvb_ts_packet_header {
  55. uint8_t sync_byte;
  56. union {
  57. uint16_t bitfield;
  58. struct {
  59. uint16_t pid:13;
  60. uint16_t transport_priority:1;
  61. uint16_t payload_unit_start_indicator:1;
  62. uint16_t transport_error_indicator:1;
  63. } __attribute__((packed));
  64. } __attribute__((packed));
  65. uint8_t continuity_counter:4;
  66. uint8_t adaptation_field_control:2;
  67. uint8_t transport_scrambling_control:2;
  68. /* Only if adaptation_field_control > 1 */
  69. uint8_t adaptation_field_length;
  70. } __attribute__((packed));
  71. /**
  72. * @struct dvb_table_header
  73. * @brief Header of a MPEG-TS table
  74. * @ingroup dvb_table
  75. *
  76. * @param table_id table id
  77. * @param section_length section length
  78. * @param syntax syntax
  79. * @param id TS ID
  80. * @param current_next current next
  81. * @param version version
  82. * @param section_id section number
  83. * @param last_section last section number
  84. *
  85. * All MPEG-TS tables start with this header.
  86. */
  87. struct dvb_table_header {
  88. uint8_t table_id;
  89. union {
  90. uint16_t bitfield;
  91. struct {
  92. uint16_t section_length:12;
  93. uint8_t one:2;
  94. uint8_t zero:1;
  95. uint8_t syntax:1;
  96. } __attribute__((packed));
  97. } __attribute__((packed));
  98. uint16_t id; /* TS ID */
  99. uint8_t current_next:1;
  100. uint8_t version:5;
  101. uint8_t one2:2;
  102. uint8_t section_id; /* section_number */
  103. uint8_t last_section; /* last_section_number */
  104. } __attribute__((packed));
  105. struct dvb_v5_fe_parms;
  106. #ifdef __cplusplus
  107. extern "C" {
  108. #endif
  109. /**
  110. * @brief Initializes and parses MPEG-TS table header
  111. * @ingroup dvb_table
  112. *
  113. * @param header pointer to struct dvb_table_header to be parsed
  114. */
  115. void dvb_table_header_init (struct dvb_table_header *header);
  116. /**
  117. * @brief Prints the content of the MPEG-TS table header
  118. * @ingroup dvb_table
  119. *
  120. * @param parms struct dvb_v5_fe_parms pointer to the opened device
  121. * @param header pointer to struct dvb_table_header to be printed
  122. */
  123. void dvb_table_header_print(struct dvb_v5_fe_parms *parms,
  124. const struct dvb_table_header *header);
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. #endif