| 1 |
/* |
| 2 |
* Copyright (c) 2013 - Mauro Carvalho Chehab <[email protected]> |
| 3 |
* Copyright (c) 2013 - 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 vct.h |
| 23 |
* @ingroup dvb_table |
| 24 |
* @brief Provides the descriptors for TVCT and CVCT tables |
| 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 |
* - ATSC A/65:2009 |
| 32 |
* |
| 33 |
* @see http://www.etherguidesystems.com/help/sdos/atsc/syntax/tablesections/TVCT.aspx |
| 34 |
* @see http://www.etherguidesystems.com/help/sdos/atsc/syntax/tablesections/CVCT.aspx |
| 35 |
* |
| 36 |
* @par Bug Report |
| 37 |
* Please submit bug reports and patches to [email protected] |
| 38 |
*/ |
| 39 |
|
| 40 |
#ifndef _VCT_H |
| 41 |
#define _VCT_H |
| 42 |
|
| 43 |
#include <stdint.h> |
| 44 |
#include <unistd.h> /* ssize_t */ |
| 45 |
|
| 46 |
#include <libdvbv5/atsc_header.h> |
| 47 |
|
| 48 |
/** |
| 49 |
* @def ATSC_TABLE_TVCT |
| 50 |
* @brief TVCT table ID |
| 51 |
* @ingroup dvb_table |
| 52 |
* @def ATSC_TABLE_CVCT |
| 53 |
* @brief CVCT table ID |
| 54 |
* @ingroup dvb_table |
| 55 |
* @def ATSC_TABLE_VCT_PID |
| 56 |
* @brief Program ID with the VCT tables on it |
| 57 |
* @ingroup dvb_table |
| 58 |
*/ |
| 59 |
#define ATSC_TABLE_TVCT 0xc8 |
| 60 |
#define ATSC_TABLE_CVCT 0xc9 |
| 61 |
#define ATSC_TABLE_VCT_PID 0x1ffb |
| 62 |
|
| 63 |
/** |
| 64 |
* @struct atsc_table_vct_channel |
| 65 |
* @brief ATSC VCT channel table (covers both CVCT and TVCT) |
| 66 |
* @ingroup dvb_table |
| 67 |
* |
| 68 |
* @param modulation_mode modulation mode |
| 69 |
* @param minor_channel_number minor channel number |
| 70 |
* @param major_channel_number major channel number |
| 71 |
* @param carrier_frequency carrier frequency |
| 72 |
* @param channel_tsid channel tsid |
| 73 |
* @param program_number program number |
| 74 |
* @param service_type service type |
| 75 |
* @param hide_guide hide guide |
| 76 |
* @param out_of_band out of band (CVCT only) |
| 77 |
* @param path_select path select (CVCT only) |
| 78 |
* @param hidden hidden |
| 79 |
* @param access_controlled access controlled |
| 80 |
* @param ETM_location ETM location |
| 81 |
* @param source_id source ID |
| 82 |
* @param descriptors_length length of the descriptors |
| 83 |
* |
| 84 |
* @param descriptor pointer to struct dvb_desc |
| 85 |
* @param next pointer to another struct atsc_table_vct_channel |
| 86 |
* @param descriptors_length length of the descriptors |
| 87 |
* @param short_name short name. The __short_name is converted |
| 88 |
* from UTF-16 to locale charset when parsed |
| 89 |
* |
| 90 |
* This structure is used to store the original VCT channel table, |
| 91 |
* converting the integer fields to the CPU endianness. |
| 92 |
* |
| 93 |
* The undocumented parameters are used only internally by the API and/or |
| 94 |
* are fields that are reserved. They shouldn't be used, as they may change |
| 95 |
* on future API releases. |
| 96 |
* |
| 97 |
* Everything after atsc_table_vct_channel::descriptor (including it) won't |
| 98 |
* be bit-mapped * to the data parsed from the MPEG TS. So, metadata are |
| 99 |
* added there. |
| 100 |
*/ |
| 101 |
struct atsc_table_vct_channel { |
| 102 |
uint16_t __short_name[7]; |
| 103 |
|
| 104 |
union { |
| 105 |
uint32_t bitfield1; |
| 106 |
struct { |
| 107 |
uint32_t modulation_mode:8; |
| 108 |
uint32_t minor_channel_number:10; |
| 109 |
uint32_t major_channel_number:10; |
| 110 |
uint32_t reserved1:4; |
| 111 |
} __attribute__((packed)); |
| 112 |
} __attribute__((packed)); |
| 113 |
|
| 114 |
uint32_t carrier_frequency; |
| 115 |
uint16_t channel_tsid; |
| 116 |
uint16_t program_number; |
| 117 |
union { |
| 118 |
uint16_t bitfield2; |
| 119 |
struct { |
| 120 |
uint16_t service_type:6; |
| 121 |
uint16_t reserved2:3; |
| 122 |
uint16_t hide_guide:1; |
| 123 |
uint16_t out_of_band:1; /* CVCT only */ |
| 124 |
uint16_t path_select:1; /* CVCT only */ |
| 125 |
uint16_t hidden:1; |
| 126 |
uint16_t access_controlled:1; |
| 127 |
uint16_t ETM_location:2; |
| 128 |
|
| 129 |
} __attribute__((packed)); |
| 130 |
} __attribute__((packed)); |
| 131 |
|
| 132 |
uint16_t source_id; |
| 133 |
union { |
| 134 |
uint16_t bitfield3; |
| 135 |
struct { |
| 136 |
uint16_t descriptors_length:10; |
| 137 |
uint16_t reserved3:6; |
| 138 |
} __attribute__((packed)); |
| 139 |
} __attribute__((packed)); |
| 140 |
|
| 141 |
/* |
| 142 |
* Everything after atsc_table_vct_channel::descriptor (including it) |
| 143 |
* won't be bit-mapped to the data parsed from the MPEG TS. So, |
| 144 |
* metadata are added there |
| 145 |
*/ |
| 146 |
struct dvb_desc *descriptor; |
| 147 |
struct atsc_table_vct_channel *next; |
| 148 |
|
| 149 |
/* The channel_short_name is converted to locale charset by vct.c */ |
| 150 |
|
| 151 |
char short_name[32]; |
| 152 |
} __attribute__((packed)); |
| 153 |
|
| 154 |
/** |
| 155 |
* @struct atsc_table_vct |
| 156 |
* @brief ATSC VCT table (covers both CVCT and TVCT) |
| 157 |
* @ingroup dvb_table |
| 158 |
* |
| 159 |
* @param header struct dvb_table_header content |
| 160 |
* @param protocol_version protocol version |
| 161 |
* @param num_channels_in_section num channels in section |
| 162 |
* @param channel pointer to struct channel |
| 163 |
* @param descriptor pointer to struct descriptor |
| 164 |
* |
| 165 |
* Everything after atsc_table_vct::channel (including it) won't be bit-mapped |
| 166 |
* to the data parsed from the MPEG TS. So, metadata are added there |
| 167 |
*/ |
| 168 |
struct atsc_table_vct { |
| 169 |
struct dvb_table_header header; |
| 170 |
uint8_t protocol_version; |
| 171 |
|
| 172 |
uint8_t num_channels_in_section; |
| 173 |
|
| 174 |
struct atsc_table_vct_channel *channel; |
| 175 |
struct dvb_desc *descriptor; |
| 176 |
} __attribute__((packed)); |
| 177 |
|
| 178 |
/** |
| 179 |
* @union atsc_table_vct_descriptor_length |
| 180 |
* @brief ATSC VCT descriptor length |
| 181 |
* @ingroup dvb_table |
| 182 |
* |
| 183 |
* @param descriptor_length descriptor length |
| 184 |
* |
| 185 |
* Used internally by the library to parse the descriptor length endianness. |
| 186 |
*/ |
| 187 |
union atsc_table_vct_descriptor_length { |
| 188 |
uint16_t bitfield; |
| 189 |
struct { |
| 190 |
uint16_t descriptor_length:10; |
| 191 |
uint16_t reserved:6; |
| 192 |
} __attribute__((packed)); |
| 193 |
} __attribute__((packed)); |
| 194 |
|
| 195 |
/** |
| 196 |
* @brief Macro used to find channels on a VCT table |
| 197 |
* @ingroup dvb_table |
| 198 |
* |
| 199 |
* @param _channel channel to seek |
| 200 |
* @param _vct pointer to struct atsc_table_vct_channel |
| 201 |
*/ |
| 202 |
#define atsc_vct_channel_foreach(_channel, _vct) \ |
| 203 |
if (_vct && _vct->channel) \ |
| 204 |
for (struct atsc_table_vct_channel *_channel = _vct->channel; _channel; _channel = _channel->next) \ |
| 205 |
|
| 206 |
struct dvb_v5_fe_parms; |
| 207 |
|
| 208 |
#ifdef __cplusplus |
| 209 |
extern "C" { |
| 210 |
#endif |
| 211 |
|
| 212 |
/** |
| 213 |
* @brief Initializes and parses VCT table |
| 214 |
* @ingroup dvb_table |
| 215 |
* |
| 216 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 217 |
* @param buf buffer containing the VCT raw data |
| 218 |
* @param buflen length of the buffer |
| 219 |
* @param table pointer to struct atsc_table_vct to be allocated and filled |
| 220 |
* |
| 221 |
* This function allocates an ATSC VCT table and fills the fields inside |
| 222 |
* the struct. It also makes sure that all fields will follow the CPU |
| 223 |
* endianness. Due to that, the content of the buffer may change. |
| 224 |
* |
| 225 |
* @return On success, it returns the size of the allocated struct. |
| 226 |
* A negative value indicates an error. |
| 227 |
*/ |
| 228 |
ssize_t atsc_table_vct_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, |
| 229 |
ssize_t buflen, struct atsc_table_vct **table); |
| 230 |
/** |
| 231 |
* @brief Frees all data allocated by the VCT table parser |
| 232 |
* @ingroup dvb_table |
| 233 |
* |
| 234 |
* @param table pointer to struct atsc_table_vct to be freed |
| 235 |
*/ |
| 236 |
void atsc_table_vct_free(struct atsc_table_vct *table); |
| 237 |
/** |
| 238 |
* @brief Prints the content of the VCT table |
| 239 |
* @ingroup dvb_table |
| 240 |
* |
| 241 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 242 |
* @param table pointer to struct atsc_table_vct |
| 243 |
*/ |
| 244 |
void atsc_table_vct_print(struct dvb_v5_fe_parms *parms, |
| 245 |
struct atsc_table_vct *table); |
| 246 |
|
| 247 |
#ifdef __cplusplus |
| 248 |
} |
| 249 |
#endif |
| 250 |
|
| 251 |
#endif |