]> git.sesse.net Git - vlc/blob - src/input/demux.c
* include/vlc_codec.h: defines decoders/encoders related structures here.
[vlc] / src / input / demux.c
1 /*****************************************************************************
2  * demux.c
3  *****************************************************************************
4  * Copyright (C) 1999-2003 VideoLAN
5  * $Id: demux.c,v 1.4 2003/10/08 21:01:07 gbazin Exp $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include <stdlib.h>
25 #include <vlc/vlc.h>
26 #include <vlc/input.h>
27
28 #include "ninput.h"
29
30 int demux_vaControl( input_thread_t *p_input, int i_query, va_list args )
31 {
32     if( p_input->pf_demux_control )
33     {
34         return p_input->pf_demux_control( p_input, i_query, args );
35     }
36     return VLC_EGENERIC;
37 }
38
39 int demux_Control( input_thread_t *p_input, int i_query, ...  )
40 {
41     va_list args;
42     int     i_result;
43
44     va_start( args, i_query );
45     i_result = demux_vaControl( p_input, i_query, args );
46     va_end( args );
47
48     return i_result;
49 }
50
51 static void SeekOffset( input_thread_t *p_input, int64_t i_pos );
52
53 int demux_vaControlDefault( input_thread_t *p_input, int i_query,
54                             va_list args )
55 {
56     int     i_ret;
57     double  f, *pf;
58     int64_t i64, *pi64;
59
60     vlc_mutex_lock( &p_input->stream.stream_lock );
61     switch( i_query )
62     {
63         case DEMUX_GET_POSITION:
64             pf = (double*)va_arg( args, double * );
65             if( p_input->stream.p_selected_area->i_size <= 0 )
66             {
67                 *pf = 0.0;
68             }
69             else
70             {
71                 *pf = (double)p_input->stream.p_selected_area->i_tell /
72                       (double)p_input->stream.p_selected_area->i_size;
73             }
74             i_ret = VLC_SUCCESS;
75             break;
76
77         case DEMUX_SET_POSITION:
78             f = (double)va_arg( args, double );
79             if( p_input->stream.b_seekable && p_input->pf_seek != NULL &&
80                 f >= 0.0 && f <= 1.0 )
81             {
82                 SeekOffset( p_input, (int64_t)(f *
83                             (double)p_input->stream.p_selected_area->i_size) );
84                 i_ret = VLC_SUCCESS;
85             }
86             else
87             {
88                 i_ret = VLC_EGENERIC;
89             }
90             break;
91
92         case DEMUX_GET_TIME:
93             pi64 = (int64_t*)va_arg( args, int64_t * );
94             if( p_input->stream.i_mux_rate > 0 )
95             {
96                 *pi64 = (int64_t)1000000 *
97                         ( p_input->stream.p_selected_area->i_tell / 50 ) /
98                         p_input->stream.i_mux_rate;
99                 i_ret = VLC_SUCCESS;
100             }
101             else
102             {
103                 *pi64 = 0;
104                 i_ret = VLC_EGENERIC;
105             }
106             break;
107
108         case DEMUX_SET_TIME:
109             i64 = (int64_t)va_arg( args, int64_t );
110             if( p_input->stream.i_mux_rate > 0 &&
111                 p_input->stream.b_seekable &&
112                 p_input->pf_seek != NULL && i64 >= 0 )
113             {
114                 SeekOffset( p_input, i64 * 50 *
115                                      (int64_t)p_input->stream.i_mux_rate /
116                                      (int64_t)1000000 );
117                 i_ret = VLC_SUCCESS;
118             }
119             else
120             {
121                 i_ret = VLC_EGENERIC;
122             }
123             break;
124
125         case DEMUX_GET_LENGTH:
126             pi64 = (int64_t*)va_arg( args, int64_t * );
127             if( p_input->stream.i_mux_rate > 0 )
128             {
129                 *pi64 = (int64_t)1000000 *
130                         ( p_input->stream.p_selected_area->i_size / 50 ) /
131                         p_input->stream.i_mux_rate;
132                 i_ret = VLC_SUCCESS;
133             }
134             else
135             {
136                 *pi64 = 0;
137                 i_ret = VLC_EGENERIC;
138             }
139             break;
140         case DEMUX_GET_FPS:
141             i_ret = VLC_EGENERIC;
142             break;
143
144         default:
145             msg_Err( p_input, "unknown query in demux_vaControlDefault !!!" );
146             i_ret = VLC_EGENERIC;
147             break;
148     }
149     vlc_mutex_unlock( &p_input->stream.stream_lock );
150
151     return i_ret;
152 }
153
154 static void SeekOffset( input_thread_t *p_input, int64_t i_pos )
155 {
156     /* Reinitialize buffer manager. */
157     input_AccessReinit( p_input );
158
159     vlc_mutex_unlock( &p_input->stream.stream_lock );
160     p_input->pf_seek( p_input, i_pos );
161     vlc_mutex_lock( &p_input->stream.stream_lock );
162 }