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.31 2001/12/09 17:01:37 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 */
37 #include "stream_control.h"
38 #include "input_ext-dec.h"
39 #include "input_ext-intf.h"
40 #include "input_ext-plugins.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 );
125 vlc_cond_signal( &p_input->stream.stream_wait );
126 vlc_mutex_unlock( &p_input->stream.stream_lock );
129 /*****************************************************************************
130 * input_Seek: changes the stream postion
131 *****************************************************************************/
132 void input_Seek( input_thread_t * p_input, off_t i_position )
134 char psz_time1[OFFSETTOTIME_MAX_SIZE];
135 char psz_time2[OFFSETTOTIME_MAX_SIZE];
137 vlc_mutex_lock( &p_input->stream.stream_lock );
138 p_input->stream.p_selected_area->i_seek = i_position;
140 intf_WarnMsg( 3, "input: seeking position %lld/%lld (%s/%s)", i_position,
141 p_input->stream.p_selected_area->i_size,
142 input_OffsetToTime( p_input, psz_time1, i_position ),
143 input_OffsetToTime( p_input, psz_time2,
144 p_input->stream.p_selected_area->i_size ) );
146 vlc_cond_signal( &p_input->stream.stream_wait );
147 vlc_mutex_unlock( &p_input->stream.stream_lock );
150 /*****************************************************************************
151 * input_OffsetToTime : converts an off_t value to a time indicator, using
153 *****************************************************************************
154 * BEWARE : this function assumes that you already own the lock on
155 * p_input->stream.stream_lock
156 *****************************************************************************/
157 char * input_OffsetToTime( input_thread_t * p_input, char * psz_buffer,
162 if( p_input->stream.i_mux_rate )
164 i_seconds = i_offset / 50 / p_input->stream.i_mux_rate;
165 snprintf( psz_buffer, OFFSETTOTIME_MAX_SIZE, "%d:%02d:%02d",
166 (int) (i_seconds / (60 * 60)),
167 (int) (i_seconds / 60 % 60),
168 (int) (i_seconds % 60) );
169 return( psz_buffer );
173 /* Divide by zero is not my friend. */
174 sprintf( psz_buffer, "-:--:--" );
175 return( psz_buffer );
179 /*****************************************************************************
180 * input_DumpStream: dumps the contents of a stream descriptor
181 *****************************************************************************
182 * BEWARE : this function assumes that you already own the lock on
183 * p_input->stream.stream_lock
184 *****************************************************************************/
185 void input_DumpStream( input_thread_t * p_input )
188 char psz_time1[OFFSETTOTIME_MAX_SIZE];
189 char psz_time2[OFFSETTOTIME_MAX_SIZE];
191 #define S p_input->stream
192 intf_Msg( "input info: Dumping stream ID 0x%x [OK:%d/D:%d]", S.i_stream_id,
193 S.c_packets_read, S.c_packets_trashed );
195 intf_Msg( "input info: seekable stream, position: %lld/%lld (%s/%s)",
196 S.p_selected_area->i_tell, S.p_selected_area->i_size,
197 input_OffsetToTime( p_input, psz_time1,
198 S.p_selected_area->i_tell ),
199 input_OffsetToTime( p_input, psz_time2,
200 S.p_selected_area->i_size ) );
202 intf_Msg( "input info: %s", S.b_pace_control ? "pace controlled" :
203 "pace un-controlled" );
205 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
207 #define P p_input->stream.pp_programs[i]
208 intf_Msg( "input info: Dumping program 0x%x, version %d (%s)",
209 P->i_number, P->i_version,
210 P->b_is_ok ? "complete" : "partial" );
212 for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
214 #define ES p_input->stream.pp_programs[i]->pp_es[j]
215 intf_Msg( "input info: ES 0x%x, stream 0x%x, type 0x%x, %s [OK:%d/ERR:%d]",
216 ES->i_id, ES->i_stream_id, ES->i_type,
217 ES->p_decoder_fifo != NULL ? "selected" : "not selected",
218 ES->c_packets, ES->c_invalid_packets );
224 /*****************************************************************************
225 * input_ChangeES: answers to a user request with calls to (Un)SelectES
226 *****************************************************************************
227 * Useful since the interface plugins know p_es
228 * This functon is deprecated, use input_ToggleEs instead.
229 *****************************************************************************/
230 int input_ChangeES( input_thread_t * p_input, es_descriptor_t * p_es,
238 vlc_mutex_lock( &p_input->stream.stream_lock );
240 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
242 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
257 if( p_input->stream.pp_selected_es[i_index] != p_es )
259 input_UnselectES( p_input,
260 p_input->stream.pp_selected_es[i_index] );
261 input_SelectES( p_input, p_es );
262 intf_WarnMsg( 3, "input info: es selected -> %s (0x%x)",
263 p_es->psz_desc, p_es->i_id );
268 input_SelectES( p_input, p_es );
269 intf_WarnMsg( 3, "input info: es selected -> %s (0x%x)",
270 p_es->psz_desc, p_es->i_id );
277 intf_WarnMsg( 3, "input info: es unselected -> %s (0x%x)",
278 p_input->stream.pp_selected_es[i_index]->psz_desc,
279 p_input->stream.pp_selected_es[i_index]->i_id );
281 input_UnselectES( p_input,
282 p_input->stream.pp_selected_es[i_index] );
286 vlc_mutex_unlock( &p_input->stream.stream_lock );
291 /*****************************************************************************
292 * input_ToggleES: answers to a user request with calls to (Un)SelectES
293 *****************************************************************************
294 * Useful since the interface plugins know p_es.
295 * It only works for audio & spu ( to be sure nothing nasty is being done ).
296 * b_select is a boolean to know if we have to select or unselect ES
297 *****************************************************************************/
298 int input_ToggleES( input_thread_t * p_input, es_descriptor_t * p_es,
302 vlc_mutex_lock( &p_input->stream.stream_lock );
308 p_input->stream.p_newly_selected_es = p_es;
312 p_input->stream.p_removed_es = p_es;
316 vlc_mutex_unlock( &p_input->stream.stream_lock );
321 /****************************************************************************
322 * input_ChangeArea: interface request an area change
323 ****************************************************************************/
324 int input_ChangeArea( input_thread_t * p_input, input_area_t * p_area )
326 vlc_mutex_lock( &p_input->stream.stream_lock );
328 p_input->stream.p_new_area = p_area;
330 vlc_mutex_unlock( &p_input->stream.stream_lock );
335 /****************************************************************************
336 * input_ChangeProgram: interface request an area change
337 ****************************************************************************/
338 int input_ChangeProgram( input_thread_t * p_input,
339 pgrm_descriptor_t * p_program )
341 vlc_mutex_lock( &p_input->stream.stream_lock );
343 p_input->stream.p_new_program = p_program;
345 vlc_mutex_unlock( &p_input->stream.stream_lock );
350 /****************************************************************************
351 * input_ToggleGrayscale: change to grayscale or color output
352 ****************************************************************************/
353 int input_ToggleGrayscale( input_thread_t * p_input )
355 /* No need to warn the input thread since only the decoders and outputs
357 vlc_mutex_lock( &p_input->stream.control.control_lock );
358 p_input->stream.control.b_grayscale =
359 !p_input->stream.control.b_grayscale;
361 intf_WarnMsg( 3, "input warning: changing to %s output",
362 p_input->stream.control.b_grayscale ? "grayscale" : "color" );
364 vlc_mutex_unlock( &p_input->stream.control.control_lock );
369 /****************************************************************************
370 * input_ToggleMute: activate/deactivate mute mode
371 ****************************************************************************/
372 int input_ToggleMute( input_thread_t * p_input )
374 /* We need to feed the decoders with 0, and only input can do that, so
375 * pass the message to the input thread. */
376 vlc_mutex_lock( &p_input->stream.stream_lock );
377 p_input->stream.b_new_mute = !p_input->stream.control.b_mute;
379 intf_WarnMsg( 3, "input warning: %s mute mode",
380 p_input->stream.control.b_mute ? "activating" : "deactivating" );
382 vlc_mutex_unlock( &p_input->stream.stream_lock );
387 /****************************************************************************
388 * input_SetSMP: change the number of video decoder threads
389 ****************************************************************************/
390 int input_SetSMP( input_thread_t * p_input, int i_smp )
392 /* No need to warn the input thread since only the decoders
394 vlc_mutex_lock( &p_input->stream.control.control_lock );
395 p_input->stream.control.i_smp = i_smp;
396 vlc_mutex_unlock( &p_input->stream.control.control_lock );