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 modify 6 * it under the terms of the GNU Lesser General Public License as published by 7 * the Free Software Foundation version 2.1 of the License. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 18 * 19 * Described at ISO/IEC 13818-1 20 */ 21 22 #ifndef _HEADER_H 23 #define _HEADER_H 24 25 #include <stdint.h> 26 #include <unistd.h> /* ssize_t */ 27 28 /** 29 * @file header.h 30 * @ingroup dvb_table 31 * @brief Provides the MPEG TS table headers 32 * @copyright GNU Lesser General Public License version 2.1 (LGPLv2.1) 33 * @author Mauro Carvalho Chehab 34 * @author Andre Roth 35 * 36 * @par Bug Report 37 * Please submit bug reports and patches to linux-media@vger.kernel.org 38 */ 39 40 /** 41 * @struct dvb_ts_packet_header 42 * @brief Header of a MPEG-TS transport packet 43 * @ingroup dvb_table 44 * 45 * @param sync_byte sync byte 46 * @param pid Program ID 47 * @param transport_priority transport priority 48 * @param payload_unit_start_indicator payload unit start indicator 49 * @param transport_error_indicator transport error indicator 50 * @param continuity_counter continuity counter 51 * @param adaptation_field_control adaptation field control 52 * @param transport_scrambling_control transport scrambling control 53 * @param adaptation_field_length adaptation field length 54 * 55 * @see http://www.etherguidesystems.com/Help/SDOs/MPEG/Semantics/MPEG-2/transport_packet.aspx 56 */ 57 struct dvb_ts_packet_header { 58 uint8_t sync_byte; 59 union { 60 uint16_t bitfield; 61 struct { 62 uint16_t pid:13; 63 uint16_t transport_priority:1; 64 uint16_t payload_unit_start_indicator:1; 65 uint16_t transport_error_indicator:1; 66 } __attribute__((packed)); 67 } __attribute__((packed)); 68 uint8_t continuity_counter:4; 69 uint8_t adaptation_field_control:2; 70 uint8_t transport_scrambling_control:2; 71 72 /* Only if adaptation_field_control > 1 */ 73 uint8_t adaptation_field_length; 74 /* Only if adaptation_field_length >= 1 */ 75 struct { 76 uint8_t extension:1; 77 uint8_t private_data:1; 78 uint8_t splicing_point:1; 79 uint8_t OPCR:1; 80 uint8_t PCR:1; 81 uint8_t priority:1; 82 uint8_t random_access:1; 83 uint8_t discontinued:1; 84 } __attribute__((packed)); 85 } __attribute__((packed)); 86 87 /** 88 * @struct dvb_table_header 89 * @brief Header of a MPEG-TS table 90 * @ingroup dvb_table 91 * 92 * @param table_id table id 93 * @param section_length section length 94 * @param syntax syntax 95 * @param id Table ID extension 96 * @param current_next current next 97 * @param version version 98 * @param section_id section number 99 * @param last_section last section number 100 * 101 * All MPEG-TS tables start with this header. 102 */ 103 struct dvb_table_header { 104 uint8_t table_id; 105 union { 106 uint16_t bitfield; 107 struct { 108 uint16_t section_length:12; 109 uint8_t one:2; 110 uint8_t zero:1; 111 uint8_t syntax:1; 112 } __attribute__((packed)); 113 } __attribute__((packed)); 114 uint16_t id; /* TS ID */ 115 uint8_t current_next:1; 116 uint8_t version:5; 117 uint8_t one2:2; 118 119 uint8_t section_id; /* section_number */ 120 uint8_t last_section; /* last_section_number */ 121 } __attribute__((packed)); 122 123 struct dvb_v5_fe_parms; 124 125 #ifdef __cplusplus 126 extern "C" { 127 #endif 128 129 /** 130 * @brief Initializes and parses MPEG-TS table header 131 * @ingroup dvb_table 132 * 133 * @param header pointer to struct dvb_table_header to be parsed 134 */ 135 void dvb_table_header_init (struct dvb_table_header *header); 136 /** 137 * @brief Prints the content of the MPEG-TS table header 138 * @ingroup dvb_table 139 * 140 * @param parms struct dvb_v5_fe_parms pointer to the opened device 141 * @param header pointer to struct dvb_table_header to be printed 142 */ 143 void dvb_table_header_print(struct dvb_v5_fe_parms *parms, 144 const struct dvb_table_header *header); 145 146 #ifdef __cplusplus 147 } 148 #endif 149 150 #endif 151