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 $
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 *****************************************************************************/
36 #include "stream_control.h"
37 #include "input_ext-dec.h"
38 #include "input_ext-intf.h"
42 /*****************************************************************************
43 * input_SetStatus: change the reading status
44 *****************************************************************************/
45 void input_SetStatus( input_thread_t * p_input, int i_mode )
47 vlc_mutex_lock( &p_input->stream.stream_lock );
51 case INPUT_STATUS_END:
52 p_input->stream.i_new_status = PLAYING_S;
54 intf_Msg( "input: end of stream" );
57 case INPUT_STATUS_PLAY:
58 p_input->stream.i_new_status = PLAYING_S;
59 intf_Msg( "input: playing at normal rate" );
62 case INPUT_STATUS_PAUSE:
63 /* XXX: we don't need to check i_status, because input_clock.c
65 p_input->stream.i_new_status = PAUSE_S;
66 intf_Msg( "input: toggling pause" );
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 )
73 p_input->stream.i_new_status = PLAYING_S;
74 intf_Msg( "input: playing at normal rate" );
78 p_input->stream.i_new_status = FORWARD_S;
80 if( p_input->stream.control.i_rate < DEFAULT_RATE
81 && p_input->stream.control.i_status == FORWARD_S )
83 p_input->stream.i_new_rate =
84 p_input->stream.control.i_rate / 2;
88 p_input->stream.i_new_rate = DEFAULT_RATE / 2;
90 intf_Msg( "input: playing at %i:1 fast forward",
91 DEFAULT_RATE / p_input->stream.i_new_rate );
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 )
99 p_input->stream.i_new_status = PLAYING_S;
100 intf_Msg( "input: playing at normal rate" );
104 p_input->stream.i_new_status = FORWARD_S;
106 if( p_input->stream.control.i_rate > DEFAULT_RATE
107 && p_input->stream.control.i_status == FORWARD_S )
109 p_input->stream.i_new_rate =
110 p_input->stream.control.i_rate * 2;
114 p_input->stream.i_new_rate = DEFAULT_RATE * 2;
116 intf_Msg( "input: playing at 1:%i slow motion",
117 p_input->stream.i_new_rate / DEFAULT_RATE );
124 vlc_cond_signal( &p_input->stream.stream_wait );
125 vlc_mutex_unlock( &p_input->stream.stream_lock );
128 /*****************************************************************************
129 * input_SetRate: change the reading rate
130 *****************************************************************************/
131 void input_SetRate( input_thread_t * p_input, int i_mode )
136 /*****************************************************************************
137 * input_Seek: changes the stream postion
138 *****************************************************************************/
139 void input_Seek( input_thread_t * p_input, off_t i_position )
141 char psz_time1[OFFSETTOTIME_MAX_SIZE];
142 char psz_time2[OFFSETTOTIME_MAX_SIZE];
144 vlc_mutex_lock( &p_input->stream.stream_lock );
145 p_input->stream.p_selected_area->i_seek = i_position;
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 ) );
153 vlc_cond_signal( &p_input->stream.stream_wait );
154 vlc_mutex_unlock( &p_input->stream.stream_lock );
157 /*****************************************************************************
158 * input_OffsetToTime : converts an off_t value to a time indicator, using
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,
169 if( p_input->stream.i_mux_rate )
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 );
180 /* Divide by zero is not my friend. */
181 sprintf( psz_buffer, "-:--:--" );
182 return( psz_buffer );
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 )
195 char psz_time1[OFFSETTOTIME_MAX_SIZE];
196 char psz_time2[OFFSETTOTIME_MAX_SIZE];
198 #define S p_input->stream
199 intf_Msg( "input info: Dumping stream ID 0x%x", S.i_stream_id );
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 ) );
208 intf_Msg( "input info: %s", S.b_pace_control ? "pace controlled" :
209 "pace un-controlled" );
211 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
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" );
218 for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
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");
229 /*****************************************************************************
230 * input_ChangeES: answers to a user request with calls to (Un)SelectES
232 * Useful since the interface plugins know p_es
233 *****************************************************************************/
234 int input_ChangeES( input_thread_t * p_input, es_descriptor_t * p_es,
243 b_audio = ( i_type == 1 ) ? 1 : 0;
244 b_spu = ( i_type == 2 ) ? 1 : 0;
246 vlc_mutex_lock( &p_input->stream.stream_lock );
248 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
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 ) )
266 if( p_input->stream.pp_selected_es[i_index] != p_es )
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 );
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 );
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 );
290 input_UnselectES( p_input,
291 p_input->stream.pp_selected_es[i_index] );
295 vlc_mutex_unlock( &p_input->stream.stream_lock );