1 /*****************************************************************************
2 * input_dec.c: Functions for the management of decoders
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: input_dec.c,v 1.8 2001/02/08 13:52:35 massiot Exp $
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
36 #include "stream_control.h"
37 #include "input_ext-dec.h"
38 #include "input_ext-intf.h"
42 /*****************************************************************************
43 * input_RunDecoder: spawns a new decoder thread
44 *****************************************************************************/
45 vlc_thread_t input_RunDecoder( decoder_capabilities_t * p_decoder,
48 return( p_decoder->pf_create_thread( p_data ) );
51 /*****************************************************************************
52 * input_EndDecoder: kills a decoder thread and waits until it's finished
53 *****************************************************************************/
54 void input_EndDecoder( input_thread_t * p_input, es_descriptor_t * p_es )
58 p_es->p_decoder_fifo->b_die = 1;
60 /* Make sure the thread leaves the NextDataPacket() function by
61 * sending it a few null packets. */
62 for( i_dummy = 0; i_dummy < PADDING_PACKET_NUMBER; i_dummy++ )
64 input_NullPacket( p_input, p_es );
67 if( p_es->p_pes != NULL )
69 input_DecodePES( p_es->p_decoder_fifo, p_es->p_pes );
72 /* Waiting for the thread to exit */
73 vlc_thread_join( p_es->thread_id );
75 /* Freeing all packets still in the decoder fifo. */
76 while( !DECODER_FIFO_ISEMPTY( *p_es->p_decoder_fifo ) )
78 p_es->p_decoder_fifo->pf_delete_pes(
79 p_es->p_decoder_fifo->p_packets_mgt,
80 DECODER_FIFO_START( *p_es->p_decoder_fifo ) );
81 DECODER_FIFO_INCSTART( *p_es->p_decoder_fifo );
84 /* Destroy the lock and cond */
85 vlc_cond_destroy( &p_es->p_decoder_fifo->data_wait );
86 vlc_mutex_destroy( &p_es->p_decoder_fifo->data_lock );
88 free( p_es->p_decoder_fifo );
89 p_es->p_decoder_fifo = NULL;
92 /*****************************************************************************
94 *****************************************************************************
95 * Put a PES in the decoder's fifo.
96 *****************************************************************************/
97 void input_DecodePES( decoder_fifo_t * p_decoder_fifo, pes_packet_t * p_pes )
99 vlc_mutex_lock( &p_decoder_fifo->data_lock );
101 if( !DECODER_FIFO_ISFULL( *p_decoder_fifo ) )
103 p_decoder_fifo->buffer[p_decoder_fifo->i_end] = p_pes;
104 DECODER_FIFO_INCEND( *p_decoder_fifo );
106 /* Warn the decoder that it's got work to do. */
107 vlc_cond_signal( &p_decoder_fifo->data_wait );
111 /* The FIFO is full !!! This should not happen. */
112 p_decoder_fifo->pf_delete_pes( p_decoder_fifo->p_packets_mgt,
114 intf_ErrMsg( "PES trashed - fifo full !" );
116 vlc_mutex_unlock( &p_decoder_fifo->data_lock );
119 /*****************************************************************************
120 * input_EscapeDiscontinuity: send a NULL packet to the decoders
121 *****************************************************************************/
122 void input_EscapeDiscontinuity( input_thread_t * p_input,
123 pgrm_descriptor_t * p_pgrm )
127 for( i_es = 0; i_es < p_pgrm->i_es_number; i_es++ )
129 es_descriptor_t * p_es = p_pgrm->pp_es[i_es];
131 if( p_es->p_decoder_fifo != NULL )
133 for( i = 0; i < PADDING_PACKET_NUMBER; i++ )
135 input_NullPacket( p_input, p_es );
141 /*****************************************************************************
142 * input_EscapeAudioDiscontinuity: send a NULL packet to the audio decoders
143 *****************************************************************************/
144 void input_EscapeAudioDiscontinuity( input_thread_t * p_input,
145 pgrm_descriptor_t * p_pgrm )
149 for( i_es = 0; i_es < p_pgrm->i_es_number; i_es++ )
151 es_descriptor_t * p_es = p_pgrm->pp_es[i_es];
153 if( p_es->p_decoder_fifo != NULL && p_es->b_audio )
155 for( i = 0; i < PADDING_PACKET_NUMBER; i++ )
157 input_NullPacket( p_input, p_es );