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
6 *****************************************************************************
7 * Copyright (C) 1998, 1999, 2000 VideoLAN
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 GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public
22 * License along with this program; if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
25 *****************************************************************************/
29 /*****************************************************************************
31 *****************************************************************************/
32 int input_NetlistInit ( input_thread_t *p_input );
33 void input_NetlistEnd ( input_thread_t *p_input );
35 static __inline__ void input_NetlistFreePES( input_thread_t *p_input, pes_packet_t *p_pes_packet );
36 static __inline__ void input_NetlistFreeTS( input_thread_t *p_input, ts_packet_t *p_ts_packet );
37 static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input );
39 /*****************************************************************************
40 * input_NetlistFreePES: add a PES packet to the netlist
41 *****************************************************************************
42 * Add a PES packet to the PES netlist, so that the packet can immediately be
43 * reused by the demultiplexer. We put this function directly in the .h file,
44 * because it is very frequently called.
45 *****************************************************************************/
46 static __inline__ void input_NetlistFreePES( input_thread_t *p_input,
47 pes_packet_t *p_pes_packet )
50 ts_packet_t * p_ts_packet;
54 /* We will be playing with indexes, so we take a lock. */
55 vlc_mutex_lock( &p_input->netlist.lock );
57 /* Free all TS packets in this PES structure. */
58 p_ts_packet = p_pes_packet->p_first_ts;
59 for( i_dummy = 0; i_dummy < p_pes_packet->i_ts_packets; i_dummy++ )
63 #ifdef INPUT_LIFO_TS_NETLIST
64 p_input->netlist.i_ts_index--;
65 p_input->netlist.p_ts_free[p_input->netlist.i_ts_index].iov_base
68 p_input->netlist.p_ts_free[p_input->netlist.i_ts_end].iov_base
70 p_input->netlist.i_ts_end++;
71 p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
73 p_ts_packet = p_ts_packet->p_next_ts;
76 /* Free the PES structure. */
77 #ifdef INPUT_LIFO_PES_NETLIST
78 p_input->netlist.i_pes_index--;
79 p_input->netlist.p_pes_free[p_input->netlist.i_pes_index] = p_pes_packet;
81 p_input->netlist.p_pes_free[p_input->netlist.i_pes_end] = p_pes_packet;
82 p_input->netlist.i_pes_end++;
83 p_input->netlist.i_pes_end &= INPUT_MAX_PES; /* loop */
86 vlc_mutex_unlock( &p_input->netlist.lock );
89 /*****************************************************************************
90 * input_NetlistFreeTS: add a TS packet to the netlist
91 *****************************************************************************
92 * Add a TS packet to the TS netlist, so that the packet can immediately be
93 * reused by the demultiplexer. Shouldn't be called by other threads (they
94 * should only use input_FreePES.
95 *****************************************************************************/
96 static __inline__ void input_NetlistFreeTS( input_thread_t *p_input,
97 ts_packet_t *p_ts_packet )
101 /* We will be playing with indexes, so we take a lock. */
102 vlc_mutex_lock( &p_input->netlist.lock );
104 /* Free the TS structure. */
105 #ifdef INPUT_LIFO_TS_NETLIST
106 p_input->netlist.i_ts_index--;
107 p_input->netlist.p_ts_free[p_input->netlist.i_ts_index].iov_base = p_ts_packet;
109 p_input->netlist.p_ts_free[p_input->netlist.i_ts_end].iov_base = p_ts_packet;
110 p_input->netlist.i_ts_end++;
111 p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
114 vlc_mutex_unlock( &p_input->netlist.lock );
117 /*****************************************************************************
118 * input_NetlistGetPES: remove a PES packet from the netlist
119 *****************************************************************************
120 * Add a TS packet to the TS netlist, so that the packet can immediately be
121 * reused by the demultiplexer. Shouldn't be called by other threads (they
122 * should only use input_FreePES.
123 *****************************************************************************/
124 static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input )
126 pes_packet_t * p_pes_packet;
128 #ifdef INPUT_LIFO_PES_NETLIST
129 /* i_pes_index might be accessed by a decoder thread to give back a
131 vlc_mutex_lock( &p_input->netlist.lock );
133 /* Verify that we still have PES packet in the netlist */
134 if( (INPUT_MAX_PES - p_input->netlist.i_pes_index ) <= 1 )
136 intf_ErrMsg("input error: PES netlist is empty !\n");
140 /* Fetch a new PES packet */
141 p_pes_packet = p_input->netlist.p_pes_free[p_input->netlist.i_pes_index];
142 p_input->netlist.i_pes_index++;
143 vlc_mutex_unlock( &p_input->netlist.lock );
146 /* No need to lock, since we are the only ones accessing i_pes_start. */
148 /* Verify that we still have PES packet in the netlist */
149 if( ((p_input->netlist.i_pes_end -1 - p_input->netlist.i_pes_start) & INPUT_MAX_PES) <= 1 )
151 intf_ErrMsg("input error: PES netlist is empty !\n");
155 p_pes_packet = p_input->netlist.p_pes_free[p_input->netlist.i_pes_start];
156 p_input->netlist.i_pes_start++;
157 p_input->netlist.i_pes_start &= INPUT_MAX_PES; /* loop */
158 #endif /* netlist type */
160 /* Initialize PES flags. */
161 p_pes_packet->b_data_loss = 0;
162 p_pes_packet->b_data_alignment = 0;
163 p_pes_packet->b_has_pts = 0;
164 p_pes_packet->b_random_access = 0;
165 p_pes_packet->b_discard_payload = 0;
166 p_pes_packet->i_pes_size = 0;
167 p_pes_packet->i_ts_packets = 0;
168 p_pes_packet->p_first_ts = NULL;
169 p_pes_packet->p_last_ts = NULL;
171 return( p_pes_packet );