]> git.sesse.net Git - vlc/blob - src/input/input_ext-intf.c
* Fixed a segfault in the input thread creation, as well as a possible
[vlc] / src / input / input_ext-intf.c
1 /*****************************************************************************
2  * input_ext-intf.c: services to the interface
3  *****************************************************************************
4  * Copyright (C) 1998, 1999, 2000 VideoLAN
5  *
6  * Authors: Christophe Massiot <massiot@via.ecp.fr>
7  *
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.
12  * 
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
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include "defs.h"
27
28 #include "config.h"
29 #include "common.h"
30 #include "threads.h"
31 #include "mtime.h"
32
33 #include "intf_msg.h"
34
35 #include "stream_control.h"
36 #include "input_ext-dec.h"
37 #include "input_ext-intf.h"
38
39 #include "input.h"
40
41 /*****************************************************************************
42  * input_SetStatus: change the reading status
43  *****************************************************************************/
44 void input_SetStatus( input_thread_t * p_input, int i_mode )
45 {
46     vlc_mutex_lock( &p_input->stream.stream_lock );
47
48     switch( i_mode )
49     {
50     case INPUT_STATUS_END:
51         p_input->stream.i_new_status = PLAYING_S;
52         p_input->b_eof = 1;
53         intf_Msg( "input: end of stream" );
54         break;
55
56     case INPUT_STATUS_PLAY:
57         p_input->stream.i_new_status = PLAYING_S;
58         intf_Msg( "input: playing at normal rate" );
59         break;
60
61     case INPUT_STATUS_PAUSE:
62         /* XXX: we don't need to check i_status, because input_clock.c
63          * does it for us */
64         p_input->stream.i_new_status = PAUSE_S;
65         intf_Msg( "input: toggling pause" );
66         break;
67
68     case INPUT_STATUS_FASTER:
69         /* If we are already going too fast, go back to default rate */
70         if( p_input->stream.control.i_rate * 8 <= DEFAULT_RATE )
71         {
72             p_input->stream.i_new_status = PLAYING_S;
73             intf_Msg( "input: playing at normal rate" );
74         }
75         else
76         {
77             p_input->stream.i_new_status = FORWARD_S;
78
79             if( p_input->stream.control.i_rate < DEFAULT_RATE
80                     && p_input->stream.control.i_status == FORWARD_S )
81             {
82                 p_input->stream.i_new_rate =
83                                     p_input->stream.control.i_rate / 2;
84             }
85             else
86             {
87                 p_input->stream.i_new_rate = DEFAULT_RATE / 2;
88             }
89             intf_Msg( "input: playing at %i:1 fast forward",
90                       DEFAULT_RATE / p_input->stream.i_new_rate );
91         }
92         break;
93
94     case INPUT_STATUS_SLOWER:
95         /* If we are already going too slow, go back to default rate */
96         if( p_input->stream.control.i_rate >= 8 * DEFAULT_RATE )
97         {
98             p_input->stream.i_new_status = PLAYING_S;
99             intf_Msg( "input: playing at normal rate" );
100         }
101         else
102         {
103             p_input->stream.i_new_status = FORWARD_S;
104
105             if( p_input->stream.control.i_rate > DEFAULT_RATE
106                     && p_input->stream.control.i_status == FORWARD_S )
107             {
108                 p_input->stream.i_new_rate =
109                                     p_input->stream.control.i_rate * 2;
110             }
111             else
112             {
113                 p_input->stream.i_new_rate = DEFAULT_RATE * 2;
114             }
115             intf_Msg( "input: playing at 1:%i slow motion",
116                       p_input->stream.i_new_rate / DEFAULT_RATE );
117         }
118         break;
119
120     default:
121     }
122
123     vlc_cond_signal( &p_input->stream.stream_wait );
124     vlc_mutex_unlock( &p_input->stream.stream_lock );
125 }
126
127 /*****************************************************************************
128  * input_SetRate: change the reading rate
129  *****************************************************************************/
130 void input_SetRate( input_thread_t * p_input, int i_mode )
131 {
132     ; /* FIXME: stub */
133 }
134  
135 /*****************************************************************************
136  * input_Seek: changes the stream postion
137  *****************************************************************************/
138 void input_Seek( input_thread_t * p_input, off_t i_position )
139 {
140     vlc_mutex_lock( &p_input->stream.stream_lock );
141     p_input->stream.i_seek = i_position;
142
143     intf_Msg( "input: seeking position %lld/%lld", i_position,
144                                                    p_input->stream.i_size );
145
146     vlc_cond_signal( &p_input->stream.stream_wait );
147     vlc_mutex_unlock( &p_input->stream.stream_lock );
148 }
149