]> git.sesse.net Git - vlc/blob - modules/demux/mpeg/system.h
* include/vlc_common.h:
[vlc] / modules / demux / mpeg / system.h
1 /*****************************************************************************
2  * system.h: MPEG demultiplexing.
3  *****************************************************************************
4  * Copyright (C) 1999-2002 VideoLAN
5  * $Id: system.h,v 1.10 2003/10/25 00:49:14 sam Exp $
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*
25  * Optional MPEG demultiplexing
26  */
27
28 /*****************************************************************************
29  * Constants
30  *****************************************************************************/
31 #define TS_PACKET_SIZE      188                       /* Size of a TS packet */
32 #define TS_SYNC_CODE        0x47                /* First byte of a TS packet */
33 #define PSI_SECTION_SIZE    4096            /* Maximum size of a PSI section */
34
35 #define PAT_UNINITIALIZED    (1 << 6)
36 #define PMT_UNINITIALIZED    (1 << 6)
37
38 #define PSI_IS_PAT          0x00
39 #define PSI_IS_PMT          0x01
40 #define UNKNOWN_PSI         0xff
41
42 /* ES streams types - see ISO/IEC 13818-1 table 2-29 numbers.
43  * these values are used in mpeg_system.c, and in
44  * the following plugins: mpeg_ts, mpeg_ts_dvbpsi, satellite. */
45 #define MPEG1_VIDEO_ES      0x01
46 #define MPEG2_VIDEO_ES      0x02
47 #define MPEG1_AUDIO_ES      0x03
48 #define MPEG2_AUDIO_ES      0x04
49 /* This one is "private PES". It may carry teletext, DVD subtitles, A52
50  * We have to check for the presence of a descriptor to have the codec */
51 #define PES_PRIVATE_ES      0x06
52
53 #define MPEG4_VIDEO_ES      0x10
54 #define MPEG4_AUDIO_ES      0x11
55
56 #define MPEG2_MOTO_VIDEO_ES 0x80
57 #define A52_AUDIO_ES        0x81
58 /* These ones might violate the usage : */
59 #define DVD_SPU_ES          0x82
60 #define LPCM_AUDIO_ES       0x83
61 #define SDDS_AUDIO_ES       0x84
62 #define DTS_AUDIO_ES        0x85
63 /* These ones are only here to work around a bug in VLS - VLS doesn't
64  * skip the first bytes of the PES payload (stream private ID) when
65  * streaming. This is incompatible with all equipments. 'B' is for
66  * buggy. Please note that they are associated with FOURCCs '***b'.
67  * --Meuuh 2002-08-30
68  */
69 #define A52B_AUDIO_ES       0x91
70 #define DVDB_SPU_ES         0x92
71 #define LPCMB_AUDIO_ES      0x93
72
73 #define MSCODEC_VIDEO_ES    0xa0
74
75 /****************************************************************************
76  * psi_callback_t
77  ****************************************************************************
78  * Used by TS demux to handle a PSI, either with the builtin decoder, either
79  * with a library such as libdvbpsi
80  ****************************************************************************/
81 typedef void( * psi_callback_t )(
82         input_thread_t  * p_input,
83         data_packet_t   * p_data,
84         es_descriptor_t * p_es,
85         vlc_bool_t        b_unit_start );
86
87
88 /****************************************************************************
89  * mpeg_demux_t
90  ****************************************************************************
91  * Demux callbacks exported by the helper plugin
92  ****************************************************************************/
93 typedef struct mpeg_demux_t
94 {
95     module_t * p_module;
96
97     ssize_t           (*pf_read_ps)  ( input_thread_t *, data_packet_t ** );
98     es_descriptor_t * (*pf_parse_ps) ( input_thread_t *, data_packet_t * );
99     void              (*pf_demux_ps) ( input_thread_t *, data_packet_t * );
100
101     ssize_t           (*pf_read_ts)  ( input_thread_t *, data_packet_t ** );
102     void              (*pf_demux_ts) ( input_thread_t *, data_packet_t *,
103                                        psi_callback_t );
104 } mpeg_demux_t;
105
106 /*****************************************************************************
107  * psi_section_t
108  *****************************************************************************
109  * Describes a PSI section. Beware, it doesn't contain pointers to the TS
110  * packets that contain it as for a PES, but the data themselves
111  *****************************************************************************/
112 typedef struct psi_section_t
113 {
114     byte_t                  buffer[PSI_SECTION_SIZE];
115
116     uint8_t                 i_section_number;
117     uint8_t                 i_last_section_number;
118     uint8_t                 i_version_number;
119     uint16_t                i_section_length;
120     uint16_t                i_read_in_section;
121
122     /* the PSI is complete */
123     vlc_bool_t              b_is_complete;
124
125     /* packet missed up ? */
126     vlc_bool_t              b_trash;
127
128     /*about sections  */
129     vlc_bool_t              b_section_complete;
130
131     /* where are we currently ? */
132     byte_t                * p_current;
133
134 } psi_section_t;
135
136 /*****************************************************************************
137  * decoder_descriptor_t
138  *****************************************************************************/
139 typedef struct decoder_config_descriptor_s
140 {
141     uint8_t                 i_objectTypeIndication;
142     uint8_t                 i_streamType;
143     vlc_bool_t              b_upStream;
144     uint32_t                i_bufferSizeDB;
145     uint32_t                i_maxBitrate;
146     uint32_t                i_avgBitrate;
147
148     int                     i_decoder_specific_info_len;
149     uint8_t                 *p_decoder_specific_info;
150
151 } decoder_config_descriptor_t;
152
153 /*****************************************************************************
154  * sl_descriptor_t:
155  *****************************************************************************/
156 typedef struct sl_config_descriptor_s
157 {
158     vlc_bool_t              b_useAccessUnitStartFlag;
159     vlc_bool_t              b_useAccessUnitEndFlag;
160     vlc_bool_t              b_useRandomAccessPointFlag;
161     vlc_bool_t              b_useRandomAccessUnitsOnlyFlag;
162     vlc_bool_t              b_usePaddingFlag;
163     vlc_bool_t              b_useTimeStampsFlags;
164     vlc_bool_t              b_useIdleFlag;
165     vlc_bool_t              b_durationFlag;
166     uint32_t                i_timeStampResolution;
167     uint32_t                i_OCRResolution;
168     uint8_t                 i_timeStampLength;
169     uint8_t                 i_OCRLength;
170     uint8_t                 i_AU_Length;
171     uint8_t                 i_instantBitrateLength;
172     uint8_t                 i_degradationPriorityLength;
173     uint8_t                 i_AU_seqNumLength;
174     uint8_t                 i_packetSeqNumLength;
175
176     uint32_t                i_timeScale;
177     uint16_t                i_accessUnitDuration;
178     uint16_t                i_compositionUnitDuration;
179
180     uint64_t                i_startDecodingTimeStamp;
181     uint64_t                i_startCompositionTimeStamp;
182
183 } sl_config_descriptor_t;
184
185 /*****************************************************************************
186  * es_mpeg4_descriptor_t: XXX it's not complete but should be enough
187  *****************************************************************************/
188 typedef struct es_mpeg4_descriptor_s
189 {
190     vlc_bool_t              b_ok;
191     uint16_t                i_es_id;
192
193     vlc_bool_t              b_streamDependenceFlag;
194     vlc_bool_t              b_OCRStreamFlag;
195     uint8_t                 i_streamPriority;
196
197     char                    *psz_url;
198
199     uint16_t                i_dependOn_es_id;
200     uint16_t                i_OCR_es_id;
201
202     decoder_config_descriptor_t    dec_descr;
203     sl_config_descriptor_t         sl_descr;
204 } es_mpeg4_descriptor_t;
205
206 /*****************************************************************************
207  * iod_descriptor_t: XXX it's not complete but should be enough
208  *****************************************************************************/
209 typedef struct iod_descriptor_s
210 {
211     uint8_t                i_iod_label;
212
213     /* IOD */
214     uint16_t                i_od_id;
215     char                    *psz_url;
216
217     uint8_t                 i_ODProfileLevelIndication;
218     uint8_t                 i_sceneProfileLevelIndication;
219     uint8_t                 i_audioProfileLevelIndication;
220     uint8_t                 i_visualProfileLevelIndication;
221     uint8_t                 i_graphicsProfileLevelIndication;
222
223     es_mpeg4_descriptor_t   es_descr[255];
224
225 } iod_descriptor_t;
226
227 /*****************************************************************************
228  * es_ts_data_t: extension of es_descriptor_t
229  *****************************************************************************/
230 typedef struct es_ts_data_t
231 {
232     vlc_bool_t              b_psi;   /* Does the stream have to be handled by
233                                       *                    the PSI decoder ? */
234
235     int                     i_psi_type;  /* There are different types of PSI */
236
237     psi_section_t *         p_psi_section;                    /* PSI packets */
238
239     /* Markers */
240     int                     i_continuity_counter;
241
242     /* mpeg4 in TS data specific */
243     int                     b_mpeg4;
244     uint16_t                i_es_id;
245
246     es_mpeg4_descriptor_t   *p_es_descr;   /* es_descr of IOD */
247
248 } es_ts_data_t;
249
250 /*****************************************************************************
251  * pgrm_ts_data_t: extension of pgrm_descriptor_t
252  *****************************************************************************/
253 typedef struct pgrm_ts_data_t
254 {
255     uint16_t                i_pcr_pid;             /* PCR ES, for TS streams */
256     int                     i_pmt_version;
257     /* libdvbpsi pmt decoder handle */
258     void *                  p_pmt_handle;
259
260     /* mpeg4 in TS data specific */
261     vlc_bool_t              b_mpeg4;
262     iod_descriptor_t        iod;
263
264 } pgrm_ts_data_t;
265
266 /*****************************************************************************
267  * stream_ts_data_t: extension of stream_descriptor_t
268  *****************************************************************************/
269 typedef struct stream_ts_data_t
270 {
271     int                     i_pat_version; /* Current version of the PAT */
272     vlc_bool_t              b_buggy_psi;
273     /* libdvbpsi PMT decoder handle */
274     void *                  p_pat_handle;
275 } stream_ts_data_t;
276
277 /*****************************************************************************
278  * stream_ps_data_t: extension of stream_descriptor_t
279  *****************************************************************************/
280 typedef struct stream_ps_data_t
281 {
282     vlc_bool_t              b_has_PSM;                 /* very rare, in fact */
283
284     uint8_t                 i_PSM_version;
285 } stream_ps_data_t;
286
287 /* PSM version is 5 bits, so -1 is not a valid value */
288 #define EMPTY_PSM_VERSION   -1
289