]> git.sesse.net Git - vlc/blob - src/input/input_ext-intf.c
* Header cleaning: filled all empty authors fields, added CVS $Id stuff.
[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  * $Id: input_ext-intf.c,v 1.17 2001/03/21 13:42:34 sam 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 #include "defs.h"
28
29 #include "config.h"
30 #include "common.h"
31 #include "threads.h"
32 #include "mtime.h"
33
34 #include "intf_msg.h"
35
36 #include "stream_control.h"
37 #include "input_ext-dec.h"
38 #include "input_ext-intf.h"
39
40 #include "input.h"
41
42 /*****************************************************************************
43  * input_SetStatus: change the reading status
44  *****************************************************************************/
45 void input_SetStatus( input_thread_t * p_input, int i_mode )
46 {
47     vlc_mutex_lock( &p_input->stream.stream_lock );
48
49     switch( i_mode )
50     {
51     case INPUT_STATUS_END:
52         p_input->stream.i_new_status = PLAYING_S;
53         p_input->b_eof = 1;
54         intf_Msg( "input: end of stream" );
55         break;
56
57     case INPUT_STATUS_PLAY:
58         p_input->stream.i_new_status = PLAYING_S;
59         intf_Msg( "input: playing at normal rate" );
60         break;
61
62     case INPUT_STATUS_PAUSE:
63         /* XXX: we don't need to check i_status, because input_clock.c
64          * does it for us */
65         p_input->stream.i_new_status = PAUSE_S;
66         intf_Msg( "input: toggling pause" );
67         break;
68
69     case INPUT_STATUS_FASTER:
70         /* If we are already going too fast, go back to default rate */
71         if( p_input->stream.control.i_rate * 8 <= DEFAULT_RATE )
72         {
73             p_input->stream.i_new_status = PLAYING_S;
74             intf_Msg( "input: playing at normal rate" );
75         }
76         else
77         {
78             p_input->stream.i_new_status = FORWARD_S;
79
80             if( p_input->stream.control.i_rate < DEFAULT_RATE
81                     && p_input->stream.control.i_status == FORWARD_S )
82             {
83                 p_input->stream.i_new_rate =
84                                     p_input->stream.control.i_rate / 2;
85             }
86             else
87             {
88                 p_input->stream.i_new_rate = DEFAULT_RATE / 2;
89             }
90             intf_Msg( "input: playing at %i:1 fast forward",
91                       DEFAULT_RATE / p_input->stream.i_new_rate );
92         }
93         break;
94
95     case INPUT_STATUS_SLOWER:
96         /* If we are already going too slow, go back to default rate */
97         if( p_input->stream.control.i_rate >= 8 * DEFAULT_RATE )
98         {
99             p_input->stream.i_new_status = PLAYING_S;
100             intf_Msg( "input: playing at normal rate" );
101         }
102         else
103         {
104             p_input->stream.i_new_status = FORWARD_S;
105
106             if( p_input->stream.control.i_rate > DEFAULT_RATE
107                     && p_input->stream.control.i_status == FORWARD_S )
108             {
109                 p_input->stream.i_new_rate =
110                                     p_input->stream.control.i_rate * 2;
111             }
112             else
113             {
114                 p_input->stream.i_new_rate = DEFAULT_RATE * 2;
115             }
116             intf_Msg( "input: playing at 1:%i slow motion",
117                       p_input->stream.i_new_rate / DEFAULT_RATE );
118         }
119         break;
120
121     default:
122     }
123
124     vlc_cond_signal( &p_input->stream.stream_wait );
125     vlc_mutex_unlock( &p_input->stream.stream_lock );
126 }
127
128 /*****************************************************************************
129  * input_SetRate: change the reading rate
130  *****************************************************************************/
131 void input_SetRate( input_thread_t * p_input, int i_mode )
132 {
133     ; /* FIXME: stub */
134 }
135  
136 /*****************************************************************************
137  * input_Seek: changes the stream postion
138  *****************************************************************************/
139 void input_Seek( input_thread_t * p_input, off_t i_position )
140 {
141     char        psz_time1[OFFSETTOTIME_MAX_SIZE];
142     char        psz_time2[OFFSETTOTIME_MAX_SIZE];
143
144     vlc_mutex_lock( &p_input->stream.stream_lock );
145     p_input->stream.p_selected_area->i_seek = i_position;
146
147     intf_Msg( "input: seeking position %lld/%lld (%s/%s)", i_position,
148                     p_input->stream.p_selected_area->i_size,
149                     input_OffsetToTime( p_input, psz_time1, i_position ),
150                     input_OffsetToTime( p_input, psz_time2,
151                                 p_input->stream.p_selected_area->i_size ) );
152
153     vlc_cond_signal( &p_input->stream.stream_wait );
154     vlc_mutex_unlock( &p_input->stream.stream_lock );
155 }
156
157 /*****************************************************************************
158  * input_OffsetToTime : converts an off_t value to a time indicator, using
159  *                      mux_rate
160  *****************************************************************************
161  * BEWARE : this function assumes that you already own the lock on
162  * p_input->stream.stream_lock
163  *****************************************************************************/
164 char * input_OffsetToTime( input_thread_t * p_input, char * psz_buffer,
165                            off_t i_offset )
166 {
167     mtime_t         i_seconds;
168
169     if( p_input->stream.i_mux_rate )
170     {
171         i_seconds = i_offset / 50 / p_input->stream.i_mux_rate;
172         snprintf( psz_buffer, OFFSETTOTIME_MAX_SIZE, "%d:%02d:%02d",
173                  (int) (i_seconds / (60 * 60)),
174                  (int) (i_seconds / 60 % 60),
175                  (int) (i_seconds % 60) );
176         return( psz_buffer );
177     }
178     else
179     {
180         /* Divide by zero is not my friend. */
181         sprintf( psz_buffer, "-:--:--" );
182         return( psz_buffer );
183     }
184 }
185
186 /*****************************************************************************
187  * input_DumpStream: dumps the contents of a stream descriptor
188  *****************************************************************************
189  * BEWARE : this function assumes that you already own the lock on
190  * p_input->stream.stream_lock
191  *****************************************************************************/
192 void input_DumpStream( input_thread_t * p_input )
193 {
194     int         i, j;
195     char        psz_time1[OFFSETTOTIME_MAX_SIZE];
196     char        psz_time2[OFFSETTOTIME_MAX_SIZE];
197
198 #define S   p_input->stream
199     intf_Msg( "input info: Dumping stream ID 0x%x", S.i_stream_id );
200     if( S.b_seekable )
201         intf_Msg( "input info: seekable stream, position: %lld/%lld (%s/%s)",
202                   S.p_selected_area->i_tell, S.p_selected_area->i_size,
203                   input_OffsetToTime( p_input, psz_time1,
204                                       S.p_selected_area->i_tell ),
205                   input_OffsetToTime( p_input, psz_time2,
206                                       S.p_selected_area->i_size ) );
207     else
208         intf_Msg( "input info: %s", S.b_pace_control ? "pace controlled" :
209                   "pace un-controlled" );
210 #undef S
211     for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
212     {
213 #define P   p_input->stream.pp_programs[i]
214         intf_Msg( "input info: Dumping program 0x%x, version %d (%s)",
215                   P->i_number, P->i_version,
216                   P->b_is_ok ? "complete" : "partial" );
217 #undef P
218         for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
219         {
220 #define ES  p_input->stream.pp_programs[i]->pp_es[j]
221             intf_Msg( "input info: ES 0x%x, stream 0x%x, type 0x%x, %s",
222                       ES->i_id, ES->i_stream_id, ES->i_type,
223                       ES->p_decoder_fifo != NULL ? "selected" : "not selected");
224 #undef ES
225         }
226     }
227 }
228
229 /*****************************************************************************
230  * input_ChangeES: answers to a user request with calls to (Un)SelectES
231  * ---
232  * Useful since the interface plugins know p_es
233  *****************************************************************************/
234 int input_ChangeES( input_thread_t * p_input, es_descriptor_t * p_es,
235                     int i_type )
236 {
237     boolean_t               b_audio;
238     boolean_t               b_spu;
239     int                     i_index;
240     int                     i;
241
242     i_index = -1;
243     b_audio = ( i_type == 1 ) ? 1 : 0;
244     b_spu   = ( i_type == 2 ) ? 1 : 0;
245
246     vlc_mutex_lock( &p_input->stream.stream_lock );
247
248     for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
249     {
250         if( ( b_audio && p_input->stream.pp_selected_es[i]->b_audio ) 
251          || ( b_spu   && p_input->stream.pp_selected_es[i]->b_spu ) )
252         {
253             i_index = i;
254             break;
255         }
256     }
257
258
259     if( p_es != NULL )
260     {
261
262     
263         if( i_index != -1 )
264         {
265             
266             if( p_input->stream.pp_selected_es[i_index] != p_es )
267             {
268                 input_UnselectES( p_input,
269                                   p_input->stream.pp_selected_es[i_index] );
270                 input_SelectES( p_input, p_es );
271                 intf_WarnMsg( 1, "input info: es selected -> %s (0x%x)",
272                                                 p_es->psz_desc, p_es->i_id );
273             }
274         }
275         else
276         {
277             input_SelectES( p_input, p_es );
278             intf_WarnMsg( 1, "input info: es selected -> %s (0x%x)",
279                           p_es->psz_desc, p_es->i_id );
280         }
281     }
282     else
283     {
284         if( i_index != -1 )
285         {
286             intf_WarnMsg( 1, "input info: es unselected -> %s (0x%x)",
287                           p_input->stream.pp_selected_es[i_index]->psz_desc,
288                           p_input->stream.pp_selected_es[i_index]->i_id );
289
290             input_UnselectES( p_input,
291                               p_input->stream.pp_selected_es[i_index] );
292         }
293     }
294
295     vlc_mutex_unlock( &p_input->stream.stream_lock );
296
297     return 0;
298 }