Changeset 6da08521b20cf48028bfdef07438577f7cf11272

Show
Ignore:
Timestamp:
02/12/03 02:54:30 (5 years ago)
Author:
Rocky Bernstein <rocky@videolan.org>
git-committer:
Rocky Bernstein <rocky@videolan.org> 1070330070 +0000
git-parent:

[59173c65552ee499e502e4961215e85526e483ff]

git-author:
Rocky Bernstein <rocky@videolan.org> 1070330070 +0000
Message:

Add secstotimestr and msecstotimestr to convert (milli)seconds to a
time string.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/mtime.h

    rbc061e8 r6da0852  
    1010 ***************************************************************************** 
    1111 * Copyright (C) 1996, 1997, 1998, 1999, 2000 VideoLAN 
    12  * $Id: mtime.h,v 1.13 2002/11/11 14:39:11 sam Exp $ 
     12 * $Id: mtime.h,v 1.14 2003/12/02 01:54:30 rocky Exp $ 
    1313 * 
    1414 * Authors: Vincent Seguin <seguin@via.ecp.fr> 
     
    4848#define MSTRTIME_MAX_SIZE 22 
    4949 
     50#define msecstotimestr(psz_buffer, msecs) \ 
     51  secstotimestr( psz_buffer, (msecs / (int) 1000) ) 
     52 
    5053/***************************************************************************** 
    5154 * Prototypes 
     
    5558VLC_EXPORT( void,    mwait,    ( mtime_t date ) ); 
    5659VLC_EXPORT( void,    msleep,   ( mtime_t delay ) ); 
     60VLC_EXPORT( char *,  secstotimestr, ( char *psz_buffer, int secs ) ); 
    5761 
  • modules/access/cdda/access.c

    rbe7869a r6da0852  
    33 ***************************************************************************** 
    44 * Copyright (C) 2000,2003 VideoLAN 
    5  * $Id: access.c,v 1.7 2003/12/01 03:34:30 rocky Exp $ 
     5 * $Id: access.c,v 1.8 2003/12/02 01:54:30 rocky Exp $ 
    66 * 
    77 * Authors: Rocky Bernstein <rocky@panix.com>  
     
    519519} 
    520520 
    521 static  
    522 char * secs2TimeStr( int64_t i_sec ) 
    523 { 
    524   int h = i_sec / 3600; 
    525   int m = ( i_sec / 60 ) % 60; 
    526   int s = i_sec % 60; 
    527   static char buffer[20]; 
    528  
    529   snprintf(buffer, 20, "%d:%2.2d:%2.2d", h, m, s); 
    530   return buffer; 
    531 } 
    532  
    533521#define meta_info_add_str(title, str) \ 
    534522  if ( str ) {                      \ 
     
    552540      { 
    553541    int64_t i_sec = (int64_t) p_cdda->cddb.disc->length; 
    554     input_AddInfo( p_cat, _("Duration"), "%s", secs2TimeStr( i_sec ) ); 
     542    char psz_buffer[MSTRTIME_MAX_SIZE]; 
     543    input_AddInfo( p_cat, _("Duration"), "%s",  
     544               secstotimestr( psz_buffer, i_sec ) ); 
    555545      } else  
    556546      { 
     
    586576  { 
    587577    track_t i_track = p_cdda->i_nb_tracks; 
     578    char psz_buffer[MSTRTIME_MAX_SIZE]; 
    588579    mtime_t i_duration =  
    589580      (p_cdda->p_sectors[i_track] - p_cdda->p_sectors[i_track-1])  
    590581      / CDIO_CD_FRAMES_PER_SEC; 
    591582 
    592     input_AddInfo( p_cat, _("Duration"), "%s", secs2TimeStr( i_duration ) ); 
     583    input_AddInfo( p_cat, _("Duration"), "%s",  
     584           secstotimestr( psz_buffer, i_duration ) ); 
    593585  } 
    594586} 
     
    830822    case 's': 
    831823      if (p_cdda->i_cddb_enabled) { 
     824    char psz_buffer[MSTRTIME_MAX_SIZE]; 
    832825    mtime_t i_duration =  
    833826      (p_cdda->p_sectors[i_track] - p_cdda->p_sectors[i_track-1])  
    834827      / CDIO_CD_FRAMES_PER_SEC; 
    835     add_format_str_info(secs2TimeStr(i_duration)); 
     828    add_format_str_info(secstotimestr( psz_buffer, i_duration ) ); 
    836829      } else goto not_special; 
    837830      break; 
  • modules/demux/mkv.cpp

    r93187b3 r6da0852  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001 VideoLAN 
    5  * $Id: mkv.cpp,v 1.47 2003/11/28 22:23:04 fenrir Exp $ 
     5 * $Id: mkv.cpp,v 1.48 2003/12/02 01:54:30 rocky Exp $ 
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    21722172    if( p_sys->f_duration > 1000.1 ) 
    21732173    { 
    2174         int64_t i_sec = (int64_t)p_sys->f_duration / 1000; 
    2175         int h,m,s; 
    2176  
    2177         h = i_sec / 3600; 
    2178         m = ( i_sec / 60 ) % 60; 
    2179         s = i_sec % 60; 
    2180  
    2181         input_AddInfo( p_cat, _("Duration"), "%d:%2.2d:%2.2d" , h, m, s ); 
     2174    char psz_buffer[MSTRTIME_MAX_SIZE]; 
     2175        input_AddInfo( p_cat, _("Duration"),  
     2176               msecstotimestr( psz_buffer, p_sys->f_duration ) ); 
    21822177    } 
    21832178 
  • modules/gui/gtk/playlist.c

    r03b32e8 r6da0852  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001 VideoLAN 
    5  * $Id: playlist.c,v 1.5 2003/11/30 19:42:52 sigmunau Exp $ 
     5 * $Id: playlist.c,v 1.6 2003/12/02 01:54:30 rocky Exp $ 
    66 * 
    77 * Authors: Pierre Baillet <oct@zoy.org> 
     
    695695    for( i_dummy = p_playlist->i_size ; i_dummy-- ; ) 
    696696    { 
    697         char psz_duration[14]; 
     697        char psz_duration[MSTRTIME_MAX_SIZE]; 
    698698        mtime_t dur = p_playlist->pp_items[i_dummy]->i_duration; 
    699699        if ( dur != -1 ) 
    700700        { 
    701             sprintf( psz_duration, "%d:%2.2d:%2.2d", (int)(dur / 3600), 
    702                      (int)(( dur % 3600 ) / 60), (int)(dur % 60) ); 
     701      secstotimestr( psz_duration, dur ); 
    703702        } 
    704703        else 
  • src/misc/mtime.c

    r6350ac8 r6da0852  
    44 ***************************************************************************** 
    55 * Copyright (C) 1998-2001 VideoLAN 
    6  * $Id: mtime.c,v 1.36 2003/06/05 11:52:19 gbazin Exp $ 
     6 * $Id: mtime.c,v 1.37 2003/12/02 01:54:30 rocky Exp $ 
    77 * 
    88 * Authors: Vincent Seguin <seguin@via.ecp.fr> 
     
    6868 * mstrtime: return a date in a readable format 
    6969 ***************************************************************************** 
    70  * This functions is provided for any interface function which need to print a 
    71  * date. psz_buffer should be a buffer long enough to store the formatted 
     70 * This function converts a mtime date into a string. 
     71 * psz_buffer should be a buffer long enough to store the formatted 
    7272 * date. 
    7373 *****************************************************************************/ 
     74/** 
     75 * \brief return a date in a readable format 
     76 * \param date to be converted 
     77 * \param psz_buffer should be a buffer at least MSTRTIME_MAX_SIZE characters 
     78 * \return psz_buffer is returned so this can be used as printf parameter. 
     79 */ 
    7480char *mstrtime( char *psz_buffer, mtime_t date ) 
    7581{ 
    7682    static mtime_t ll1000 = 1000, ll60 = 60, ll24 = 24; 
    7783 
    78     sprintf( psz_buffer, "%02d:%02d:%02d-%03d.%03d", 
     84    snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%02d:%02d:%02d-%03d.%03d", 
    7985             (int) (date / (ll1000 * ll1000 * ll60 * ll60) % ll24), 
    8086             (int) (date / (ll1000 * ll1000 * ll60) % ll60), 
     
    8389             (int) (date % ll1000) ); 
    8490    return( psz_buffer ); 
     91} 
     92 
     93/***************************************************************************** 
     94 * secstotimestr: convert seconds to a time in the format h:mm:ss  
     95 ***************************************************************************** 
     96 * This function is provided for any interface function which need to print a 
     97 * time string in the format h:mm:ss 
     98 * date. 
     99 *****************************************************************************/ 
     100/** 
     101 * \brief convert seconds to a time in the format h:mm:ss  
     102 * \param secs  the date to be converted 
     103 * \param psz_buffer should be a buffer at least MSTRTIME_MAX_SIZE characters 
     104 * \return psz_buffer is returned so this can be used as printf parameter. 
     105 */ 
     106char *secstotimestr( char *psz_buffer, int secs ) 
     107{ 
     108  snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%d:%2.2d:%2.2d", 
     109        (int) (secs / 3600), (int)(( secs % 3600 ) / 60),  
     110        (int)(secs % 60) ); 
     111  return( psz_buffer ); 
    85112} 
    86113