Changeset 6da08521b20cf48028bfdef07438577f7cf11272
- 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
| rbc061e8 |
r6da0852 |
|
| 10 | 10 | ***************************************************************************** |
|---|
| 11 | 11 | * 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 $ |
|---|
| 13 | 13 | * |
|---|
| 14 | 14 | * Authors: Vincent Seguin <seguin@via.ecp.fr> |
|---|
| … | … | |
| 48 | 48 | #define MSTRTIME_MAX_SIZE 22 |
|---|
| 49 | 49 | |
|---|
| | 50 | #define msecstotimestr(psz_buffer, msecs) \ |
|---|
| | 51 | secstotimestr( psz_buffer, (msecs / (int) 1000) ) |
|---|
| | 52 | |
|---|
| 50 | 53 | /***************************************************************************** |
|---|
| 51 | 54 | * Prototypes |
|---|
| … | … | |
| 55 | 58 | VLC_EXPORT( void, mwait, ( mtime_t date ) ); |
|---|
| 56 | 59 | VLC_EXPORT( void, msleep, ( mtime_t delay ) ); |
|---|
| | 60 | VLC_EXPORT( char *, secstotimestr, ( char *psz_buffer, int secs ) ); |
|---|
| 57 | 61 | |
|---|
| rbe7869a |
r6da0852 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * 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 $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Rocky Bernstein <rocky@panix.com> |
|---|
| … | … | |
| 519 | 519 | } |
|---|
| 520 | 520 | |
|---|
| 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 | | |
|---|
| 533 | 521 | #define meta_info_add_str(title, str) \ |
|---|
| 534 | 522 | if ( str ) { \ |
|---|
| … | … | |
| 552 | 540 | { |
|---|
| 553 | 541 | 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 ) ); |
|---|
| 555 | 545 | } else |
|---|
| 556 | 546 | { |
|---|
| … | … | |
| 586 | 576 | { |
|---|
| 587 | 577 | track_t i_track = p_cdda->i_nb_tracks; |
|---|
| | 578 | char psz_buffer[MSTRTIME_MAX_SIZE]; |
|---|
| 588 | 579 | mtime_t i_duration = |
|---|
| 589 | 580 | (p_cdda->p_sectors[i_track] - p_cdda->p_sectors[i_track-1]) |
|---|
| 590 | 581 | / CDIO_CD_FRAMES_PER_SEC; |
|---|
| 591 | 582 | |
|---|
| 592 | | input_AddInfo( p_cat, _("Duration"), "%s", secs2TimeStr( i_duration ) ); |
|---|
| | 583 | input_AddInfo( p_cat, _("Duration"), "%s", |
|---|
| | 584 | secstotimestr( psz_buffer, i_duration ) ); |
|---|
| 593 | 585 | } |
|---|
| 594 | 586 | } |
|---|
| … | … | |
| 830 | 822 | case 's': |
|---|
| 831 | 823 | if (p_cdda->i_cddb_enabled) { |
|---|
| | 824 | char psz_buffer[MSTRTIME_MAX_SIZE]; |
|---|
| 832 | 825 | mtime_t i_duration = |
|---|
| 833 | 826 | (p_cdda->p_sectors[i_track] - p_cdda->p_sectors[i_track-1]) |
|---|
| 834 | 827 | / CDIO_CD_FRAMES_PER_SEC; |
|---|
| 835 | | add_format_str_info(secs2TimeStr(i_duration)); |
|---|
| | 828 | add_format_str_info(secstotimestr( psz_buffer, i_duration ) ); |
|---|
| 836 | 829 | } else goto not_special; |
|---|
| 837 | 830 | break; |
|---|
| r93187b3 |
r6da0852 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * 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 $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Laurent Aimar <fenrir@via.ecp.fr> |
|---|
| … | … | |
| 2172 | 2172 | if( p_sys->f_duration > 1000.1 ) |
|---|
| 2173 | 2173 | { |
|---|
| 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 ) ); |
|---|
| 2182 | 2177 | } |
|---|
| 2183 | 2178 | |
|---|
| r03b32e8 |
r6da0852 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * 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 $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Pierre Baillet <oct@zoy.org> |
|---|
| … | … | |
| 695 | 695 | for( i_dummy = p_playlist->i_size ; i_dummy-- ; ) |
|---|
| 696 | 696 | { |
|---|
| 697 | | char psz_duration[14]; |
|---|
| | 697 | char psz_duration[MSTRTIME_MAX_SIZE]; |
|---|
| 698 | 698 | mtime_t dur = p_playlist->pp_items[i_dummy]->i_duration; |
|---|
| 699 | 699 | if ( dur != -1 ) |
|---|
| 700 | 700 | { |
|---|
| 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 ); |
|---|
| 703 | 702 | } |
|---|
| 704 | 703 | else |
|---|
| r6350ac8 |
r6da0852 |
|
| 4 | 4 | ***************************************************************************** |
|---|
| 5 | 5 | * 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 $ |
|---|
| 7 | 7 | * |
|---|
| 8 | 8 | * Authors: Vincent Seguin <seguin@via.ecp.fr> |
|---|
| … | … | |
| 68 | 68 | * mstrtime: return a date in a readable format |
|---|
| 69 | 69 | ***************************************************************************** |
|---|
| 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 |
|---|
| 72 | 72 | * date. |
|---|
| 73 | 73 | *****************************************************************************/ |
|---|
| | 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 | */ |
|---|
| 74 | 80 | char *mstrtime( char *psz_buffer, mtime_t date ) |
|---|
| 75 | 81 | { |
|---|
| 76 | 82 | static mtime_t ll1000 = 1000, ll60 = 60, ll24 = 24; |
|---|
| 77 | 83 | |
|---|
| 78 | | sprintf( psz_buffer, "%02d:%02d:%02d-%03d.%03d", |
|---|
| | 84 | snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%02d:%02d:%02d-%03d.%03d", |
|---|
| 79 | 85 | (int) (date / (ll1000 * ll1000 * ll60 * ll60) % ll24), |
|---|
| 80 | 86 | (int) (date / (ll1000 * ll1000 * ll60) % ll60), |
|---|
| … | … | |
| 83 | 89 | (int) (date % ll1000) ); |
|---|
| 84 | 90 | 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 | */ |
|---|
| | 106 | char *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 ); |
|---|
| 85 | 112 | } |
|---|
| 86 | 113 | |
|---|