Commit 6da08521 authored by Rocky Bernstein's avatar Rocky Bernstein

Add secstotimestr and msecstotimestr to convert (milli)seconds to a

time string.
parent 59173c65
......@@ -9,7 +9,7 @@
* Functions prototyped are implemented in interface/mtime.c.
*****************************************************************************
* Copyright (C) 1996, 1997, 1998, 1999, 2000 VideoLAN
* $Id: mtime.h,v 1.13 2002/11/11 14:39:11 sam Exp $
* $Id: mtime.h,v 1.14 2003/12/02 01:54:30 rocky Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
*
......@@ -47,6 +47,9 @@
*****************************************************************************/
#define MSTRTIME_MAX_SIZE 22
#define msecstotimestr(psz_buffer, msecs) \
secstotimestr( psz_buffer, (msecs / (int) 1000) )
/*****************************************************************************
* Prototypes
*****************************************************************************/
......@@ -54,4 +57,5 @@ VLC_EXPORT( char *, mstrtime, ( char *psz_buffer, mtime_t date ) );
VLC_EXPORT( mtime_t, mdate, ( void ) );
VLC_EXPORT( void, mwait, ( mtime_t date ) );
VLC_EXPORT( void, msleep, ( mtime_t delay ) );
VLC_EXPORT( char *, secstotimestr, ( char *psz_buffer, int secs ) );
......@@ -2,7 +2,7 @@
* cddax.c : CD digital audio input module for vlc using libcdio
*****************************************************************************
* Copyright (C) 2000,2003 VideoLAN
* $Id: access.c,v 1.7 2003/12/01 03:34:30 rocky Exp $
* $Id: access.c,v 1.8 2003/12/02 01:54:30 rocky Exp $
*
* Authors: Rocky Bernstein <rocky@panix.com>
* Laurent Aimar <fenrir@via.ecp.fr>
......@@ -518,18 +518,6 @@ static void CDDASeek( input_thread_t * p_input, off_t i_off )
}
static
char * secs2TimeStr( int64_t i_sec )
{
int h = i_sec / 3600;
int m = ( i_sec / 60 ) % 60;
int s = i_sec % 60;
static char buffer[20];
snprintf(buffer, 20, "%d:%2.2d:%2.2d", h, m, s);
return buffer;
}
#define meta_info_add_str(title, str) \
if ( str ) { \
printf("field %s str %s\n", title, str); \
......@@ -551,7 +539,9 @@ static void InformationCreate( input_thread_t *p_input )
if( p_cdda->cddb.disc->length > 1000 )
{
int64_t i_sec = (int64_t) p_cdda->cddb.disc->length;
input_AddInfo( p_cat, _("Duration"), "%s", secs2TimeStr( i_sec ) );
char psz_buffer[MSTRTIME_MAX_SIZE];
input_AddInfo( p_cat, _("Duration"), "%s",
secstotimestr( psz_buffer, i_sec ) );
} else
{
use_cddb = 0;
......@@ -585,11 +575,13 @@ static void InformationCreate( input_thread_t *p_input )
if (!use_cddb)
{
track_t i_track = p_cdda->i_nb_tracks;
char psz_buffer[MSTRTIME_MAX_SIZE];
mtime_t i_duration =
(p_cdda->p_sectors[i_track] - p_cdda->p_sectors[i_track-1])
/ CDIO_CD_FRAMES_PER_SEC;
input_AddInfo( p_cat, _("Duration"), "%s", secs2TimeStr( i_duration ) );
input_AddInfo( p_cat, _("Duration"), "%s",
secstotimestr( psz_buffer, i_duration ) );
}
}
......@@ -829,10 +821,11 @@ CDDAFormatStr(const input_thread_t *p_input, cdda_data_t *p_cdda,
case 's':
if (p_cdda->i_cddb_enabled) {
char psz_buffer[MSTRTIME_MAX_SIZE];
mtime_t i_duration =
(p_cdda->p_sectors[i_track] - p_cdda->p_sectors[i_track-1])
/ CDIO_CD_FRAMES_PER_SEC;
add_format_str_info(secs2TimeStr(i_duration));
add_format_str_info(secstotimestr( psz_buffer, i_duration ) );
} else goto not_special;
break;
......
......@@ -2,7 +2,7 @@
* mkv.cpp : matroska demuxer
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: mkv.cpp,v 1.47 2003/11/28 22:23:04 fenrir Exp $
* $Id: mkv.cpp,v 1.48 2003/12/02 01:54:30 rocky Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
......@@ -2171,14 +2171,9 @@ static void InformationsCreate( input_thread_t *p_input )
p_cat = input_InfoCategory( p_input, "Matroska" );
if( p_sys->f_duration > 1000.1 )
{
int64_t i_sec = (int64_t)p_sys->f_duration / 1000;
int h,m,s;
h = i_sec / 3600;
m = ( i_sec / 60 ) % 60;
s = i_sec % 60;
input_AddInfo( p_cat, _("Duration"), "%d:%2.2d:%2.2d" , h, m, s );
char psz_buffer[MSTRTIME_MAX_SIZE];
input_AddInfo( p_cat, _("Duration"),
msecstotimestr( psz_buffer, p_sys->f_duration ) );
}
if( p_sys->psz_title )
......
......@@ -2,7 +2,7 @@
* gtk_playlist.c : Interface for the playlist dialog
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: playlist.c,v 1.5 2003/11/30 19:42:52 sigmunau Exp $
* $Id: playlist.c,v 1.6 2003/12/02 01:54:30 rocky Exp $
*
* Authors: Pierre Baillet <oct@zoy.org>
* Stphane Borel <stef@via.ecp.fr>
......@@ -694,12 +694,11 @@ void GtkRebuildCList( GtkCList * p_clist, playlist_t * p_playlist )
vlc_mutex_lock( &p_playlist->object_lock );
for( i_dummy = p_playlist->i_size ; i_dummy-- ; )
{
char psz_duration[14];
char psz_duration[MSTRTIME_MAX_SIZE];
mtime_t dur = p_playlist->pp_items[i_dummy]->i_duration;
if ( dur != -1 )
{
sprintf( psz_duration, "%d:%2.2d:%2.2d", (int)(dur / 3600),
(int)(( dur % 3600 ) / 60), (int)(dur % 60) );
secstotimestr( psz_duration, dur );
}
else
{
......
......@@ -3,7 +3,7 @@
* Functions are prototyped in mtime.h.
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
* $Id: mtime.c,v 1.36 2003/06/05 11:52:19 gbazin Exp $
* $Id: mtime.c,v 1.37 2003/12/02 01:54:30 rocky Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
*
......@@ -67,15 +67,21 @@ int nanosleep(struct timespec *, struct timespec *);
/*****************************************************************************
* mstrtime: return a date in a readable format
*****************************************************************************
* This functions is provided for any interface function which need to print a
* date. psz_buffer should be a buffer long enough to store the formatted
* This function converts a mtime date into a string.
* psz_buffer should be a buffer long enough to store the formatted
* date.
*****************************************************************************/
/**
* \brief return a date in a readable format
* \param date to be converted
* \param psz_buffer should be a buffer at least MSTRTIME_MAX_SIZE characters
* \return psz_buffer is returned so this can be used as printf parameter.
*/
char *mstrtime( char *psz_buffer, mtime_t date )
{
static mtime_t ll1000 = 1000, ll60 = 60, ll24 = 24;
sprintf( psz_buffer, "%02d:%02d:%02d-%03d.%03d",
snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%02d:%02d:%02d-%03d.%03d",
(int) (date / (ll1000 * ll1000 * ll60 * ll60) % ll24),
(int) (date / (ll1000 * ll1000 * ll60) % ll60),
(int) (date / (ll1000 * ll1000) % ll60),
......@@ -84,6 +90,27 @@ char *mstrtime( char *psz_buffer, mtime_t date )
return( psz_buffer );
}
/*****************************************************************************
* secstotimestr: convert seconds to a time in the format h:mm:ss
*****************************************************************************
* This function is provided for any interface function which need to print a
* time string in the format h:mm:ss
* date.
*****************************************************************************/
/**
* \brief convert seconds to a time in the format h:mm:ss
* \param secs the date to be converted
* \param psz_buffer should be a buffer at least MSTRTIME_MAX_SIZE characters
* \return psz_buffer is returned so this can be used as printf parameter.
*/
char *secstotimestr( char *psz_buffer, int secs )
{
snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%d:%2.2d:%2.2d",
(int) (secs / 3600), (int)(( secs % 3600 ) / 60),
(int)(secs % 60) );
return( psz_buffer );
}
/*****************************************************************************
* mdate: return high precision date
*****************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment