~ubuntu-branches/ubuntu/precise/me-tv/precise-proposed

« back to all changes in this revision

Viewing changes to src/libucsi/mpeg/pmt_section.h

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Kern
  • Date: 2008-07-23 14:03:56 UTC
  • mfrom: (1.1.3 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080723140356-m6ze7fbkydes42c7
Tags: 0.5.33-3
Fix xine-lib ffmpeg dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * section and descriptor parser
3
 
 *
4
 
 * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
5
 
 * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
6
 
 *
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.
11
 
 *
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.
16
 
 *
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
20
 
 */
21
 
 
22
 
#ifndef _UCSI_MPEG_PMT_SECTION_H
23
 
#define _UCSI_MPEG_PMT_SECTION_H 1
24
 
 
25
 
#ifdef __cplusplus
26
 
extern "C"
27
 
{
28
 
#endif
29
 
 
30
 
#include <libucsi/section.h>
31
 
 
32
 
/**
33
 
 * mpeg_pmt_section structure.
34
 
 */
35
 
struct mpeg_pmt_section {
36
 
        struct section_ext head;
37
 
 
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[] */
44
 
} __ucsi_packed;
45
 
 
46
 
/**
47
 
 * A stream within an mpeg_pmt_section.
48
 
 */
49
 
struct mpeg_pmt_stream {
50
 
        uint8_t stream_type;
51
 
  EBIT2(uint16_t reserved_1             : 3; ,
52
 
        uint16_t pid                    :13; );
53
 
  EBIT2(uint16_t reserved_2             : 4; ,
54
 
        uint16_t es_info_length         :12; );
55
 
 
56
 
        /* struct descriptor descriptors[] */
57
 
} __ucsi_packed;
58
 
 
59
 
/**
60
 
 * Process an mpeg_pmt_section section.
61
 
 *
62
 
 * @param section Pointer to the generic section header.
63
 
 * @return Pointer to the mpeg_pmt_section structure, or NULL on error.
64
 
 */
65
 
extern struct mpeg_pmt_section *mpeg_pmt_section_codec(struct section_ext *section);
66
 
 
67
 
/**
68
 
 * Accessor for program_number field of a PMT.
69
 
 *
70
 
 * @param pmt PMT pointer.
71
 
 * @return The program_number.
72
 
 */
73
 
static inline uint16_t mpeg_pmt_section_program_number(struct mpeg_pmt_section *pmt)
74
 
{
75
 
        return pmt->head.table_id_ext;
76
 
}
77
 
 
78
 
/**
79
 
 * Convenience iterator for the descriptors field of the mpeg_pmt_section structure.
80
 
 *
81
 
 * @param pmt Pointer to the mpeg_pmt_section structure.
82
 
 * @param pos Variable holding a pointer to the current descriptor.
83
 
 */
84
 
#define mpeg_pmt_section_descriptors_for_each(pmt, pos) \
85
 
        for ((pos) = mpeg_pmt_section_descriptors_first(pmt); \
86
 
             (pos); \
87
 
             (pos) = mpeg_pmt_section_descriptors_next(pmt, pos))
88
 
 
89
 
/**
90
 
 * Convenience iterator for the streams field of the mpeg_pmt_section structure.
91
 
 *
92
 
 * @param pmt Pointer to the mpeg_pmt_section structure.
93
 
 * @param pos Variable holding a pointer to the current mpeg_pmt_stream.
94
 
 */
95
 
#define mpeg_pmt_section_streams_for_each(pmt, pos) \
96
 
        for ((pos) = mpeg_pmt_section_streams_first(pmt); \
97
 
             (pos); \
98
 
             (pos) = mpeg_pmt_section_streams_next(pmt, pos))
99
 
 
100
 
/**
101
 
 * Convenience iterator for the descriptors field of an mpeg_pmt_stream structure.
102
 
 *
103
 
 * @param stream Pointer to the mpeg_pmt_stream structure.
104
 
 * @param pos Variable holding a pointer to the current descriptor.
105
 
 */
106
 
#define mpeg_pmt_stream_descriptors_for_each(stream, pos) \
107
 
        for ((pos) = mpeg_pmt_stream_descriptors_first(stream); \
108
 
             (pos); \
109
 
             (pos) = mpeg_pmt_stream_descriptors_next(stream, pos))
110
 
 
111
 
 
112
 
 
113
 
 
114
 
 
115
 
 
116
 
 
117
 
 
118
 
 
119
 
 
120
 
/******************************** PRIVATE CODE ********************************/
121
 
static inline struct descriptor *
122
 
        mpeg_pmt_section_descriptors_first(struct mpeg_pmt_section * pmt)
123
 
{
124
 
        if (pmt->program_info_length == 0)
125
 
                return NULL;
126
 
 
127
 
        return (struct descriptor *)
128
 
                ((uint8_t *) pmt + sizeof(struct mpeg_pmt_section));
129
 
}
130
 
 
131
 
static inline struct descriptor *
132
 
        mpeg_pmt_section_descriptors_next(struct mpeg_pmt_section *pmt,
133
 
                                          struct descriptor* pos)
134
 
{
135
 
        return next_descriptor((uint8_t *) pmt + sizeof(struct mpeg_pmt_section),
136
 
                               pmt->program_info_length,
137
 
                               pos);
138
 
}
139
 
 
140
 
static inline struct mpeg_pmt_stream *
141
 
        mpeg_pmt_section_streams_first(struct mpeg_pmt_section * pmt)
142
 
{
143
 
        size_t pos = sizeof(struct mpeg_pmt_section) + pmt->program_info_length;
144
 
 
145
 
        if (pos >= section_ext_length(&pmt->head))
146
 
                return NULL;
147
 
 
148
 
        return (struct mpeg_pmt_stream *)((uint8_t *)pmt + pos);
149
 
}
150
 
 
151
 
static inline struct mpeg_pmt_stream *
152
 
        mpeg_pmt_section_streams_next(struct mpeg_pmt_section * pmt,
153
 
                                      struct mpeg_pmt_stream * pos)
154
 
{
155
 
        uint8_t *end = (uint8_t*) pmt + section_ext_length(&pmt->head);
156
 
        uint8_t *next = (uint8_t *) pos + sizeof(struct mpeg_pmt_stream) +
157
 
                        pos->es_info_length;
158
 
 
159
 
        if (next >= end)
160
 
                return NULL;
161
 
 
162
 
        return (struct mpeg_pmt_stream *) next;
163
 
}
164
 
 
165
 
static inline struct descriptor *
166
 
        mpeg_pmt_stream_descriptors_first(struct mpeg_pmt_stream *stream)
167
 
{
168
 
        if (stream->es_info_length == 0)
169
 
                return NULL;
170
 
 
171
 
        return (struct descriptor *)
172
 
                ((uint8_t*) stream + sizeof(struct mpeg_pmt_stream));
173
 
}
174
 
 
175
 
static inline struct descriptor *
176
 
        mpeg_pmt_stream_descriptors_next(struct mpeg_pmt_stream *stream,
177
 
                                         struct descriptor* pos)
178
 
{
179
 
        return next_descriptor((uint8_t *) stream + sizeof(struct mpeg_pmt_stream),
180
 
                               stream->es_info_length,
181
 
                               pos);
182
 
}
183
 
 
184
 
#ifdef __cplusplus
185
 
}
186
 
#endif
187
 
 
188
 
#endif