| 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 |
#ifndef _NIT_H |
| 22 |
#define _NIT_H |
| 23 |
|
| 24 |
#include <stdint.h> |
| 25 |
#include <unistd.h> /* ssize_t */ |
| 26 |
|
| 27 |
#include <libdvbv5/header.h> |
| 28 |
#include <libdvbv5/descriptors.h> |
| 29 |
|
| 30 |
/** |
| 31 |
* @file nit.h |
| 32 |
* @ingroup dvb_table |
| 33 |
* @brief Provides the descriptors for NIT MPEG-TS table |
| 34 |
* @copyright GNU Lesser General Public License version 2.1 (LGPLv2.1) |
| 35 |
* @author Mauro Carvalho Chehab |
| 36 |
* @author Andre Roth |
| 37 |
* |
| 38 |
* @par Bug Report |
| 39 |
* Please submit bug report and patches to [email protected] |
| 40 |
* |
| 41 |
* @par Relevant specs |
| 42 |
* The table described herein is defined at: |
| 43 |
* - ISO/IEC 13818-1 |
| 44 |
* - ETSI EN 300 468 |
| 45 |
* |
| 46 |
* @par Bug Report |
| 47 |
* Please submit bug reports and patches to [email protected] |
| 48 |
*/ |
| 49 |
|
| 50 |
/** |
| 51 |
* @def DVB_TABLE_NIT |
| 52 |
* @brief NIT table ID |
| 53 |
* @ingroup dvb_table |
| 54 |
* @def DVB_TABLE_NIT2 |
| 55 |
* @brief NIT table ID (alternative table ID) |
| 56 |
* @ingroup dvb_table |
| 57 |
* @def DVB_TABLE_NIT_PID |
| 58 |
* @brief NIT Program ID |
| 59 |
* @ingroup dvb_table |
| 60 |
*/ |
| 61 |
#define DVB_TABLE_NIT 0x40 |
| 62 |
#define DVB_TABLE_NIT2 0x41 |
| 63 |
#define DVB_TABLE_NIT_PID 0x10 |
| 64 |
|
| 65 |
/** |
| 66 |
* @union dvb_table_nit_transport_header |
| 67 |
* @brief MPEG-TS NIT transport header |
| 68 |
* @ingroup dvb_table |
| 69 |
* |
| 70 |
* @param transport_length transport length |
| 71 |
* |
| 72 |
* This structure is used to store the original NIT transport header, |
| 73 |
* converting the integer fields to the CPU endianness. |
| 74 |
* |
| 75 |
* The undocumented parameters are used only internally by the API and/or |
| 76 |
* are fields that are reserved. They shouldn't be used, as they may change |
| 77 |
* on future API releases. |
| 78 |
*/ |
| 79 |
union dvb_table_nit_transport_header { |
| 80 |
uint16_t bitfield; |
| 81 |
struct { |
| 82 |
uint16_t transport_length:12; |
| 83 |
uint16_t reserved:4; |
| 84 |
} __attribute__((packed)); |
| 85 |
} __attribute__((packed)); |
| 86 |
|
| 87 |
/** |
| 88 |
* @struct dvb_table_nit_transport |
| 89 |
* @brief MPEG-TS NIT transport table |
| 90 |
* @ingroup dvb_table |
| 91 |
* |
| 92 |
* @param transport_id transport id |
| 93 |
* @param network_id network id |
| 94 |
* @param desc_length desc length |
| 95 |
* @param descriptor pointer to struct dvb_desc |
| 96 |
* @param next pointer to struct dvb_table_nit_transport |
| 97 |
* |
| 98 |
* This structure is used to store the original NIT transport 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_nit_transport::descriptor (including it) won't |
| 106 |
* be bit-mapped to the data parsed from the MPEG TS. So, metadata are added |
| 107 |
* there. |
| 108 |
*/ |
| 109 |
struct dvb_table_nit_transport { |
| 110 |
uint16_t transport_id; |
| 111 |
uint16_t network_id; |
| 112 |
union { |
| 113 |
uint16_t bitfield; |
| 114 |
struct { |
| 115 |
uint16_t desc_length:12; |
| 116 |
uint16_t reserved:4; |
| 117 |
} __attribute__((packed)); |
| 118 |
} __attribute__((packed)); |
| 119 |
struct dvb_desc *descriptor; |
| 120 |
struct dvb_table_nit_transport *next; |
| 121 |
} __attribute__((packed)); |
| 122 |
|
| 123 |
/** |
| 124 |
* @struct dvb_table_nit |
| 125 |
* @brief MPEG-TS NIT table |
| 126 |
* @ingroup dvb_table |
| 127 |
* |
| 128 |
* @param header struct dvb_table_header content |
| 129 |
* @param desc_length descriptor length |
| 130 |
* @param descriptor pointer to struct dvb_desc |
| 131 |
* @param transport pointer to struct dvb_table_nit_transport |
| 132 |
* |
| 133 |
* This structure is used to store the original NIT table, |
| 134 |
* converting the integer fields to the CPU endianness. |
| 135 |
* |
| 136 |
* The undocumented parameters are used only internally by the API and/or |
| 137 |
* are fields that are reserved. They shouldn't be used, as they may change |
| 138 |
* on future API releases. |
| 139 |
* |
| 140 |
* Everything after dvb_table_nit::descriptor (including it) won't be bit-mapped |
| 141 |
* to the data parsed from the MPEG TS. So, metadata are added there. |
| 142 |
*/ |
| 143 |
struct dvb_table_nit { |
| 144 |
struct dvb_table_header header; |
| 145 |
union { |
| 146 |
uint16_t bitfield; |
| 147 |
struct { |
| 148 |
uint16_t desc_length:12; |
| 149 |
uint16_t reserved:4; |
| 150 |
} __attribute__((packed)); |
| 151 |
} __attribute__((packed)); |
| 152 |
struct dvb_desc *descriptor; |
| 153 |
struct dvb_table_nit_transport *transport; |
| 154 |
} __attribute__((packed)); |
| 155 |
|
| 156 |
/** |
| 157 |
* @brief typedef for a callback used when a NIT table entry is found |
| 158 |
* @ingroup dvb_table |
| 159 |
* |
| 160 |
* @param nit a struct dvb_table_nit pointer |
| 161 |
* @param desc a struct dvb_desc pointer |
| 162 |
* @param priv an opaque optional pointer |
| 163 |
*/ |
| 164 |
typedef void nit_handler_callback_t(struct dvb_table_nit *nit, |
| 165 |
struct dvb_desc *desc, |
| 166 |
void *priv); |
| 167 |
|
| 168 |
/** |
| 169 |
* @brief typedef for a callback used when a NIT transport table entry is found |
| 170 |
* @ingroup dvb_table |
| 171 |
* |
| 172 |
* @param nit a struct dvb_table_nit pointer |
| 173 |
* @param tran a struct dvb_table_nit_transport pointer |
| 174 |
* @param desc a struct dvb_desc pointer |
| 175 |
* @param priv an opaque optional pointer |
| 176 |
*/ |
| 177 |
typedef void nit_tran_handler_callback_t(struct dvb_table_nit *nit, |
| 178 |
struct dvb_table_nit_transport *tran, |
| 179 |
struct dvb_desc *desc, |
| 180 |
void *priv); |
| 181 |
|
| 182 |
/** |
| 183 |
* @brief Macro used to find a transport inside a NIT table |
| 184 |
* @ingroup dvb_table |
| 185 |
* |
| 186 |
* @param _tran transport to seek |
| 187 |
* @param _nit pointer to struct dvb_table_nit_transport |
| 188 |
*/ |
| 189 |
#define dvb_nit_transport_foreach( _tran, _nit ) \ |
| 190 |
if (_nit && _nit->transport) \ |
| 191 |
for (struct dvb_table_nit_transport *_tran = _nit->transport; _tran; _tran = _tran->next) \ |
| 192 |
|
| 193 |
struct dvb_v5_fe_parms; |
| 194 |
|
| 195 |
#ifdef __cplusplus |
| 196 |
extern "C" { |
| 197 |
#endif |
| 198 |
|
| 199 |
/** |
| 200 |
* @brief Initializes and parses NIT table |
| 201 |
* @ingroup dvb_table |
| 202 |
* |
| 203 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 204 |
* @param buf buffer containing the NIT raw data |
| 205 |
* @param buflen length of the buffer |
| 206 |
* @param table pointer to struct dvb_table_nit to be allocated and filled |
| 207 |
* |
| 208 |
* This function allocates a NIT table and fills the fields inside |
| 209 |
* the struct. It also makes sure that all fields will follow the CPU |
| 210 |
* endianness. Due to that, the content of the buffer may change. |
| 211 |
* |
| 212 |
* @return On success, it returns the size of the allocated struct. |
| 213 |
* A negative value indicates an error. |
| 214 |
*/ |
| 215 |
ssize_t dvb_table_nit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, |
| 216 |
ssize_t buflen, struct dvb_table_nit **table); |
| 217 |
|
| 218 |
/** |
| 219 |
* @brief Frees all data allocated by the NIT table parser |
| 220 |
* @ingroup dvb_table |
| 221 |
* |
| 222 |
* @param table pointer to struct dvb_table_nit to be freed |
| 223 |
*/ |
| 224 |
void dvb_table_nit_free(struct dvb_table_nit *table); |
| 225 |
|
| 226 |
/** |
| 227 |
* @brief Prints the content of the NIT table |
| 228 |
* @ingroup dvb_table |
| 229 |
* |
| 230 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 231 |
* @param table pointer to struct dvb_table_nit |
| 232 |
*/ |
| 233 |
void dvb_table_nit_print(struct dvb_v5_fe_parms *parms, struct dvb_table_nit *table); |
| 234 |
|
| 235 |
/** |
| 236 |
* @brief For each entry at NIT and NIT transport tables, call a callback |
| 237 |
* @ingroup dvb_table |
| 238 |
* |
| 239 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 240 |
* @param table pointer to struct dvb_table_nit |
| 241 |
* @param descriptor indicates the NIT table descriptor to seek |
| 242 |
* @param call_nit a nit_handler_callback_t function to be called when a |
| 243 |
* new entry at the NIT table is found (or NULL). |
| 244 |
* @param call_tran a nit_tran_handler_callback_t function to be called |
| 245 |
* when a new entry at the NIT transport table is found |
| 246 |
* (or NULL). |
| 247 |
* @param priv an opaque pointer to be optionally used by the |
| 248 |
* callbacks. The function won't touch on it, just use |
| 249 |
* as an argument for the callback functions. |
| 250 |
* |
| 251 |
* When parsing a NIT entry, we need to call some code to properly handle |
| 252 |
* when a given descriptor in the table is found. This is used, for example, |
| 253 |
* to create newer transponders to seek during scan. |
| 254 |
* |
| 255 |
* For example, to seek for the CATV delivery system descriptor and call a |
| 256 |
* function that would add a new transponder to a scan procedure: |
| 257 |
* @code |
| 258 |
* dvb_table_nit_descriptor_handler( |
| 259 |
* &parms->p, dvb_scan_handler->nit, |
| 260 |
* cable_delivery_system_descriptor, |
| 261 |
* NULL, add_update_nit_dvbc, &tr); |
| 262 |
* @endcode |
| 263 |
*/ |
| 264 |
void dvb_table_nit_descriptor_handler( |
| 265 |
struct dvb_v5_fe_parms *parms, |
| 266 |
struct dvb_table_nit *table, |
| 267 |
enum descriptors descriptor, |
| 268 |
nit_handler_callback_t *call_nit, |
| 269 |
nit_tran_handler_callback_t *call_tran, |
| 270 |
void *priv); |
| 271 |
|
| 272 |
#ifdef __cplusplus |
| 273 |
} |
| 274 |
#endif |
| 275 |
|
| 276 |
#endif |