1
0
mirror of https://github.com/nu774/fdkaac.git synced 2025-06-05 23:29:14 +02:00

fix corner case of progress display

This commit is contained in:
nu774
2013-01-09 16:39:39 +09:00
parent 6887939854
commit 00799c5e44

View File

@ -6,6 +6,8 @@
# include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <limits.h>
#include <float.h>
#include <time.h> #include <time.h>
#if HAVE_STDINT_H #if HAVE_STDINT_H
# include <stdint.h> # include <stdint.h>
@ -51,11 +53,14 @@ void aacenc_progress_init(aacenc_progress_t *progress, int64_t total,
void aacenc_progress_update(aacenc_progress_t *progress, int64_t current, void aacenc_progress_update(aacenc_progress_t *progress, int64_t current,
int period) int period)
{ {
int percent = 100.0 * current / progress->total + .5;
double seconds = current / progress->timescale; double seconds = current / progress->timescale;
double ellapsed = (aacenc_timer() - progress->start) / 1000.0; double ellapsed = (aacenc_timer() - progress->start) / 1000.0;
double eta = ellapsed * (progress->total / (double)current - 1.0); double speed = ellapsed ? seconds / ellapsed : 1.0;
double speed = ellapsed ? seconds / ellapsed : 0.0; int percent = progress->total ? 100.0 * current / progress->total + .5
: 100;
double eta = current ? ellapsed * (progress->total / (double)current - 1.0)
: progress->total ? DBL_MAX : 0;
if (current < progress->processed + period) if (current < progress->processed + period)
return; return;