| 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 pmt.h |
| 23 |
* @ingroup dvb_table |
| 24 |
* @brief Provides the descriptors for PMT 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/pmts.aspx |
| 34 |
* |
| 35 |
* @par Bug Report |
| 36 |
* Please submit bug reports and patches to [email protected] |
| 37 |
*/ |
| 38 |
|
| 39 |
#ifndef _PMT_H |
| 40 |
#define _PMT_H |
| 41 |
|
| 42 |
#include <stdint.h> |
| 43 |
#include <unistd.h> /* ssize_t */ |
| 44 |
|
| 45 |
#include <libdvbv5/header.h> |
| 46 |
|
| 47 |
/** |
| 48 |
* @def DVB_TABLE_PMT |
| 49 |
* @brief PMT table ID |
| 50 |
* @ingroup dvb_table |
| 51 |
*/ |
| 52 |
#define DVB_TABLE_PMT 0x02 |
| 53 |
|
| 54 |
/** |
| 55 |
* @enum dvb_streams |
| 56 |
* @brief Add support for MPEG-TS Stream types |
| 57 |
* @ingroup dvb_table |
| 58 |
* |
| 59 |
* @var stream_video |
| 60 |
* @brief ISO/IEC 11172 Video |
| 61 |
* @var stream_video_h262 |
| 62 |
* @brief ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or ISO/IEC 11172-2 constrained parameter video stream |
| 63 |
* @var stream_audio |
| 64 |
* @brief ISO/IEC 11172 Audio |
| 65 |
* @var stream_audio_13818_3 |
| 66 |
* @brief ISO/IEC 13818-3 Audio |
| 67 |
* @var stream_private_sections |
| 68 |
* @brief ITU-T Rec. H.222.0 | ISO/IEC 13818-1 private_sections |
| 69 |
* @var stream_private_data |
| 70 |
* @brief ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES packets containing private data |
| 71 |
* @var stream_mheg |
| 72 |
* @brief ISO/IEC 13522 MHEG |
| 73 |
* @var stream_h222 |
| 74 |
* @brief ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A DSM-CC |
| 75 |
* @var stream_h222_1 |
| 76 |
* @brief ITU-T Rec. H.222.1 |
| 77 |
* @var stream_13818_6_A |
| 78 |
* @brief ISO/IEC 13818-6 type A |
| 79 |
* @var stream_13818_6_B |
| 80 |
* @brief ISO/IEC 13818-6 type B |
| 81 |
* @var stream_13818_6_C |
| 82 |
* @brief ISO/IEC 13818-6 type C |
| 83 |
* @var stream_13818_6_D |
| 84 |
* @brief ISO/IEC 13818-6 type D |
| 85 |
* @var stream_h222_aux |
| 86 |
* @brief ITU-T Rec. H.222.0 | ISO/IEC 13818-1 auxiliary |
| 87 |
* @var stream_audio_adts |
| 88 |
* @brief ISO/IEC 13818-7 Audio with ADTS transport syntax |
| 89 |
* @var stream_video_14496_2 |
| 90 |
* @brief ISO/IEC 14496-2 Visual |
| 91 |
* @var stream_audio_latm |
| 92 |
* @brief ISO/IEC 14496-3 Audio with the LATM transport syntax as defined in ISO/IEC 14496-3 / AMD 1 |
| 93 |
* @var stream_14496_1_pes |
| 94 |
* @brief ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in PES packets |
| 95 |
* @var stream_14496_1_iso |
| 96 |
* @brief ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in ISO/IEC14496_sections. |
| 97 |
* @var stream_download |
| 98 |
* @brief ISO/IEC 13818-6 Synchronized Download Protocol |
| 99 |
*/ |
| 100 |
enum dvb_streams { |
| 101 |
stream_video = 0x01, |
| 102 |
stream_video_h262 = 0x02, |
| 103 |
stream_audio = 0x03, |
| 104 |
stream_audio_13818_3 = 0x04, |
| 105 |
stream_private_sections = 0x05, |
| 106 |
stream_private_data = 0x06, |
| 107 |
stream_mheg = 0x07, |
| 108 |
stream_h222 = 0x08, |
| 109 |
stream_h222_1 = 0x09, |
| 110 |
stream_13818_6_A = 0x0A, |
| 111 |
stream_13818_6_B = 0x0B, |
| 112 |
stream_13818_6_C = 0x0C, |
| 113 |
stream_13818_6_D = 0x0D, |
| 114 |
stream_h222_aux = 0x0E, |
| 115 |
stream_audio_adts = 0x0F, |
| 116 |
stream_video_14496_2 = 0x10, |
| 117 |
stream_audio_latm = 0x11, |
| 118 |
stream_14496_1_pes = 0x12, |
| 119 |
stream_14496_1_iso = 0x13, |
| 120 |
stream_download = 0x14, |
| 121 |
stream_video_h264 = 0x1b, |
| 122 |
stream_audio_14496_3 = 0x1c, |
| 123 |
stream_video_hevc = 0x24, |
| 124 |
stream_video_cavs = 0x42, |
| 125 |
stream_video_moto = 0x80, |
| 126 |
stream_audio_a52 = 0x81, |
| 127 |
stream_scte_27 = 0x82, |
| 128 |
stream_audio_sdds = 0x84, |
| 129 |
stream_audio_dts_hdmv = 0x85, |
| 130 |
stream_audio_e_ac3 = 0x87, |
| 131 |
stream_audio_dts = 0x8a, |
| 132 |
stream_audio_a52_vls = 0x91, |
| 133 |
stream_spu_vls = 0x92, |
| 134 |
stream_audio_sdds2 = 0x94, |
| 135 |
}; |
| 136 |
|
| 137 |
/** |
| 138 |
* @brief Converts from enum dvb_streams into a string |
| 139 |
* @ingroup dvb_table |
| 140 |
*/ |
| 141 |
extern const char *pmt_stream_name[]; |
| 142 |
|
| 143 |
/** |
| 144 |
* @struct dvb_table_pmt_stream |
| 145 |
* @brief MPEG-TS PMT stream table |
| 146 |
* @ingroup dvb_table |
| 147 |
* |
| 148 |
* @param type stream type |
| 149 |
* @param elementary_pid elementary pid |
| 150 |
* @param desc_length descriptor length |
| 151 |
* @param zero zero |
| 152 |
* @param descriptor pointer to struct dvb_desc |
| 153 |
* @param next pointer to struct dvb_table_pmt_stream |
| 154 |
|
| 155 |
* |
| 156 |
* This structure is used to store the original PMT stream table, |
| 157 |
* converting the integer fields to the CPU endianness. |
| 158 |
* |
| 159 |
* The undocumented parameters are used only internally by the API and/or |
| 160 |
* are fields that are reserved. They shouldn't be used, as they may change |
| 161 |
* on future API releases. |
| 162 |
* |
| 163 |
* Everything after dvb_table_pmt_stream::descriptor (including it) won't be |
| 164 |
* bit-mapped to the data parsed from the MPEG TS. So, metadata are added there. |
| 165 |
*/ |
| 166 |
struct dvb_table_pmt_stream { |
| 167 |
uint8_t type; |
| 168 |
union { |
| 169 |
uint16_t bitfield; |
| 170 |
struct { |
| 171 |
uint16_t elementary_pid:13; |
| 172 |
uint16_t reserved:3; |
| 173 |
} __attribute__((packed)); |
| 174 |
} __attribute__((packed)); |
| 175 |
union { |
| 176 |
uint16_t bitfield2; |
| 177 |
struct { |
| 178 |
uint16_t desc_length:10; |
| 179 |
uint16_t zero:2; |
| 180 |
uint16_t reserved2:4; |
| 181 |
} __attribute__((packed)); |
| 182 |
} __attribute__((packed)); |
| 183 |
struct dvb_desc *descriptor; |
| 184 |
struct dvb_table_pmt_stream *next; |
| 185 |
} __attribute__((packed)); |
| 186 |
|
| 187 |
/** |
| 188 |
* @struct dvb_table_pmt |
| 189 |
* @brief MPEG-TS PMT table |
| 190 |
* @ingroup dvb_table |
| 191 |
* |
| 192 |
* @param header struct dvb_table_header content |
| 193 |
* @param pcr_pid PCR PID |
| 194 |
* @param desc_length descriptor length |
| 195 |
* @param descriptor pointer to struct dvb_desc |
| 196 |
* @param stream pointer to struct dvb_table_pmt_stream |
| 197 |
* |
| 198 |
* This structure is used to store the original PMT stream table, |
| 199 |
* converting the integer fields to the CPU endianness. |
| 200 |
* |
| 201 |
* The undocumented parameters are used only internally by the API and/or |
| 202 |
* are fields that are reserved. They shouldn't be used, as they may change |
| 203 |
* on future API releases. |
| 204 |
* |
| 205 |
* Everything after dvb_table_pmt::descriptor (including it) won't be |
| 206 |
* bit-mapped to the data parsed from the MPEG TS. So, metadata are added there. |
| 207 |
*/ |
| 208 |
struct dvb_table_pmt { |
| 209 |
struct dvb_table_header header; |
| 210 |
union { |
| 211 |
uint16_t bitfield; |
| 212 |
struct { |
| 213 |
uint16_t pcr_pid:13; |
| 214 |
uint16_t reserved2:3; |
| 215 |
} __attribute__((packed)); |
| 216 |
} __attribute__((packed)); |
| 217 |
|
| 218 |
union { |
| 219 |
uint16_t bitfield2; |
| 220 |
struct { |
| 221 |
uint16_t desc_length:10; |
| 222 |
uint16_t zero3:2; |
| 223 |
uint16_t reserved3:4; |
| 224 |
} __attribute__((packed)); |
| 225 |
} __attribute__((packed)); |
| 226 |
struct dvb_desc *descriptor; |
| 227 |
struct dvb_table_pmt_stream *stream; |
| 228 |
} __attribute__((packed)); |
| 229 |
|
| 230 |
/** @brief First field at the struct */ |
| 231 |
#define dvb_pmt_field_first header |
| 232 |
|
| 233 |
/** @brief First field that are not part of the received data */ |
| 234 |
#define dvb_pmt_field_last descriptor |
| 235 |
|
| 236 |
/** |
| 237 |
* @brief Macro used to find streams on a PMT table |
| 238 |
* @ingroup dvb_table |
| 239 |
* |
| 240 |
* @param _stream stream to seek |
| 241 |
* @param _pmt pointer to struct dvb_table_pmt_stream |
| 242 |
*/ |
| 243 |
#define dvb_pmt_stream_foreach(_stream, _pmt) \ |
| 244 |
if (_pmt && _pmt->stream) \ |
| 245 |
for (struct dvb_table_pmt_stream *_stream = _pmt->stream; _stream; _stream = _stream->next) \ |
| 246 |
|
| 247 |
struct dvb_v5_fe_parms; |
| 248 |
|
| 249 |
#ifdef __cplusplus |
| 250 |
extern "C" { |
| 251 |
#endif |
| 252 |
|
| 253 |
/** |
| 254 |
* @brief Initializes and parses PMT table |
| 255 |
* @ingroup dvb_table |
| 256 |
* |
| 257 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 258 |
* @param buf buffer containing the PMT raw data |
| 259 |
* @param buflen length of the buffer |
| 260 |
* @param table pointer to struct dvb_table_pmt to be allocated and filled |
| 261 |
* |
| 262 |
* This function allocates a PMT table and fills the fields inside |
| 263 |
* the struct. It also makes sure that all fields will follow the CPU |
| 264 |
* endianness. Due to that, the content of the buffer may change. |
| 265 |
* |
| 266 |
* @return On success, it returns the size of the allocated struct. |
| 267 |
* A negative value indicates an error. |
| 268 |
*/ |
| 269 |
ssize_t dvb_table_pmt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, |
| 270 |
ssize_t buflen, struct dvb_table_pmt **table); |
| 271 |
|
| 272 |
/** |
| 273 |
* @brief Frees all data allocated by the PMT table parser |
| 274 |
* @ingroup dvb_table |
| 275 |
* |
| 276 |
* @param table pointer to struct dvb_table_pmt to be freed |
| 277 |
*/ |
| 278 |
void dvb_table_pmt_free(struct dvb_table_pmt *table); |
| 279 |
|
| 280 |
/** |
| 281 |
* @brief Prints the content of the PAT table |
| 282 |
* @ingroup dvb_table |
| 283 |
* |
| 284 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 285 |
* @param table pointer to struct dvb_table_pmt |
| 286 |
*/ |
| 287 |
void dvb_table_pmt_print(struct dvb_v5_fe_parms *parms, |
| 288 |
const struct dvb_table_pmt *table); |
| 289 |
|
| 290 |
#ifdef __cplusplus |
| 291 |
} |
| 292 |
#endif |
| 293 |
|
| 294 |
#endif |