]> git.sesse.net Git - vlc/blob - include/input_ext-plugins.h
34943a7b518496fc90511c84e3233100dcb3cbdc
[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-2002 VideoLAN
6  * $Id: input_ext-plugins.h,v 1.30 2002/06/01 18:04:48 sam 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 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
35                                      * is natural.                           */
36 #define NO_SEEK             -1
37
38 /*****************************************************************************
39  * Prototypes from input_programs.c
40  *****************************************************************************/
41 VLC_EXPORT( int,  input_InitStream,( input_thread_t *, size_t ) );
42 VLC_EXPORT( void, input_EndStream, ( input_thread_t * ) );
43 VLC_EXPORT( pgrm_descriptor_t *, input_FindProgram,( input_thread_t *, u16 ) );
44 VLC_EXPORT( pgrm_descriptor_t *, input_AddProgram, ( input_thread_t *, u16, size_t ) );
45 VLC_EXPORT( void, input_DelProgram,( input_thread_t *, pgrm_descriptor_t * ) );
46 VLC_EXPORT( int, input_SetProgram,( input_thread_t *, pgrm_descriptor_t * ) );
47 VLC_EXPORT( input_area_t *, input_AddArea,( input_thread_t * ) );
48 VLC_EXPORT( void, input_DelArea,   ( input_thread_t *, input_area_t * ) );
49 VLC_EXPORT( es_descriptor_t *, input_FindES,( input_thread_t *, u16 ) );
50 VLC_EXPORT( es_descriptor_t *, input_AddES, ( input_thread_t *, pgrm_descriptor_t *, u16, size_t ) );
51 VLC_EXPORT( void, input_DelES,     ( input_thread_t *, es_descriptor_t * ) );
52 VLC_EXPORT( int,  input_SelectES,  ( input_thread_t *, es_descriptor_t * ) );
53 VLC_EXPORT( int,  input_UnselectES,( input_thread_t *, es_descriptor_t * ) );
54
55 /*****************************************************************************
56  * Prototypes from input_dec.c
57  *****************************************************************************/
58 //decoder_capabilities_t * input_ProbeDecoder( void );
59 decoder_fifo_t * input_RunDecoder( input_thread_t *, es_descriptor_t * );
60 void input_EndDecoder( input_thread_t *, es_descriptor_t * );
61 VLC_EXPORT( void, input_DecodePES, ( decoder_fifo_t *, pes_packet_t * ) );
62 void input_EscapeDiscontinuity( input_thread_t * );
63 void input_EscapeAudioDiscontinuity( input_thread_t * );
64
65 /*****************************************************************************
66  * Prototypes from input_clock.c
67  *****************************************************************************/
68 void input_ClockInit( pgrm_descriptor_t * );
69 VLC_EXPORT( int,  input_ClockManageControl, ( input_thread_t *, pgrm_descriptor_t *, mtime_t ) );
70 VLC_EXPORT( void, input_ClockManageRef, ( input_thread_t *, pgrm_descriptor_t *, mtime_t ) );
71 VLC_EXPORT( mtime_t, input_ClockGetTS, ( input_thread_t *, pgrm_descriptor_t *, mtime_t ) );
72
73 /*****************************************************************************
74  * Prototypes from input_ext-plugins.h (buffers management)
75  *****************************************************************************/
76 #define input_BuffersInit(a) __input_BuffersInit(CAST_TO_VLC_OBJECT(a))
77 void * __input_BuffersInit( vlc_object_t * );
78 VLC_EXPORT( void, input_BuffersEnd, ( input_thread_t *, input_buffers_t * ) );
79
80 VLC_EXPORT( data_buffer_t *, input_NewBuffer,   ( input_buffers_t *, size_t ) );
81 VLC_EXPORT( void, input_ReleaseBuffer,          ( input_buffers_t *, data_buffer_t * ) );
82 VLC_EXPORT( data_packet_t *, input_ShareBuffer, ( input_buffers_t *, data_buffer_t * ) );
83 VLC_EXPORT( data_packet_t *, input_NewPacket,   ( input_buffers_t *, size_t ) );
84 VLC_EXPORT( void, input_DeletePacket,           ( input_buffers_t *, data_packet_t * ) );
85 VLC_EXPORT( pes_packet_t *, input_NewPES, ( input_buffers_t * ) );
86 VLC_EXPORT( void, input_DeletePES,        ( input_buffers_t *, pes_packet_t * ) );
87 VLC_EXPORT( ssize_t, input_FillBuffer,  ( input_thread_t * ) );
88 VLC_EXPORT( ssize_t, input_Peek,        ( input_thread_t *, byte_t **, size_t ) );
89 VLC_EXPORT( ssize_t, input_SplitBuffer, ( input_thread_t *, data_packet_t **, size_t ) );
90 VLC_EXPORT( int, input_AccessInit,      ( input_thread_t * ) );
91 VLC_EXPORT( void, input_AccessReinit,   ( input_thread_t * ) );
92 VLC_EXPORT( void, input_AccessEnd,      ( input_thread_t * ) );
93
94 /*****************************************************************************
95  * Create a NULL packet for padding in case of a data loss
96  *****************************************************************************/
97 static inline void input_NullPacket( input_thread_t * p_input,
98                                      es_descriptor_t * p_es )
99 {
100     data_packet_t *             p_pad_data;
101     pes_packet_t *              p_pes;
102
103     if( (p_pad_data = input_NewPacket( p_input->p_method_data,
104                     PADDING_PACKET_SIZE )) == NULL )
105     {
106         msg_Err( p_input, "no new packet" );
107         p_input->b_error = 1;
108         return;
109     }
110
111     memset( p_pad_data->p_payload_start, 0, PADDING_PACKET_SIZE );
112     p_pad_data->b_discard_payload = 1;
113     p_pes = p_es->p_pes;
114
115     if( p_pes != NULL )
116     {
117         p_pes->b_discontinuity = 1;
118         p_pes->p_last->p_next = p_pad_data;
119         p_pes->p_last = p_pad_data;
120         p_pes->i_nb_data++;
121     }
122     else
123     {
124         if( (p_pes = input_NewPES( p_input->p_method_data )) == NULL )
125         {
126             msg_Err( p_input, "no PES packet" );
127             p_input->b_error = 1;
128             return;
129         }
130
131         p_pes->i_rate = p_input->stream.control.i_rate;
132         p_pes->p_first = p_pes->p_last = p_pad_data;
133         p_pes->i_nb_data = 1;
134         p_pes->b_discontinuity = 1;
135         input_DecodePES( p_es->p_decoder_fifo, p_pes );
136     }
137 }
138
139
140 /*
141  * Optional MPEG demultiplexing
142  */
143
144 /*****************************************************************************
145  * Constants
146  *****************************************************************************/
147 #define TS_PACKET_SIZE      188                       /* Size of a TS packet */
148 #define TS_SYNC_CODE        0x47                /* First byte of a TS packet */
149 #define PSI_SECTION_SIZE    4096            /* Maximum size of a PSI section */
150
151 #define PAT_UNINITIALIZED    (1 << 6)
152 #define PMT_UNINITIALIZED    (1 << 6)
153
154 #define PSI_IS_PAT          0x00
155 #define PSI_IS_PMT          0x01
156 #define UNKNOWN_PSI         0xff
157
158 /****************************************************************************
159  * psi_callback_t
160  ****************************************************************************
161  * Used by TS demux to handle a PSI, either with the builtin decoder, either
162  * with a library such as libdvbpsi
163  ****************************************************************************/
164 typedef void( * psi_callback_t )( 
165         input_thread_t  * p_input,
166         data_packet_t   * p_data,
167         es_descriptor_t * p_es,
168         vlc_bool_t        b_unit_start );
169
170
171 /*****************************************************************************
172  * psi_section_t
173  *****************************************************************************
174  * Describes a PSI section. Beware, it doesn't contain pointers to the TS
175  * packets that contain it as for a PES, but the data themselves
176  *****************************************************************************/
177 typedef struct psi_section_s
178 {
179     byte_t                  buffer[PSI_SECTION_SIZE];
180
181     u8                      i_section_number;
182     u8                      i_last_section_number;
183     u8                      i_version_number;
184     u16                     i_section_length;
185     u16                     i_read_in_section;
186     
187     /* the PSI is complete */
188     vlc_bool_t              b_is_complete;
189     
190     /* packet missed up ? */
191     vlc_bool_t              b_trash;
192
193     /*about sections  */ 
194     vlc_bool_t              b_section_complete;
195
196     /* where are we currently ? */
197     byte_t                * p_current;
198
199 } psi_section_t;
200
201 /*****************************************************************************
202  * es_ts_data_t: extension of es_descriptor_t
203  *****************************************************************************/
204 typedef struct es_ts_data_s
205 {
206     vlc_bool_t              b_psi;   /* Does the stream have to be handled by
207                                       *                    the PSI decoder ? */
208
209     int                     i_psi_type;  /* There are different types of PSI */
210     
211     psi_section_t *         p_psi_section;                    /* PSI packets */
212
213     /* Markers */
214     int                     i_continuity_counter;
215 } es_ts_data_t;
216
217 /*****************************************************************************
218  * pgrm_ts_data_t: extension of pgrm_descriptor_t
219  *****************************************************************************/
220 typedef struct pgrm_ts_data_s
221 {
222     u16                     i_pcr_pid;             /* PCR ES, for TS streams */
223     int                     i_pmt_version;
224     /* libdvbpsi pmt decoder handle */
225     void *                  p_pmt_handle;
226 } pgrm_ts_data_t;
227
228 /*****************************************************************************
229  * stream_ts_data_t: extension of stream_descriptor_t
230  *****************************************************************************/
231 typedef struct stream_ts_data_s
232 {
233     int i_pat_version;          /* Current version of the PAT */
234     /* libdvbpsi pmt decoder handle */
235     void *                  p_pat_handle;
236 } stream_ts_data_t;
237
238 /*****************************************************************************
239  * stream_ps_data_t: extension of stream_descriptor_t
240  *****************************************************************************/
241 typedef struct stream_ps_data_s
242 {
243     vlc_bool_t              b_has_PSM;                 /* very rare, in fact */
244
245     u8                      i_PSM_version;
246 } stream_ps_data_t;
247
248 /* PSM version is 5 bits, so -1 is not a valid value */
249 #define EMPTY_PSM_VERSION   -1
250
251
252 /*****************************************************************************
253  * Prototypes
254  *****************************************************************************/
255 VLC_EXPORT( void, input_ParsePES,  ( input_thread_t *, es_descriptor_t * ) );
256 VLC_EXPORT( void, input_GatherPES, ( input_thread_t *, data_packet_t *, es_descriptor_t *, vlc_bool_t, vlc_bool_t ) );
257 VLC_EXPORT( ssize_t, input_ReadPS, ( input_thread_t *, data_packet_t ** ) );
258 VLC_EXPORT( es_descriptor_t *, input_ParsePS, ( input_thread_t *, data_packet_t * ) );
259 VLC_EXPORT( ssize_t, input_ReadTS, ( input_thread_t *, data_packet_t ** ) );
260 VLC_EXPORT( void, input_DemuxPS,   ( input_thread_t *, data_packet_t * ) );
261 VLC_EXPORT( void, input_DemuxTS,   ( input_thread_t *, data_packet_t *, void(*) ( input_thread_t *, data_packet_t *, es_descriptor_t *, vlc_bool_t ) ) );
262
263 /*
264  * Optional standard file descriptor operations (input_ext-plugins.h)
265  */
266
267 /*****************************************************************************
268  * input_socket_t: private access plug-in data
269  *****************************************************************************/
270 struct input_socket_s
271 {
272     /* Unbuffered file descriptor */
273     int i_handle;
274 };
275
276 /*****************************************************************************
277  * Prototypes
278  *****************************************************************************/
279 VLC_EXPORT( void, input_FDClose, ( input_thread_t * ) );
280 VLC_EXPORT( void, input_FDNetworkClose, ( input_thread_t * ) );
281 VLC_EXPORT( ssize_t, input_FDRead, ( input_thread_t *, byte_t *, size_t ) );
282 VLC_EXPORT( ssize_t, input_FDNetworkRead, ( input_thread_t *, byte_t *, size_t ) );
283 VLC_EXPORT( void, input_FDSeek, ( input_thread_t *, off_t ) );
284