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