Changeset 4754:177fec6e1c4e in roaraudio for roarclients/roarvorbis.c
- Timestamp:
- 02/05/11 20:04:12 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roarclients/roarvorbis.c
r4708 r4754 78 78 } 79 79 80 int cf_vorbis_vfvio_seek (void *datasource, ogg_int64_t offset, int whence) { 81 return roar_vio_lseek(datasource, offset, whence); 82 } 83 84 long cf_vorbis_vfvio_tell (void *datasource) { 85 return roar_vio_lseek(datasource, 0, SEEK_CUR); 86 } 80 87 81 88 ov_callbacks _g_cf_vorbis_vfvio = { 82 89 .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, 84 91 .close_func = (int (*)(void * )) _g_cf_vorbis_vfvio_return_err, 85 .tell_func = (long (*)(void * )) _g_cf_vorbis_vfvio_return_err92 .tell_func = cf_vorbis_vfvio_tell 86 93 }; 87 94 … … 218 225 219 226 return 0; 227 } 228 229 230 const 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 250 void 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); 220 272 } 221 273 … … 243 295 struct roar_audio_info info; 244 296 char pcmout[4096]; 297 double time_total; 298 ssize_t bits_per_sec = -1; 299 ssize_t bits_written = -1; 245 300 246 301 … … 293 348 } 294 349 350 time_total = ov_time_total(&vf, -1); 351 295 352 if ( vcltfile != NULL ) { 296 353 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY|O_CREAT|O_APPEND, 0644) == -1 ) … … 317 374 return 1; 318 375 } 376 bits_per_sec = roar_info2bitspersec(&info); 319 377 320 378 last_section = current_section; … … 328 386 } else { 329 387 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(). 332 397 333 398 ov_clear(&vf);
Note: See TracChangeset
for help on using the changeset viewer.