]> git.sesse.net Git - vlc/blob - modules/demux/mpeg/system.h
40a6504ce0b8f68790a89f1faae125038e19eb0b
[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.7 2003/03/18 23:59:07 massiot 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 #define A52DVB_AUDIO_ES     0x06
50
51 #define MPEG4_VIDEO_ES      0x10
52 #define MPEG4_AUDIO_ES      0x11
53
54 #define MPEG2_MOTO_VIDEO_ES 0x80
55 #define A52_AUDIO_ES        0x81
56 /* These ones might violate the usage : */
57 #define DVD_SPU_ES          0x82
58 #define LPCM_AUDIO_ES       0x83
59 #define SDDS_AUDIO_ES       0x84
60 #define DTS_AUDIO_ES        0x85
61 /* These ones are only here to work around a bug in VLS - VLS doesn't
62  * skip the first bytes of the PES payload (stream private ID) when
63  * streaming. This is incompatible with all equipments. 'B' is for
64  * buggy. Please note that they are associated with FOURCCs '***b'.
65  * --Meuuh 2002-08-30
66  */
67 #define A52B_AUDIO_ES       0x91
68 #define DVDB_SPU_ES         0x92
69 #define LPCMB_AUDIO_ES      0x93
70
71 #define MSCODEC_VIDEO_ES    0xa0
72
73 /****************************************************************************
74  * psi_callback_t
75  ****************************************************************************
76  * Used by TS demux to handle a PSI, either with the builtin decoder, either
77  * with a library such as libdvbpsi
78  ****************************************************************************/
79 typedef void( * psi_callback_t )( 
80         input_thread_t  * p_input,
81         data_packet_t   * p_data,
82         es_descriptor_t * p_es,
83         vlc_bool_t        b_unit_start );
84
85
86 /****************************************************************************
87  * mpeg_demux_t
88  ****************************************************************************
89  * Demux callbacks exported by the helper plugin
90  ****************************************************************************/
91 typedef struct mpeg_demux_t
92 {
93     module_t * p_module;
94
95     ssize_t           (*pf_read_ps)  ( input_thread_t *, data_packet_t ** );
96     es_descriptor_t * (*pf_parse_ps) ( input_thread_t *, data_packet_t * );
97     void              (*pf_demux_ps) ( input_thread_t *, data_packet_t * );
98
99     ssize_t           (*pf_read_ts)  ( input_thread_t *, data_packet_t ** );
100     void              (*pf_demux_ts) ( input_thread_t *, data_packet_t *,
101                                        psi_callback_t );
102 } mpeg_demux_t;
103
104 /*****************************************************************************
105  * psi_section_t
106  *****************************************************************************
107  * Describes a PSI section. Beware, it doesn't contain pointers to the TS
108  * packets that contain it as for a PES, but the data themselves
109  *****************************************************************************/
110 typedef struct psi_section_t
111 {
112     byte_t                  buffer[PSI_SECTION_SIZE];
113
114     u8                      i_section_number;
115     u8                      i_last_section_number;
116     u8                      i_version_number;
117     u16                     i_section_length;
118     u16                     i_read_in_section;
119     
120     /* the PSI is complete */
121     vlc_bool_t              b_is_complete;
122     
123     /* packet missed up ? */
124     vlc_bool_t              b_trash;
125
126     /*about sections  */ 
127     vlc_bool_t              b_section_complete;
128
129     /* where are we currently ? */
130     byte_t                * p_current;
131
132 } psi_section_t;
133
134 /*****************************************************************************
135  * decoder_descriptor_t
136  *****************************************************************************/
137 typedef struct decoder_config_descriptor_s
138 {
139     uint8_t                 i_objectTypeIndication;
140     uint8_t                 i_streamType;
141     vlc_bool_t              b_upStream;
142     uint32_t                i_bufferSizeDB;
143     uint32_t                i_maxBitrate;
144     uint32_t                i_avgBitrate;
145
146     int                     i_decoder_specific_info_len;
147     uint8_t                 *p_decoder_specific_info;
148
149 } decoder_config_descriptor_t;
150
151 /*****************************************************************************
152  * sl_descriptor_t:
153  *****************************************************************************/
154 typedef struct sl_config_descriptor_s
155 {
156     vlc_bool_t              b_useAccessUnitStartFlag;
157     vlc_bool_t              b_useAccessUnitEndFlag;
158     vlc_bool_t              b_useRandomAccessPointFlag;
159     vlc_bool_t              b_useRandomAccessUnitsOnlyFlag;
160     vlc_bool_t              b_usePaddingFlag;
161     vlc_bool_t              b_useTimeStampsFlags;
162     vlc_bool_t              b_useIdleFlag;
163     vlc_bool_t              b_durationFlag;
164     uint32_t                i_timeStampResolution;
165     uint32_t                i_OCRResolution;
166     uint8_t                 i_timeStampLength;
167     uint8_t                 i_OCRLength;
168     uint8_t                 i_AU_Length;
169     uint8_t                 i_instantBitrateLength;
170     uint8_t                 i_degradationPriorityLength;
171     uint8_t                 i_AU_seqNumLength;
172     uint8_t                 i_packetSeqNumLength;
173
174     uint32_t                i_timeScale;
175     uint16_t                i_accessUnitDuration;
176     uint16_t                i_compositionUnitDuration;
177
178     uint64_t                i_startDecodingTimeStamp;
179     uint64_t                i_startCompositionTimeStamp;
180
181 } sl_config_descriptor_t;
182
183 /*****************************************************************************
184  * es_mpeg4_descriptor_t: XXX it's not complete but should be enough
185  *****************************************************************************/
186 typedef struct es_mpeg4_descriptor_s
187 {
188     vlc_bool_t              b_ok;
189     uint16_t                i_es_id;
190
191     vlc_bool_t              b_streamDependenceFlag;
192     vlc_bool_t              b_OCRStreamFlag;
193     uint8_t                 i_streamPriority;
194
195     char                    *psz_url;
196
197     uint16_t                i_dependOn_es_id;
198     uint16_t                i_OCR_es_id;
199
200     decoder_config_descriptor_t    dec_descr;
201     sl_config_descriptor_t         sl_descr;
202 } es_mpeg4_descriptor_t;
203
204 /*****************************************************************************
205  * iod_descriptor_t: XXX it's not complete but should be enough
206  *****************************************************************************/
207 typedef struct iod_descriptor_s
208 {
209     uint8_t                i_iod_label;
210
211     /* IOD */
212     uint16_t                i_od_id;
213     char                    *psz_url;
214
215     uint8_t                 i_ODProfileLevelIndication;
216     uint8_t                 i_sceneProfileLevelIndication;
217     uint8_t                 i_audioProfileLevelIndication;
218     uint8_t                 i_visualProfileLevelIndication;
219     uint8_t                 i_graphicsProfileLevelIndication;
220
221     es_mpeg4_descriptor_t   es_descr[255];
222
223 } iod_descriptor_t;
224
225 /*****************************************************************************
226  * es_ts_data_t: extension of es_descriptor_t
227  *****************************************************************************/
228 typedef struct es_ts_data_t
229 {
230     vlc_bool_t              b_psi;   /* Does the stream have to be handled by
231                                       *                    the PSI decoder ? */
232
233     int                     i_psi_type;  /* There are different types of PSI */
234
235     psi_section_t *         p_psi_section;                    /* PSI packets */
236
237     /* Markers */
238     int                     i_continuity_counter;
239
240     /* mpeg4 in TS data specific */
241     int                     b_mpeg4;
242     uint16_t                i_es_id;
243
244     es_mpeg4_descriptor_t   *p_es_descr;   /* es_descr of IOD */
245
246 } es_ts_data_t;
247
248 /*****************************************************************************
249  * pgrm_ts_data_t: extension of pgrm_descriptor_t
250  *****************************************************************************/
251 typedef struct pgrm_ts_data_t
252 {
253     u16                     i_pcr_pid;             /* PCR ES, for TS streams */
254     int                     i_pmt_version;
255     /* libdvbpsi pmt decoder handle */
256     void *                  p_pmt_handle;
257
258     /* mpeg4 in TS data specific */
259     vlc_bool_t              b_mpeg4;
260     iod_descriptor_t        iod;
261
262 } pgrm_ts_data_t;
263
264 /*****************************************************************************
265  * stream_ts_data_t: extension of stream_descriptor_t
266  *****************************************************************************/
267 typedef struct stream_ts_data_t
268 {
269     int                     i_pat_version; /* Current version of the PAT */
270     vlc_bool_t              b_buggy_psi;
271     /* libdvbpsi PMT decoder handle */
272     void *                  p_pat_handle;
273 } stream_ts_data_t;
274
275 /*****************************************************************************
276  * stream_ps_data_t: extension of stream_descriptor_t
277  *****************************************************************************/
278 typedef struct stream_ps_data_t
279 {
280     vlc_bool_t              b_has_PSM;                 /* very rare, in fact */
281
282     u8                      i_PSM_version;
283 } stream_ps_data_t;
284
285 /* PSM version is 5 bits, so -1 is not a valid value */
286 #define EMPTY_PSM_VERSION   -1
287