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.21 2001/04/27 16:08:26 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() */
38 #include "stream_control.h"
39 #include "input_ext-dec.h"
40 #include "input_ext-intf.h"
44 /*****************************************************************************
45 * input_SetStatus: change the reading status
46 *****************************************************************************/
47 void input_SetStatus( input_thread_t * p_input, int i_mode )
49 vlc_mutex_lock( &p_input->stream.stream_lock );
53 case INPUT_STATUS_END:
54 p_input->stream.i_new_status = PLAYING_S;
56 intf_Msg( "input: end of stream" );
59 case INPUT_STATUS_PLAY:
60 p_input->stream.i_new_status = PLAYING_S;
61 intf_Msg( "input: playing at normal rate" );
64 case INPUT_STATUS_PAUSE:
65 /* XXX: we don't need to check i_status, because input_clock.c
67 p_input->stream.i_new_status = PAUSE_S;
68 intf_Msg( "input: toggling pause" );
71 case INPUT_STATUS_FASTER:
72 /* If we are already going too fast, go back to default rate */
73 if( p_input->stream.control.i_rate * 8 <= DEFAULT_RATE )
75 p_input->stream.i_new_status = PLAYING_S;
76 intf_Msg( "input: playing at normal rate" );
80 p_input->stream.i_new_status = FORWARD_S;
82 if( p_input->stream.control.i_rate < DEFAULT_RATE
83 && p_input->stream.control.i_status == FORWARD_S )
85 p_input->stream.i_new_rate =
86 p_input->stream.control.i_rate / 2;
90 p_input->stream.i_new_rate = DEFAULT_RATE / 2;
92 intf_Msg( "input: playing at %i:1 fast forward",
93 DEFAULT_RATE / p_input->stream.i_new_rate );
97 case INPUT_STATUS_SLOWER:
98 /* If we are already going too slow, go back to default rate */
99 if( p_input->stream.control.i_rate >= 8 * DEFAULT_RATE )
101 p_input->stream.i_new_status = PLAYING_S;
102 intf_Msg( "input: playing at normal rate" );
106 p_input->stream.i_new_status = FORWARD_S;
108 if( p_input->stream.control.i_rate > DEFAULT_RATE
109 && p_input->stream.control.i_status == FORWARD_S )
111 p_input->stream.i_new_rate =
112 p_input->stream.control.i_rate * 2;
116 p_input->stream.i_new_rate = DEFAULT_RATE * 2;
118 intf_Msg( "input: playing at 1:%i slow motion",
119 p_input->stream.i_new_rate / DEFAULT_RATE );
127 vlc_cond_signal( &p_input->stream.stream_wait );
128 vlc_mutex_unlock( &p_input->stream.stream_lock );
131 /*****************************************************************************
132 * input_SetRate: change the reading rate
133 *****************************************************************************/
134 void input_SetRate( input_thread_t * p_input, int i_mode )
139 /*****************************************************************************
140 * input_Seek: changes the stream postion
141 *****************************************************************************/
142 void input_Seek( input_thread_t * p_input, off_t i_position )
144 char psz_time1[OFFSETTOTIME_MAX_SIZE];
145 char psz_time2[OFFSETTOTIME_MAX_SIZE];
147 vlc_mutex_lock( &p_input->stream.stream_lock );
148 p_input->stream.p_selected_area->i_seek = i_position;
150 intf_WarnMsg( 1, "input: seeking position %lld/%lld (%s/%s)", i_position,
151 p_input->stream.p_selected_area->i_size,
152 input_OffsetToTime( p_input, psz_time1, i_position ),
153 input_OffsetToTime( p_input, psz_time2,
154 p_input->stream.p_selected_area->i_size ) );
156 vlc_cond_signal( &p_input->stream.stream_wait );
157 vlc_mutex_unlock( &p_input->stream.stream_lock );
160 /*****************************************************************************
161 * input_OffsetToTime : converts an off_t value to a time indicator, using
163 *****************************************************************************
164 * BEWARE : this function assumes that you already own the lock on
165 * p_input->stream.stream_lock
166 *****************************************************************************/
167 char * input_OffsetToTime( input_thread_t * p_input, char * psz_buffer,
172 if( p_input->stream.i_mux_rate )
174 i_seconds = i_offset / 50 / p_input->stream.i_mux_rate;
175 snprintf( psz_buffer, OFFSETTOTIME_MAX_SIZE, "%d:%02d:%02d",
176 (int) (i_seconds / (60 * 60)),
177 (int) (i_seconds / 60 % 60),
178 (int) (i_seconds % 60) );
179 return( psz_buffer );
183 /* Divide by zero is not my friend. */
184 sprintf( psz_buffer, "-:--:--" );
185 return( psz_buffer );
189 /*****************************************************************************
190 * input_DumpStream: dumps the contents of a stream descriptor
191 *****************************************************************************
192 * BEWARE : this function assumes that you already own the lock on
193 * p_input->stream.stream_lock
194 *****************************************************************************/
195 void input_DumpStream( input_thread_t * p_input )
198 char psz_time1[OFFSETTOTIME_MAX_SIZE];
199 char psz_time2[OFFSETTOTIME_MAX_SIZE];
201 #define S p_input->stream
202 intf_Msg( "input info: Dumping stream ID 0x%x", S.i_stream_id );
204 intf_Msg( "input info: seekable stream, position: %lld/%lld (%s/%s)",
205 S.p_selected_area->i_tell, S.p_selected_area->i_size,
206 input_OffsetToTime( p_input, psz_time1,
207 S.p_selected_area->i_tell ),
208 input_OffsetToTime( p_input, psz_time2,
209 S.p_selected_area->i_size ) );
211 intf_Msg( "input info: %s", S.b_pace_control ? "pace controlled" :
212 "pace un-controlled" );
214 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
216 #define P p_input->stream.pp_programs[i]
217 intf_Msg( "input info: Dumping program 0x%x, version %d (%s)",
218 P->i_number, P->i_version,
219 P->b_is_ok ? "complete" : "partial" );
221 for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
223 #define ES p_input->stream.pp_programs[i]->pp_es[j]
224 intf_Msg( "input info: ES 0x%x, stream 0x%x, type 0x%x, %s",
225 ES->i_id, ES->i_stream_id, ES->i_type,
226 ES->p_decoder_fifo != NULL ? "selected" : "not selected");
232 /*****************************************************************************
233 * input_ChangeES: answers to a user request with calls to (Un)SelectES
235 * Useful since the interface plugins know p_es
236 *****************************************************************************/
237 int input_ChangeES( input_thread_t * p_input, es_descriptor_t * p_es,
245 vlc_mutex_lock( &p_input->stream.stream_lock );
247 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
249 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
264 if( p_input->stream.pp_selected_es[i_index] != p_es )
266 input_UnselectES( p_input,
267 p_input->stream.pp_selected_es[i_index] );
268 input_SelectES( p_input, p_es );
269 intf_WarnMsg( 1, "input info: es selected -> %s (0x%x)",
270 p_es->psz_desc, p_es->i_id );
275 input_SelectES( p_input, p_es );
276 intf_WarnMsg( 1, "input info: es selected -> %s (0x%x)",
277 p_es->psz_desc, p_es->i_id );
284 intf_WarnMsg( 1, "input info: es unselected -> %s (0x%x)",
285 p_input->stream.pp_selected_es[i_index]->psz_desc,
286 p_input->stream.pp_selected_es[i_index]->i_id );
288 input_UnselectES( p_input,
289 p_input->stream.pp_selected_es[i_index] );
293 vlc_mutex_unlock( &p_input->stream.stream_lock );
298 /*****************************************************************************
299 * input_ToggleES: answers to a user request with calls to (Un)SelectES
300 *****************************************************************************
301 * Useful since the interface plugins know p_es.
302 * It only works for audio & spu ( to be sure nothing nasty is being done ).
303 * b_select is a boolean to know if we have to select or unselect ES
304 *****************************************************************************/
305 int input_ToggleES( input_thread_t * p_input, es_descriptor_t * p_es,
309 vlc_mutex_lock( &p_input->stream.stream_lock );
315 input_SelectES( p_input, p_es );
319 input_UnselectES( p_input, p_es );
323 vlc_mutex_unlock( &p_input->stream.stream_lock );