1 /*******************************************************************************
2 * input_netlist.h: netlist interface
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
8 *******************************************************************************/
10 /******************************************************************************
12 ******************************************************************************/
13 int input_NetlistOpen( input_thread_t *p_input );
14 void input_NetlistClean( input_thread_t *p_input );
15 /* ?? implement also a "normal" (non inline, non static) function in input_netlist.c,
16 which will be used when inline is disabled */
17 /* ?? test */ static __inline__ void input_NetlistFreePES( input_thread_t *p_input,
18 pes_packet_t *p_pes_packet );
19 static __inline__ void input_NetlistFreeTS( input_thread_t *p_input,
20 ts_packet_t *p_ts_packet );
21 static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input );
23 /*******************************************************************************
24 * input_NetlistFreePES: add a PES packet to the netlist
25 *******************************************************************************
26 * Add a PES packet to the PES netlist, so that the packet can immediately be
27 * reused by the demultiplexer. We put this function directly in the .h file,
28 * because it is very frequently called.
29 *******************************************************************************/
30 static __inline__ void input_NetlistFreePES( input_thread_t *p_input,
31 pes_packet_t *p_pes_packet )
34 ts_packet_t * p_ts_packet;
38 /* We will be playing with indexes, so we take a lock. */
39 vlc_mutex_lock( &p_input->netlist.lock );
41 /* Free all TS packets in this PES structure. */
42 p_ts_packet = p_pes_packet->p_first_ts;
43 for( i_dummy = 0; i_dummy < p_pes_packet->i_ts_packets; i_dummy++ )
47 #ifdef INPUT_LIFO_TS_NETLIST
48 p_input->netlist.i_ts_index--;
49 p_input->netlist.p_ts_free[p_input->netlist.i_ts_index].iov_base
52 p_input->netlist.p_ts_free[p_input->netlist.i_ts_end].iov_base
54 p_input->netlist.i_ts_end++;
55 p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
57 p_ts_packet = p_ts_packet->p_next_ts;
60 /* Free the PES structure. */
61 #ifdef INPUT_LIFO_PES_NETLIST
62 p_input->netlist.i_pes_index--;
63 p_input->netlist.p_pes_free[p_input->netlist.i_pes_index] = p_pes_packet;
65 p_input->netlist.p_pes_free[p_input->netlist.i_pes_end] = p_pes_packet;
66 p_input->netlist.i_pes_end++;
67 p_input->netlist.i_pes_end &= INPUT_MAX_PES; /* loop */
70 vlc_mutex_unlock( &p_input->netlist.lock );
73 /*******************************************************************************
74 * input_NetlistFreeTS: add a TS packet to the netlist
75 *******************************************************************************
76 * Add a TS packet to the TS netlist, so that the packet can immediately be
77 * reused by the demultiplexer. Shouldn't be called by other threads (they
78 * should only use input_FreePES.
79 *******************************************************************************/
80 static __inline__ void input_NetlistFreeTS( input_thread_t *p_input,
81 ts_packet_t *p_ts_packet )
85 /* We will be playing with indexes, so we take a lock. */
86 vlc_mutex_lock( &p_input->netlist.lock );
88 /* Free the TS structure. */
89 #ifdef INPUT_LIFO_TS_NETLIST
90 p_input->netlist.i_ts_index--;
91 p_input->netlist.p_ts_free[p_input->netlist.i_ts_index].iov_base = p_ts_packet;
93 p_input->netlist.p_ts_free[p_input->netlist.i_ts_end].iov_base = p_ts_packet;
94 p_input->netlist.i_ts_end++;
95 p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
98 vlc_mutex_unlock( &p_input->netlist.lock );
101 /*******************************************************************************
102 * input_NetlistGetPES: remove a PES packet from the netlist
103 *******************************************************************************
104 * Add a TS packet to the TS netlist, so that the packet can immediately be
105 * reused by the demultiplexer. Shouldn't be called by other threads (they
106 * should only use input_FreePES.
107 *******************************************************************************/
108 static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input )
110 pes_packet_t * p_pes_packet;
112 #ifdef INPUT_LIFO_PES_NETLIST
113 /* i_pes_index might be accessed by a decoder thread to give back a
115 vlc_mutex_lock( &p_input->netlist.lock );
117 /* Verify that we still have PES packet in the netlist */
118 if( (INPUT_MAX_PES - p_input->netlist.i_pes_index ) <= 1 )
120 intf_ErrMsg("input error: PES netlist is empty !\n");
124 /* Fetch a new PES packet */
125 p_pes_packet = p_input->netlist.p_pes_free[p_input->netlist.i_pes_index];
126 p_input->netlist.i_pes_index++;
127 vlc_mutex_unlock( &p_input->netlist.lock );
130 /* No need to lock, since we are the only ones accessing i_pes_start. */
132 /* Verify that we still have PES packet in the netlist */
133 if( ((p_input->netlist.i_pes_end -1 - p_input->netlist.i_pes_start) & INPUT_MAX_PES) <= 1 )
135 intf_ErrMsg("input error: PES netlist is empty !\n");
139 p_pes_packet = p_input->netlist.p_pes_free[p_input->netlist.i_pes_start];
140 p_input->netlist.i_pes_start++;
141 p_input->netlist.i_pes_start &= INPUT_MAX_PES; /* loop */
142 #endif /* netlist type */
144 /* Initialize PES flags. */
145 p_pes_packet->b_data_loss = 0;
146 p_pes_packet->b_data_alignment = 0;
147 p_pes_packet->b_has_pts = 0;
148 p_pes_packet->b_random_access = 0;
149 p_pes_packet->b_discard_payload = 0;
150 p_pes_packet->i_pes_size = 0;
151 p_pes_packet->i_ts_packets = 0;
152 p_pes_packet->p_first_ts = NULL;
153 p_pes_packet->p_last_ts = NULL;
155 return( p_pes_packet );