1 /*****************************************************************************
2 * input_ext-intf.h: structures of the input exported to the interface
3 * This header provides structures to read the stream descriptors and
4 * control the pace of reading.
5 *****************************************************************************
6 * Copyright (C) 1999, 2000 VideoLAN
7 * $Id: input_ext-intf.h,v 1.56 2002/01/07 02:12:29 sam Exp $
9 * Authors: Christophe Massiot <massiot@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
27 * Communication input -> interface
30 #define REQUESTED_MPEG 1
31 #define REQUESTED_AC3 2
32 #define REQUESTED_LPCM 3
33 #define REQUESTED_NOAUDIO 255
35 #define OFFSETTOTIME_MAX_SIZE 10
37 /*****************************************************************************
38 * input_bank_t, p_input_bank (global variable)
39 *****************************************************************************
40 * This global variable is accessed by any function using the input.
41 *****************************************************************************/
42 typedef struct input_bank_s
44 /* Array to all the input threads */
45 struct input_thread_s *pp_input[ INPUT_MAX_THREADS ];
48 vlc_mutex_t lock; /* Global lock */
53 extern input_bank_t *p_input_bank;
55 # define p_input_bank (p_symbols->p_input_bank)
58 /*****************************************************************************
59 * es_descriptor_t: elementary stream descriptor
60 *****************************************************************************
61 * Describes an elementary stream, and includes fields required to handle and
62 * demultiplex this elementary stream.
63 *****************************************************************************/
64 typedef struct es_descriptor_s
66 u16 i_id; /* stream ID for PS, PID for TS */
67 u8 i_stream_id; /* stream ID defined in the PES */
68 u8 i_type; /* stream type */
69 boolean_t b_audio; /* is the stream an audio stream that
70 * will need to be discarded with
71 * fast forward and slow motion ? */
72 u8 i_cat; /* stream category: video, audio,
75 char psz_desc[20]; /* description of ES: audio language
76 * for instance ; NULL if not
79 /* Demultiplexer information */
81 struct pgrm_descriptor_s *
82 p_pgrm; /* very convenient in the demultiplexer */
84 /* PES parser information */
85 struct pes_packet_s * p_pes; /* Current PES */
86 int i_pes_real_size; /* as indicated by the header */
88 /* Decoder information */
89 struct decoder_fifo_s * p_decoder_fifo;
90 vlc_thread_t thread_id; /* ID of the decoder */
92 count_t c_packets; /* total packets read */
93 count_t c_invalid_packets; /* invalid packets read */
95 /* Module properties */
96 struct module_s * p_module;
97 struct decoder_config_s * p_config;
101 /* Special PID values - note that the PID is only on 13 bits, and that values
102 * greater than 0x1fff have no meaning in a stream */
103 #define PROGRAM_ASSOCIATION_TABLE_PID 0x0000
104 #define CONDITIONNAL_ACCESS_TABLE_PID 0x0001 /* not used */
105 #define EMPTY_ID 0xffff /* empty record in a table */
108 /* ES Categories to be used by interface plugins */
109 #define VIDEO_ES 0x00
110 #define AUDIO_ES 0x01
113 #define UNKNOWN_ES 0xFF
115 /*****************************************************************************
117 *****************************************************************************
118 * Describes a program and list associated elementary streams. It is build by
119 * the PSI decoder upon the informations carried in program map sections
120 *****************************************************************************/
121 typedef struct pgrm_descriptor_s
123 /* Program characteristics */
124 u16 i_number; /* program number */
125 u8 i_version; /* version number */
126 boolean_t b_is_ok; /* Is the description up to date ? */
128 /* Service Descriptor (program name) - DVB extension */
132 /* Synchronization information */
134 mtime_t cr_ref, sysdate_ref;
135 mtime_t last_cr; /* reference to detect unexpected stream
138 count_t c_average_count;
139 /* counter used to compute dynamic average values */
142 /* Demultiplexer data */
145 int i_es_number; /* size of the following array */
146 es_descriptor_t ** pp_es; /* array of pointers to ES */
151 #define SYNCHRO_START 1
152 #define SYNCHRO_REINIT 2
154 /*****************************************************************************
156 *****************************************************************************
157 * Attributes for current area (title for DVD)
158 *****************************************************************************/
159 typedef struct input_area_s
161 /* selected area attributes */
162 int i_id; /* identificator for area */
163 off_t i_start; /* start offset of area */
164 off_t i_size; /* total size of the area
165 * (in arbitrary units) */
167 /* navigation parameters */
168 off_t i_tell; /* actual location in the area
169 * (in arbitrary units) */
170 off_t i_seek; /* next requested location
171 * (changed by the interface thread */
173 /* area subdivision */
174 int i_part_nb; /* number of parts (chapter for DVD)*/
175 int i_part; /* currently selected part */
177 int i_angle_nb; /* number of angles/title units */
180 /* offset to plugin related data */
184 /*****************************************************************************
185 * stream_descriptor_t
186 *****************************************************************************
187 * Describes a stream and list its associated programs. Build upon
188 * the information carried in program association sections (for instance)
189 *****************************************************************************/
190 typedef struct stream_descriptor_s
192 u16 i_stream_id; /* stream id */
193 boolean_t b_changed; /* if stream has been changed,
194 we have to inform the interface */
195 vlc_mutex_t stream_lock; /* to be taken every time you read
196 * or modify stream, pgrm or es */
198 /* Input method data */
199 int i_method; /* input method for stream: file,
201 boolean_t b_pace_control; /* can we read when we want ? */
202 boolean_t b_seekable; /* can we do lseek() ? */
204 /* if (b_seekable) : */
206 input_area_t ** pp_areas; /* list of areas in stream == offset
207 * interval with own properties */
208 input_area_t * p_selected_area;
209 input_area_t * p_new_area; /* Newly selected area from
212 u32 i_mux_rate; /* the rate we read the stream (in
213 * units of 50 bytes/s) ; 0 if undef */
215 /* New status and rate requested by the interface */
216 int i_new_status, i_new_rate;
217 int b_new_mute; /* int because it can be -1 */
218 vlc_cond_t stream_wait; /* interface -> input in case of a
219 * status change request */
221 /* Demultiplexer data */
224 /* Programs descriptions */
225 int i_pgrm_number; /* size of the following array */
226 pgrm_descriptor_t ** pp_programs; /* array of pointers to pgrm */
227 pgrm_descriptor_t * p_selected_program; /* currently
229 pgrm_descriptor_t * p_new_program; /* Newly selected program */
230 /* ES descriptions */
232 es_descriptor_t ** pp_es; /* carried elementary streams */
233 int i_selected_es_number;
234 es_descriptor_t ** pp_selected_es; /* ES with a decoder */
235 es_descriptor_t * p_newly_selected_es; /* ES selected from
237 es_descriptor_t * p_removed_es; /* ES removed from the interface */
241 stream_ctrl_t control;
244 count_t c_packets_read; /* packets read */
245 count_t c_packets_trashed; /* trashed packets */
246 } stream_descriptor_t;
248 #define MUTE_NO_CHANGE -1
250 /*****************************************************************************
252 *****************************************************************************
253 * This structure includes all the local static variables of an input thread
254 *****************************************************************************/
255 typedef struct input_thread_s
257 /* Thread properties and locks */
258 boolean_t b_die; /* 'die' flag */
261 vlc_thread_t thread_id; /* id for thread functions */
262 int * pi_status; /* temporary status flag */
265 struct module_s * p_input_module;
268 void (* pf_init)( struct input_thread_s * );
269 void (* pf_open)( struct input_thread_s * );
270 void (* pf_close)( struct input_thread_s * );
271 void (* pf_end)( struct input_thread_s * );
272 void (* pf_init_bit_stream)( struct bit_stream_s *,
273 struct decoder_fifo_s *,
274 void (* pf_bitstream_callback)( struct bit_stream_s *,
278 /* Read & Demultiplex */
279 int (* pf_read)( struct input_thread_s *,
280 struct data_packet_s ** );
281 void (* pf_demux)( struct input_thread_s *,
282 struct data_packet_s * );
284 /* Packet management facilities */
285 struct data_packet_s *(*pf_new_packet)( void *, size_t );
286 struct pes_packet_s *(* pf_new_pes)( void * );
287 void (* pf_delete_packet)( void *,
288 struct data_packet_s * );
289 void (* pf_delete_pes)( void *, struct pes_packet_s * );
291 /* Stream control capabilities */
292 int (* pf_set_program)( struct input_thread_s *,
293 struct pgrm_descriptor_s * );
294 int (* pf_set_area)( struct input_thread_s *,
295 struct input_area_s * );
296 int (* pf_rewind)( struct input_thread_s * );
297 /* NULL if we don't support going *
298 * backwards (it's gonna be fun) */
299 void (* pf_seek)( struct input_thread_s *, off_t );
303 int i_handle; /* socket or file descriptor */
304 FILE * p_stream; /* if applicable */
305 void * p_handle; /* if i_handle isn't suitable */
306 void * p_method_data; /* data of the packet manager */
307 void * p_plugin_data; /* data of the plugin */
309 /* General stream description */
310 stream_descriptor_t stream; /* PAT tables */
316 /* The first figure is a general method that can be used in interface plugins ;
317 * The second figure is a detailed sub-method */
318 #define INPUT_METHOD_NONE 0x0 /* input thread is inactive */
319 #define INPUT_METHOD_FILE 0x10 /* stream is read from file p_source */
320 #define INPUT_METHOD_DISC 0x20 /* stream is read directly from disc */
321 #define INPUT_METHOD_DVD 0x21 /* stream is read from DVD */
322 #define INPUT_METHOD_VCD 0x22 /* stream is read from VCD */
323 #define INPUT_METHOD_NETWORK 0x30 /* stream is read from network */
324 #define INPUT_METHOD_UCAST 0x31 /* UDP unicast */
325 #define INPUT_METHOD_MCAST 0x32 /* UDP multicast */
326 #define INPUT_METHOD_BCAST 0x33 /* UDP broadcast */
327 #define INPUT_METHOD_VLAN_BCAST 0x34 /* UDP broadcast with VLANs */
330 /* Status changing methods */
331 #define INPUT_STATUS_END 0
332 #define INPUT_STATUS_PLAY 1
333 #define INPUT_STATUS_PAUSE 2
334 #define INPUT_STATUS_FASTER 3
335 #define INPUT_STATUS_SLOWER 4
337 /*****************************************************************************
339 *****************************************************************************/
341 void input_InitBank ( void );
342 void input_EndBank ( void );
344 struct input_thread_s * input_CreateThread ( struct playlist_item_s *,
346 void input_DestroyThread ( struct input_thread_s *, int *pi_status );
348 void input_SetStatus ( struct input_thread_s *, int );
349 void input_Seek ( struct input_thread_s *, off_t );
350 void input_DumpStream ( struct input_thread_s * );
351 char * input_OffsetToTime ( struct input_thread_s *, char *, off_t );
352 int input_ChangeES ( struct input_thread_s *,
353 struct es_descriptor_s *, u8 );
354 int input_ToggleES ( struct input_thread_s *,
355 struct es_descriptor_s *, boolean_t );
356 int input_ChangeArea ( struct input_thread_s *, struct input_area_s * );
357 int input_ToggleGrayscale( struct input_thread_s * );
358 int input_ToggleMute ( struct input_thread_s * );
359 int input_SetSMP ( struct input_thread_s *, int );
361 # define input_SetStatus p_symbols->input_SetStatus
362 # define input_Seek p_symbols->input_Seek
363 # define input_DumpStream p_symbols->input_DumpStream
364 # define input_OffsetToTime p_symbols->input_OffsetToTime
365 # define input_ChangeES p_symbols->input_ChangeES
366 # define input_ToggleES p_symbols->input_ToggleES
367 # define input_ChangeArea p_symbols->input_ChangeArea