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.22 2001/04/28 03:36:25 sam 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 *****************************************************************************/
29 #include <string.h> /* memcpy(), memset() */
30 #include <sys/types.h> /* off_t */
33 #define snprintf _snprintf
43 #include "stream_control.h"
44 #include "input_ext-dec.h"
45 #include "input_ext-intf.h"
49 /*****************************************************************************
50 * input_SetStatus: change the reading status
51 *****************************************************************************/
52 void input_SetStatus( input_thread_t * p_input, int i_mode )
54 vlc_mutex_lock( &p_input->stream.stream_lock );
58 case INPUT_STATUS_END:
59 p_input->stream.i_new_status = PLAYING_S;
61 intf_Msg( "input: end of stream" );
64 case INPUT_STATUS_PLAY:
65 p_input->stream.i_new_status = PLAYING_S;
66 intf_Msg( "input: playing at normal rate" );
69 case INPUT_STATUS_PAUSE:
70 /* XXX: we don't need to check i_status, because input_clock.c
72 p_input->stream.i_new_status = PAUSE_S;
73 intf_Msg( "input: toggling pause" );
76 case INPUT_STATUS_FASTER:
77 /* If we are already going too fast, go back to default rate */
78 if( p_input->stream.control.i_rate * 8 <= DEFAULT_RATE )
80 p_input->stream.i_new_status = PLAYING_S;
81 intf_Msg( "input: playing at normal rate" );
85 p_input->stream.i_new_status = FORWARD_S;
87 if( p_input->stream.control.i_rate < DEFAULT_RATE
88 && p_input->stream.control.i_status == FORWARD_S )
90 p_input->stream.i_new_rate =
91 p_input->stream.control.i_rate / 2;
95 p_input->stream.i_new_rate = DEFAULT_RATE / 2;
97 intf_Msg( "input: playing at %i:1 fast forward",
98 DEFAULT_RATE / p_input->stream.i_new_rate );
102 case INPUT_STATUS_SLOWER:
103 /* If we are already going too slow, go back to default rate */
104 if( p_input->stream.control.i_rate >= 8 * DEFAULT_RATE )
106 p_input->stream.i_new_status = PLAYING_S;
107 intf_Msg( "input: playing at normal rate" );
111 p_input->stream.i_new_status = FORWARD_S;
113 if( p_input->stream.control.i_rate > DEFAULT_RATE
114 && p_input->stream.control.i_status == FORWARD_S )
116 p_input->stream.i_new_rate =
117 p_input->stream.control.i_rate * 2;
121 p_input->stream.i_new_rate = DEFAULT_RATE * 2;
123 intf_Msg( "input: playing at 1:%i slow motion",
124 p_input->stream.i_new_rate / DEFAULT_RATE );
132 vlc_cond_signal( &p_input->stream.stream_wait );
133 vlc_mutex_unlock( &p_input->stream.stream_lock );
136 /*****************************************************************************
137 * input_SetRate: change the reading rate
138 *****************************************************************************/
139 void input_SetRate( input_thread_t * p_input, int i_mode )
144 /*****************************************************************************
145 * input_Seek: changes the stream postion
146 *****************************************************************************/
147 void input_Seek( input_thread_t * p_input, off_t i_position )
149 char psz_time1[OFFSETTOTIME_MAX_SIZE];
150 char psz_time2[OFFSETTOTIME_MAX_SIZE];
152 vlc_mutex_lock( &p_input->stream.stream_lock );
153 p_input->stream.p_selected_area->i_seek = i_position;
155 intf_WarnMsg( 1, "input: seeking position %lld/%lld (%s/%s)", i_position,
156 p_input->stream.p_selected_area->i_size,
157 input_OffsetToTime( p_input, psz_time1, i_position ),
158 input_OffsetToTime( p_input, psz_time2,
159 p_input->stream.p_selected_area->i_size ) );
161 vlc_cond_signal( &p_input->stream.stream_wait );
162 vlc_mutex_unlock( &p_input->stream.stream_lock );
165 /*****************************************************************************
166 * input_OffsetToTime : converts an off_t value to a time indicator, using
168 *****************************************************************************
169 * BEWARE : this function assumes that you already own the lock on
170 * p_input->stream.stream_lock
171 *****************************************************************************/
172 char * input_OffsetToTime( input_thread_t * p_input, char * psz_buffer,
177 if( p_input->stream.i_mux_rate )
179 i_seconds = i_offset / 50 / p_input->stream.i_mux_rate;
180 snprintf( psz_buffer, OFFSETTOTIME_MAX_SIZE, "%d:%02d:%02d",
181 (int) (i_seconds / (60 * 60)),
182 (int) (i_seconds / 60 % 60),
183 (int) (i_seconds % 60) );
184 return( psz_buffer );
188 /* Divide by zero is not my friend. */
189 sprintf( psz_buffer, "-:--:--" );
190 return( psz_buffer );
194 /*****************************************************************************
195 * input_DumpStream: dumps the contents of a stream descriptor
196 *****************************************************************************
197 * BEWARE : this function assumes that you already own the lock on
198 * p_input->stream.stream_lock
199 *****************************************************************************/
200 void input_DumpStream( input_thread_t * p_input )
203 char psz_time1[OFFSETTOTIME_MAX_SIZE];
204 char psz_time2[OFFSETTOTIME_MAX_SIZE];
206 #define S p_input->stream
207 intf_Msg( "input info: Dumping stream ID 0x%x", S.i_stream_id );
209 intf_Msg( "input info: seekable stream, position: %lld/%lld (%s/%s)",
210 S.p_selected_area->i_tell, S.p_selected_area->i_size,
211 input_OffsetToTime( p_input, psz_time1,
212 S.p_selected_area->i_tell ),
213 input_OffsetToTime( p_input, psz_time2,
214 S.p_selected_area->i_size ) );
216 intf_Msg( "input info: %s", S.b_pace_control ? "pace controlled" :
217 "pace un-controlled" );
219 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
221 #define P p_input->stream.pp_programs[i]
222 intf_Msg( "input info: Dumping program 0x%x, version %d (%s)",
223 P->i_number, P->i_version,
224 P->b_is_ok ? "complete" : "partial" );
226 for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
228 #define ES p_input->stream.pp_programs[i]->pp_es[j]
229 intf_Msg( "input info: ES 0x%x, stream 0x%x, type 0x%x, %s",
230 ES->i_id, ES->i_stream_id, ES->i_type,
231 ES->p_decoder_fifo != NULL ? "selected" : "not selected");
237 /*****************************************************************************
238 * input_ChangeES: answers to a user request with calls to (Un)SelectES
240 * Useful since the interface plugins know p_es
241 *****************************************************************************/
242 int input_ChangeES( input_thread_t * p_input, es_descriptor_t * p_es,
250 vlc_mutex_lock( &p_input->stream.stream_lock );
252 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
254 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
269 if( p_input->stream.pp_selected_es[i_index] != p_es )
271 input_UnselectES( p_input,
272 p_input->stream.pp_selected_es[i_index] );
273 input_SelectES( p_input, p_es );
274 intf_WarnMsg( 1, "input info: es selected -> %s (0x%x)",
275 p_es->psz_desc, p_es->i_id );
280 input_SelectES( p_input, p_es );
281 intf_WarnMsg( 1, "input info: es selected -> %s (0x%x)",
282 p_es->psz_desc, p_es->i_id );
289 intf_WarnMsg( 1, "input info: es unselected -> %s (0x%x)",
290 p_input->stream.pp_selected_es[i_index]->psz_desc,
291 p_input->stream.pp_selected_es[i_index]->i_id );
293 input_UnselectES( p_input,
294 p_input->stream.pp_selected_es[i_index] );
298 vlc_mutex_unlock( &p_input->stream.stream_lock );
303 /*****************************************************************************
304 * input_ToggleES: answers to a user request with calls to (Un)SelectES
305 *****************************************************************************
306 * Useful since the interface plugins know p_es.
307 * It only works for audio & spu ( to be sure nothing nasty is being done ).
308 * b_select is a boolean to know if we have to select or unselect ES
309 *****************************************************************************/
310 int input_ToggleES( input_thread_t * p_input, es_descriptor_t * p_es,
314 vlc_mutex_lock( &p_input->stream.stream_lock );
320 input_SelectES( p_input, p_es );
324 input_UnselectES( p_input, p_es );
328 vlc_mutex_unlock( &p_input->stream.stream_lock );