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-2002 VideoLAN
6 * $Id: input_ext-plugins.h,v 1.21 2002/03/04 23:56:37 massiot Exp $
8 * Authors: Christophe Massiot <massiot@via.ecp.fr>
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.
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.
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 *****************************************************************************/
26 * Communication plugin -> input
29 /* FIXME: you've gotta move this move this, you've gotta move this move this */
30 #define PADDING_PACKET_SIZE 188 /* Size of the NULL packet inserted in case
31 * of data loss (this should be < 188). */
32 #define PADDING_PACKET_NUMBER 10 /* Number of padding packets top insert to
33 * escape a decoder. */
34 #define INPUT_DEFAULT_BUFSIZE 65536 /* Default buffer size to use when none
38 /*****************************************************************************
39 * Prototypes from input_programs.c
40 *****************************************************************************/
42 int input_InitStream( struct input_thread_s *, size_t );
43 void input_EndStream ( struct input_thread_s * );
44 struct pgrm_descriptor_s * input_FindProgram( struct input_thread_s *, u16 );
45 struct pgrm_descriptor_s * input_AddProgram ( struct input_thread_s *,
47 void input_DelProgram( struct input_thread_s *, struct pgrm_descriptor_s * );
48 int input_SetProgram( struct input_thread_s *, struct pgrm_descriptor_s * );
49 struct input_area_s * input_AddArea( struct input_thread_s * );
50 void input_DelArea ( struct input_thread_s *, struct input_area_s * );
51 struct es_descriptor_s * input_FindES( struct input_thread_s *, u16 );
52 struct es_descriptor_s * input_AddES ( struct input_thread_s *,
53 struct pgrm_descriptor_s *, u16,
55 void input_DelES ( struct input_thread_s *, struct es_descriptor_s * );
56 int input_SelectES ( struct input_thread_s *, struct es_descriptor_s * );
57 int input_UnselectES( struct input_thread_s *, struct es_descriptor_s * );
59 # define input_InitStream p_symbols->input_InitStream
60 # define input_EndStream p_symbols->input_EndStream
61 # define input_SetProgram p_symbols->input_SetProgram
62 # define input_FindES p_symbols->input_FindES
63 # define input_AddES p_symbols->input_AddES
64 # define input_DelES p_symbols->input_DelES
65 # define input_SelectES p_symbols->input_SelectES
66 # define input_UnselectES p_symbols->input_UnselectES
67 # define input_AddProgram p_symbols->input_AddProgram
68 # define input_DelProgram p_symbols->input_DelProgram
69 # define input_AddArea p_symbols->input_AddArea
70 # define input_DelArea p_symbols->input_DelArea
73 /*****************************************************************************
74 * Prototypes from input_dec.c
75 *****************************************************************************/
77 //decoder_capabilities_s * input_ProbeDecoder( void );
78 vlc_thread_t input_RunDecoder( struct input_thread_s *,
79 struct es_descriptor_s * );
80 void input_EndDecoder( struct input_thread_s *, struct es_descriptor_s * );
81 void input_DecodePES ( struct decoder_fifo_s *, struct pes_packet_s * );
82 void input_EscapeDiscontinuity( struct input_thread_s *,
83 struct pgrm_descriptor_s * );
84 void input_EscapeAudioDiscontinuity( struct input_thread_s * );
86 # define input_DecodePES p_symbols->input_DecodePES
89 /*****************************************************************************
90 * Prototypes from input_clock.c
91 *****************************************************************************/
93 void input_ClockInit( struct pgrm_descriptor_s * );
94 int input_ClockManageControl( struct input_thread_s *,
95 struct pgrm_descriptor_s *, mtime_t );
96 void input_ClockManageRef( struct input_thread_s *,
97 struct pgrm_descriptor_s *, mtime_t );
98 mtime_t input_ClockGetTS( struct input_thread_s *,
99 struct pgrm_descriptor_s *, mtime_t );
101 # define input_ClockManageControl p_symbols->input_ClockManageControl
104 /*****************************************************************************
105 * Prototypes from input_ext-plugins.h (buffers management)
106 *****************************************************************************/
108 void * input_BuffersInit( void );
109 void input_BuffersEnd( struct input_buffers_s * );
110 struct data_buffer_s * input_NewBuffer( struct input_buffers_s *, size_t );
111 void input_ReleaseBuffer( struct input_buffers_s *, struct data_buffer_s * );
112 struct data_packet_s * input_ShareBuffer( struct input_buffers_s *,
113 struct data_buffer_s * );
114 struct data_packet_s * input_NewPacket( struct input_buffers_s *, size_t );
115 void input_DeletePacket( struct input_buffers_s *, struct data_packet_s * );
116 struct pes_packet_s * input_NewPES( struct input_buffers_s * );
117 void input_DeletePES( struct input_buffers_s *, struct pes_packet_s * );
118 ssize_t input_FillBuffer( struct input_thread_s * );
119 ssize_t input_Peek( struct input_thread_s *, byte_t **, size_t );
120 ssize_t input_SplitBuffer( struct input_thread_s *, data_packet_t **, size_t );
121 int input_AccessInit( struct input_thread_s * );
122 void input_AccessReinit( struct input_thread_s * );
123 void input_AccessEnd( struct input_thread_s * );
125 # define input_BuffersInit p_symbols->input_BuffersInit
126 # define input_BuffersEnd p_symbols->input_BuffersEnd
127 # define input_NewBuffer p_symbols->input_NewBuffer
128 # define input_ReleaseBuffer p_symbols->input_ReleaseBuffer
129 # define input_ShareBuffer p_symbols->input_ShareBuffer
130 # define input_NewPacket p_symbols->input_NewPacket
131 # define input_DeletePacket p_symbols->input_DeletePacket
132 # define input_NewPES p_symbols->input_NewPES
133 # define input_DeletePES p_symbols->input_DeletePES
134 # define input_FillBuffer p_symbols->input_FillBuffer
135 # define input_Peek p_symbols->input_Peek
136 # define input_SplitBuffer p_symbols->input_SplitBuffer
137 # define input_AccessInit p_symbols->input_AccessInit
138 # define input_AccessReinit p_symbols->input_AccessReinit
139 # define input_AccessEnd p_symbols->input_AccessEnd
142 /*****************************************************************************
143 * Create a NULL packet for padding in case of a data loss
144 *****************************************************************************/
145 static __inline__ void input_NullPacket( input_thread_t * p_input,
146 es_descriptor_t * p_es )
148 data_packet_t * p_pad_data;
149 pes_packet_t * p_pes;
151 if( (p_pad_data = input_NewPacket( p_input->p_method_data,
152 PADDING_PACKET_SIZE )) == NULL )
154 intf_ErrMsg("input error: no new packet");
155 p_input->b_error = 1;
159 memset( p_pad_data->p_payload_start, 0, PADDING_PACKET_SIZE );
160 p_pad_data->b_discard_payload = 1;
165 p_pes->b_discontinuity = 1;
166 p_pes->p_last->p_next = p_pad_data;
167 p_pes->p_last = p_pad_data;
172 if( (p_pes = input_NewPES( p_input->p_method_data )) == NULL )
174 intf_ErrMsg("input error: no PES packet");
175 p_input->b_error = 1;
179 p_pes->i_rate = p_input->stream.control.i_rate;
180 p_pes->p_first = p_pes->p_last = p_pad_data;
181 p_pes->i_nb_data = 1;
182 p_pes->b_discontinuity = 1;
183 input_DecodePES( p_es->p_decoder_fifo, p_pes );
189 * Optional MPEG demultiplexing
192 /*****************************************************************************
194 *****************************************************************************/
195 #define TS_PACKET_SIZE 188 /* Size of a TS packet */
196 #define TS_SYNC_CODE 0x47 /* First byte of a TS packet */
197 #define PSI_SECTION_SIZE 4096 /* Maximum size of a PSI section */
199 #define PAT_UNINITIALIZED (1 << 6)
200 #define PMT_UNINITIALIZED (1 << 6)
202 #define PSI_IS_PAT 0x00
203 #define PSI_IS_PMT 0x01
204 #define UNKNOWN_PSI 0xff
206 /*****************************************************************************
208 *****************************************************************************
209 * Describes a PSI section. Beware, it doesn't contain pointers to the TS
210 * packets that contain it as for a PES, but the data themselves
211 *****************************************************************************/
212 typedef struct psi_section_s
214 byte_t buffer[PSI_SECTION_SIZE];
217 u8 i_last_section_number;
219 u16 i_section_length;
220 u16 i_read_in_section;
222 /* the PSI is complete */
223 boolean_t b_is_complete;
225 /* packet missed up ? */
229 boolean_t b_section_complete;
231 /* where are we currently ? */
236 /*****************************************************************************
237 * es_ts_data_t: extension of es_descriptor_t
238 *****************************************************************************/
239 typedef struct es_ts_data_s
241 boolean_t b_psi; /* Does the stream have to be handled by
242 * the PSI decoder ? */
244 int i_psi_type; /* There are different types of PSI */
246 psi_section_t * p_psi_section; /* PSI packets */
249 int i_continuity_counter;
252 /*****************************************************************************
253 * pgrm_ts_data_t: extension of pgrm_descriptor_t
254 *****************************************************************************/
255 typedef struct pgrm_ts_data_s
257 u16 i_pcr_pid; /* PCR ES, for TS streams */
261 /*****************************************************************************
262 * stream_ts_data_t: extension of stream_descriptor_t
263 *****************************************************************************/
264 typedef struct stream_ts_data_s
266 int i_pat_version; /* Current version of the PAT */
269 /*****************************************************************************
270 * stream_ps_data_t: extension of stream_descriptor_t
271 *****************************************************************************/
272 typedef struct stream_ps_data_s
274 boolean_t b_has_PSM; /* very rare, in fact */
279 /* PSM version is 5 bits, so -1 is not a valid value */
280 #define EMPTY_PSM_VERSION -1
283 /*****************************************************************************
285 *****************************************************************************/
287 void input_ParsePES ( struct input_thread_s *, struct es_descriptor_s * );
288 void input_GatherPES ( struct input_thread_s *, struct data_packet_s *,
289 struct es_descriptor_s *, boolean_t, boolean_t );
290 ssize_t input_ReadPS ( struct input_thread_s *, struct data_packet_s ** );
291 es_descriptor_t * input_ParsePS( struct input_thread_s *,
292 struct data_packet_s * );
293 ssize_t input_ReadTS ( struct input_thread_s *, struct data_packet_s ** );
294 void input_DemuxPS ( struct input_thread_s *, struct data_packet_s * );
295 void input_DemuxTS ( struct input_thread_s *, struct data_packet_s * );
296 void input_DemuxPSI ( struct input_thread_s *, struct data_packet_s *,
297 struct es_descriptor_s *, boolean_t, boolean_t );
299 # define input_ParsePES p_symbols->input_ParsePES
300 # define input_GatherPES p_symbols->input_GatherPES
301 # define input_ReadPS p_symbols->input_ReadPS
302 # define input_ParsePS p_symbols->input_ParsePS
303 # define input_DemuxPS p_symbols->input_DemuxPS
304 # define input_ReadTS p_symbols->input_ReadTS
305 # define input_DemuxTS p_symbols->input_DemuxTS
306 # define input_DemuxPSI p_symbols->input_DemuxPSI
311 * Optional standard file descriptor operations (input_ext-plugins.h)
314 /*****************************************************************************
315 * input_socket_t: private access plug-in data
316 *****************************************************************************/
317 typedef struct input_socket_s
319 /* Unbuffered file descriptor */
323 /*****************************************************************************
325 *****************************************************************************/
327 void input_FDClose( struct input_thread_s * );
328 ssize_t input_FDRead( input_thread_t *, byte_t *, size_t );
329 ssize_t input_FDNetworkRead( input_thread_t *, byte_t *, size_t );
330 void input_FDSeek( struct input_thread_s *, off_t );
332 # define input_FDClose p_symbols->input_FDClose
333 # define input_FDRead p_symbols->input_FDRead
334 # define input_FDNetworkRead p_symbols->input_FDNetworkRead
335 # define input_FDSeek p_symbols->input_FDSeek