]> git.sesse.net Git - vlc/blob - include/input_netlist.h
. suppression d'un bug cosm�tique dans l'affichage des plugins qui en
[vlc] / include / input_netlist.h
1 /*****************************************************************************
2  * input_netlist.h: netlist interface
3  * The netlists are an essential part of the input structure. We maintain a
4  * list of free TS packets and free PES packets to avoid continuous malloc
5  * and free.
6  *****************************************************************************
7  * Copyright (C) 1998, 1999, 2000 VideoLAN
8  *
9  * Authors:
10  *
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.
15  * 
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.
20  *
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  *****************************************************************************/
25
26 #include "intf_msg.h"
27
28 /*****************************************************************************
29  * Prototypes
30  *****************************************************************************/
31 int     input_NetlistInit       ( input_thread_t *p_input );
32 void    input_NetlistEnd        ( input_thread_t *p_input );
33
34 static __inline__ void input_NetlistFreePES( input_thread_t *p_input, pes_packet_t *p_pes_packet );
35 static __inline__ void input_NetlistFreeTS( input_thread_t *p_input, ts_packet_t *p_ts_packet );
36 static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input );
37
38 /*****************************************************************************
39  * input_NetlistFreePES: add a PES packet to the netlist
40  *****************************************************************************
41  * Add a PES packet to the PES netlist, so that the packet can immediately be
42  * reused by the demultiplexer. We put this function directly in the .h file,
43  * because it is very frequently called.
44  *****************************************************************************/
45 static __inline__ void input_NetlistFreePES( input_thread_t *p_input,
46                                   pes_packet_t *p_pes_packet )
47 {
48     int             i_dummy;
49     ts_packet_t *   p_ts_packet;
50
51     ASSERT(p_pes_packet);
52
53     /* We will be playing with indexes, so we take a lock. */
54     vlc_mutex_lock( &p_input->netlist.lock );
55
56     /* Free all TS packets in this PES structure. */
57     p_ts_packet = p_pes_packet->p_first_ts;
58     for( i_dummy = 0; i_dummy < p_pes_packet->i_ts_packets; i_dummy++ )
59     {
60         ASSERT(p_ts_packet);
61
62 #ifdef INPUT_LIFO_TS_NETLIST
63         p_input->netlist.i_ts_index--;
64         p_input->netlist.p_ts_free[p_input->netlist.i_ts_index].iov_base
65                              = (void *)p_ts_packet;
66 #else /* FIFO */
67         p_input->netlist.p_ts_free[p_input->netlist.i_ts_end].iov_base
68                              = (void *)p_ts_packet;
69         p_input->netlist.i_ts_end++;
70         p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
71 #endif
72         p_ts_packet = p_ts_packet->p_next_ts;
73     }
74
75     /* Free the PES structure. */
76 #ifdef INPUT_LIFO_PES_NETLIST
77     p_input->netlist.i_pes_index--;
78     p_input->netlist.p_pes_free[p_input->netlist.i_pes_index] = p_pes_packet;
79 #else /* FIFO */
80     p_input->netlist.p_pes_free[p_input->netlist.i_pes_end] = p_pes_packet;
81     p_input->netlist.i_pes_end++;
82     p_input->netlist.i_pes_end &= INPUT_MAX_PES; /* loop */
83 #endif
84
85     vlc_mutex_unlock( &p_input->netlist.lock );
86 }
87
88 /*****************************************************************************
89  * input_NetlistFreeTS: add a TS packet to the netlist
90  *****************************************************************************
91  * Add a TS packet to the TS netlist, so that the packet can immediately be
92  * reused by the demultiplexer. Shouldn't be called by other threads (they
93  * should only use input_FreePES.
94  *****************************************************************************/
95 static __inline__ void input_NetlistFreeTS( input_thread_t *p_input,
96                                             ts_packet_t *p_ts_packet )
97 {
98     ASSERT(p_ts_packet);
99
100     /* We will be playing with indexes, so we take a lock. */
101     vlc_mutex_lock( &p_input->netlist.lock );
102
103     /* Free the TS structure. */
104 #ifdef INPUT_LIFO_TS_NETLIST
105     p_input->netlist.i_ts_index--;
106     p_input->netlist.p_ts_free[p_input->netlist.i_ts_index].iov_base
107         = (void *)p_ts_packet;
108 #else /* FIFO */
109     p_input->netlist.p_ts_free[p_input->netlist.i_ts_end].iov_base
110         = (void *)p_ts_packet;
111     p_input->netlist.i_ts_end++;
112     p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
113 #endif
114
115     vlc_mutex_unlock( &p_input->netlist.lock );
116 }
117
118 /*****************************************************************************
119  * input_NetlistGetPES: remove a PES packet from the netlist
120  *****************************************************************************
121  * Add a TS packet to the TS netlist, so that the packet can immediately be
122  * reused by the demultiplexer. Shouldn't be called by other threads (they
123  * should only use input_FreePES.
124  *****************************************************************************/
125 static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input )
126 {
127     pes_packet_t *          p_pes_packet;
128
129 #ifdef INPUT_LIFO_PES_NETLIST
130     /* i_pes_index might be accessed by a decoder thread to give back a
131      * packet. */
132     vlc_mutex_lock( &p_input->netlist.lock );
133
134     /* Verify that we still have PES packet in the netlist */
135     if( (INPUT_MAX_PES - p_input->netlist.i_pes_index ) <= 1 )
136     {
137         intf_ErrMsg("input error: PES netlist is empty !\n");
138         return( NULL );
139     }
140
141     /* Fetch a new PES packet */
142     p_pes_packet = p_input->netlist.p_pes_free[p_input->netlist.i_pes_index];
143     p_input->netlist.i_pes_index++;
144     vlc_mutex_unlock( &p_input->netlist.lock );
145
146 #else /* FIFO */
147     /* No need to lock, since we are the only ones accessing i_pes_start. */
148
149     /* Verify that we still have PES packet in the netlist */
150     if( ((p_input->netlist.i_pes_end -1 - p_input->netlist.i_pes_start) & INPUT_MAX_PES) <= 1 )
151     {
152         intf_ErrMsg("input error: PES netlist is empty !\n");
153         return( NULL );
154     }
155
156     p_pes_packet = p_input->netlist.p_pes_free[p_input->netlist.i_pes_start];
157     p_input->netlist.i_pes_start++;
158     p_input->netlist.i_pes_start &= INPUT_MAX_PES; /* loop */
159 #endif /* netlist type */
160
161     /* Initialize PES flags. */
162     p_pes_packet->b_data_loss = 0;
163     p_pes_packet->b_data_alignment = 0;
164     p_pes_packet->b_has_pts = 0;
165     p_pes_packet->b_random_access = 0;
166     p_pes_packet->b_discard_payload = 0;
167     p_pes_packet->i_pes_size = 0;
168     p_pes_packet->i_pes_real_size = 0;
169     p_pes_packet->i_ts_packets = 0;
170     p_pes_packet->p_first_ts = NULL;
171     p_pes_packet->p_last_ts = NULL;
172
173     return( p_pes_packet );
174 }