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 along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include <vlc_input.h>
29 inline bool StreamTime::havePosition() const {
30 input_thread_t
*p_input
= getIntf()->p_sys
->p_input
;
31 return p_input
&& ( var_GetFloat( p_input
, "position" ) != 0.0 );
35 void StreamTime::set( float percentage
, bool updateVLC
)
37 VarPercent::set( percentage
);
39 // Avoid looping forever...
40 if( updateVLC
&& getIntf()->p_sys
->p_input
)
41 var_SetFloat( getIntf()->p_sys
->p_input
, "position", percentage
);
45 string
StreamTime::getAsStringPercent() const
47 int value
= (int)(100. * get());
48 // 0 <= value <= 100, so we need 4 chars
50 snprintf( str
, 4, "%d", value
);
55 string
StreamTime::formatTime( int seconds
, bool bShortFormat
) const
57 char psz_time
[MSTRTIME_MAX_SIZE
];
58 if( bShortFormat
&& (seconds
< 60 * 60) )
60 snprintf( psz_time
, MSTRTIME_MAX_SIZE
, "%02d:%02d",
61 (int) (seconds
/ 60 % 60),
62 (int) (seconds
% 60) );
66 snprintf( psz_time
, MSTRTIME_MAX_SIZE
, "%d:%02d:%02d",
67 (int) (seconds
/ (60 * 60)),
68 (int) (seconds
/ 60 % 60),
69 (int) (seconds
% 60) );
71 return string(psz_time
);
75 string
StreamTime::getAsStringCurrTime( bool bShortFormat
) const
80 mtime_t time
= var_GetTime( getIntf()->p_sys
->p_input
, "time" );
81 return formatTime( time
/ 1000000, bShortFormat
);
85 string
StreamTime::getAsStringTimeLeft( bool bShortFormat
) const
90 mtime_t time
= var_GetTime( getIntf()->p_sys
->p_input
, "time" ),
91 duration
= var_GetTime( getIntf()->p_sys
->p_input
, "length" );
93 return formatTime( (duration
- time
) / 1000000, bShortFormat
);
97 string
StreamTime::getAsStringDuration( bool bShortFormat
) const
102 mtime_t time
= var_GetTime( getIntf()->p_sys
->p_input
, "length" );
103 return formatTime( time
/ 1000000, bShortFormat
);