]> git.sesse.net Git - vlc/blob - include/input_ext-plugins.h
* Big clean-up to allow compiling every module as plugins.
[vlc] / include / input_ext-plugins.h
1 /*****************************************************************************
2  * input_ext-plugins.h: structures of the input not exported to other modules,
3  *                      but exported to plug-ins
4  *****************************************************************************
5  * Copyright (C) 1999, 2000, 2001 VideoLAN
6  * $Id: input_ext-plugins.h,v 1.6 2001/11/25 22:52:21 gbazin Exp $
7  *
8  * Authors: Christophe Massiot <massiot@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*
26  * Communication plugin -> input
27  */
28
29 /* FIXME: you've gotta move this move this, you've gotta move this move this */
30 #define INPUT_READ_ONCE     7   /* We live in a world dominated by Ethernet. *
31                                  * Ethernet MTU is 1500 bytes, so in a UDP   *
32                                  * packet we can put : 1500/188 = 7 TS       *
33                                  * packets. Have a nice day and merry Xmas.  */
34 #define PADDING_PACKET_SIZE 188 /* Size of the NULL packet inserted in case
35                                  * of data loss (this should be < 188).      */
36 #define PADDING_PACKET_NUMBER 10 /* Number of padding packets top insert to
37                                   * escape a decoder.                        */
38 #define NO_SEEK             -1
39
40 /*****************************************************************************
41  * Prototypes from input_ext-dec.c
42  *****************************************************************************/
43 #ifndef PLUGIN
44 void InitBitstream  ( struct bit_stream_s *, struct decoder_fifo_s *,
45                       void (* pf_bitstream_callback)( struct bit_stream_s *,
46                                                       boolean_t ),
47                       void * p_callback_arg );
48 void NextDataPacket ( struct bit_stream_s * );
49 #endif
50
51 /*****************************************************************************
52  * Prototypes from input_programs.c
53  *****************************************************************************/
54 #ifndef PLUGIN
55 int  input_InitStream( struct input_thread_s *, size_t );
56 void input_EndStream ( struct input_thread_s * );
57 struct pgrm_descriptor_s * input_FindProgram( struct input_thread_s *, u16 );
58 struct pgrm_descriptor_s * input_AddProgram ( struct input_thread_s *,
59                                               u16, size_t );
60 void input_DelProgram( struct input_thread_s *, struct pgrm_descriptor_s * );
61 struct input_area_s * input_AddArea( struct input_thread_s * );
62 void input_DelArea   ( struct input_thread_s *, struct input_area_s * );
63 struct es_descriptor_s * input_FindES( struct input_thread_s *, u16 );
64 struct es_descriptor_s * input_AddES ( struct input_thread_s *,
65                                        struct pgrm_descriptor_s *, u16,
66                                        size_t );
67 void input_DelES     ( struct input_thread_s *, struct es_descriptor_s * );
68 int  input_SelectES  ( struct input_thread_s *, struct es_descriptor_s * );
69 int  input_UnselectES( struct input_thread_s *, struct es_descriptor_s * );
70 #endif
71
72 /*****************************************************************************
73  * Prototypes from input_dec.c
74  *****************************************************************************/
75 #ifndef PLUGIN
76 //decoder_capabilities_s * input_ProbeDecoder( void );
77 vlc_thread_t input_RunDecoder( struct input_thread_s *,
78                                struct es_descriptor_s * );
79 void input_EndDecoder( struct input_thread_s *, struct es_descriptor_s * );
80 void input_DecodePES ( struct decoder_fifo_s *, struct pes_packet_s * );
81 void input_EscapeDiscontinuity( struct input_thread_s *,
82                                 struct pgrm_descriptor_s * );
83 void input_EscapeAudioDiscontinuity( struct input_thread_s * );
84 #endif
85
86 /*****************************************************************************
87  * Prototypes from input_clock.c
88  *****************************************************************************/
89 #ifndef PLUGIN
90 void input_ClockInit( struct pgrm_descriptor_s * );
91 int  input_ClockManageControl( struct input_thread_s *,
92                                struct pgrm_descriptor_s *, mtime_t );
93 void input_ClockManageRef( struct input_thread_s *,
94                            struct pgrm_descriptor_s *, mtime_t );
95 mtime_t input_ClockGetTS( struct input_thread_s *,
96                           struct pgrm_descriptor_s *, mtime_t );
97 #endif
98
99 /*****************************************************************************
100  * Create a NULL packet for padding in case of a data loss
101  *****************************************************************************/
102 static __inline__ void input_NullPacket( input_thread_t * p_input,
103                                          es_descriptor_t * p_es )
104 {
105     data_packet_t *             p_pad_data;
106     pes_packet_t *              p_pes;
107
108     if( (p_pad_data = p_input->pf_new_packet(
109                     p_input->p_method_data,
110                     PADDING_PACKET_SIZE )) == NULL )
111     {
112         intf_ErrMsg("Out of memory");
113         p_input->b_error = 1;
114         return;
115     }
116
117     memset( p_pad_data->p_buffer, 0, PADDING_PACKET_SIZE );
118     p_pad_data->b_discard_payload = 1;
119     p_pes = p_es->p_pes;
120
121     if( p_pes != NULL )
122     {
123         p_pes->b_discontinuity = 1;
124         p_es->p_last->p_next = p_pad_data;
125         p_es->p_last = p_pad_data;
126     }
127     else
128     {
129         if( (p_pes = p_input->pf_new_pes( p_input->p_method_data )) == NULL )
130         {
131             intf_ErrMsg("Out of memory");
132             p_input->b_error = 1;
133             return;
134         }
135
136         p_pes->i_rate = p_input->stream.control.i_rate;
137         p_pes->p_first = p_pad_data;
138         p_pes->b_discontinuity = 1;
139         input_DecodePES( p_es->p_decoder_fifo, p_pes );
140     }
141 }
142
143
144 /*
145  * Optional netlist management
146  */
147
148 /*****************************************************************************
149  * netlist_t: structure to manage a netlist
150  *****************************************************************************/
151 typedef struct netlist_s
152 {
153     vlc_mutex_t             lock;
154
155     size_t                  i_buffer_size;
156
157     /* Buffers */
158     byte_t *                p_buffers;                 /* Big malloc'ed area */
159     data_packet_t *         p_data;                        /* malloc'ed area */
160     pes_packet_t *          p_pes;                         /* malloc'ed area */
161
162     /* FIFOs of free packets */
163     data_packet_t **        pp_free_data;
164     pes_packet_t **         pp_free_pes;
165     struct iovec *          p_free_iovec;
166     
167     /* FIFO size */
168     unsigned int            i_nb_iovec;
169     unsigned int            i_nb_pes;
170     unsigned int            i_nb_data;
171
172     /* Index */
173     unsigned int            i_iovec_start, i_iovec_end;
174     unsigned int            i_data_start, i_data_end;
175     unsigned int            i_pes_start, i_pes_end;
176
177     /* Reference counters for iovec */
178     unsigned int *          pi_refcount;
179
180     /* Number of blocs read once by readv */
181     unsigned int            i_read_once;
182 } netlist_t;
183
184 /*****************************************************************************
185  * Prototypes
186  *****************************************************************************/
187 #ifndef PLUGIN
188 int                     input_NetlistInit( struct input_thread_s *,
189                                            int i_nb_iovec,
190                                            int i_nb_data,
191                                            int i_nb_pes,
192                                            size_t i_buffer_size,
193                                            int i_read_once );
194
195 struct iovec *          input_NetlistGetiovec( void * p_method_data );
196 void                    input_NetlistMviovec( void * , int,
197                                               struct data_packet_s **);
198 struct data_packet_s *  input_NetlistNewPtr( void * );
199 struct data_packet_s *  input_NetlistNewPacket( void *, size_t );
200 struct pes_packet_s *   input_NetlistNewPES( void * );
201 void                    input_NetlistDeletePacket( void *,
202                                                    struct data_packet_s * );
203 void                    input_NetlistDeletePES( void *,
204                                                 struct pes_packet_s * );
205 void                    input_NetlistEnd( struct input_thread_s * );
206 #endif
207
208
209 /*
210  * Optional MPEG demultiplexing
211  */
212
213 /*****************************************************************************
214  * Constants
215  *****************************************************************************/
216 #define TS_PACKET_SIZE      188                       /* Size of a TS packet */
217 #define PSI_SECTION_SIZE    4096            /* Maximum size of a PSI section */
218
219 #define PAT_UNINITIALIZED    (1 << 6)
220 #define PMT_UNINITIALIZED    (1 << 6)
221
222 #define PSI_IS_PAT          0x00
223 #define PSI_IS_PMT          0x01
224 #define UNKNOWN_PSI         0xff
225
226 /*****************************************************************************
227  * psi_section_t
228  *****************************************************************************
229  * Describes a PSI section. Beware, it doesn't contain pointers to the TS
230  * packets that contain it as for a PES, but the data themselves
231  *****************************************************************************/
232 typedef struct psi_section_s
233 {
234     byte_t                  buffer[PSI_SECTION_SIZE];
235
236     u8                      i_section_number;
237     u8                      i_last_section_number;
238     u8                      i_version_number;
239     u16                     i_section_length;
240     u16                     i_read_in_section;
241     
242     /* the PSI is complete */
243     boolean_t               b_is_complete;
244     
245     /* packet missed up ? */
246     boolean_t               b_trash;
247
248     /*about sections  */ 
249     boolean_t               b_section_complete;
250
251     /* where are we currently ? */
252     byte_t                * p_current;
253
254 } psi_section_t;
255
256 /*****************************************************************************
257  * es_ts_data_t: extension of es_descriptor_t
258  *****************************************************************************/
259 typedef struct es_ts_data_s
260 {
261     boolean_t               b_psi;   /* Does the stream have to be handled by
262                                       *                    the PSI decoder ? */
263
264     int                     i_psi_type;  /* There are different types of PSI */
265     
266     psi_section_t *         p_psi_section;                    /* PSI packets */
267
268     /* Markers */
269     int                     i_continuity_counter;
270 } es_ts_data_t;
271
272 /*****************************************************************************
273  * pgrm_ts_data_t: extension of pgrm_descriptor_t
274  *****************************************************************************/
275 typedef struct pgrm_ts_data_s
276 {
277     u16                     i_pcr_pid;             /* PCR ES, for TS streams */
278     int                     i_pmt_version;
279 } pgrm_ts_data_t;
280
281 /*****************************************************************************
282  * stream_ts_data_t: extension of stream_descriptor_t
283  *****************************************************************************/
284 typedef struct stream_ts_data_s
285 {
286     int i_pat_version;          /* Current version of the PAT */
287 } stream_ts_data_t;
288
289 /*****************************************************************************
290  * stream_ps_data_t: extension of stream_descriptor_t
291  *****************************************************************************/
292 typedef struct stream_ps_data_s
293 {
294     boolean_t               b_has_PSM;                 /* very rare, in fact */
295
296     u8                      i_PSM_version;
297 } stream_ps_data_t;
298
299 /* PSM version is 5 bits, so -1 is not a valid value */
300 #define EMPTY_PSM_VERSION   -1
301
302
303 /*****************************************************************************
304  * Prototypes
305  *****************************************************************************/
306 #ifndef PLUGIN
307 void input_ParsePES  ( struct input_thread_s *, struct es_descriptor_s * );
308 void input_GatherPES ( struct input_thread_s *, struct data_packet_s *,
309                        struct es_descriptor_s *, boolean_t, boolean_t );
310 es_descriptor_t * input_ParsePS( struct input_thread_s *,
311                                  struct data_packet_s * );
312 void input_DemuxPS   ( struct input_thread_s *, struct data_packet_s * );
313 void input_DemuxTS   ( struct input_thread_s *, struct data_packet_s * );
314 void input_DemuxPSI  ( struct input_thread_s *, struct data_packet_s *,
315                        struct es_descriptor_s *, boolean_t, boolean_t );
316 #endif