]> git.sesse.net Git - vlc/blob - src/input/input_dec.c
* New decoder spawning API input_dec.c ;
[vlc] / src / input / input_dec.c
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.1 2000/12/21 19:24:27 massiot Exp $
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 /* FIXME: we shouldn't be obliged to include these */
28 #include "defs.h"
29
30 #include "config.h"
31 #include "common.h"
32 #include "threads.h"
33 #include "mtime.h"
34
35 #include "stream_control.h"
36 #include "input_ext-dec.h"
37
38 /*****************************************************************************
39  * input_RunDecoder: spawns a new decoder thread
40  *****************************************************************************/
41 vlc_thread_t input_RunDecoder( decoder_capabilities_t * p_decoder,
42                                void * p_data )
43 {
44     return( p_decoder->pf_create_thread( p_data ) );
45 }
46
47 /*****************************************************************************
48  * input_EndDecoder: kills a decoder thread and waits until it's finished
49  *****************************************************************************/
50 void input_EndDecoder( decoder_fifo_t * p_decoder_fifo, vlc_thread_t thread_id )
51 {
52     p_decoder_fifo->b_die = 1;
53
54     /* Make sure the thread leaves the NextDataPacket() function */
55     vlc_mutex_lock( &p_decoder_fifo->data_lock);
56     vlc_cond_signal( &p_decoder_fifo->data_wait );
57     vlc_mutex_unlock( &p_decoder_fifo->data_lock );
58
59     /* Waiting for the thread to exit */
60     vlc_thread_join( thread_id );
61
62     /* Freeing all packets still in the decoder fifo. */
63     while( !DECODER_FIFO_ISEMPTY( *p_decoder_fifo ) )
64     {
65         p_decoder_fifo->pf_delete_pes( p_decoder_fifo->p_packets_mgt,
66                                        DECODER_FIFO_START( *p_decoder_fifo ) );
67         DECODER_FIFO_INCSTART( *p_decoder_fifo );
68     }
69 }
70