5 #include "mpeg2/ts/PMT.h"
21 if (_descriptor != NULL)
25 if (_elements != NULL)
27 for (int i = 0; i < _element_count; ++i)
29 if (_elements[i]._descriptor != NULL)
31 free(_elements[i]._descriptor);
38 bool PMT::decode_section()
41 _table_id = _section[0x00];
42 if (_table_id == TABLE_ID_PMT)
44 _section_syntax_indicator = (_section[0x01] & 0x80) >> 7;
45 _section_length = ((_section[0x01] << 8) + _section[0x02]) & 0x0FFF;
46 _program_number = (_section[0x03] << 8) + _section[0x04];
47 _version_number = (_section[0x05] & 0x3E) >> 1;
48 _current_next_indicator = _section[0x05] & 0x01;
49 _section_number = _section[0x06];
50 _last_section_number = _section[0x07];
51 _PCR_PID = ((_section[0x08] << 8) + _section[0x09]) & 0x1FFF;
52 _program_info_length = ((_section[0x0a] << 8) + _section[0x0b]) & 0x0FFF;
53 if (_descriptor != NULL)
57 _descriptor = (uint8_t *)malloc(_program_info_length);
58 memcpy(_descriptor, &_section[0x0c], _program_info_length);
60 if (_elements != NULL)
62 for (int i = 0; i < _element_count; ++i)
64 if (_elements[i]._descriptor != NULL)
66 free(_elements[i]._descriptor);
73 uint16_t offset = 0x0c + _program_info_length;
76 while (offset < (_length - 4))
78 if (_elements == NULL)
80 _elements = (struct _element *)malloc(sizeof(struct _element));
84 _elements = (struct _element *)realloc(_elements, sizeof(struct _element) * (_element_count + 1));
86 _elements[_element_count]._stream_type = _section[offset];
87 _elements[_element_count]._elementary_PID = ((_section[offset + 1] << 8) + _section[offset + 2]) & 0x1FFF;
88 _elements[_element_count]._ES_info_length = ((_section[offset + 3] << 8) + _section[offset + 4]) & 0x0FFF;
89 _elements[_element_count]._descriptor = (uint8_t *)malloc(_elements[_element_count]._ES_info_length);
90 memcpy(_elements[_element_count]._descriptor, &_section[offset + 5], _elements[_element_count]._ES_info_length);
91 offset += (5 + _elements[_element_count]._ES_info_length);
106 _section_syntax_indicator = 0;
110 _current_next_indicator = 0;
112 _last_section_number = 0;
114 _program_info_length = 0;
115 if (_descriptor != NULL)
120 if (_elements != NULL)
122 for (int i = 0; i < _element_count; ++i)
124 if (_elements[i]._descriptor != NULL)
126 free(_elements[i]._descriptor);