Changeset 4754:177fec6e1c4e in roaraudio


Ignore:
Timestamp:
02/05/11 20:04:12 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Added time display to roarvorbis (Closes: #102)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4751 r4754  
    44        * Updated configure (Closes: #94, #27) 
    55        * Disable more stuff in minimal build (Closes: #104) 
     6        * Added time display to roarvorbis (Closes: #102) 
    67 
    78v. 0.4beta3 - Wed Jan 26 2011 23:26 CET 
  • roarclients/roarvorbis.c

    r4708 r4754  
    7878} 
    7979 
     80int cf_vorbis_vfvio_seek  (void *datasource, ogg_int64_t offset, int whence) { 
     81 return roar_vio_lseek(datasource, offset, whence); 
     82} 
     83 
     84long cf_vorbis_vfvio_tell (void *datasource) { 
     85 return roar_vio_lseek(datasource, 0, SEEK_CUR); 
     86} 
    8087 
    8188ov_callbacks _g_cf_vorbis_vfvio = { 
    8289  .read_func  = cf_vorbis_vfvio_read, 
    83   .seek_func  = (int    (*)(void *, ogg_int64_t, int      )) _g_cf_vorbis_vfvio_return_err, 
     90  .seek_func  = cf_vorbis_vfvio_seek, 
    8491  .close_func = (int    (*)(void *                        )) _g_cf_vorbis_vfvio_return_err, 
    85   .tell_func  = (long   (*)(void *                        )) _g_cf_vorbis_vfvio_return_err 
     92  .tell_func  = cf_vorbis_vfvio_tell 
    8693}; 
    8794 
     
    218225 
    219226 return 0; 
     227} 
     228 
     229 
     230const char * time2str(double t, char * buf, size_t len) { 
     231 int h, m; 
     232 
     233 if ( t < 0 ) { 
     234//  strncpy(buf, "unknown", len); 
     235//  return buf; 
     236  *buf++ = '-'; 
     237  t *= -1; 
     238 } 
     239 
     240 h  = t / 3600; 
     241 t -= h * 3600; 
     242 m  = t / 60; 
     243 t -= m * 60; 
     244 
     245 snprintf(buf, len, "%.2i:%.2i:%.2i", h, m, (int)t); 
     246 
     247 return buf; 
     248} 
     249 
     250void print_time (OggVorbis_File * vf, roar_vs_t * vss, double time_total, struct roar_audio_info * info) { 
     251 ssize_t pos; 
     252 double time_cur; 
     253 long bitrate_cur = ov_bitrate_instant(vf); 
     254 float bitrate = bitrate_cur / 1000.0; 
     255 char time_buf[3][10]; 
     256 
     257 pos = roar_vs_position(vss, ROAR_VS_BACKEND_DEFAULT, NULL); 
     258 
     259 if ( pos == -1 ) { 
     260  time_cur = ov_time_tell(vf); 
     261 } else { 
     262  time_cur = (double)pos/(double)(info->channels*info->rate); 
     263 } 
     264 
     265 time2str(time_cur, time_buf[0], sizeof(time_buf[0])); 
     266 time2str(time_total-time_cur, time_buf[1], sizeof(time_buf[1])); 
     267 time2str(time_total, time_buf[2], sizeof(time_buf[2])); 
     268 
     269 //Time: 00:02.53 [03:26.20] of 03:28.73  (122.7 kbps)  Output Buffer  43.8% 
     270 fprintf(stderr, "\rTime: %s [%s] of %s  (%.1f kbps)            ", time_buf[0], time_buf[1], time_buf[2], bitrate); 
     271 fflush(stderr); 
    220272} 
    221273 
     
    243295 struct roar_audio_info info; 
    244296 char pcmout[4096]; 
     297 double time_total; 
     298 ssize_t bits_per_sec = -1; 
     299 ssize_t bits_written = -1; 
    245300 
    246301 
     
    293348 } 
    294349 
     350 time_total = ov_time_total(&vf, -1); 
     351 
    295352 if ( vcltfile != NULL ) { 
    296353  if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY|O_CREAT|O_APPEND, 0644) == -1 ) 
     
    317374    return 1; 
    318375   } 
     376   bits_per_sec = roar_info2bitspersec(&info); 
    319377 
    320378  last_section = current_section; 
     
    328386  } else { 
    329387   roar_vs_write(vss, pcmout, ret, NULL); 
    330   } 
    331  } 
     388   bits_written += ret * 8; 
     389   if ( bits_written > bits_per_sec ) { 
     390    bits_written = 0; 
     391    print_time(&vf, vss, time_total, &info); 
     392   } 
     393  } 
     394 } 
     395 
     396 fprintf(stderr, "\n"); // end the lion of print_time(). 
    332397 
    333398 ov_clear(&vf); 
Note: See TracChangeset for help on using the changeset viewer.