1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include <stdio.h> // snprintf
28 #include <vlc_input.h>
30 void StreamTime::set( float percentage, bool updateVLC )
32 VarPercent::set( percentage );
34 // Avoid looping forever...
35 if( updateVLC && getIntf()->p_sys->p_input )
38 pos.f_float = percentage;
40 var_Set( getIntf()->p_sys->p_input, "position", pos );
45 const string StreamTime::getAsStringPercent() const
47 int value = (int)(100. * get());
48 // 0 <= value <= 100, so we need 4 chars
49 char *str = new char[4];
50 snprintf( str, 4, "%d", value );
58 const string StreamTime::getAsStringCurrTime( bool bShortFormat ) const
60 if( getIntf()->p_sys->p_input == NULL )
65 vlc_value_t pos; pos.f_float = 0.0;
66 var_Get( getIntf()->p_sys->p_input, "position", &pos );
67 if( pos.f_float == 0.0 )
72 vlc_value_t time; time.i_time = 0L;
73 var_Get( getIntf()->p_sys->p_input, "time", &time );
75 return formatTime( time.i_time / 1000000, bShortFormat );
79 const string StreamTime::getAsStringTimeLeft( bool bShortFormat ) const
81 if( getIntf()->p_sys->p_input == NULL )
87 var_Get( getIntf()->p_sys->p_input, "position", &pos );
88 if( pos.f_float == 0.0 )
93 vlc_value_t time, duration;
94 var_Get( getIntf()->p_sys->p_input, "time", &time );
95 var_Get( getIntf()->p_sys->p_input, "length", &duration );
97 return formatTime( (duration.i_time - time.i_time) / 1000000,
102 const string StreamTime::getAsStringDuration( bool bShortFormat ) const
104 if( getIntf()->p_sys->p_input == NULL )
109 vlc_value_t pos; pos.f_float = 0.0;
110 var_Get( getIntf()->p_sys->p_input, "position", &pos );
111 if( pos.f_float == 0.0 )
117 var_Get( getIntf()->p_sys->p_input, "length", &time );
119 return formatTime( time.i_time / 1000000, bShortFormat );
123 const string StreamTime::formatTime( int seconds, bool bShortFormat ) const
125 char *psz_time = new char[MSTRTIME_MAX_SIZE];
126 if( bShortFormat && (seconds < 60 * 60) )
128 snprintf( psz_time, MSTRTIME_MAX_SIZE, "%02d:%02d",
129 (int) (seconds / 60 % 60),
130 (int) (seconds % 60) );
134 snprintf( psz_time, MSTRTIME_MAX_SIZE, "%d:%02d:%02d",
135 (int) (seconds / (60 * 60)),
136 (int) (seconds / 60 % 60),
137 (int) (seconds % 60) );
140 string ret = psz_time;