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_NetlistInit ( input_thread_t *p_input );
14 void input_NetlistEnd ( input_thread_t *p_input );
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 );
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 )
31 ts_packet_t * p_ts_packet;
35 /* We will be playing with indexes, so we take a lock. */
36 vlc_mutex_lock( &p_input->netlist.lock );
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++ )
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
49 p_input->netlist.p_ts_free[p_input->netlist.i_ts_end].iov_base
51 p_input->netlist.i_ts_end++;
52 p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
54 p_ts_packet = p_ts_packet->p_next_ts;
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;
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 */
67 vlc_mutex_unlock( &p_input->netlist.lock );
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 )
82 /* We will be playing with indexes, so we take a lock. */
83 vlc_mutex_lock( &p_input->netlist.lock );
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;
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 */
95 vlc_mutex_unlock( &p_input->netlist.lock );
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 )
107 pes_packet_t * p_pes_packet;
109 #ifdef INPUT_LIFO_PES_NETLIST
110 /* i_pes_index might be accessed by a decoder thread to give back a
112 vlc_mutex_lock( &p_input->netlist.lock );
114 /* Verify that we still have PES packet in the netlist */
115 if( (INPUT_MAX_PES - p_input->netlist.i_pes_index ) <= 1 )
117 intf_ErrMsg("input error: PES netlist is empty !\n");
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 );
127 /* No need to lock, since we are the only ones accessing i_pes_start. */
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 )
132 intf_ErrMsg("input error: PES netlist is empty !\n");
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 */
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;
152 return( p_pes_packet );