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.31 2001/04/10 17:47:05 stef 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
29 #define INPUT_MAX_PLUGINS 1
31 #define REQUESTED_MPEG 1
32 #define REQUESTED_AC3 2
33 #define REQUESTED_LPCM 3
34 #define REQUESTED_NOAUDIO 255
36 #define OFFSETTOTIME_MAX_SIZE 10
38 /*****************************************************************************
39 * es_descriptor_t: elementary stream descriptor
40 *****************************************************************************
41 * Describes an elementary stream, and includes fields required to handle and
42 * demultiplex this elementary stream.
43 *****************************************************************************/
44 struct decoder_fifo_s; /* defined in input_ext-dec.h */
45 struct pgrm_descriptor_s;
47 typedef struct es_descriptor_s
49 u16 i_id; /* stream ID for PS, PID for TS */
50 u8 i_stream_id; /* stream ID defined in the PES */
51 u8 i_type; /* stream type */
52 boolean_t b_audio; /* is the stream an audio stream that
53 * will need to be discarded with
54 * fast forward and slow motion ? */
55 u8 i_cat; /* stream category: video, audio,
58 char psz_desc[20]; /* description of ES: audio language
59 * for instance ; NULL if not
62 /* Demultiplexer information */
64 struct pgrm_descriptor_s *
65 p_pgrm; /* very convenient in the demultiplexer */
67 /* PES parser information */
68 struct pes_packet_s * p_pes; /* Current PES */
69 struct data_packet_s * p_last; /* The last packet gathered at present */
70 int i_pes_real_size; /* as indicated by the header */
72 /* Decoder information */
73 struct decoder_fifo_s * p_decoder_fifo;
74 vlc_thread_t thread_id; /* ID of the decoder */
77 count_t c_payload_bytes;/* total of payload useful bytes */
78 count_t c_packets; /* total packets read */
79 count_t c_invalid_packets; /* invalid packets read */
83 /* Special PID values - note that the PID is only on 13 bits, and that values
84 * greater than 0x1fff have no meaning in a stream */
85 #define PROGRAM_ASSOCIATION_TABLE_PID 0x0000
86 #define CONDITIONNAL_ACCESS_TABLE_PID 0x0001 /* not used */
87 #define EMPTY_ID 0xffff /* empty record in a table */
89 /* ES streams types - see ISO/IEC 13818-1 table 2-29 numbers */
90 #define MPEG1_VIDEO_ES 0x01
91 #define MPEG2_VIDEO_ES 0x02
92 #define MPEG1_AUDIO_ES 0x03
93 #define MPEG2_AUDIO_ES 0x04
94 #define AC3_AUDIO_ES 0x81
95 /* These ones might violate the norm : */
96 #define DVD_SPU_ES 0x82
97 #define LPCM_AUDIO_ES 0x83
98 #define UNKNOWN_ES 0xFF
100 /* ES Categories to be used by interface plugins */
101 #define VIDEO_ES 0x00
102 #define AUDIO_ES 0x01
105 #define UNKNOWN_ES 0xFF
106 /*****************************************************************************
108 *****************************************************************************
109 * Describes a program and list associated elementary streams. It is build by
110 * the PSI decoder upon the informations carried in program map sections
111 *****************************************************************************/
112 typedef struct pgrm_descriptor_s
114 /* Program characteristics */
115 u16 i_number; /* program number */
116 u8 i_version; /* version number */
117 boolean_t b_is_ok; /* Is the description up to date ? */
119 /* Service Descriptor (program name) - DVB extension */
123 /* Synchronization information */
125 mtime_t cr_ref, sysdate_ref;
126 mtime_t last_cr; /* reference to detect unexpected stream
128 count_t c_average_count;
129 /* counter used to compute dynamic average values */
132 /* Demultiplexer data */
135 /* Decoders control */
136 struct vout_thread_s * p_vout;
137 struct aout_thread_s * p_aout;
139 int i_es_number; /* size of the following array */
140 es_descriptor_t ** pp_es; /* array of pointers to ES */
145 #define SYNCHRO_START 1
146 #define SYNCHRO_REINIT 2
148 /*****************************************************************************
150 *****************************************************************************
151 * Attributes for current area (title for DVD)
152 *****************************************************************************/
153 typedef struct input_area_s
155 /* selected area attributes */
156 int i_id; /* identificator for area */
157 off_t i_start; /* start offset of area */
158 off_t i_size; /* total size of the area
159 * (in arbitrary units) */
161 /* navigation parameters */
162 off_t i_tell; /* actual location in the area
163 * (in arbitrary units) */
164 off_t i_seek; /* next requested location
165 * (changed by the interface thread */
167 /* area subdivision */
168 int i_part_nb; /* number of parts (chapter for DVD)*/
169 int i_part; /* currently selected part */
171 /* offset to plugin related data */
175 /*****************************************************************************
176 * stream_descriptor_t
177 *****************************************************************************
178 * Describes a stream and list its associated programs. Build upon
179 * the information carried in program association sections (for instance)
180 *****************************************************************************/
181 typedef struct stream_descriptor_s
183 u16 i_stream_id; /* stream id */
184 vlc_mutex_t stream_lock; /* to be taken every time you read
185 * or modify stream, pgrm or es */
187 /* Input method data */
188 boolean_t b_pace_control; /* can we read when we want ? */
189 boolean_t b_seekable; /* can we do lseek() ? */
191 /* if (b_seekable) : */
193 input_area_t ** pp_areas; /* list of areas in stream == offset
194 * interval with own properties */
195 input_area_t * p_selected_area;
196 u32 i_mux_rate; /* the rate we read the stream (in
197 * units of 50 bytes/s) ; 0 if undef */
199 /* New status and rate requested by the interface */
200 int i_new_status, i_new_rate;
201 vlc_cond_t stream_wait; /* interface -> input in case of a
202 * status change request */
204 /* Demultiplexer data */
207 /* Programs descriptions */
208 int i_pgrm_number; /* size of the following array */
209 pgrm_descriptor_t ** pp_programs; /* array of pointers to pgrm */
211 /* ES descriptions */
213 es_descriptor_t ** pp_es; /* carried elementary streams */
214 int i_selected_es_number;
215 es_descriptor_t ** pp_selected_es; /* ES with a decoder */
218 stream_ctrl_t control;
219 } stream_descriptor_t;
221 /*****************************************************************************
223 *****************************************************************************
224 * This structure gives plugins pointers to the useful functions of input
225 *****************************************************************************/
226 struct input_thread_s;
227 struct data_packet_s;
228 struct es_descriptor_s;
230 typedef struct i_p_config_s
232 int (* pf_peek_stream)( struct input_thread_s *,
233 byte_t * buffer, size_t );
234 void (* pf_demux_pes)( struct input_thread_s *,
235 struct data_packet_s *,
236 struct es_descriptor_s *,
237 boolean_t b_unit_start,
238 boolean_t b_packet_lost );
241 /*****************************************************************************
243 *****************************************************************************
244 * This structure includes all the local static variables of an input thread
245 *****************************************************************************/
246 struct aout_thread_s;
247 struct vout_thread_s;
249 typedef struct input_thread_s
251 /* Thread properties and locks */
252 boolean_t b_die; /* 'die' flag */
255 vlc_thread_t thread_id; /* id for thread functions */
256 int * pi_status; /* temporary status flag */
259 struct module_s * p_input_module;
262 void (* pf_init)( struct input_thread_s * );
263 void (* pf_open)( struct input_thread_s * );
264 void (* pf_close)( struct input_thread_s * );
265 void (* pf_end)( struct input_thread_s * );
267 /* Read & Demultiplex */
268 int (* pf_read)( struct input_thread_s *,
269 struct data_packet_s * pp_packets[] );
270 void (* pf_demux)( struct input_thread_s *,
271 struct data_packet_s * );
273 /* Packet management facilities */
274 struct data_packet_s *(*pf_new_packet)( void *, size_t );
275 struct pes_packet_s *(* pf_new_pes)( void * );
276 void (* pf_delete_packet)( void *,
277 struct data_packet_s * );
278 void (* pf_delete_pes)( void *, struct pes_packet_s * );
280 /* Stream control capabilities */
281 int (* pf_set_area)( struct input_thread_s *,
282 struct input_area_s * );
283 int (* pf_rewind)( struct input_thread_s * );
284 /* NULL if we don't support going *
285 * backwards (it's gonna be fun) */
286 void (* pf_seek)( struct input_thread_s *, off_t );
288 i_p_config_t i_p_config; /* plugin configuration */
291 int i_handle; /* socket or file descriptor */
292 int i_read_once; /* number of packet read by
294 void * p_method_data; /* data of the packet manager */
295 void * p_plugin_data; /* data of the plugin */
297 /* General stream description */
298 stream_descriptor_t stream; /* PAT tables */
300 /* For auto-launch of decoders */
301 struct aout_thread_s * p_default_aout;
302 struct vout_thread_s * p_default_vout;
306 count_t c_bytes; /* bytes read */
307 count_t c_payload_bytes; /* payload useful bytes */
308 count_t c_packets_read; /* packets read */
309 count_t c_packets_trashed; /* trashed packets */
315 * Communication interface -> input
318 /*****************************************************************************
320 *****************************************************************************
321 * This structure is given by the interface to an input thread
322 *****************************************************************************/
323 typedef struct input_config_s
325 /* Input method description */
326 int i_method; /* input method */
327 char * p_source; /* source */
329 /* For auto-launch of decoders */
330 struct aout_thread_s * p_default_aout;
331 struct vout_thread_s * p_default_vout;
335 #define INPUT_METHOD_NONE 0 /* input thread is inactive */
336 #define INPUT_METHOD_FILE 10 /* stream is read from file p_source */
337 #define INPUT_METHOD_DVD 11 /* stream is read from dvd device */
338 #define INPUT_METHOD_UCAST 20 /* UDP unicast */
339 #define INPUT_METHOD_MCAST 21 /* UDP multicast */
340 #define INPUT_METHOD_BCAST 22 /* UDP broadcast */
341 #define INPUT_METHOD_VLAN_BCAST 32 /* UDP broadcast with VLANs */
343 /* Status changing methods */
344 #define INPUT_STATUS_END 0
345 #define INPUT_STATUS_PLAY 1
346 #define INPUT_STATUS_PAUSE 2
347 #define INPUT_STATUS_FASTER 3
348 #define INPUT_STATUS_SLOWER 4
350 /*****************************************************************************
352 *****************************************************************************/
353 struct input_thread_s * input_CreateThread ( struct playlist_item_s *,
355 void input_DestroyThread( struct input_thread_s *, int *pi_status );
357 void input_SetStatus( struct input_thread_s *, int );
358 void input_SetRate ( struct input_thread_s *, int );
359 void input_Seek ( struct input_thread_s *, off_t );
360 void input_DumpStream( struct input_thread_s * );
361 char * input_OffsetToTime( struct input_thread_s *, char * psz_buffer, off_t );
362 int input_ChangeES ( struct input_thread_s *, struct es_descriptor_s *, u8 );
363 int input_ToggleES ( struct input_thread_s *,
364 struct es_descriptor_s *,