Debian Codegraph @

lib/include/libdvbv5/pat.h

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