| 1 |
/* |
| 2 |
* Copyright (c) 2013 - Andre Roth <[email protected]> |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU Lesser General Public License as published by |
| 6 |
* the Free Software Foundation version 2.1 of the License. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program; if not, write to the Free Software |
| 15 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 |
* Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| 17 |
* |
| 18 |
*/ |
| 19 |
|
| 20 |
/** |
| 21 |
* @file atsc_eit.h |
| 22 |
* @ingroup dvb_table |
| 23 |
* @brief Provides the table parser for the ATSC EIT (Event Information Table) |
| 24 |
* @copyright GNU Lesser General Public License version 2.1 (LGPLv2.1) |
| 25 |
* @author Mauro Carvalho Chehab |
| 26 |
* @author Andre Roth |
| 27 |
* |
| 28 |
* @par Relevant specs |
| 29 |
* The table described herein is defined at: |
| 30 |
* - ATSC A/65:2009 |
| 31 |
* |
| 32 |
* @see |
| 33 |
* http://www.etherguidesystems.com/help/sdos/atsc/syntax/tablesections/eitks.aspx |
| 34 |
* |
| 35 |
* @par Bug Report |
| 36 |
* Please submit bug reports and patches to [email protected] |
| 37 |
*/ |
| 38 |
|
| 39 |
#ifndef _ATSC_EIT_H |
| 40 |
#define _ATSC_EIT_H |
| 41 |
|
| 42 |
#include <stdint.h> |
| 43 |
#include <unistd.h> /* ssize_t */ |
| 44 |
#include <time.h> |
| 45 |
|
| 46 |
#include <libdvbv5/atsc_header.h> |
| 47 |
|
| 48 |
/** |
| 49 |
* @def ATSC_TABLE_EIT |
| 50 |
* @brief ATSC EIT table ID |
| 51 |
* @ingroup dvb_table |
| 52 |
*/ |
| 53 |
#define ATSC_TABLE_EIT 0xCB |
| 54 |
|
| 55 |
/** |
| 56 |
* @struct atsc_table_eit_event |
| 57 |
* @brief ATSC EIT event table |
| 58 |
* @ingroup dvb_table |
| 59 |
* |
| 60 |
* @param event_id an uniquelly (inside a service ID) event ID |
| 61 |
* @param title_length title length. Zero means no title |
| 62 |
* @param duration duration in seconds |
| 63 |
* @param etm Extended Text Message location |
| 64 |
* @param descriptor pointer to struct dvb_desc |
| 65 |
* @param next pointer to struct atsc_table_eit_event |
| 66 |
* @param start event start (in struct tm format) |
| 67 |
* @param source_id source id (obtained from ATSC header) |
| 68 |
* |
| 69 |
* This structure is used to store the original ATSC EIT event table, |
| 70 |
* converting the integer fields to the CPU endianness, and converting the |
| 71 |
* timestamps to a way that it is better handled on Linux. |
| 72 |
* |
| 73 |
* The undocumented parameters are used only internally by the API and/or |
| 74 |
* are fields that are reserved. They shouldn't be used, as they may change |
| 75 |
* on future API releases. |
| 76 |
* |
| 77 |
* Everything after atsc_table_eit_event::descriptor (including it) won't |
| 78 |
* be bit-mapped to the data parsed from the MPEG TS. So, metadata are added |
| 79 |
* there. |
| 80 |
*/ |
| 81 |
struct atsc_table_eit_event { |
| 82 |
union { |
| 83 |
uint16_t bitfield; |
| 84 |
struct { |
| 85 |
uint16_t event_id:14; |
| 86 |
uint16_t one:2; |
| 87 |
} __attribute__((packed)); |
| 88 |
} __attribute__((packed)); |
| 89 |
uint32_t start_time; |
| 90 |
union { |
| 91 |
uint32_t bitfield2; |
| 92 |
struct { |
| 93 |
uint32_t title_length:8; |
| 94 |
uint32_t duration:20; |
| 95 |
uint32_t etm:2; |
| 96 |
uint32_t one2:2; |
| 97 |
uint32_t :2; |
| 98 |
} __attribute__((packed)); |
| 99 |
} __attribute__((packed)); |
| 100 |
struct dvb_desc *descriptor; |
| 101 |
struct atsc_table_eit_event *next; |
| 102 |
struct tm start; |
| 103 |
uint16_t source_id; |
| 104 |
} __attribute__((packed)); |
| 105 |
|
| 106 |
/** |
| 107 |
* @union atsc_table_eit_desc_length |
| 108 |
* @brief ATSC EIT descriptor length |
| 109 |
* @ingroup dvb_table |
| 110 |
* |
| 111 |
* @param desc_length descriptor length |
| 112 |
* |
| 113 |
* This structure is used to store the original ATSC EIT event table, |
| 114 |
* converting the integer fields to the CPU endianness, and converting the |
| 115 |
* timestamps to a way that it is better handled on Linux. |
| 116 |
* |
| 117 |
* The undocumented parameters are used only internally by the API and/or |
| 118 |
* are fields that are reserved. They shouldn't be used, as they may change |
| 119 |
* on future API releases. |
| 120 |
*/ |
| 121 |
union atsc_table_eit_desc_length { |
| 122 |
uint16_t bitfield; |
| 123 |
struct { |
| 124 |
uint16_t desc_length:12; |
| 125 |
uint16_t reserved:4; |
| 126 |
} __attribute__((packed)); |
| 127 |
} __attribute__((packed)); |
| 128 |
|
| 129 |
/** |
| 130 |
* @struct atsc_table_eit |
| 131 |
* @brief ATSC EIT table |
| 132 |
* @ingroup dvb_table |
| 133 |
* |
| 134 |
* @param header struct dvb_table_header content |
| 135 |
* @param protocol_version protocol version |
| 136 |
* @param events events |
| 137 |
* @param event pointer to struct atsc_table_eit_event |
| 138 |
* |
| 139 |
* This structure is used to store the original ATSC EIT table, |
| 140 |
* converting the integer fields to the CPU endianness. |
| 141 |
* |
| 142 |
* Everything after atsc_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 atsc_table_eit { |
| 147 |
struct dvb_table_header header; |
| 148 |
uint8_t protocol_version; |
| 149 |
uint8_t events; |
| 150 |
struct atsc_table_eit_event *event; |
| 151 |
} __attribute__((packed)); |
| 152 |
|
| 153 |
/** |
| 154 |
* @brief Macro used to find event on an ATSC EIT table |
| 155 |
* @ingroup dvb_table |
| 156 |
* |
| 157 |
* @param _event event to seek |
| 158 |
* @param _eit pointer to struct atsc_table_eit_event |
| 159 |
*/ |
| 160 |
#define atsc_eit_event_foreach(_event, _eit) \ |
| 161 |
if (_eit && _eit->event) \ |
| 162 |
for( struct atsc_table_eit_event *_event = _eit->event; _event; _event = _event->next ) \ |
| 163 |
|
| 164 |
struct dvb_v5_fe_parms; |
| 165 |
|
| 166 |
#ifdef __cplusplus |
| 167 |
extern "C" { |
| 168 |
#endif |
| 169 |
|
| 170 |
/** |
| 171 |
* @brief Initializes and parses ATSC EIT table |
| 172 |
* @ingroup dvb_table |
| 173 |
* |
| 174 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 175 |
* @param buf buffer containing the EIT raw data |
| 176 |
* @param buflen length of the buffer |
| 177 |
* @param table pointer to struct atsc_table_eit to be allocated and filled |
| 178 |
* |
| 179 |
* This function allocates an ATSC EIT table and fills the fields inside |
| 180 |
* the struct. It also makes sure that all fields will follow the CPU |
| 181 |
* endianness. Due to that, the content of the buffer may change. |
| 182 |
* |
| 183 |
* @return On success, it returns the size of the allocated struct. |
| 184 |
* A negative value indicates an error. |
| 185 |
*/ |
| 186 |
ssize_t atsc_table_eit_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, |
| 187 |
ssize_t buflen, struct atsc_table_eit **table); |
| 188 |
|
| 189 |
/** |
| 190 |
* @brief Frees all data allocated by the ATSC EIT table parser |
| 191 |
* @ingroup dvb_table |
| 192 |
* |
| 193 |
* @param table pointer to struct atsc_table_eit to be freed |
| 194 |
*/ |
| 195 |
void atsc_table_eit_free(struct atsc_table_eit *table); |
| 196 |
|
| 197 |
/** |
| 198 |
* @brief Prints the content of the ATSC EIT table |
| 199 |
* @ingroup dvb_table |
| 200 |
* |
| 201 |
* @param parms struct dvb_v5_fe_parms pointer to the opened device |
| 202 |
* @param table pointer to struct atsc_table_eit |
| 203 |
*/ |
| 204 |
void atsc_table_eit_print(struct dvb_v5_fe_parms *parms, |
| 205 |
struct atsc_table_eit *table); |
| 206 |
|
| 207 |
/** |
| 208 |
* @brief Converts an ATSC EIT formatted timestamp into struct tm |
| 209 |
* @ingroup ancillary |
| 210 |
* |
| 211 |
* @param start_time event on ATSC EIT time format |
| 212 |
* @param tm pointer to struct tm where the converted timestamp will |
| 213 |
* be stored. |
| 214 |
*/ |
| 215 |
void atsc_time(const uint32_t start_time, struct tm *tm); |
| 216 |
|
| 217 |
#ifdef __cplusplus |
| 218 |
} |
| 219 |
#endif |
| 220 |
|
| 221 |
#endif |