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.25 2002/05/10 02:04:16 fenrir 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 pgrm_descriptor_s * input_FindProgram( struct input_thread_s *, u16 );
53 struct es_descriptor_s * input_AddES ( struct input_thread_s *,
54 struct pgrm_descriptor_s *, u16,
56 void input_DelES ( struct input_thread_s *, struct es_descriptor_s * );
57 int input_SelectES ( struct input_thread_s *, struct es_descriptor_s * );
58 int input_UnselectES( struct input_thread_s *, struct es_descriptor_s * );
60 # define input_InitStream p_symbols->input_InitStream
61 # define input_EndStream p_symbols->input_EndStream
62 # define input_SetProgram p_symbols->input_SetProgram
63 # define input_FindES p_symbols->input_FindES
64 # define input_FindProgram p_symbols->input_FindProgram
65 # define input_AddES p_symbols->input_AddES
66 # define input_DelES p_symbols->input_DelES
67 # define input_SelectES p_symbols->input_SelectES
68 # define input_UnselectES p_symbols->input_UnselectES
69 # define input_AddProgram p_symbols->input_AddProgram
70 # define input_DelProgram p_symbols->input_DelProgram
71 # define input_AddArea p_symbols->input_AddArea
72 # define input_DelArea p_symbols->input_DelArea
75 /*****************************************************************************
76 * Prototypes from input_dec.c
77 *****************************************************************************/
79 //decoder_capabilities_s * input_ProbeDecoder( void );
80 vlc_thread_t input_RunDecoder( struct input_thread_s *,
81 struct es_descriptor_s * );
82 void input_EndDecoder( struct input_thread_s *, struct es_descriptor_s * );
83 void input_DecodePES ( struct decoder_fifo_s *, struct pes_packet_s * );
84 void input_EscapeDiscontinuity( struct input_thread_s *,
85 struct pgrm_descriptor_s * );
86 void input_EscapeAudioDiscontinuity( struct input_thread_s * );
88 # define input_DecodePES p_symbols->input_DecodePES
91 /*****************************************************************************
92 * Prototypes from input_clock.c
93 *****************************************************************************/
95 void input_ClockInit( struct pgrm_descriptor_s * );
96 int input_ClockManageControl( struct input_thread_s *,
97 struct pgrm_descriptor_s *, mtime_t );
98 void input_ClockManageRef( struct input_thread_s *,
99 struct pgrm_descriptor_s *, mtime_t );
100 mtime_t input_ClockGetTS( struct input_thread_s *,
101 struct pgrm_descriptor_s *, mtime_t );
103 # define input_ClockManageRef p_symbols->input_ClockManageRef
104 # define input_ClockManageControl p_symbols->input_ClockManageControl
105 # define input_ClockGetTS p_symbols->input_ClockGetTS
108 /*****************************************************************************
109 * Prototypes from input_ext-plugins.h (buffers management)
110 *****************************************************************************/
112 void * input_BuffersInit( void );
113 void input_BuffersEnd( struct input_buffers_s * );
114 struct data_buffer_s * input_NewBuffer( struct input_buffers_s *, size_t );
115 void input_ReleaseBuffer( struct input_buffers_s *, struct data_buffer_s * );
116 struct data_packet_s * input_ShareBuffer( struct input_buffers_s *,
117 struct data_buffer_s * );
118 struct data_packet_s * input_NewPacket( struct input_buffers_s *, size_t );
119 void input_DeletePacket( struct input_buffers_s *, struct data_packet_s * );
120 struct pes_packet_s * input_NewPES( struct input_buffers_s * );
121 void input_DeletePES( struct input_buffers_s *, struct pes_packet_s * );
122 ssize_t input_FillBuffer( struct input_thread_s * );
123 ssize_t input_Peek( struct input_thread_s *, byte_t **, size_t );
124 ssize_t input_SplitBuffer( struct input_thread_s *, data_packet_t **, size_t );
125 int input_AccessInit( struct input_thread_s * );
126 void input_AccessReinit( struct input_thread_s * );
127 void input_AccessEnd( struct input_thread_s * );
129 # define input_BuffersInit p_symbols->input_BuffersInit
130 # define input_BuffersEnd p_symbols->input_BuffersEnd
131 # define input_NewBuffer p_symbols->input_NewBuffer
132 # define input_ReleaseBuffer p_symbols->input_ReleaseBuffer
133 # define input_ShareBuffer p_symbols->input_ShareBuffer
134 # define input_NewPacket p_symbols->input_NewPacket
135 # define input_DeletePacket p_symbols->input_DeletePacket
136 # define input_NewPES p_symbols->input_NewPES
137 # define input_DeletePES p_symbols->input_DeletePES
138 # define input_FillBuffer p_symbols->input_FillBuffer
139 # define input_Peek p_symbols->input_Peek
140 # define input_SplitBuffer p_symbols->input_SplitBuffer
141 # define input_AccessInit p_symbols->input_AccessInit
142 # define input_AccessReinit p_symbols->input_AccessReinit
143 # define input_AccessEnd p_symbols->input_AccessEnd
146 /*****************************************************************************
147 * Create a NULL packet for padding in case of a data loss
148 *****************************************************************************/
149 static __inline__ void input_NullPacket( input_thread_t * p_input,
150 es_descriptor_t * p_es )
152 data_packet_t * p_pad_data;
153 pes_packet_t * p_pes;
155 if( (p_pad_data = input_NewPacket( p_input->p_method_data,
156 PADDING_PACKET_SIZE )) == NULL )
158 intf_ErrMsg("input error: no new packet");
159 p_input->b_error = 1;
163 memset( p_pad_data->p_payload_start, 0, PADDING_PACKET_SIZE );
164 p_pad_data->b_discard_payload = 1;
169 p_pes->b_discontinuity = 1;
170 p_pes->p_last->p_next = p_pad_data;
171 p_pes->p_last = p_pad_data;
176 if( (p_pes = input_NewPES( p_input->p_method_data )) == NULL )
178 intf_ErrMsg("input error: no PES packet");
179 p_input->b_error = 1;
183 p_pes->i_rate = p_input->stream.control.i_rate;
184 p_pes->p_first = p_pes->p_last = p_pad_data;
185 p_pes->i_nb_data = 1;
186 p_pes->b_discontinuity = 1;
187 input_DecodePES( p_es->p_decoder_fifo, p_pes );
193 * Optional MPEG demultiplexing
196 /*****************************************************************************
198 *****************************************************************************/
199 #define TS_PACKET_SIZE 188 /* Size of a TS packet */
200 #define TS_SYNC_CODE 0x47 /* First byte of a TS packet */
201 #define PSI_SECTION_SIZE 4096 /* Maximum size of a PSI section */
203 #define PAT_UNINITIALIZED (1 << 6)
204 #define PMT_UNINITIALIZED (1 << 6)
206 #define PSI_IS_PAT 0x00
207 #define PSI_IS_PMT 0x01
208 #define UNKNOWN_PSI 0xff
210 /****************************************************************************
212 ****************************************************************************
213 * Used by TS demux to handle a PSI, either with the builtin decoder, either
214 * with a library such as libdvbpsi
215 ****************************************************************************/
216 typedef void( * psi_callback_t )(
217 input_thread_t * p_input,
218 data_packet_t * p_data,
219 es_descriptor_t * p_es,
220 boolean_t b_unit_start );
223 /*****************************************************************************
225 *****************************************************************************
226 * Describes a PSI section. Beware, it doesn't contain pointers to the TS
227 * packets that contain it as for a PES, but the data themselves
228 *****************************************************************************/
229 typedef struct psi_section_s
231 byte_t buffer[PSI_SECTION_SIZE];
234 u8 i_last_section_number;
236 u16 i_section_length;
237 u16 i_read_in_section;
239 /* the PSI is complete */
240 boolean_t b_is_complete;
242 /* packet missed up ? */
246 boolean_t b_section_complete;
248 /* where are we currently ? */
253 /*****************************************************************************
254 * es_ts_data_t: extension of es_descriptor_t
255 *****************************************************************************/
256 typedef struct es_ts_data_s
258 boolean_t b_psi; /* Does the stream have to be handled by
259 * the PSI decoder ? */
261 int i_psi_type; /* There are different types of PSI */
263 psi_section_t * p_psi_section; /* PSI packets */
266 int i_continuity_counter;
269 /*****************************************************************************
270 * pgrm_ts_data_t: extension of pgrm_descriptor_t
271 *****************************************************************************/
272 typedef struct pgrm_ts_data_s
274 u16 i_pcr_pid; /* PCR ES, for TS streams */
276 /* libdvbpsi pmt decoder handle */
280 /*****************************************************************************
281 * stream_ts_data_t: extension of stream_descriptor_t
282 *****************************************************************************/
283 typedef struct stream_ts_data_s
285 int i_pat_version; /* Current version of the PAT */
286 /* libdvbpsi pmt decoder handle */
290 /*****************************************************************************
291 * stream_ps_data_t: extension of stream_descriptor_t
292 *****************************************************************************/
293 typedef struct stream_ps_data_s
295 boolean_t b_has_PSM; /* very rare, in fact */
300 /* PSM version is 5 bits, so -1 is not a valid value */
301 #define EMPTY_PSM_VERSION -1
304 /*****************************************************************************
306 *****************************************************************************/
308 void input_ParsePES ( struct input_thread_s *, struct es_descriptor_s * );
309 void input_GatherPES ( struct input_thread_s *, struct data_packet_s *,
310 struct es_descriptor_s *, boolean_t, boolean_t );
311 ssize_t input_ReadPS ( struct input_thread_s *, struct data_packet_s ** );
312 es_descriptor_t * input_ParsePS( struct input_thread_s *,
313 struct data_packet_s * );
314 ssize_t input_ReadTS ( struct input_thread_s *, struct data_packet_s ** );
315 void input_DemuxPS ( struct input_thread_s *, struct data_packet_s * );
316 void input_DemuxTS ( struct input_thread_s *, struct data_packet_s *,
319 # define input_ParsePES p_symbols->input_ParsePES
320 # define input_GatherPES p_symbols->input_GatherPES
321 # define input_ReadPS p_symbols->input_ReadPS
322 # define input_ParsePS p_symbols->input_ParsePS
323 # define input_DemuxPS p_symbols->input_DemuxPS
324 # define input_ReadTS p_symbols->input_ReadTS
325 # define input_DemuxTS p_symbols->input_DemuxTS
330 * Optional standard file descriptor operations (input_ext-plugins.h)
333 /*****************************************************************************
334 * input_socket_t: private access plug-in data
335 *****************************************************************************/
336 typedef struct input_socket_s
338 /* Unbuffered file descriptor */
342 /*****************************************************************************
344 *****************************************************************************/
346 void input_FDClose( struct input_thread_s * );
347 ssize_t input_FDRead( input_thread_t *, byte_t *, size_t );
348 ssize_t input_FDNetworkRead( input_thread_t *, byte_t *, size_t );
349 void input_FDSeek( struct input_thread_s *, off_t );
351 # define input_FDClose p_symbols->input_FDClose
352 # define input_FDRead p_symbols->input_FDRead
353 # define input_FDNetworkRead p_symbols->input_FDNetworkRead
354 # define input_FDSeek p_symbols->input_FDSeek