aboutsummaryrefslogtreecommitdiffstats
path: root/src/tables/atsc_mgt.c
blob: 35372746cdc047a2724265d4384919ecedf14c5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
/*
Copyright (C) 2006  Adam Charrett
Copyright (C) 2011-2012  Michael Krufky

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

mgt.c

Decode PSIP Master Guide Table.

*/
#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

#if defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#elif defined(HAVE_STDINT_H)
#include <stdint.h>
#endif

#include <assert.h>

#include "../dvbpsi.h"
#include "../dvbpsi_private.h"
#include "../psi.h"
#include "../descriptor.h"
#include "../demux.h"

#include "atsc_mgt.h"

typedef struct dvbpsi_atsc_mgt_decoder_s
{
    DVBPSI_DECODER_COMMON

    dvbpsi_atsc_mgt_callback      pf_mgt_callback;
    void *                        p_cb_data;

    dvbpsi_atsc_mgt_t             current_mgt;
    dvbpsi_atsc_mgt_t *           p_building_mgt;

} dvbpsi_atsc_mgt_decoder_t;

static dvbpsi_descriptor_t *dvbpsi_atsc_MGTAddDescriptor(
                                               dvbpsi_atsc_mgt_t *p_mgt,
                                               uint8_t i_tag, uint8_t i_length,
                                               uint8_t *p_data);

static dvbpsi_atsc_mgt_table_t *dvbpsi_atsc_MGTAddTable(dvbpsi_atsc_mgt_t* p_mgt,
						 uint16_t i_table_type,
						 uint16_t i_table_type_pid,
						 uint8_t  i_table_type_version,
						 uint32_t i_number_bytes);

static dvbpsi_descriptor_t *dvbpsi_atsc_MGTTableAddDescriptor(
                                               dvbpsi_atsc_mgt_table_t *p_table,
                                               uint8_t i_tag, uint8_t i_length,
                                               uint8_t *p_data);

static void dvbpsi_atsc_GatherMGTSections(dvbpsi_t * p_dvbpsi,
                                          dvbpsi_decoder_t *p_decoder,
                                          dvbpsi_psi_section_t * p_section);

static void dvbpsi_atsc_DecodeMGTSections(dvbpsi_atsc_mgt_t* p_mgt,
                              dvbpsi_psi_section_t* p_section);

/*****************************************************************************
 * dvbpsi_atsc_AttachMGT
 *****************************************************************************
 * Initialize a MGT subtable decoder.
 *****************************************************************************/
bool dvbpsi_atsc_AttachMGT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
                           dvbpsi_atsc_mgt_callback pf_callback, void* p_cb_data)
{
    assert(p_dvbpsi);
    assert(p_dvbpsi->p_decoder);

    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;

    if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
    {
        dvbpsi_error(p_dvbpsi, "ATSC MGT decoder",
                     "Already a decoder for (table_id == 0x%02x extension == 0x%04x)",
                     i_table_id, i_extension);
        return false;
    }

    dvbpsi_atsc_mgt_decoder_t*  p_mgt_decoder;
    p_mgt_decoder = (dvbpsi_atsc_mgt_decoder_t*) dvbpsi_decoder_new(NULL,
                                                  0, true, sizeof(dvbpsi_atsc_mgt_decoder_t));
    if(p_mgt_decoder == NULL)
        return false;

    dvbpsi_demux_subdec_t* p_subdec;
    p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_atsc_DetachMGT,
                                         dvbpsi_atsc_GatherMGTSections, DVBPSI_DECODER(p_mgt_decoder));
    if (p_subdec == NULL)
    {
        dvbpsi_decoder_delete(DVBPSI_DECODER(p_mgt_decoder));
        return false;
    }

    /* Attach the subtable decoder to the demux */
    dvbpsi_AttachDemuxSubDecoder(p_demux, p_subdec);

    /* MGT decoder information */
    p_mgt_decoder->pf_mgt_callback = pf_callback;
    p_mgt_decoder->p_cb_data = p_cb_data;
    p_mgt_decoder->p_building_mgt = NULL;

    return true;
}

/*****************************************************************************
 * dvbpsi_atsc_DetachMGT
 *****************************************************************************
 * Close a MGT decoder.
 *****************************************************************************/
void dvbpsi_atsc_DetachMGT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
{
    assert(p_dvbpsi);
    assert(p_dvbpsi->p_decoder);

    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;

    dvbpsi_demux_subdec_t* p_subdec;
    p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
    if (p_subdec == NULL)
    {
        dvbpsi_error(p_dvbpsi, "ATSC MGT Decoder",
                         "No such MGT decoder (table_id == 0x%02x,"
                         "extension == 0x%04x)",
                         i_table_id, i_extension);
        return;
    }

    dvbpsi_atsc_mgt_decoder_t* p_mgt_decoder;
    p_mgt_decoder = (dvbpsi_atsc_mgt_decoder_t*)p_subdec->p_decoder;
    if (!p_mgt_decoder)
        return;

    if (p_mgt_decoder->p_building_mgt)
        dvbpsi_atsc_DeleteMGT(p_mgt_decoder->p_building_mgt);
    p_mgt_decoder->p_building_mgt = NULL;

    dvbpsi_DetachDemuxSubDecoder(p_demux, p_subdec);
    dvbpsi_DeleteDemuxSubDecoder(p_subdec);
}

/*****************************************************************************
 * dvbpsi_atsc_InitMGT
 *****************************************************************************
 * Initialize a pre-allocated dvbpsi_atsc_mgt_t structure.
 *****************************************************************************/
void dvbpsi_atsc_InitMGT(dvbpsi_atsc_mgt_t* p_mgt, uint8_t i_table_id, uint16_t i_extension,
                         uint8_t i_version, uint8_t i_protocol, bool b_current_next)
{
    assert(p_mgt);

    p_mgt->i_table_id = i_table_id;
    p_mgt->i_extension = i_extension;

    p_mgt->i_version = i_version;
    p_mgt->b_current_next = b_current_next;
    p_mgt->i_protocol = i_protocol;
    p_mgt->p_first_table = NULL;
    p_mgt->p_first_descriptor = NULL;
}

dvbpsi_atsc_mgt_t *dvbpsi_atsc_NewMGT(uint8_t i_table_id, uint16_t i_extension,
                                      uint8_t i_version, uint8_t i_protocol, bool b_current_next)
{
    dvbpsi_atsc_mgt_t* p_mgt;
    p_mgt = (dvbpsi_atsc_mgt_t*)calloc(1, sizeof(dvbpsi_atsc_mgt_t));
    if (p_mgt != NULL)
        dvbpsi_atsc_InitMGT(p_mgt, i_table_id, i_extension, i_version, i_protocol, b_current_next);
    return p_mgt;
}

/*****************************************************************************
 * dvbpsi_atsc_EmptyMGT
 *****************************************************************************
 * Clean a dvbpsi_atsc_mgt_t structure.
 *****************************************************************************/
void dvbpsi_atsc_EmptyMGT(dvbpsi_atsc_mgt_t* p_mgt)
{
  dvbpsi_atsc_mgt_table_t* p_table = p_mgt->p_first_table;

  while(p_table != NULL)
  {
    dvbpsi_atsc_mgt_table_t* p_tmp = p_table->p_next;
    dvbpsi_DeleteDescriptors(p_table->p_first_descriptor);
    free(p_table);
    p_table = p_tmp;
  }
  dvbpsi_DeleteDescriptors(p_mgt->p_first_descriptor);
  p_mgt->p_first_table = NULL;
  p_mgt->p_first_descriptor = NULL;
}

void dvbpsi_atsc_DeleteMGT(dvbpsi_atsc_mgt_t *p_mgt)
{
    if (p_mgt)
        dvbpsi_atsc_EmptyMGT(p_mgt);
    free(p_mgt);
    p_mgt = NULL;
}

/*****************************************************************************
 * dvbpsi_atsc_MGTAddDescriptor
 *****************************************************************************
 * Add a descriptor to the MGT table.
 *****************************************************************************/
static dvbpsi_descriptor_t *dvbpsi_atsc_MGTAddDescriptor(
                                               dvbpsi_atsc_mgt_t *p_mgt,
                                               uint8_t i_tag, uint8_t i_length,
                                               uint8_t *p_data)
{
    dvbpsi_descriptor_t * p_descriptor
                        = dvbpsi_NewDescriptor(i_tag, i_length, p_data);
    if (p_descriptor == NULL)
        return NULL;

    p_mgt->p_first_descriptor = dvbpsi_AddDescriptor(p_mgt->p_first_descriptor,
                                                     p_descriptor);
    assert(p_mgt->p_first_descriptor);
    if (p_mgt->p_first_descriptor == NULL)
        return NULL;

    return p_descriptor;
}

/*****************************************************************************
 * dvbpsi_atsc_MGTAddTable
 *****************************************************************************
 * Add a Table description at the end of the MGT.
 *****************************************************************************/
static dvbpsi_atsc_mgt_table_t *dvbpsi_atsc_MGTAddTable(dvbpsi_atsc_mgt_t* p_mgt,
						 uint16_t i_table_type,
						 uint16_t i_table_type_pid,
						 uint8_t  i_table_type_version,
						 uint32_t i_number_bytes)
{
  dvbpsi_atsc_mgt_table_t * p_table
                = (dvbpsi_atsc_mgt_table_t*)malloc(sizeof(dvbpsi_atsc_mgt_table_t));
  if(p_table)
  {
    p_table->i_table_type = i_table_type;
    p_table->i_table_type_pid = i_table_type_pid;
    p_table->i_table_type_version = i_table_type_version;
    p_table->i_number_bytes = i_number_bytes;

    p_table->p_first_descriptor = NULL;
    p_table->p_next = NULL;

    if(p_mgt->p_first_table== NULL)
    {
      p_mgt->p_first_table = p_table;
    }
    else
    {
      dvbpsi_atsc_mgt_table_t * p_last_table = p_mgt->p_first_table;
      while(p_last_table->p_next != NULL)
        p_last_table = p_last_table->p_next;
      p_last_table->p_next = p_table;
    }
  }

  return p_table;
}

/*****************************************************************************
 * dvbpsi_MGTTableAddDescriptor
 *****************************************************************************
 * Add a descriptor in the MGT table description.
 *****************************************************************************/
static dvbpsi_descriptor_t *dvbpsi_atsc_MGTTableAddDescriptor(
                                               dvbpsi_atsc_mgt_table_t *p_table,
                                               uint8_t i_tag, uint8_t i_length,
                                               uint8_t *p_data)
{
  dvbpsi_descriptor_t * p_descriptor
                        = dvbpsi_NewDescriptor(i_tag, i_length, p_data);
  if(p_descriptor)
  {
    if(p_table->p_first_descriptor == NULL)
    {
      p_table->p_first_descriptor = p_descriptor;
    }
    else
    {
      dvbpsi_descriptor_t * p_last_descriptor = p_table->p_first_descriptor;
      while(p_last_descriptor->p_next != NULL)
        p_last_descriptor = p_last_descriptor->p_next;
      p_last_descriptor->p_next = p_descriptor;
    }
  }

  return p_descriptor;
}

/*****************************************************************************
 * dvbpsi_ReInitMGT                                                          *
 *****************************************************************************/
static void dvbpsi_ReInitMGT(dvbpsi_atsc_mgt_decoder_t *p_decoder, const bool b_force)
{
    assert(p_decoder);

    dvbpsi_decoder_reset(DVBPSI_DECODER(p_decoder), b_force);

    /* Force redecoding */
    if (b_force)
    {
        /* Free structures */
        if (p_decoder->p_building_mgt)
            dvbpsi_atsc_DeleteMGT(p_decoder->p_building_mgt);
    }
    p_decoder->p_building_mgt = NULL;
}

static bool dvbpsi_CheckMGT(dvbpsi_t *p_dvbpsi, dvbpsi_atsc_mgt_decoder_t *p_decoder,
                            dvbpsi_psi_section_t *p_section)
{
    bool b_reinit = false;

    assert(p_dvbpsi);
    assert(p_decoder);

    if (p_decoder->p_building_mgt->i_table_id_ext != p_section->i_extension)
    {
        /* transport_stream_id */
        dvbpsi_error(p_dvbpsi, "ATSC MGT decoder",
                     "'transport_stream_id' differs"
                     " whereas no TS discontinuity has occured");
        b_reinit = true;
    }
    else if (p_decoder->p_building_mgt->i_version != p_section->i_version)
    {
        /* version_number */
        dvbpsi_error(p_dvbpsi, "ATSC MGT decoder",
                     "'version_number' differs"
                     " whereas no discontinuity has occured");
        b_reinit = true;
    }
    else if (p_decoder->i_last_section_number != p_section->i_last_number)
    {
        /* last_section_number */
        dvbpsi_error(p_dvbpsi, "ATSC MGT decoder",
                     "'last_section_number' differs"
                     " whereas no discontinuity has occured");
        b_reinit = true;
    }

    return b_reinit;
}

static bool dvbpsi_AddSectionMGT(dvbpsi_t *p_dvbpsi, dvbpsi_atsc_mgt_decoder_t *p_decoder,
                                 dvbpsi_psi_section_t* p_section)
{
    assert(p_dvbpsi);
    assert(p_decoder);
    assert(p_section);

    /* Initialize the structures if it's the first section received */
    if (!p_decoder->p_building_mgt)
    {
        p_decoder->p_building_mgt = dvbpsi_atsc_NewMGT(p_section->i_table_id,
                                                       p_section->i_extension,
                                                       p_section->i_version,
                                                       p_section->p_payload_start[0],
                                                       p_section->b_current_next);
        if (!p_decoder->p_building_mgt)
            return false;

        p_decoder->i_last_section_number = p_section->i_last_number;
    }

    /* Add to linked list of sections */
    if (dvbpsi_decoder_psi_section_add(DVBPSI_DECODER(p_decoder), p_section))
        dvbpsi_debug(p_dvbpsi, "ATSC MGT decoder", "overwrite section number %d",
                     p_section->i_number);
    return true;
}

/*****************************************************************************
 * dvbpsi_atsc_GatherMGTSections
 *****************************************************************************
 * Callback for the subtable demultiplexor.
 *****************************************************************************/
static void dvbpsi_atsc_GatherMGTSections(dvbpsi_t * p_dvbpsi,
                              dvbpsi_decoder_t *p_decoder,
                              dvbpsi_psi_section_t * p_section)
{
    assert(p_dvbpsi);
    assert(p_dvbpsi->p_decoder);

    if (!dvbpsi_CheckPSISection(p_dvbpsi, p_section, 0xC7, "ATSC MGT decoder"))
    {
        dvbpsi_DeletePSISections(p_section);
        return;
    }

    /* We have a valid MGT section */
    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
    dvbpsi_atsc_mgt_decoder_t * p_mgt_decoder = (dvbpsi_atsc_mgt_decoder_t*)p_decoder;
    if (!p_mgt_decoder)
    {
        dvbpsi_error(p_dvbpsi, "ATSC MGT decoder", "No decoder specified");
        dvbpsi_DeletePSISections(p_section);
        return;
    }

    /* TS discontinuity check */
    if (p_demux->b_discontinuity)
    {
        dvbpsi_ReInitMGT(p_mgt_decoder, true);
        p_mgt_decoder->b_discontinuity = false;
        p_demux->b_discontinuity = false;
    }
    else
    {
        /* Perform a few sanity checks */
        if (p_mgt_decoder->p_building_mgt)
        {
            if (dvbpsi_CheckMGT(p_dvbpsi, p_mgt_decoder, p_section))
                dvbpsi_ReInitMGT(p_mgt_decoder, true);
        }
        else
        {
            if (   (p_mgt_decoder->b_current_valid)
                && (p_mgt_decoder->current_mgt.i_version == p_section->i_version)
                && (p_mgt_decoder->current_mgt.b_current_next ==
                                               p_section->b_current_next))
            {
                /* Don't decode since this version is already decoded */
                dvbpsi_debug(p_dvbpsi, "ATSC MGT decoder",
                             "ignoring already decoded section %d",
                             p_section->i_number);
                dvbpsi_DeletePSISections(p_section);
                return;
            }
#if 0 /* Do we need to signal b_current_next here? or later */
            if ((p_mgt_decoder->b_current_valid) &&
                (p_mgt_decoder->current_mgt.i_version == p_section->i_version))
            {
                /* Signal a new MGT if the previous one wasn't active */
                if ((!p_mgt_decoder->current_mgt.b_current_next) &&
                     (p_section->b_current_next))
                {
                    dvbpsi_atsc_mgt_t * p_mgt = (dvbpsi_atsc_mgt_t*)malloc(sizeof(dvbpsi_atsc_mgt_t));
                    if (p_mgt)
                    {
                        p_mgt_decoder->current_mgt.b_current_next = true;
                        *p_mgt = p_mgt_decoder->current_mgt;
                        p_mgt_decoder->pf_mgt_callback(p_mgt_decoder->p_cb_data, p_mgt);
                    }
                    else
                        dvbpsi_error(p_dvbpsi, "ATSC MGT decoder", "Could not signal new ATSC MGT.");
                }
            }
            dvbpsi_DeletePSISections(p_section);
            return;
#endif
        }
    }

    /* Add section to MGT */
    if (!dvbpsi_AddSectionMGT(p_dvbpsi, p_mgt_decoder, p_section))
    {
        dvbpsi_error(p_dvbpsi, "ATSC MGT decoder", "failed decoding section %d",
                     p_section->i_number);
        dvbpsi_DeletePSISections(p_section);
        return;
    }

    /* Check if we have all the sections */
    if (dvbpsi_decoder_psi_sections_completed(DVBPSI_DECODER(p_mgt_decoder)))
    {
        assert(p_mgt_decoder->pf_mgt_callback);

        /* Save the current information */
        p_mgt_decoder->current_mgt = *p_mgt_decoder->p_building_mgt;
        p_mgt_decoder->b_current_valid = true;
        /* Decode the sections */
        dvbpsi_atsc_DecodeMGTSections(p_mgt_decoder->p_building_mgt,
                                      p_mgt_decoder->p_sections);
        /* signal the new MGT */
        p_mgt_decoder->pf_mgt_callback(p_mgt_decoder->p_cb_data,
                                       p_mgt_decoder->p_building_mgt);
        /* Delete sections and Reinitialize the structures */
        dvbpsi_ReInitMGT(p_mgt_decoder, false);
        assert(p_mgt_decoder->p_sections == NULL);
    }
}

/*****************************************************************************
 * dvbpsi_DecodeMGTSection
 *****************************************************************************
 * MGT decoder.
 *****************************************************************************/
static void dvbpsi_atsc_DecodeMGTSections(dvbpsi_atsc_mgt_t* p_mgt,
                                          dvbpsi_psi_section_t* p_section)
{
  uint8_t *p_byte, *p_end;

  while(p_section)
  {
    uint16_t i_tables_defined = (p_section->p_payload_start[1] << 8) |
                                (p_section->p_payload_start[2]);
    uint16_t i_tables_count = 0;
    uint16_t i_length = 0;

    for(p_byte = p_section->p_payload_start + 3;
        ((p_byte + 6) < p_section->p_payload_end) && (i_tables_count < i_tables_defined);
        i_tables_count ++)
    {
	dvbpsi_atsc_mgt_table_t* p_table;
	uint16_t i_table_type         = ((uint16_t)(p_byte[0]) << 8) |
	                                ((uint16_t)(p_byte[1]));
	uint16_t i_table_type_pid     = ((uint16_t)(p_byte[2] & 0x1f) << 8) |
	                                ((uint16_t)(p_byte[3] & 0xff));
	uint8_t  i_table_type_version = ((uint8_t) (p_byte[4] & 0x1f));
	uint32_t i_number_bytes       = ((uint32_t)(p_byte[5] << 24)) |
                                        ((uint32_t)(p_byte[6] << 16)) |
                                        ((uint32_t)(p_byte[7] <<  8)) |
                                        ((uint32_t)(p_byte[8]));
        i_length = ((uint16_t)(p_byte[9] & 0xf) <<8) | p_byte[10];

        p_table = dvbpsi_atsc_MGTAddTable(p_mgt,
					  i_table_type,
					  i_table_type_pid,
					  i_table_type_version,
					  i_number_bytes);

        /* Table descriptors */
        p_byte += 11;
        p_end = p_byte + i_length;
        if( p_end > p_section->p_payload_end ) break;

        while(p_byte + 2 <= p_end)
        {
            uint8_t i_tag = p_byte[0];
            uint8_t i_len = p_byte[1];
            if(i_len + 2 <= p_end - p_byte)
              dvbpsi_atsc_MGTTableAddDescriptor(p_table, i_tag, i_len, p_byte + 2);
            p_byte += 2 + i_len;
        }
    }

    /* Table descriptors */
    i_length = ((uint16_t)(p_byte[0] & 0xf) <<8) | p_byte[1];
    p_byte += 2;
    p_end = p_byte + i_length;

    while(p_byte + 2 <= p_end)
    {
        uint8_t i_tag = p_byte[0];
        uint8_t i_len = p_byte[1];
        if(i_length + 2 <= p_end - p_byte)
          dvbpsi_atsc_MGTAddDescriptor(p_mgt, i_tag, i_len, p_byte + 2);
        p_byte += 2 + i_len;
    }
    p_section = p_section->p_next;
  }
}

Privacy Policy