| 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 eit.h |
| 23 |
* @ingroup dvb_table |
| 24 |
* @brief Provides the table parser for the DVB EIT (Event Information 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 |
* - ETSI EN 300 468 |
| 32 |
* |
| 33 |
* @see |
| 34 |
* http://www.etherguidesystems.com/Help/SDOs/dvb/syntax/tablesections/EIT.aspx |
| 35 |
* |
| 36 |
* @par Bug Report |
| 37 |
* Please submit bug reports and patches to [email protected] |
| 38 |
*/ |
| 39 |
|
| 40 |
#ifndef _EIT_H |
| 41 |
#define _EIT_H |
| 42 |
|
| 43 |
#include <stdint.h> |
| 44 |
#include <unistd.h> /* ssize_t */ |
| 45 |
#include <time.h> |
| 46 |
|
| 47 |
#include <libdvbv5/header.h> |
| 48 |
|
| 49 |
/** |
| 50 |
* @def DVB_TABLE_EIT |
| 51 |
* @brief DVB EIT table ID for the actual TS |
| 52 |
* @ingroup dvb_table |
| 53 |
* @def DVB_TABLE_EIT_OTHER |
| 54 |
* @brief DVB EIT table ID for other TS |
| 55 |
* @ingroup dvb_table |
| 56 |
* @def DVB_TABLE_EIT_PID |
| 57 |
* @brief DVB EIT Program ID |
| 58 |
* @ingroup dvb_table |
| 59 |
* @def DVB_TABLE_EIT_SCHEDULE |
| 60 |
* @brief Start table ID for the DVB EIT schedule data on the actual TS |
| 61 |
* The range has 0x0f elements (0x50 to 0x5F). |
| 62 |
* @ingroup dvb_table |
| 63 |
* @def DVB_TABLE_EIT_SCHEDULE_OTHER |
| 64 |
* @brief Start table ID for the DVB EIT schedule data on other TS |
| 65 |
* The range has 0x0f elements (0x60 to 0x6F). |
| 66 |
* @ingroup dvb_table |
| 67 |
*/ |
| 68 |
#define DVB_TABLE_EIT 0x4E |
| 69 |
#define DVB_TABLE_EIT_OTHER 0x4F |
| 70 |
#define DVB_TABLE_EIT_PID 0x12 |
| 71 |
|
| 72 |
#define DVB_TABLE_EIT_SCHEDULE 0x50 |
| 73 |
#define DVB_TABLE_EIT_SCHEDULE_OTHER 0x60 |
| 74 |
|
| 75 |
/** |
| 76 |
* @struct dvb_table_eit_event |
| 77 |
* @brief DVB EIT event table |
| 78 |
* @ingroup dvb_table |
| 79 |
* |
| 80 |
* @param event_id an uniquelly (inside a service ID) event ID |
| 81 |
* @param desc_length descriptor's length |
| 82 |
* @param free_CA_mode free CA mode. 0 indicates that the event |
| 83 |
* is not scrambled |
| 84 |
* @param running_status running status of the event. The status can |
| 85 |
* be translated to string via |
| 86 |
* dvb_eit_running_status_name string table. |
| 87 |
* @param descriptor pointer to struct dvb_desc |
| 88 |
* @param next pointer to struct dvb_table_eit_event |
| 89 |
* @param tm_start event start (in struct tm format) |
| 90 |
* @param duration duration in seconds |
| 91 |
* @param service_id service ID |
| 92 |
* |
| 93 |
* This structure is used to store the original EIT event table, |
| 94 |
* converting the integer fields to the CPU endianness, and converting the |
| 95 |
* timestamps to a way that it is better handled on Linux. |
| 96 |
* |
| 97 |
* The undocumented parameters are used only internally by the API and/or |
| 98 |
* are fields that are reserved. They shouldn't be used, as they may change |
| 99 |
* on future API releases. |
| 100 |
* |
| 101 |
* Everything after dvb_table_eit_event::descriptor (including it) won't |
| 102 |
* be bit-mapped to the data parsed from the MPEG TS. So, metadata are added |
| 103 |
* there. |
| 104 |
*/ |
| 105 |
struct dvb_table_eit_event { |
| 106 |
uint16_t event_id; |
| 107 |
union { |
| 108 |
uint16_t bitfield1; /* first 2 bytes are MJD, they need to be bswapped */ |
| 109 |
uint8_t dvbstart[5]; |
| 110 |
} __attribute__((packed)); |
| 111 |
uint8_t dvbduration[3]; |
| 112 |
union { |
| 113 |
uint16_t bitfield2; |
| 114 |
struct { |
| 115 |
uint16_t desc_length:12; |
| 116 |
uint16_t free_CA_mode:1; |
| 117 |
uint16_t running_status:3; |
| 118 |
} __attribute__((packed)); |
| 119 |
} __attribute__((packed)); |
| 120 |
struct dvb_desc *descriptor; |
| 121 |
struct dvb_table_eit_event *next; |
| 122 |
struct tm start; |
| 123 |
uint32_t duration; |
| 124 |
uint16_t service_id; |
| 125 |
} __attribute__((packed)); |
| 126 |
|
| 127 |
/** |
| 128 |
* @struct dvb_table_eit |
| 129 |
* @brief DVB EIT table |
| 130 |
* @ingroup dvb_table |
| 131 |
* |
| 132 |
* @param header struct dvb_table_header content |
| 133 |
* @param transport_id transport id |
| 134 |
* @param network_id network id |
| 135 |
* @param last_segment last segment |
| 136 |
* @param last_table_id last table id |
| 137 |
* @param event pointer to struct dvb_table_eit_event |
| 138 |
* |
| 139 |
* This structure is used to store the original EIT table, |
| 140 |
* converting the integer fields to the CPU endianness. |
| 141 |
* |
| 142 |
* Everything after dvb_table_eit::event (including it) won't |
| 143 |
* be bit-mapped to the data parsed from the MPEG TS. So, metadata are added |
| 144 |
* there. |
| 145 |
*/ |
| 146 |
struct dvb_table_eit { |
| 147 |
struct dvb_table_header header; |
| 148 |
uint16_t transport_id; |
| 149 |
uint16_t network_id; |
| 150 |
uint8_t last_segment; |
| 151 |
uint8_t last_table_id; |
| 152 |
struct dvb_table_eit_event *event; |
| 153 |
} __attribute__((packed)); |
| 154 |
|
| 155 |
/** |
| 156 |
* @brief Macro used to find event on a DVB EIT table |
| 157 |
* @ingroup dvb_table |
| 158 |
* |
| 159 |
* @param _event event to seek |
| 160 |
* @param _eit pointer to struct dvb_table_eit_event |
| 161 |
*/ |
| 162 |
#define dvb_eit_event_foreach(_event, _eit) \ |
| 163 |
if (_eit && _eit->event) \ |
| 164 |
for( struct dvb_table_eit_event *_event = _eit->event; _event; _event = _event->next ) \ |
| 165 |
|
| 166 |
struct dvb_v5_fe_parms; |
| 167 |
|
| 168 |
/** @brief Converts a running_status field into string */ |
| 169 |
extern const char *dvb_eit_running_status_name[8]; |
| 170 |
|
| 171 |
#ifdef __cplusplus |
| 172 |
extern "C" { |
| 173 |
#endif |
| 174 |
|
| 175 |
/** |
| 176 |
* @brief Initializes and parses EIT table |
| 177 |
* @ingroup dvb_table |
| 178 |
* |
| 179 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 180 |
* @param buf buffer containing the EIT raw data |
| 181 |
* @param buflen length of the buffer |
| 182 |
* @param table pointer to struct dvb_table_eit to be allocated and filled |
| 183 |
* |
| 184 |
* This function allocates an EIT table and fills the fields inside |
| 185 |
* the struct. It also makes sure that all fields will follow the CPU |
| 186 |
* endianness. Due to that, the content of the buffer may change. |
| 187 |
* |
| 188 |
* @return On success, it returns the size of the allocated struct. |
| 189 |
* A negative value indicates an error. |
| 190 |
*/ |
| 191 |
ssize_t dvb_table_eit_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, |
| 192 |
ssize_t buflen, struct dvb_table_eit **table); |
| 193 |
|
| 194 |
/** |
| 195 |
* @brief Frees all data allocated by the DVB EIT table parser |
| 196 |
* @ingroup dvb_table |
| 197 |
* |
| 198 |
* @param table pointer to struct dvb_table_eit to be freed |
| 199 |
*/ |
| 200 |
void dvb_table_eit_free(struct dvb_table_eit *table); |
| 201 |
|
| 202 |
/** |
| 203 |
* @brief Prints the content of the DVB EIT table |
| 204 |
* @ingroup dvb_table |
| 205 |
* |
| 206 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 207 |
* @param table pointer to struct dvb_table_eit |
| 208 |
*/ |
| 209 |
void dvb_table_eit_print(struct dvb_v5_fe_parms *parms, |
| 210 |
struct dvb_table_eit *table); |
| 211 |
|
| 212 |
/** |
| 213 |
* @brief Converts a DVB EIT formatted timestamp into struct tm |
| 214 |
* @ingroup dvb_table |
| 215 |
* |
| 216 |
* @param data event on DVB EIT time format |
| 217 |
* @param tm pointer to struct tm where the converted timestamp will |
| 218 |
* be stored. |
| 219 |
*/ |
| 220 |
void dvb_time(const uint8_t data[5], struct tm *tm); |
| 221 |
|
| 222 |
#ifdef __cplusplus |
| 223 |
} |
| 224 |
#endif |
| 225 |
|
| 226 |
#endif |