]> git.sesse.net Git - vlc/blob - include/input_ext-plugins.h
b01bd0ae44286c421b8b469012ececb6f8be011d
[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.2 2001/07/18 14:21:00 massiot 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 void InitBitstream  ( struct bit_stream_s *, struct decoder_fifo_s *,
44                       void (* pf_bitstream_callback)( struct bit_stream_s *,
45                                                       boolean_t ),
46                       void * p_callback_arg );
47 void NextDataPacket ( struct bit_stream_s * );
48
49 /*****************************************************************************
50  * Prototypes from input_programs.c
51  *****************************************************************************/
52 int  input_InitStream( struct input_thread_s *, size_t );
53 void input_EndStream ( struct input_thread_s * );
54 struct pgrm_descriptor_s * input_FindProgram( struct input_thread_s *, u16 );
55 struct pgrm_descriptor_s * input_AddProgram ( struct input_thread_s *,
56                                               u16, size_t );
57 void input_DelProgram( struct input_thread_s *, struct pgrm_descriptor_s * );
58 struct input_area_s * input_AddArea( struct input_thread_s * );
59 void input_DelArea   ( struct input_thread_s *, struct input_area_s * );
60 struct es_descriptor_s * input_FindES( struct input_thread_s *, u16 );
61 struct es_descriptor_s * input_AddES ( struct input_thread_s *,
62                                        struct pgrm_descriptor_s *, u16,
63                                        size_t );
64 void input_DelES     ( struct input_thread_s *, struct es_descriptor_s * );
65 int  input_SelectES  ( struct input_thread_s *, struct es_descriptor_s * );
66 int  input_UnselectES( struct input_thread_s *, struct es_descriptor_s * );
67
68 /*****************************************************************************
69  * Prototypes from input_dec.c
70  *****************************************************************************/
71 //decoder_capabilities_s * input_ProbeDecoder( void );
72 vlc_thread_t input_RunDecoder( struct decoder_capabilities_s *, void * );
73 void input_EndDecoder( struct input_thread_s *, struct es_descriptor_s * );
74 void input_DecodePES ( struct decoder_fifo_s *, struct pes_packet_s * );
75 void input_EscapeDiscontinuity( struct input_thread_s *,
76                                 struct pgrm_descriptor_s * );
77 void input_EscapeAudioDiscontinuity( struct input_thread_s * );
78
79 /*****************************************************************************
80  * Prototypes from input_clock.c
81  *****************************************************************************/
82 void input_ClockInit( struct pgrm_descriptor_s * );
83 int  input_ClockManageControl( struct input_thread_s *,
84                                struct pgrm_descriptor_s *, mtime_t );
85 void input_ClockManageRef( struct input_thread_s *,
86                            struct pgrm_descriptor_s *, mtime_t );
87 mtime_t input_ClockGetTS( struct input_thread_s *,
88                           struct pgrm_descriptor_s *, mtime_t );
89
90 /*****************************************************************************
91  * Create a NULL packet for padding in case of a data loss
92  *****************************************************************************/
93 static __inline__ void input_NullPacket( input_thread_t * p_input,
94                                          es_descriptor_t * p_es )
95 {
96     data_packet_t *             p_pad_data;
97     pes_packet_t *              p_pes;
98
99     if( (p_pad_data = p_input->pf_new_packet(
100                     p_input->p_method_data,
101                     PADDING_PACKET_SIZE )) == NULL )
102     {
103         intf_ErrMsg("Out of memory");
104         p_input->b_error = 1;
105         return;
106     }
107
108     memset( p_pad_data->p_buffer, 0, PADDING_PACKET_SIZE );
109     p_pad_data->b_discard_payload = 1;
110     p_pes = p_es->p_pes;
111
112     if( p_pes != NULL )
113     {
114         p_pes->b_discontinuity = 1;
115         p_es->p_last->p_next = p_pad_data;
116         p_es->p_last = p_pad_data;
117     }
118     else
119     {
120         if( (p_pes = p_input->pf_new_pes( p_input->p_method_data )) == NULL )
121         {
122             intf_ErrMsg("Out of memory");
123             p_input->b_error = 1;
124             return;
125         }
126
127         p_pes->i_rate = p_input->stream.control.i_rate;
128         p_pes->p_first = p_pad_data;
129         p_pes->b_discontinuity = 1;
130         input_DecodePES( p_es->p_decoder_fifo, p_pes );
131     }
132 }
133
134
135 /*
136  * Optional netlist management
137  */
138
139 /*****************************************************************************
140  * netlist_t: structure to manage a netlist
141  *****************************************************************************/
142 typedef struct netlist_s
143 {
144     vlc_mutex_t             lock;
145
146     size_t                  i_buffer_size;
147
148     /* Buffers */
149     byte_t *                p_buffers;                 /* Big malloc'ed area */
150     data_packet_t *         p_data;                        /* malloc'ed area */
151     pes_packet_t *          p_pes;                         /* malloc'ed area */
152
153     /* FIFOs of free packets */
154     data_packet_t **        pp_free_data;
155     pes_packet_t **         pp_free_pes;
156     struct iovec *          p_free_iovec;
157     
158     /* FIFO size */
159     unsigned int            i_nb_pes;
160     unsigned int            i_nb_data;
161
162     /* Index */
163     unsigned int            i_data_start, i_data_end;
164     unsigned int            i_pes_start, i_pes_end;
165
166     /* Number of blocs read once by readv */
167     unsigned int            i_read_once;
168 } netlist_t;
169
170 /*****************************************************************************
171  * Prototypes
172  *****************************************************************************/
173 int                     input_NetlistInit( struct input_thread_s *,
174                                            int i_nb_data, int i_nb_pes,
175                                            size_t i_buffer_size,
176                                            int i_read_once );
177
178 struct iovec * input_NetlistGetiovec( void * p_method_data );
179 void input_NetlistMviovec( void * , size_t, struct data_packet_s **);
180 struct data_packet_s *  input_NetlistNewPacket( void *, size_t );
181 struct pes_packet_s *   input_NetlistNewPES( void * );
182 void            input_NetlistDeletePacket( void *, struct data_packet_s * );
183 void            input_NetlistDeletePES( void *, struct pes_packet_s * );
184 void            input_NetlistEnd( struct input_thread_s * );
185
186
187 /*
188  * Optional MPEG demultiplexing
189  */
190
191 /*****************************************************************************
192  * Constants
193  *****************************************************************************/
194 #define TS_PACKET_SIZE      188                       /* Size of a TS packet */
195 #define PSI_SECTION_SIZE    4096            /* Maximum size of a PSI section */
196
197 #define PAT_UNINITIALIZED    (1 << 6)
198 #define PMT_UNINITIALIZED    (1 << 6)
199
200 #define PSI_IS_PAT          0x00
201 #define PSI_IS_PMT          0x01
202 #define UNKNOWN_PSI         0xff
203
204 /*****************************************************************************
205  * psi_section_t
206  *****************************************************************************
207  * Describes a PSI section. Beware, it doesn't contain pointers to the TS
208  * packets that contain it as for a PES, but the data themselves
209  *****************************************************************************/
210 typedef struct psi_section_s
211 {
212     byte_t                  buffer[PSI_SECTION_SIZE];
213
214     u8                      i_section_number;
215     u8                      i_last_section_number;
216     u8                      i_version_number;
217     u16                     i_section_length;
218     u16                     i_read_in_section;
219     
220     /* the PSI is complete */
221     boolean_t               b_is_complete;
222     
223     /* packet missed up ? */
224     boolean_t               b_trash;
225
226     /*about sections  */ 
227     boolean_t               b_section_complete;
228
229     /* where are we currently ? */
230     byte_t                * p_current;
231
232 } psi_section_t;
233
234 /*****************************************************************************
235  * es_ts_data_t: extension of es_descriptor_t
236  *****************************************************************************/
237 typedef struct es_ts_data_s
238 {
239     boolean_t               b_psi;   /* Does the stream have to be handled by
240                                       *                    the PSI decoder ? */
241
242     int                     i_psi_type;  /* There are different types of PSI */
243     
244     psi_section_t *         p_psi_section;                    /* PSI packets */
245
246     /* Markers */
247     int                     i_continuity_counter;
248 } es_ts_data_t;
249
250 /*****************************************************************************
251  * pgrm_ts_data_t: extension of pgrm_descriptor_t
252  *****************************************************************************/
253 typedef struct pgrm_ts_data_s
254 {
255     u16                     i_pcr_pid;             /* PCR ES, for TS streams */
256     int                     i_pmt_version;
257 } pgrm_ts_data_t;
258
259 /*****************************************************************************
260  * stream_ts_data_t: extension of stream_descriptor_t
261  *****************************************************************************/
262 typedef struct stream_ts_data_s
263 {
264     int i_pat_version;          /* Current version of the PAT */
265 } stream_ts_data_t;
266
267 /*****************************************************************************
268  * stream_ps_data_t: extension of stream_descriptor_t
269  *****************************************************************************/
270 typedef struct stream_ps_data_s
271 {
272     boolean_t               b_has_PSM;                 /* very rare, in fact */
273
274     u8                      i_PSM_version;
275 } stream_ps_data_t;
276
277 /* PSM version is 5 bits, so -1 is not a valid value */
278 #define EMPTY_PSM_VERSION   -1
279
280
281 /*****************************************************************************
282  * Prototypes
283  *****************************************************************************/
284 void input_ParsePES  ( struct input_thread_s *, struct es_descriptor_s * );
285 void input_GatherPES ( struct input_thread_s *, struct data_packet_s *,
286                        struct es_descriptor_s *, boolean_t, boolean_t );
287 es_descriptor_t * input_ParsePS( struct input_thread_s *,
288                                  struct data_packet_s * );
289 void input_DemuxPS   ( struct input_thread_s *, struct data_packet_s * );
290 void input_DemuxTS   ( struct input_thread_s *, struct data_packet_s * );
291 void input_DemuxPSI  ( struct input_thread_s *, struct data_packet_s *,
292                        struct es_descriptor_s *, boolean_t, boolean_t );
293