1 /*****************************************************************************
2 * input_ext-intf.c: services to the interface
3 *****************************************************************************
4 * Copyright (C) 1998, 1999, 2000 VideoLAN
6 * Authors: Christophe Massiot <massiot@via.ecp.fr>
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.
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.
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 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
35 #include "stream_control.h"
36 #include "input_ext-dec.h"
37 #include "input_ext-intf.h"
41 /*****************************************************************************
42 * input_SetStatus: change the reading status
43 *****************************************************************************/
44 void input_SetStatus( input_thread_t * p_input, int i_mode )
46 vlc_mutex_lock( &p_input->stream.stream_lock );
50 case INPUT_STATUS_END:
51 p_input->stream.i_new_status = PLAYING_S;
53 intf_Msg( "input: end of stream" );
56 case INPUT_STATUS_PLAY:
57 p_input->stream.i_new_status = PLAYING_S;
58 intf_Msg( "input: playing at normal rate" );
61 case INPUT_STATUS_PAUSE:
62 /* XXX: we don't need to check i_status, because input_clock.c
64 p_input->stream.i_new_status = PAUSE_S;
65 intf_Msg( "input: toggling pause" );
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 )
72 p_input->stream.i_new_status = PLAYING_S;
73 intf_Msg( "input: playing at normal rate" );
77 p_input->stream.i_new_status = FORWARD_S;
79 if( p_input->stream.control.i_rate < DEFAULT_RATE
80 && p_input->stream.control.i_status == FORWARD_S )
82 p_input->stream.i_new_rate =
83 p_input->stream.control.i_rate / 2;
87 p_input->stream.i_new_rate = DEFAULT_RATE / 2;
89 intf_Msg( "input: playing at %i:1 fast forward",
90 DEFAULT_RATE / p_input->stream.i_new_rate );
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 )
98 p_input->stream.i_new_status = PLAYING_S;
99 intf_Msg( "input: playing at normal rate" );
103 p_input->stream.i_new_status = FORWARD_S;
105 if( p_input->stream.control.i_rate > DEFAULT_RATE
106 && p_input->stream.control.i_status == FORWARD_S )
108 p_input->stream.i_new_rate =
109 p_input->stream.control.i_rate * 2;
113 p_input->stream.i_new_rate = DEFAULT_RATE * 2;
115 intf_Msg( "input: playing at 1:%i slow motion",
116 p_input->stream.i_new_rate / DEFAULT_RATE );
123 vlc_cond_signal( &p_input->stream.stream_wait );
124 vlc_mutex_unlock( &p_input->stream.stream_lock );
127 /*****************************************************************************
128 * input_SetRate: change the reading rate
129 *****************************************************************************/
130 void input_SetRate( input_thread_t * p_input, int i_mode )
135 /*****************************************************************************
136 * input_Seek: changes the stream postion
137 *****************************************************************************/
138 void input_Seek( input_thread_t * p_input, off_t i_position )
140 char psz_time1[OFFSETTOTIME_MAX_SIZE];
141 char psz_time2[OFFSETTOTIME_MAX_SIZE];
143 vlc_mutex_lock( &p_input->stream.stream_lock );
144 p_input->stream.p_selected_area->i_seek = i_position;
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 ) );
152 vlc_cond_signal( &p_input->stream.stream_wait );
153 vlc_mutex_unlock( &p_input->stream.stream_lock );
156 /*****************************************************************************
157 * input_OffsetToTime : converts an off_t value to a time indicator, using
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,
168 if( p_input->stream.i_mux_rate )
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 );
179 /* Divide by zero is not my friend. */
180 sprintf( psz_buffer, "NA" );
181 return( psz_buffer );
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 )
194 char psz_time1[OFFSETTOTIME_MAX_SIZE];
195 char psz_time2[OFFSETTOTIME_MAX_SIZE];
197 #define S p_input->stream
198 intf_Msg( "input info: Dumping stream ID 0x%x", S.i_stream_id );
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 ) );
207 intf_Msg( "input info: %s", S.b_pace_control ? "pace controlled" :
208 "pace un-controlled" );
210 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
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" );
217 for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
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");
228 /*****************************************************************************
229 * input_ChangeES: answers to a user request with calls to (Un)SelectES
231 * Useful since the interface plugins know p_es
232 *****************************************************************************/
233 int input_ChangeES( input_thread_t * p_input, es_descriptor_t * p_es,
242 b_audio = ( i_type == 1 ) ? 1 : 0;
243 b_spu = ( i_type == 2 ) ? 1 : 0;
245 vlc_mutex_lock( &p_input->stream.stream_lock );
247 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
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 ) )
265 if( p_input->stream.pp_selected_es[i_index] != p_es )
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, "dvd info: ES selected -> %s (0x%x)",
271 p_es->psz_desc, p_es->i_id );
276 input_SelectES( p_input, p_es );
277 intf_WarnMsg( 1, "dvd info: selected -> %s (0x%x)",
278 p_es->psz_desc, p_es->i_id );
285 input_UnselectES( p_input,
286 p_input->stream.pp_selected_es[i_index] );
290 vlc_mutex_unlock( &p_input->stream.stream_lock );