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.43 2002/11/11 14:39:12 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() */
31 #include "stream_control.h"
32 #include "input_ext-dec.h"
33 #include "input_ext-intf.h"
34 #include "input_ext-plugins.h"
36 /*****************************************************************************
37 * input_SetStatus: change the reading status
38 *****************************************************************************/
39 void __input_SetStatus( vlc_object_t * p_this, int i_mode )
41 input_thread_t *p_input;
43 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
47 msg_Err( p_this, "no input found" );
51 vlc_mutex_lock( &p_input->stream.stream_lock );
55 case INPUT_STATUS_END:
56 p_input->stream.i_new_status = PLAYING_S;
58 msg_Dbg( p_input, "end of stream" );
61 case INPUT_STATUS_PLAY:
62 p_input->stream.i_new_status = PLAYING_S;
63 msg_Dbg( p_input, "playing at normal rate" );
66 case INPUT_STATUS_PAUSE:
67 /* XXX: we don't need to check i_status, because input_clock.c
69 p_input->stream.i_new_status = PAUSE_S;
70 msg_Dbg( p_input, "toggling pause" );
73 case INPUT_STATUS_FASTER:
74 /* If we are already going too fast, go back to default rate */
75 if( p_input->stream.control.i_rate * 8 <= DEFAULT_RATE )
77 p_input->stream.i_new_status = PLAYING_S;
78 msg_Dbg( p_input, "playing at normal rate" );
82 p_input->stream.i_new_status = FORWARD_S;
84 if( p_input->stream.control.i_rate < DEFAULT_RATE
85 && p_input->stream.control.i_status == FORWARD_S )
87 p_input->stream.i_new_rate =
88 p_input->stream.control.i_rate / 2;
92 p_input->stream.i_new_rate = DEFAULT_RATE / 2;
94 msg_Dbg( p_input, "playing at %i:1 fast forward",
95 DEFAULT_RATE / p_input->stream.i_new_rate );
99 case INPUT_STATUS_SLOWER:
100 /* If we are already going too slow, go back to default rate */
101 if( p_input->stream.control.i_rate >= 8 * DEFAULT_RATE )
103 p_input->stream.i_new_status = PLAYING_S;
104 msg_Dbg( p_input, "playing at normal rate" );
108 p_input->stream.i_new_status = FORWARD_S;
110 if( p_input->stream.control.i_rate > DEFAULT_RATE
111 && p_input->stream.control.i_status == FORWARD_S )
113 p_input->stream.i_new_rate =
114 p_input->stream.control.i_rate * 2;
118 p_input->stream.i_new_rate = DEFAULT_RATE * 2;
120 msg_Dbg( p_input, "playing at 1:%i slow motion",
121 p_input->stream.i_new_rate / DEFAULT_RATE );
129 vlc_cond_signal( &p_input->stream.stream_wait );
130 vlc_mutex_unlock( &p_input->stream.stream_lock );
132 vlc_object_release( p_input );
135 /*****************************************************************************
136 * input_Seek: changes the stream postion
137 *****************************************************************************/
138 void __input_Seek( vlc_object_t * p_this, off_t i_position, int i_whence )
140 input_thread_t *p_input;
142 char psz_time1[OFFSETTOTIME_MAX_SIZE];
143 char psz_time2[OFFSETTOTIME_MAX_SIZE];
145 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
147 if( p_input == NULL )
149 msg_Err( p_this, "no input found" );
153 vlc_mutex_lock( &p_input->stream.stream_lock );
155 #define A p_input->stream.p_selected_area
156 switch( i_whence & 0x30 )
158 case INPUT_SEEK_SECONDS:
159 i_position *= (off_t)50 * p_input->stream.i_mux_rate;
162 case INPUT_SEEK_PERCENT:
163 i_position = A->i_size * i_position / (off_t)100;
166 case INPUT_SEEK_BYTES:
171 switch( i_whence & 0x03 )
174 A->i_seek = A->i_tell + i_position;
178 A->i_seek = A->i_size + i_position;
183 A->i_seek = i_position;
191 else if( A->i_seek > A->i_size )
193 A->i_seek = A->i_size;
196 msg_Dbg( p_input, "seeking position "I64Fd"/"I64Fd" (%s/%s)",
197 A->i_seek, A->i_size,
198 input_OffsetToTime( p_input, psz_time1, i_position ),
199 input_OffsetToTime( p_input, psz_time2, A->i_size ) );
202 vlc_cond_signal( &p_input->stream.stream_wait );
203 vlc_mutex_unlock( &p_input->stream.stream_lock );
205 vlc_object_release( p_input );
208 /*****************************************************************************
209 * input_Tell: requests the stream postion
210 *****************************************************************************/
211 void __input_Tell( vlc_object_t * p_this, stream_position_t * p_position )
213 input_thread_t *p_input;
215 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
217 if( p_input == NULL )
219 p_position->i_tell = 0;
220 p_position->i_size = 0;
221 p_position->i_mux_rate = 0;
222 msg_Err( p_this, "no input found" );
226 vlc_mutex_lock( &p_input->stream.stream_lock );
228 #define A p_input->stream.p_selected_area
229 p_position->i_tell = A->i_tell;
230 p_position->i_size = A->i_size;
231 p_position->i_mux_rate = p_input->stream.i_mux_rate;
234 vlc_mutex_unlock( &p_input->stream.stream_lock );
235 vlc_object_release( p_input );
238 /*****************************************************************************
239 * input_OffsetToTime : converts an off_t value to a time indicator, using
241 *****************************************************************************
242 * BEWARE : this function assumes that you already own the lock on
243 * p_input->stream.stream_lock
244 *****************************************************************************/
245 char * input_OffsetToTime( input_thread_t * p_input, char * psz_buffer,
250 if( p_input->stream.i_mux_rate )
252 i_seconds = i_offset / 50 / p_input->stream.i_mux_rate;
253 snprintf( psz_buffer, OFFSETTOTIME_MAX_SIZE, "%d:%02d:%02d",
254 (int) (i_seconds / (60 * 60)),
255 (int) (i_seconds / 60 % 60),
256 (int) (i_seconds % 60) );
257 return( psz_buffer );
261 /* Divide by zero is not my friend. */
262 sprintf( psz_buffer, "-:--:--" );
263 return( psz_buffer );
267 /*****************************************************************************
268 * input_DumpStream: dumps the contents of a stream descriptor
269 *****************************************************************************
270 * BEWARE : this function assumes that you already own the lock on
271 * p_input->stream.stream_lock
272 *****************************************************************************/
273 void input_DumpStream( input_thread_t * p_input )
276 char psz_time1[OFFSETTOTIME_MAX_SIZE];
277 char psz_time2[OFFSETTOTIME_MAX_SIZE];
279 #define S p_input->stream
280 msg_Dbg( p_input, "dumping stream ID 0x%x [OK:%d/D:%d]", S.i_stream_id,
281 S.c_packets_read, S.c_packets_trashed );
283 msg_Dbg( p_input, "seekable stream, position: "I64Fd"/"I64Fd" (%s/%s)",
284 S.p_selected_area->i_tell, S.p_selected_area->i_size,
285 input_OffsetToTime( p_input, psz_time1,
286 S.p_selected_area->i_tell ),
287 input_OffsetToTime( p_input, psz_time2,
288 S.p_selected_area->i_size ) );
290 msg_Dbg( p_input, "pace %scontrolled", S.b_pace_control ? "" : "un-" );
292 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
294 #define P p_input->stream.pp_programs[i]
295 msg_Dbg( p_input, "dumping program 0x%x, version %d (%s)",
296 P->i_number, P->i_version,
297 P->b_is_ok ? "complete" : "partial" );
299 for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
301 #define ES p_input->stream.pp_programs[i]->pp_es[j]
303 "ES 0x%x, stream 0x%x, fourcc `%4.4s', %s [OK:%d/ERR:%d]",
304 ES->i_id, ES->i_stream_id, (char*)&ES->i_fourcc,
305 ES->p_decoder_fifo != NULL ? "selected" : "not selected",
306 ES->c_packets, ES->c_invalid_packets );
312 /*****************************************************************************
313 * input_ToggleES: answers to a user request with calls to (Un)SelectES
314 *****************************************************************************
315 * Useful since the interface plugins know p_es.
316 * It only works for audio & spu ( to be sure nothing nasty is being done ).
317 * b_select is a boolean to know if we have to select or unselect ES
318 *****************************************************************************/
319 int input_ToggleES( input_thread_t * p_input, es_descriptor_t * p_es,
320 vlc_bool_t b_select )
322 vlc_mutex_lock( &p_input->stream.stream_lock );
328 p_input->stream.p_newly_selected_es = p_es;
332 p_input->stream.p_removed_es = p_es;
336 vlc_mutex_unlock( &p_input->stream.stream_lock );
341 /****************************************************************************
342 * input_ChangeArea: interface request an area change
343 ****************************************************************************/
344 int input_ChangeArea( input_thread_t * p_input, input_area_t * p_area )
346 vlc_mutex_lock( &p_input->stream.stream_lock );
348 p_input->stream.p_new_area = p_area;
350 vlc_mutex_unlock( &p_input->stream.stream_lock );
355 /****************************************************************************
356 * input_ChangeProgram: interface request a program change
357 ****************************************************************************/
358 int input_ChangeProgram( input_thread_t * p_input, u16 i_program_number )
360 pgrm_descriptor_t * p_program;
362 vlc_mutex_lock( &p_input->stream.stream_lock );
364 p_program = input_FindProgram( p_input, i_program_number );
366 if ( p_program == NULL )
368 msg_Err( p_input, "could not find selected program" );
372 p_input->stream.p_new_program = p_program;
374 vlc_mutex_unlock( &p_input->stream.stream_lock );
379 /****************************************************************************
380 * input_ToggleGrayscale: change to grayscale or color output
381 ****************************************************************************/
382 int input_ToggleGrayscale( input_thread_t * p_input )
384 /* No need to warn the input thread since only the decoders and outputs
386 vlc_mutex_lock( &p_input->stream.control.control_lock );
387 p_input->stream.control.b_grayscale =
388 !p_input->stream.control.b_grayscale;
390 msg_Dbg( p_input, "changing to %s output",
391 p_input->stream.control.b_grayscale ? "grayscale" : "color" );
393 vlc_mutex_unlock( &p_input->stream.control.control_lock );
398 /****************************************************************************
399 * input_ToggleMute: activate/deactivate mute mode
400 ****************************************************************************/
401 int input_ToggleMute( input_thread_t * p_input )
403 /* We need to feed the decoders with 0, and only input can do that, so
404 * pass the message to the input thread. */
405 vlc_mutex_lock( &p_input->stream.stream_lock );
406 p_input->stream.b_new_mute = !p_input->stream.control.b_mute;
408 msg_Dbg( p_input, "%s mute mode",
409 p_input->stream.control.b_mute ? "activating" : "deactivating" );
411 vlc_mutex_unlock( &p_input->stream.stream_lock );