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.40 2002/07/31 20:56:52 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 *****************************************************************************/
27 #include <string.h> /* memcpy(), memset() */
28 #include <sys/types.h> /* off_t */
32 #include "stream_control.h"
33 #include "input_ext-dec.h"
34 #include "input_ext-intf.h"
35 #include "input_ext-plugins.h"
37 /*****************************************************************************
38 * input_SetStatus: change the reading status
39 *****************************************************************************/
40 void __input_SetStatus( vlc_object_t * p_this, int i_mode )
42 input_thread_t *p_input;
44 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
48 msg_Err( p_this, "no input found" );
52 vlc_mutex_lock( &p_input->stream.stream_lock );
56 case INPUT_STATUS_END:
57 p_input->stream.i_new_status = PLAYING_S;
59 msg_Dbg( p_input, "end of stream" );
62 case INPUT_STATUS_PLAY:
63 p_input->stream.i_new_status = PLAYING_S;
64 msg_Dbg( p_input, "playing at normal rate" );
67 case INPUT_STATUS_PAUSE:
68 /* XXX: we don't need to check i_status, because input_clock.c
70 p_input->stream.i_new_status = PAUSE_S;
71 msg_Dbg( p_input, "toggling pause" );
74 case INPUT_STATUS_FASTER:
75 /* If we are already going too fast, go back to default rate */
76 if( p_input->stream.control.i_rate * 8 <= DEFAULT_RATE )
78 p_input->stream.i_new_status = PLAYING_S;
79 msg_Dbg( p_input, "playing at normal rate" );
83 p_input->stream.i_new_status = FORWARD_S;
85 if( p_input->stream.control.i_rate < DEFAULT_RATE
86 && p_input->stream.control.i_status == FORWARD_S )
88 p_input->stream.i_new_rate =
89 p_input->stream.control.i_rate / 2;
93 p_input->stream.i_new_rate = DEFAULT_RATE / 2;
95 msg_Dbg( p_input, "playing at %i:1 fast forward",
96 DEFAULT_RATE / p_input->stream.i_new_rate );
100 case INPUT_STATUS_SLOWER:
101 /* If we are already going too slow, go back to default rate */
102 if( p_input->stream.control.i_rate >= 8 * DEFAULT_RATE )
104 p_input->stream.i_new_status = PLAYING_S;
105 msg_Dbg( p_input, "playing at normal rate" );
109 p_input->stream.i_new_status = FORWARD_S;
111 if( p_input->stream.control.i_rate > DEFAULT_RATE
112 && p_input->stream.control.i_status == FORWARD_S )
114 p_input->stream.i_new_rate =
115 p_input->stream.control.i_rate * 2;
119 p_input->stream.i_new_rate = DEFAULT_RATE * 2;
121 msg_Dbg( p_input, "playing at 1:%i slow motion",
122 p_input->stream.i_new_rate / DEFAULT_RATE );
130 vlc_cond_signal( &p_input->stream.stream_wait );
131 vlc_mutex_unlock( &p_input->stream.stream_lock );
133 vlc_object_release( p_input );
136 /*****************************************************************************
137 * input_Seek: changes the stream postion
138 *****************************************************************************/
139 void __input_Seek( vlc_object_t * p_this, off_t i_position, int i_whence )
141 input_thread_t *p_input;
143 char psz_time1[OFFSETTOTIME_MAX_SIZE];
144 char psz_time2[OFFSETTOTIME_MAX_SIZE];
146 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
148 if( p_input == NULL )
150 msg_Err( p_this, "no input found" );
154 vlc_mutex_lock( &p_input->stream.stream_lock );
156 #define A p_input->stream.p_selected_area
157 switch( i_whence & 0x30 )
159 case INPUT_SEEK_SECONDS:
160 i_position *= (off_t)50 * p_input->stream.i_mux_rate;
163 case INPUT_SEEK_PERCENT:
164 i_position = A->i_size * i_position / (off_t)100;
167 case INPUT_SEEK_BYTES:
172 switch( i_whence & 0x03 )
175 A->i_seek = A->i_tell + i_position;
179 A->i_seek = A->i_size + i_position;
184 A->i_seek = i_position;
192 else if( A->i_seek > A->i_size )
194 A->i_seek = A->i_size;
197 msg_Dbg( p_input, "seeking position %lld/%lld (%s/%s)",
198 A->i_seek, A->i_size,
199 input_OffsetToTime( p_input, psz_time1, i_position ),
200 input_OffsetToTime( p_input, psz_time2, A->i_size ) );
203 vlc_cond_signal( &p_input->stream.stream_wait );
204 vlc_mutex_unlock( &p_input->stream.stream_lock );
206 vlc_object_release( p_input );
209 /*****************************************************************************
210 * input_Tell: requests the stream postion
211 *****************************************************************************/
212 void __input_Tell( vlc_object_t * p_this, stream_position_t * p_position )
214 input_thread_t *p_input;
216 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
218 if( p_input == NULL )
220 p_position->i_tell = 0;
221 p_position->i_size = 0;
222 p_position->i_mux_rate = 0;
223 msg_Err( p_this, "no input found" );
227 vlc_mutex_lock( &p_input->stream.stream_lock );
229 #define A p_input->stream.p_selected_area
230 p_position->i_tell = A->i_tell;
231 p_position->i_size = A->i_size;
232 p_position->i_mux_rate = p_input->stream.i_mux_rate;
235 vlc_mutex_unlock( &p_input->stream.stream_lock );
236 vlc_object_release( p_input );
239 /*****************************************************************************
240 * input_OffsetToTime : converts an off_t value to a time indicator, using
242 *****************************************************************************
243 * BEWARE : this function assumes that you already own the lock on
244 * p_input->stream.stream_lock
245 *****************************************************************************/
246 char * input_OffsetToTime( input_thread_t * p_input, char * psz_buffer,
251 if( p_input->stream.i_mux_rate )
253 i_seconds = i_offset / 50 / p_input->stream.i_mux_rate;
254 snprintf( psz_buffer, OFFSETTOTIME_MAX_SIZE, "%d:%02d:%02d",
255 (int) (i_seconds / (60 * 60)),
256 (int) (i_seconds / 60 % 60),
257 (int) (i_seconds % 60) );
258 return( psz_buffer );
262 /* Divide by zero is not my friend. */
263 sprintf( psz_buffer, "-:--:--" );
264 return( psz_buffer );
268 /*****************************************************************************
269 * input_DumpStream: dumps the contents of a stream descriptor
270 *****************************************************************************
271 * BEWARE : this function assumes that you already own the lock on
272 * p_input->stream.stream_lock
273 *****************************************************************************/
274 void input_DumpStream( input_thread_t * p_input )
277 char psz_time1[OFFSETTOTIME_MAX_SIZE];
278 char psz_time2[OFFSETTOTIME_MAX_SIZE];
280 #define S p_input->stream
281 msg_Dbg( p_input, "dumping stream ID 0x%x [OK:%d/D:%d]", S.i_stream_id,
282 S.c_packets_read, S.c_packets_trashed );
284 msg_Dbg( p_input, "seekable stream, position: %lld/%lld (%s/%s)",
285 S.p_selected_area->i_tell, S.p_selected_area->i_size,
286 input_OffsetToTime( p_input, psz_time1,
287 S.p_selected_area->i_tell ),
288 input_OffsetToTime( p_input, psz_time2,
289 S.p_selected_area->i_size ) );
291 msg_Dbg( p_input, "pace %scontrolled", S.b_pace_control ? "" : "un-" );
293 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
295 #define P p_input->stream.pp_programs[i]
296 msg_Dbg( p_input, "dumping program 0x%x, version %d (%s)",
297 P->i_number, P->i_version,
298 P->b_is_ok ? "complete" : "partial" );
300 for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
302 #define ES p_input->stream.pp_programs[i]->pp_es[j]
304 "ES 0x%x, stream 0x%x, fourcc `%4.4s', %s [OK:%d/ERR:%d]",
305 ES->i_id, ES->i_stream_id, (char*)&ES->i_fourcc,
306 ES->p_decoder_fifo != NULL ? "selected" : "not selected",
307 ES->c_packets, ES->c_invalid_packets );
313 /*****************************************************************************
314 * input_ToggleES: answers to a user request with calls to (Un)SelectES
315 *****************************************************************************
316 * Useful since the interface plugins know p_es.
317 * It only works for audio & spu ( to be sure nothing nasty is being done ).
318 * b_select is a boolean to know if we have to select or unselect ES
319 *****************************************************************************/
320 int input_ToggleES( input_thread_t * p_input, es_descriptor_t * p_es,
321 vlc_bool_t b_select )
323 vlc_mutex_lock( &p_input->stream.stream_lock );
329 p_input->stream.p_newly_selected_es = p_es;
333 p_input->stream.p_removed_es = p_es;
337 vlc_mutex_unlock( &p_input->stream.stream_lock );
342 /****************************************************************************
343 * input_ChangeArea: interface request an area change
344 ****************************************************************************/
345 int input_ChangeArea( input_thread_t * p_input, input_area_t * p_area )
347 vlc_mutex_lock( &p_input->stream.stream_lock );
349 p_input->stream.p_new_area = p_area;
351 vlc_mutex_unlock( &p_input->stream.stream_lock );
356 /****************************************************************************
357 * input_ChangeProgram: interface request a program change
358 ****************************************************************************/
359 int input_ChangeProgram( input_thread_t * p_input, u16 i_program_number )
361 pgrm_descriptor_t * p_program;
363 vlc_mutex_lock( &p_input->stream.stream_lock );
365 p_program = input_FindProgram( p_input, i_program_number );
367 if ( p_program == NULL )
369 msg_Err( p_input, "could not find selected program" );
373 p_input->stream.p_new_program = p_program;
375 vlc_mutex_unlock( &p_input->stream.stream_lock );
380 /****************************************************************************
381 * input_ToggleGrayscale: change to grayscale or color output
382 ****************************************************************************/
383 int input_ToggleGrayscale( input_thread_t * p_input )
385 /* No need to warn the input thread since only the decoders and outputs
387 vlc_mutex_lock( &p_input->stream.control.control_lock );
388 p_input->stream.control.b_grayscale =
389 !p_input->stream.control.b_grayscale;
391 msg_Dbg( p_input, "changing to %s output",
392 p_input->stream.control.b_grayscale ? "grayscale" : "color" );
394 vlc_mutex_unlock( &p_input->stream.control.control_lock );
399 /****************************************************************************
400 * input_ToggleMute: activate/deactivate mute mode
401 ****************************************************************************/
402 int input_ToggleMute( input_thread_t * p_input )
404 /* We need to feed the decoders with 0, and only input can do that, so
405 * pass the message to the input thread. */
406 vlc_mutex_lock( &p_input->stream.stream_lock );
407 p_input->stream.b_new_mute = !p_input->stream.control.b_mute;
409 msg_Dbg( p_input, "%s mute mode",
410 p_input->stream.control.b_mute ? "activating" : "deactivating" );
412 vlc_mutex_unlock( &p_input->stream.stream_lock );