1 /*****************************************************************************
2 * input_ext-intf.c: services to the interface
3 *****************************************************************************
4 * Copyright (C) 1998-2001 VideoLAN
5 * $Id: input_ext-intf.c,v 1.29 2001/11/28 15:08:06 massiot 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 */
38 #include "stream_control.h"
39 #include "input_ext-dec.h"
40 #include "input_ext-intf.h"
41 #include "input_ext-plugins.h"
43 /*****************************************************************************
44 * input_SetStatus: change the reading status
45 *****************************************************************************/
46 void input_SetStatus( input_thread_t * p_input, int i_mode )
48 vlc_mutex_lock( &p_input->stream.stream_lock );
52 case INPUT_STATUS_END:
53 p_input->stream.i_new_status = PLAYING_S;
55 intf_Msg( "input: end of stream" );
58 case INPUT_STATUS_PLAY:
59 p_input->stream.i_new_status = PLAYING_S;
60 intf_Msg( "input: playing at normal rate" );
63 case INPUT_STATUS_PAUSE:
64 /* XXX: we don't need to check i_status, because input_clock.c
66 p_input->stream.i_new_status = PAUSE_S;
67 intf_Msg( "input: toggling pause" );
70 case INPUT_STATUS_FASTER:
71 /* If we are already going too fast, go back to default rate */
72 if( p_input->stream.control.i_rate * 8 <= DEFAULT_RATE )
74 p_input->stream.i_new_status = PLAYING_S;
75 intf_Msg( "input: playing at normal rate" );
79 p_input->stream.i_new_status = FORWARD_S;
81 if( p_input->stream.control.i_rate < DEFAULT_RATE
82 && p_input->stream.control.i_status == FORWARD_S )
84 p_input->stream.i_new_rate =
85 p_input->stream.control.i_rate / 2;
89 p_input->stream.i_new_rate = DEFAULT_RATE / 2;
91 intf_Msg( "input: playing at %i:1 fast forward",
92 DEFAULT_RATE / p_input->stream.i_new_rate );
96 case INPUT_STATUS_SLOWER:
97 /* If we are already going too slow, go back to default rate */
98 if( p_input->stream.control.i_rate >= 8 * DEFAULT_RATE )
100 p_input->stream.i_new_status = PLAYING_S;
101 intf_Msg( "input: playing at normal rate" );
105 p_input->stream.i_new_status = FORWARD_S;
107 if( p_input->stream.control.i_rate > DEFAULT_RATE
108 && p_input->stream.control.i_status == FORWARD_S )
110 p_input->stream.i_new_rate =
111 p_input->stream.control.i_rate * 2;
115 p_input->stream.i_new_rate = DEFAULT_RATE * 2;
117 intf_Msg( "input: playing at 1:%i slow motion",
118 p_input->stream.i_new_rate / DEFAULT_RATE );
126 vlc_cond_signal( &p_input->stream.stream_wait );
127 vlc_mutex_unlock( &p_input->stream.stream_lock );
130 /*****************************************************************************
131 * input_Seek: changes the stream postion
132 *****************************************************************************/
133 void input_Seek( input_thread_t * p_input, off_t i_position )
135 char psz_time1[OFFSETTOTIME_MAX_SIZE];
136 char psz_time2[OFFSETTOTIME_MAX_SIZE];
138 vlc_mutex_lock( &p_input->stream.stream_lock );
139 p_input->stream.p_selected_area->i_seek = i_position;
141 intf_WarnMsg( 3, "input: seeking position %lld/%lld (%s/%s)", i_position,
142 p_input->stream.p_selected_area->i_size,
143 input_OffsetToTime( p_input, psz_time1, i_position ),
144 input_OffsetToTime( p_input, psz_time2,
145 p_input->stream.p_selected_area->i_size ) );
147 vlc_cond_signal( &p_input->stream.stream_wait );
148 vlc_mutex_unlock( &p_input->stream.stream_lock );
151 /*****************************************************************************
152 * input_OffsetToTime : converts an off_t value to a time indicator, using
154 *****************************************************************************
155 * BEWARE : this function assumes that you already own the lock on
156 * p_input->stream.stream_lock
157 *****************************************************************************/
158 char * input_OffsetToTime( input_thread_t * p_input, char * psz_buffer,
163 if( p_input->stream.i_mux_rate )
165 i_seconds = i_offset / 50 / p_input->stream.i_mux_rate;
166 snprintf( psz_buffer, OFFSETTOTIME_MAX_SIZE, "%d:%02d:%02d",
167 (int) (i_seconds / (60 * 60)),
168 (int) (i_seconds / 60 % 60),
169 (int) (i_seconds % 60) );
170 return( psz_buffer );
174 /* Divide by zero is not my friend. */
175 sprintf( psz_buffer, "-:--:--" );
176 return( psz_buffer );
180 /*****************************************************************************
181 * input_DumpStream: dumps the contents of a stream descriptor
182 *****************************************************************************
183 * BEWARE : this function assumes that you already own the lock on
184 * p_input->stream.stream_lock
185 *****************************************************************************/
186 void input_DumpStream( input_thread_t * p_input )
189 char psz_time1[OFFSETTOTIME_MAX_SIZE];
190 char psz_time2[OFFSETTOTIME_MAX_SIZE];
192 #define S p_input->stream
193 intf_Msg( "input info: Dumping stream ID 0x%x [OK:%d/D:%d]", S.i_stream_id,
194 S.c_packets_read, S.c_packets_trashed );
196 intf_Msg( "input info: seekable stream, position: %lld/%lld (%s/%s)",
197 S.p_selected_area->i_tell, S.p_selected_area->i_size,
198 input_OffsetToTime( p_input, psz_time1,
199 S.p_selected_area->i_tell ),
200 input_OffsetToTime( p_input, psz_time2,
201 S.p_selected_area->i_size ) );
203 intf_Msg( "input info: %s", S.b_pace_control ? "pace controlled" :
204 "pace un-controlled" );
206 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
208 #define P p_input->stream.pp_programs[i]
209 intf_Msg( "input info: Dumping program 0x%x, version %d (%s)",
210 P->i_number, P->i_version,
211 P->b_is_ok ? "complete" : "partial" );
213 for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
215 #define ES p_input->stream.pp_programs[i]->pp_es[j]
216 intf_Msg( "input info: ES 0x%x, stream 0x%x, type 0x%x, %s [OK:%d/ERR:%d]",
217 ES->i_id, ES->i_stream_id, ES->i_type,
218 ES->p_decoder_fifo != NULL ? "selected" : "not selected",
219 ES->c_packets, ES->c_invalid_packets );
225 /*****************************************************************************
226 * input_ChangeES: answers to a user request with calls to (Un)SelectES
227 *****************************************************************************
228 * Useful since the interface plugins know p_es
229 * This functon is deprecated, use input_ToggleEs instead.
230 *****************************************************************************/
231 int input_ChangeES( input_thread_t * p_input, es_descriptor_t * p_es,
239 vlc_mutex_lock( &p_input->stream.stream_lock );
241 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
243 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
258 if( p_input->stream.pp_selected_es[i_index] != p_es )
260 input_UnselectES( p_input,
261 p_input->stream.pp_selected_es[i_index] );
262 input_SelectES( p_input, p_es );
263 intf_WarnMsg( 3, "input info: es selected -> %s (0x%x)",
264 p_es->psz_desc, p_es->i_id );
269 input_SelectES( p_input, p_es );
270 intf_WarnMsg( 3, "input info: es selected -> %s (0x%x)",
271 p_es->psz_desc, p_es->i_id );
278 intf_WarnMsg( 3, "input info: es unselected -> %s (0x%x)",
279 p_input->stream.pp_selected_es[i_index]->psz_desc,
280 p_input->stream.pp_selected_es[i_index]->i_id );
282 input_UnselectES( p_input,
283 p_input->stream.pp_selected_es[i_index] );
287 vlc_mutex_unlock( &p_input->stream.stream_lock );
292 /*****************************************************************************
293 * input_ToggleES: answers to a user request with calls to (Un)SelectES
294 *****************************************************************************
295 * Useful since the interface plugins know p_es.
296 * It only works for audio & spu ( to be sure nothing nasty is being done ).
297 * b_select is a boolean to know if we have to select or unselect ES
298 *****************************************************************************/
299 int input_ToggleES( input_thread_t * p_input, es_descriptor_t * p_es,
303 vlc_mutex_lock( &p_input->stream.stream_lock );
309 p_input->stream.p_newly_selected_es = p_es;
313 p_input->stream.p_removed_es = p_es;
317 vlc_mutex_unlock( &p_input->stream.stream_lock );
322 /****************************************************************************
323 * input_ChangeArea: interface request an area change
324 ****************************************************************************/
325 int input_ChangeArea( input_thread_t * p_input, input_area_t * p_area )
327 vlc_mutex_lock( &p_input->stream.stream_lock );
329 p_input->stream.p_new_area = p_area;
331 vlc_mutex_unlock( &p_input->stream.stream_lock );
336 /****************************************************************************
337 * input_ToggleGrayscale: change to grayscale or color output
338 ****************************************************************************/
339 int input_ToggleGrayscale( input_thread_t * p_input )
341 /* No need to warn the input thread since only the decoders and outputs
343 vlc_mutex_lock( &p_input->stream.control.control_lock );
344 p_input->stream.control.b_grayscale =
345 !p_input->stream.control.b_grayscale;
347 intf_WarnMsg( 3, "input warning: changing to %s output",
348 p_input->stream.control.b_grayscale ? "grayscale" : "color" );
350 vlc_mutex_unlock( &p_input->stream.control.control_lock );
355 /****************************************************************************
356 * input_ToggleMute: activate/deactivate mute mode
357 ****************************************************************************/
358 int input_ToggleMute( input_thread_t * p_input )
360 /* We need to feed the decoders with 0, and only input can do that, so
361 * pass the message to the input thread. */
362 vlc_mutex_lock( &p_input->stream.stream_lock );
363 p_input->stream.b_new_mute = !p_input->stream.control.b_mute;
365 intf_WarnMsg( 3, "input warning: %s mute mode",
366 p_input->stream.control.b_mute ? "activating" : "deactivating" );
368 vlc_mutex_unlock( &p_input->stream.stream_lock );
373 /****************************************************************************
374 * input_SetSMP: change the number of video decoder threads
375 ****************************************************************************/
376 int input_SetSMP( input_thread_t * p_input, int i_smp )
378 /* No need to warn the input thread since only the decoders
380 vlc_mutex_lock( &p_input->stream.control.control_lock );
381 p_input->stream.control.i_smp = i_smp;
382 vlc_mutex_unlock( &p_input->stream.control.control_lock );