+/*****************************************************************************
+ * GetPES: return the first PES from the fifo
+ *****************************************************************************/
+static inline pes_packet_t *_GetPES( decoder_fifo_t * p_fifo )
+{
+ pes_packet_t * p_pes;
+
+ vlc_mutex_lock( &p_fifo->data_lock );
+
+ if( p_fifo->p_first == NULL )
+ {
+ /* No PES in the FIFO. p_last is no longer valid. */
+ p_fifo->pp_last = &p_fifo->p_first;
+
+ if( p_fifo->b_die )
+ {
+ vlc_mutex_unlock( &p_fifo->data_lock );
+ return NULL;
+ }
+
+ /* Signal the input thread we're waiting. This is only
+ * needed in case of slave clock (ES plug-in) but it won't
+ * harm. */
+ vlc_cond_signal( &p_fifo->data_wait );
+
+ /* Wait for the input to tell us when we receive a packet. */
+ vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
+ }
+
+ p_pes = p_fifo->p_first;
+
+ vlc_mutex_unlock( &p_fifo->data_lock );
+
+ return p_pes;
+}
+
+pes_packet_t * GetPES( decoder_fifo_t * p_fifo )
+{
+ return( _GetPES( p_fifo ) );
+}
+
+/*****************************************************************************
+ * NextPES: free the current PES and return the next one
+ *****************************************************************************/
+static inline pes_packet_t * _NextPES( decoder_fifo_t * p_fifo )
+{
+ pes_packet_t * p_next;
+
+ vlc_mutex_lock( &p_fifo->data_lock );
+
+ /* Free the previous PES packet. */
+ p_next = p_fifo->p_first->p_next;
+ p_fifo->p_first->p_next = NULL;
+ input_DeletePES( p_fifo->p_packets_mgt, p_fifo->p_first );
+ p_fifo->p_first = p_next;
+ p_fifo->i_depth--;
+
+ vlc_mutex_unlock( &p_fifo->data_lock );
+
+ return _GetPES( p_fifo );
+}
+
+pes_packet_t * NextPES( decoder_fifo_t * p_fifo )
+{
+ return( _NextPES( p_fifo ) );
+}
+