1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 1999-2003 VideoLAN
5 * $Id: demux.c,v 1.3 2003/09/13 17:42:16 fenrir Exp $
7 * Authors: Laurent Aimar <fenrir@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 *****************************************************************************/
26 #include <vlc/input.h>
30 int demux_vaControl( input_thread_t *p_input, int i_query, va_list args )
32 if( p_input->pf_demux_control )
34 return p_input->pf_demux_control( p_input, i_query, args );
39 int demux_Control ( input_thread_t *p_input, int i_query, ... )
44 va_start( args, i_query );
45 i_result = demux_vaControl( p_input, i_query, args );
51 static void SeekOffset( input_thread_t *p_input, int64_t i_pos );
53 int demux_vaControlDefault( input_thread_t *p_input, int i_query, va_list args )
59 vlc_mutex_lock( &p_input->stream.stream_lock );
62 case DEMUX_GET_POSITION:
63 pf = (double*)va_arg( args, double * );
64 if( p_input->stream.p_selected_area->i_size <= 0 )
70 *pf = (double)p_input->stream.p_selected_area->i_tell /
71 (double)p_input->stream.p_selected_area->i_size;
76 case DEMUX_SET_POSITION:
77 f = (double)va_arg( args, double );
78 if( p_input->stream.b_seekable && p_input->pf_seek != NULL && f >= 0.0 && f <= 1.0 )
80 SeekOffset( p_input, (int64_t)(f * (double)p_input->stream.p_selected_area->i_size) );
90 pi64 = (int64_t*)va_arg( args, int64_t * );
91 if( p_input->stream.i_mux_rate > 0 )
93 *pi64 = (int64_t)1000000 *
94 ( p_input->stream.p_selected_area->i_tell / 50 ) /
95 p_input->stream.i_mux_rate;
101 i_ret = VLC_EGENERIC;
106 i64 = (int64_t)va_arg( args, int64_t );
107 if( p_input->stream.i_mux_rate > 0 &&
108 p_input->stream.b_seekable && p_input->pf_seek != NULL && i64 >= 0 )
110 SeekOffset( p_input, i64 * 50 *
111 (int64_t)p_input->stream.i_mux_rate /
117 i_ret = VLC_EGENERIC;
121 case DEMUX_GET_LENGTH:
122 pi64 = (int64_t*)va_arg( args, int64_t * );
123 if( p_input->stream.i_mux_rate > 0 )
125 *pi64 = (int64_t)1000000 *
126 ( p_input->stream.p_selected_area->i_size / 50 ) /
127 p_input->stream.i_mux_rate;
133 i_ret = VLC_EGENERIC;
137 i_ret = VLC_EGENERIC;
141 msg_Err( p_input, "unknown query in demux_vaControlDefault !!!" );
142 i_ret = VLC_EGENERIC;
145 vlc_mutex_unlock( &p_input->stream.stream_lock );
151 static void SeekOffset( input_thread_t *p_input, int64_t i_pos )
153 /* Reinitialize buffer manager. */
154 input_AccessReinit( p_input );
156 vlc_mutex_unlock( &p_input->stream.stream_lock );
157 p_input->pf_seek( p_input, i_pos );
158 vlc_mutex_lock( &p_input->stream.stream_lock );