1 /*****************************************************************************
2  * nit.h
3  * Copyright (C) 2001-2011 VideoLAN
4  * $Id$
5  *
6  * Authors: Johann Hanne
7  *          heavily based on pmt.c which was written by
8  *          Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
9  *          Jean-Paul Saman <jpsaman@videolan.org>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24  *
25  *****************************************************************************/
26 
27 /*!
28  * \file <nit.h>
29  * \author Johann Hanne
30  * \brief Application interface for the NIT decoder and the NIT generator.
31  *
32  * Application interface for the NIT decoder and the NIT generator.
33  * New decoded NIT tables are sent by callback to the application.
34  */
35 
36 #ifndef _DVBPSI_NIT_H_
37 #define _DVBPSI_NIT_H_
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /*****************************************************************************
44  * dvbpsi_nit_ts_t
45  *****************************************************************************/
46 /*!
47  * \struct dvbpsi_nit_ts_s
48  * \brief NIT TS structure.
49  *
50  * This structure is used to store a decoded TS description.
51  * (ETSI EN 300 468 section 5.2.1).
52  */
53 /*!
54  * \typedef struct dvbpsi_nit_ts_s dvbpsi_nit_ts_t
55  * \brief dvbpsi_nit_ts_t type definition.
56  */
57 typedef struct dvbpsi_nit_ts_s
58 {
59   uint16_t                      i_ts_id;                /*!< transport stream id */
60   uint16_t                      i_orig_network_id;      /*!< original network id */
61 
62   dvbpsi_descriptor_t *         p_first_descriptor;     /*!< descriptor list */
63 
64   struct dvbpsi_nit_ts_s *      p_next;                 /*!< next element of
65                                                              the list */
66 
67 } dvbpsi_nit_ts_t;
68 
69 /*****************************************************************************
70  * dvbpsi_nit_t
71  *****************************************************************************/
72 /*!
73  * \struct dvbpsi_nit_s
74  * \brief NIT structure.
75  *
76  * This structure is used to store a decoded NIT.
77  * (ETSI EN 300 468 section 5.2.1).
78  */
79 /*!
80  * \typedef struct dvbpsi_nit_s dvbpsi_nit_t
81  * \brief dvbpsi_nit_t type definition.
82  */
83 typedef struct dvbpsi_nit_s
84 {
85     uint8_t              i_table_id;        /*!< table id */
86     uint16_t             i_extension;       /*!< subtable id */
87 
88     uint16_t             i_network_id;       /*!< network_id */
89     uint8_t              i_version;          /*!< version_number */
90     bool                 b_current_next;     /*!< current_next_indicator */
91 
92     dvbpsi_descriptor_t *p_first_descriptor; /*!< descriptor list */
93 
94     dvbpsi_nit_ts_t *    p_first_ts;         /*!< TS list */
95 
96 } dvbpsi_nit_t;
97 
98 /*****************************************************************************
99  * dvbpsi_nit_callback
100  *****************************************************************************/
101 /*!
102  * \typedef void (* dvbpsi_nit_callback)(void* p_cb_data,
103                                          dvbpsi_nit_t* p_new_nit)
104  * \brief Callback type definition.
105  */
106 typedef void (* dvbpsi_nit_callback)(void* p_cb_data, dvbpsi_nit_t* p_new_nit);
107 
108 /*****************************************************************************
109  * dvbpsi_nit_attach
110  *****************************************************************************/
111 /*!
112  * \fn bool dvbpsi_nit_attach(dvbpsi_t* p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
113                               dvbpsi_nit_callback pf_callback, void* p_cb_data)
114  * \brief Creation and initialization of a NIT decoder. It is attached to p_dvbpsi.
115  * \param p_dvbpsi dvbpsi handle to Subtable demultiplexor to which the decoder is attached.
116  * \param i_table_id Table ID, 0x40 (actual) or 0x41 (other).
117  * \param i_extension Table ID extension, here network ID.
118  * \param pf_callback function to call back on new NIT.
119  * \param p_cb_data private data given in argument to the callback.
120  * \return true on success, false on failure
121  */
122 bool dvbpsi_nit_attach(dvbpsi_t* p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
123                        dvbpsi_nit_callback pf_callback, void* p_cb_data);
124 
125 /*****************************************************************************
126  * dvbpsi_nit_detach
127  *****************************************************************************/
128 /*!
129  * \fn void dvbpsi_nit_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
130                              uint16_t i_extension)
131  * \brief Destroy a NIT decoder.
132  * \param p_dvbpsi dvbpsi handle to Subtable demultiplexor to which the decoder is attached.
133  * \param i_table_id Table ID, 0x40 (actual) or 0x41 (other).
134  * \param i_extension Table ID extension, here network ID.
135  * \return nothing.
136  */
137 void dvbpsi_nit_detach(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
138                       uint16_t i_extension);
139 
140 /*****************************************************************************
141  * dvbpsi_nit_init/dvbpsi_nit_new
142  *****************************************************************************/
143 /*!
144  * \fn void dvbpsi_nit_init(dvbpsi_nit_t* p_nit, uint8_t i_table_id, uint16_t i_extension,
145                             uint16_t i_network_id, uint8_t i_version, bool b_current_next)
146  * \brief Initialize a user-allocated dvbpsi_nit_t structure.
147  * \param i_table_id Table ID, 0x40 (actual) or 0x41 (other).
148  * \param i_extension Table ID extension, here network ID.
149  * \param p_nit pointer to the NIT structure
150  * \param i_network_id network id
151  * \param i_version NIT version
152  * \param b_current_next current next indicator
153  * \return nothing.
154  */
155 void dvbpsi_nit_init(dvbpsi_nit_t* p_nit, uint8_t i_table_id, uint16_t i_extension,
156                      uint16_t i_network_id, uint8_t i_version, bool b_current_next);
157 
158 /*!
159  * \fn dvbpsi_nit_t *dvbpsi_nit_new(uint8_t i_table_id, uint16_t i_extension,
160  *                                  uint16_t i_network_id, uint8_t i_version,
161  *                                  bool b_current_next);
162  * \brief Allocate and initialize a new dvbpsi_nit_t structure.
163  * \param i_table_id Table ID, 0x40 (actual) or 0x41 (other)
164  * \param i_extension Table ID extension, here network ID.
165  * \param i_network_id network id
166  * \param i_version NIT version
167  * \param b_current_next current next indicator
168  * \return p_nit pointer to the NIT structure
169  */
170 dvbpsi_nit_t *dvbpsi_nit_new(uint8_t i_table_id, uint16_t i_extension,
171                              uint16_t i_network_id, uint8_t i_version,
172                              bool b_current_next);
173 
174 /*****************************************************************************
175  * dvbpsi_nit_empty/dvbpsi_nit_delete
176  *****************************************************************************/
177 /*!
178  * \fn void dvbpsi_nit_empty(dvbpsi_nit_t* p_nit)
179  * \brief Clean a dvbpsi_nit_t structure.
180  * \param p_nit pointer to the NIT structure
181  * \return nothing.
182  */
183 void dvbpsi_nit_empty(dvbpsi_nit_t* p_nit);
184 
185 /*!
186  * \fn dvbpsi_nit_delete(dvbpsi_nit_t *p_nit)
187  * \brief Clean and free a dvbpsi_nit_t structure.
188  * \param p_nit pointer to the NIT structure
189  * \return nothing.
190  */
191 void dvbpsi_nit_delete(dvbpsi_nit_t *p_nit);
192 
193 /*****************************************************************************
194  * dvbpsi_nit_descriptor_add
195  *****************************************************************************/
196 /*!
197  * \fn dvbpsi_descriptor_t* dvbpsi_nit_descriptor_add(dvbpsi_nit_t* p_nit,
198                                                       uint8_t i_tag,
199                                                       uint8_t i_length,
200                                                       uint8_t* p_data)
201  * \brief Add a descriptor in the NIT.
202  * \param p_nit pointer to the NIT structure
203  * \param i_tag descriptor's tag
204  * \param i_length descriptor's length
205  * \param p_data descriptor's data
206  * \return a pointer to the added descriptor.
207  */
208 dvbpsi_descriptor_t* dvbpsi_nit_descriptor_add(dvbpsi_nit_t *p_nit,
209                                                uint8_t i_tag, uint8_t i_length,
210                                                uint8_t *p_data);
211 
212 /*****************************************************************************
213  * dvbpsi_nit_ts_add
214  *****************************************************************************/
215 /*!
216  * \fn dvbpsi_nit_ts_t* dvbpsi_nit_ts_add(dvbpsi_nit_t* p_nit,
217                                   uint16_t i_ts_id, uint16_t i_orig_network_id)
218  * \brief Add an TS in the NIT.
219  * \param p_nit pointer to the NIT structure
220  * \param i_ts_id type of TS
221  * \param i_orig_network_id PID of the TS
222  * \return a pointer to the added TS.
223  */
224 dvbpsi_nit_ts_t* dvbpsi_nit_ts_add(dvbpsi_nit_t* p_nit,
225                                  uint16_t i_ts_id, uint16_t i_orig_network_id);
226 
227 /*****************************************************************************
228  * dvbpsi_nit_ts_descriptor_add
229  *****************************************************************************/
230 /*!
231  * \fn dvbpsi_descriptor_t* dvbpsi_nit_ts_descriptor_add(dvbpsi_nit_ts_t* p_ts,
232                                                          uint8_t i_tag,
233                                                          uint8_t i_length,
234                                                          uint8_t* p_data)
235  * \brief Add a descriptor in the NIT TS.
236  * \param p_ts pointer to the TS structure
237  * \param i_tag descriptor's tag
238  * \param i_length descriptor's length
239  * \param p_data descriptor's data
240  * \return a pointer to the added descriptor.
241  */
242 dvbpsi_descriptor_t* dvbpsi_nit_ts_descriptor_add(dvbpsi_nit_ts_t* p_ts,
243                                                   uint8_t i_tag, uint8_t i_length,
244                                                   uint8_t* p_data);
245 
246 /*****************************************************************************
247  * dvbpsi_nit_sections_generate
248  *****************************************************************************/
249 /*!
250  * \fn dvbpsi_psi_section_t* dvbpsi_nit_sections_generate(dvbpsi_t *p_dvbpsi, dvbpsi_nit_t* p_nit,
251                                                    uint8_t i_table_id)
252  * \brief NIT generator
253  * \param p_dvbpsi handle to dvbpsi with attached decoder
254  * \param p_nit NIT structure
255  * \param i_table_id table id, 0x40 = actual network / 0x41 = other network
256  * \return a pointer to the list of generated PSI sections.
257  *
258  * Generate NIT sections based on the dvbpsi_nit_t structure.
259  */
260 dvbpsi_psi_section_t* dvbpsi_nit_sections_generate(dvbpsi_t* p_dvbpsi, dvbpsi_nit_t* p_nit,
261                                             uint8_t i_table_id);
262 
263 #ifdef __cplusplus
264 };
265 #endif
266 
267 #else
268 #error "Multiple inclusions of nit.h"
269 #endif
270 
271