2
* section and descriptor parser
4
* Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
5
* Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
#ifndef _UCSI_MPEG_PMT_SECTION_H
23
#define _UCSI_MPEG_PMT_SECTION_H 1
30
#include <libucsi/section.h>
33
* mpeg_pmt_section structure.
35
struct mpeg_pmt_section {
36
struct section_ext head;
38
EBIT2(uint16_t reserved_1 : 3; ,
39
uint16_t pcr_pid :13; );
40
EBIT2(uint16_t reserved_2 : 4; ,
41
uint16_t program_info_length :12; );
42
/* struct descriptor descriptors[] */
43
/* struct mpeg_pmt_stream streams[] */
47
* A stream within an mpeg_pmt_section.
49
struct mpeg_pmt_stream {
51
EBIT2(uint16_t reserved_1 : 3; ,
53
EBIT2(uint16_t reserved_2 : 4; ,
54
uint16_t es_info_length :12; );
56
/* struct descriptor descriptors[] */
60
* Process an mpeg_pmt_section section.
62
* @param section Pointer to the generic section header.
63
* @return Pointer to the mpeg_pmt_section structure, or NULL on error.
65
extern struct mpeg_pmt_section *mpeg_pmt_section_codec(struct section_ext *section);
68
* Accessor for program_number field of a PMT.
70
* @param pmt PMT pointer.
71
* @return The program_number.
73
static inline uint16_t mpeg_pmt_section_program_number(struct mpeg_pmt_section *pmt)
75
return pmt->head.table_id_ext;
79
* Convenience iterator for the descriptors field of the mpeg_pmt_section structure.
81
* @param pmt Pointer to the mpeg_pmt_section structure.
82
* @param pos Variable holding a pointer to the current descriptor.
84
#define mpeg_pmt_section_descriptors_for_each(pmt, pos) \
85
for ((pos) = mpeg_pmt_section_descriptors_first(pmt); \
87
(pos) = mpeg_pmt_section_descriptors_next(pmt, pos))
90
* Convenience iterator for the streams field of the mpeg_pmt_section structure.
92
* @param pmt Pointer to the mpeg_pmt_section structure.
93
* @param pos Variable holding a pointer to the current mpeg_pmt_stream.
95
#define mpeg_pmt_section_streams_for_each(pmt, pos) \
96
for ((pos) = mpeg_pmt_section_streams_first(pmt); \
98
(pos) = mpeg_pmt_section_streams_next(pmt, pos))
101
* Convenience iterator for the descriptors field of an mpeg_pmt_stream structure.
103
* @param stream Pointer to the mpeg_pmt_stream structure.
104
* @param pos Variable holding a pointer to the current descriptor.
106
#define mpeg_pmt_stream_descriptors_for_each(stream, pos) \
107
for ((pos) = mpeg_pmt_stream_descriptors_first(stream); \
109
(pos) = mpeg_pmt_stream_descriptors_next(stream, pos))
120
/******************************** PRIVATE CODE ********************************/
121
static inline struct descriptor *
122
mpeg_pmt_section_descriptors_first(struct mpeg_pmt_section * pmt)
124
if (pmt->program_info_length == 0)
127
return (struct descriptor *)
128
((uint8_t *) pmt + sizeof(struct mpeg_pmt_section));
131
static inline struct descriptor *
132
mpeg_pmt_section_descriptors_next(struct mpeg_pmt_section *pmt,
133
struct descriptor* pos)
135
return next_descriptor((uint8_t *) pmt + sizeof(struct mpeg_pmt_section),
136
pmt->program_info_length,
140
static inline struct mpeg_pmt_stream *
141
mpeg_pmt_section_streams_first(struct mpeg_pmt_section * pmt)
143
size_t pos = sizeof(struct mpeg_pmt_section) + pmt->program_info_length;
145
if (pos >= section_ext_length(&pmt->head))
148
return (struct mpeg_pmt_stream *)((uint8_t *)pmt + pos);
151
static inline struct mpeg_pmt_stream *
152
mpeg_pmt_section_streams_next(struct mpeg_pmt_section * pmt,
153
struct mpeg_pmt_stream * pos)
155
uint8_t *end = (uint8_t*) pmt + section_ext_length(&pmt->head);
156
uint8_t *next = (uint8_t *) pos + sizeof(struct mpeg_pmt_stream) +
162
return (struct mpeg_pmt_stream *) next;
165
static inline struct descriptor *
166
mpeg_pmt_stream_descriptors_first(struct mpeg_pmt_stream *stream)
168
if (stream->es_info_length == 0)
171
return (struct descriptor *)
172
((uint8_t*) stream + sizeof(struct mpeg_pmt_stream));
175
static inline struct descriptor *
176
mpeg_pmt_stream_descriptors_next(struct mpeg_pmt_stream *stream,
177
struct descriptor* pos)
179
return next_descriptor((uint8_t *) stream + sizeof(struct mpeg_pmt_stream),
180
stream->es_info_length,