1 /*****************************************************************************
2 * decoder_fifo.c: auxiliaries functions used in decoder_fifo.h
3 *****************************************************************************
4 * Copyright (C) 1998, 1999, 2000 VideoLAN
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 *****************************************************************************/
24 #include <sys/types.h> /* on BSD, uio.h needs types.h */
25 #include <sys/uio.h> /* for input.h */
32 #include "debug.h" /* XXX?? temporaire, requis par netlist.h */
35 #include "input_netlist.h"
36 #include "decoder_fifo.h"
38 void decoder_fifo_next( bit_stream_t * p_bit_stream )
40 /* We are looking for the next TS packet that contains real data,
41 * and not just a PES header */
44 /* We were reading the last TS packet of this PES packet... It's
45 * time to jump to the next PES packet */
46 if ( p_bit_stream->p_ts->p_next_ts == NULL )
48 /* We are going to read/write the start and end indexes of the
49 * decoder fifo and to use the fifo's conditional variable,
50 * that's why we need to take the lock before */
51 vlc_mutex_lock( &p_bit_stream->p_decoder_fifo->data_lock );
53 /* Is the input thread dying ? */
54 if ( p_bit_stream->p_input->b_die )
56 vlc_mutex_unlock( &(p_bit_stream->p_decoder_fifo->data_lock) );
60 /* We should increase the start index of the decoder fifo, but
61 * if we do this now, the input thread could overwrite the
62 * pointer to the current PES packet, and we weren't able to
63 * give it back to the netlist. That's why we free the PES
65 input_NetlistFreePES( p_bit_stream->p_input, DECODER_FIFO_START(*p_bit_stream->p_decoder_fifo) );
66 DECODER_FIFO_INCSTART( *p_bit_stream->p_decoder_fifo );
68 while ( DECODER_FIFO_ISEMPTY(*p_bit_stream->p_decoder_fifo) )
70 vlc_cond_wait( &p_bit_stream->p_decoder_fifo->data_wait, &p_bit_stream->p_decoder_fifo->data_lock );
71 if ( p_bit_stream->p_input->b_die )
73 vlc_mutex_unlock( &(p_bit_stream->p_decoder_fifo->data_lock) );
78 /* The next byte could be found in the next PES packet */
79 p_bit_stream->p_ts = DECODER_FIFO_START( *p_bit_stream->p_decoder_fifo )->p_first_ts;
81 /* We can release the fifo's data lock */
82 vlc_mutex_unlock( &p_bit_stream->p_decoder_fifo->data_lock );
84 /* Perhaps the next TS packet of the current PES packet contains
85 * real data (ie its payload's size is greater than 0) */
88 p_bit_stream->p_ts = p_bit_stream->p_ts->p_next_ts;
90 } while ( p_bit_stream->p_ts->i_payload_start == p_bit_stream->p_ts->i_payload_end );
92 /* We've found a TS packet which contains interesting data... */
93 p_bit_stream->p_byte = p_bit_stream->p_ts->buffer + p_bit_stream->p_ts->i_payload_start;
94 p_bit_stream->p_end = p_bit_stream->p_ts->buffer + p_bit_stream->p_ts->i_payload_end;