]> git.sesse.net Git - vlc/blob - src/input/input_ext-intf.c
b4921ae6d02a1a1d5c3c0c8902a6ff3e52de4f23
[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     char        psz_time1[OFFSETTOTIME_MAX_SIZE];
141     char        psz_time2[OFFSETTOTIME_MAX_SIZE];
142
143     vlc_mutex_lock( &p_input->stream.stream_lock );
144     p_input->stream.p_selected_area->i_seek = i_position;
145
146     intf_Msg( "input: seeking position %lld/%lld (%s/%s)", i_position,
147                     p_input->stream.p_selected_area->i_size,
148                     input_OffsetToTime( p_input, psz_time1, i_position ),
149                     input_OffsetToTime( p_input, psz_time2,
150                                 p_input->stream.p_selected_area->i_size ) );
151
152     vlc_cond_signal( &p_input->stream.stream_wait );
153     vlc_mutex_unlock( &p_input->stream.stream_lock );
154 }
155
156 /*****************************************************************************
157  * input_OffsetToTime : converts an off_t value to a time indicator, using
158  *                      mux_rate
159  *****************************************************************************
160  * BEWARE : this function assumes that you already own the lock on
161  * p_input->stream.stream_lock
162  *****************************************************************************/
163 char * input_OffsetToTime( input_thread_t * p_input, char * psz_buffer,
164                            off_t i_offset )
165 {
166     mtime_t         i_seconds;
167
168     if( p_input->stream.i_mux_rate )
169     {
170         i_seconds = i_offset / 50 / p_input->stream.i_mux_rate;
171         snprintf( psz_buffer, OFFSETTOTIME_MAX_SIZE, "%d:%02d:%02d",
172                  (int) (i_seconds / (60 * 60)),
173                  (int) (i_seconds / 60 % 60),
174                  (int) (i_seconds % 60) );
175         return( psz_buffer );
176     }
177     else
178     {
179         /* Divide by zero is not my friend. */
180         sprintf( psz_buffer, "NA" );
181         return( psz_buffer );
182     }
183 }
184
185 /*****************************************************************************
186  * input_DumpStream: dumps the contents of a stream descriptor
187  *****************************************************************************
188  * BEWARE : this function assumes that you already own the lock on
189  * p_input->stream.stream_lock
190  *****************************************************************************/
191 void input_DumpStream( input_thread_t * p_input )
192 {
193     int         i, j;
194     char        psz_time1[OFFSETTOTIME_MAX_SIZE];
195     char        psz_time2[OFFSETTOTIME_MAX_SIZE];
196
197 #define S   p_input->stream
198     intf_Msg( "input info: Dumping stream ID 0x%x", S.i_stream_id );
199     if( S.b_seekable )
200         intf_Msg( "input info: seekable stream, position: %lld/%lld (%s/%s)",
201                   S.p_selected_area->i_tell, S.p_selected_area->i_size,
202                   input_OffsetToTime( p_input, psz_time1,
203                                       S.p_selected_area->i_tell ),
204                   input_OffsetToTime( p_input, psz_time2,
205                                       S.p_selected_area->i_size ) );
206     else
207         intf_Msg( "input info: %s", S.b_pace_control ? "pace controlled" :
208                   "pace un-controlled" );
209 #undef S
210     for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
211     {
212 #define P   p_input->stream.pp_programs[i]
213         intf_Msg( "input info: Dumping program 0x%x, version %d (%s)",
214                   P->i_number, P->i_version,
215                   P->b_is_ok ? "complete" : "partial" );
216 #undef P
217         for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
218         {
219 #define ES  p_input->stream.pp_programs[i]->pp_es[j]
220             intf_Msg( "input info: ES 0x%x, stream 0x%x, type 0x%x, %s",
221                       ES->i_id, ES->i_stream_id, ES->i_type,
222                       ES->p_decoder_fifo != NULL ? "selected" : "not selected");
223 #undef ES
224         }
225     }
226 }
227
228 /*****************************************************************************
229  * input_ChangeES: answers to a user request with calls to (Un)SelectES
230  * ---
231  * Useful since the interface plugins know p_es
232  *****************************************************************************/
233 int input_ChangeES( input_thread_t * p_input, es_descriptor_t * p_es,
234                     int i_type )
235 {
236     boolean_t               b_audio;
237     boolean_t               b_spu;
238     int                     i_index;
239     int                     i;
240
241     i_index = -1;
242     b_audio = ( i_type == 1 ) ? 1 : 0;
243     b_spu   = ( i_type == 2 ) ? 1 : 0;
244
245     vlc_mutex_lock( &p_input->stream.stream_lock );
246
247     for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
248     {
249         if( ( b_audio && p_input->stream.pp_selected_es[i]->b_audio ) 
250          || ( b_spu   && p_input->stream.pp_selected_es[i]->b_spu ) )
251         {
252             i_index = i;
253             break;
254         }
255     }
256
257
258     if( p_es != NULL )
259     {
260
261     
262         if( i_index != -1 )
263         {
264             
265             if( p_input->stream.pp_selected_es[i_index] != p_es )
266             {
267                 input_UnselectES( p_input,
268                                   p_input->stream.pp_selected_es[i_index] );
269                 input_SelectES( p_input, p_es );
270                 intf_WarnMsg( 1, "input info: es selected -> %s (0x%x)",
271                                                 p_es->psz_desc, p_es->i_id );
272             }
273         }
274         else
275         {
276             input_SelectES( p_input, p_es );
277             intf_WarnMsg( 1, "input info: es selected -> %s (0x%x)",
278                           p_es->psz_desc, p_es->i_id );
279         }
280     }
281     else
282     {
283         if( i_index != -1 )
284         {
285             intf_WarnMsg( 1, "input info: es unselected -> %s (0x%x)",
286                           p_input->stream.pp_selected_es[i_index]->psz_desc,
287                           p_input->stream.pp_selected_es[i_index]->i_id );
288
289             input_UnselectES( p_input,
290                               p_input->stream.pp_selected_es[i_index] );
291         }
292     }
293
294     vlc_mutex_unlock( &p_input->stream.stream_lock );
295
296     return 0;
297 }