| 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 _SDT_H |
| 22 |
#define _SDT_H |
| 23 |
|
| 24 |
/** |
| 25 |
* @file sdt.h |
| 26 |
* @ingroup dvb_table |
| 27 |
* @brief Provides the descriptors for SDT MPEG-TS table |
| 28 |
* @copyright GNU Lesser General Public License version 2.1 (LGPLv2.1) |
| 29 |
* @author Mauro Carvalho Chehab |
| 30 |
* @author Andre Roth |
| 31 |
* |
| 32 |
* @par Relevant specs |
| 33 |
* The table described herein is defined at: |
| 34 |
* - ISO/IEC 13818-1 |
| 35 |
* |
| 36 |
* @see http://www.etherguidesystems.com/Help/SDOs/dvb/syntax/tablesections/SDT.aspx |
| 37 |
* |
| 38 |
* @par Bug Report |
| 39 |
* Please submit bug reports and patches to [email protected] |
| 40 |
*/ |
| 41 |
|
| 42 |
#include <stdint.h> |
| 43 |
#include <unistd.h> /* ssize_t */ |
| 44 |
|
| 45 |
#include <libdvbv5/header.h> |
| 46 |
|
| 47 |
/** |
| 48 |
* @def DVB_TABLE_SDT |
| 49 |
* @brief SDT table ID |
| 50 |
* @ingroup dvb_table |
| 51 |
* @def DVB_TABLE_SDT2 |
| 52 |
* @brief SDT table ID (alternative table ID) |
| 53 |
* @ingroup dvb_table |
| 54 |
* @def DVB_TABLE_SDT_PID |
| 55 |
* @brief SDT Program ID |
| 56 |
* @ingroup dvb_table |
| 57 |
*/ |
| 58 |
#define DVB_TABLE_SDT 0x42 |
| 59 |
#define DVB_TABLE_SDT2 0x46 |
| 60 |
#define DVB_TABLE_SDT_PID 0x0011 |
| 61 |
|
| 62 |
/** |
| 63 |
* @struct dvb_table_sdt_service |
| 64 |
* @brief MPEG-TS SDT service table |
| 65 |
* @ingroup dvb_table |
| 66 |
* |
| 67 |
* @param service_id service id |
| 68 |
* @param EIT_present_following EIT present following |
| 69 |
* @param EIT_schedule EIT schedule |
| 70 |
* @param desc_length desc length |
| 71 |
* @param free_CA_mode free CA mode |
| 72 |
* @param running_status running status |
| 73 |
* @param descriptor pointer to struct dvb_desc |
| 74 |
* @param next pointer to struct dvb_table_sdt_service |
| 75 |
* |
| 76 |
* This structure is used to store the original SDT service table, |
| 77 |
* converting the integer fields to the CPU endianness. |
| 78 |
* |
| 79 |
* The undocumented parameters are used only internally by the API and/or |
| 80 |
* are fields that are reserved. They shouldn't be used, as they may change |
| 81 |
* on future API releases. |
| 82 |
* |
| 83 |
* Everything after dvb_table_sdt_service::descriptor (including it) won't |
| 84 |
* be bit-mapped to the data parsed from the MPEG TS. So, metadata are added |
| 85 |
* there. |
| 86 |
*/ |
| 87 |
struct dvb_table_sdt_service { |
| 88 |
uint16_t service_id; |
| 89 |
uint8_t EIT_present_following:1; |
| 90 |
uint8_t EIT_schedule:1; |
| 91 |
uint8_t reserved:6; |
| 92 |
union { |
| 93 |
uint16_t bitfield; |
| 94 |
struct { |
| 95 |
uint16_t desc_length:12; |
| 96 |
uint16_t free_CA_mode:1; |
| 97 |
uint16_t running_status:3; |
| 98 |
} __attribute__((packed)); |
| 99 |
} __attribute__((packed)); |
| 100 |
struct dvb_desc *descriptor; |
| 101 |
struct dvb_table_sdt_service *next; |
| 102 |
} __attribute__((packed)); |
| 103 |
|
| 104 |
/** |
| 105 |
* @struct dvb_table_sdt |
| 106 |
* @brief MPEG-TS SDT table |
| 107 |
* @ingroup dvb_table |
| 108 |
* |
| 109 |
* @param header struct dvb_table_header content |
| 110 |
* @param network_id network id |
| 111 |
* @param service pointer to struct dvb_table_sdt_service |
| 112 |
* |
| 113 |
* This structure is used to store the original SDT table, |
| 114 |
* converting the integer fields to the CPU endianness. |
| 115 |
* |
| 116 |
* The undocumented parameters are used only internally by the API and/or |
| 117 |
* are fields that are reserved. They shouldn't be used, as they may change |
| 118 |
* on future API releases. |
| 119 |
* |
| 120 |
* Everything after dvb_table_sdt::service (including it) won't be bit-mapped |
| 121 |
* to the data parsed from the MPEG TS. So, metadata are added there. |
| 122 |
*/ |
| 123 |
struct dvb_table_sdt { |
| 124 |
struct dvb_table_header header; |
| 125 |
uint16_t network_id; |
| 126 |
uint8_t reserved; |
| 127 |
struct dvb_table_sdt_service *service; |
| 128 |
} __attribute__((packed)); |
| 129 |
|
| 130 |
/** |
| 131 |
* @brief Macro used to find services on a SDT table |
| 132 |
* @ingroup dvb_table |
| 133 |
* |
| 134 |
* @param _service service to seek |
| 135 |
* @param _sdt pointer to struct dvb_table_sdt_service |
| 136 |
*/ |
| 137 |
#define dvb_sdt_service_foreach(_service, _sdt) \ |
| 138 |
if (_sdt && _sdt->service) \ |
| 139 |
for (struct dvb_table_sdt_service *_service = _sdt->service; _service; _service = _service->next ) \ |
| 140 |
|
| 141 |
struct dvb_v5_fe_parms; |
| 142 |
|
| 143 |
#ifdef __cplusplus |
| 144 |
extern "C" { |
| 145 |
#endif |
| 146 |
|
| 147 |
/** |
| 148 |
* @brief Initializes and parses SDT table |
| 149 |
* @ingroup dvb_table |
| 150 |
* |
| 151 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 152 |
* @param buf buffer containing the SDT raw data |
| 153 |
* @param buflen length of the buffer |
| 154 |
* @param table pointer to struct dvb_table_sdt to be allocated and filled |
| 155 |
* |
| 156 |
* This function allocates a SDT table and fills the fields inside |
| 157 |
* the struct. It also makes sure that all fields will follow the CPU |
| 158 |
* endianness. Due to that, the content of the buffer may change. |
| 159 |
* |
| 160 |
* @return On success, it returns the size of the allocated struct. |
| 161 |
* A negative value indicates an error. |
| 162 |
*/ |
| 163 |
ssize_t dvb_table_sdt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, |
| 164 |
ssize_t buflen, struct dvb_table_sdt **table); |
| 165 |
|
| 166 |
/** |
| 167 |
* @brief Frees all data allocated by the SDT table parser |
| 168 |
* @ingroup dvb_table |
| 169 |
* |
| 170 |
* @param table pointer to struct dvb_table_sdt to be freed |
| 171 |
*/ |
| 172 |
void dvb_table_sdt_free(struct dvb_table_sdt *table); |
| 173 |
|
| 174 |
/** |
| 175 |
* @brief Prints the content of the SDT table |
| 176 |
* @ingroup dvb_table |
| 177 |
* |
| 178 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 179 |
* @param table pointer to struct dvb_table_sdt |
| 180 |
*/ |
| 181 |
void dvb_table_sdt_print(struct dvb_v5_fe_parms *parms, struct dvb_table_sdt *table); |
| 182 |
|
| 183 |
#ifdef __cplusplus |
| 184 |
} |
| 185 |
#endif |
| 186 |
|
| 187 |
#endif |