mirror of https://github.com/xiph/flac
Make progress updates depend on wall time instead of progress
Progress updates were output too often on fast CPUs and not often enough for slow CPUs. In the Windows shell this gave the additional problem that such output is extremely slow. See https://hydrogenaud.io/index.php/topic,123014.msg1017724.html#msg1017724
This commit is contained in:
parent
e7b584eaf9
commit
6abf272158
|
@ -25,6 +25,7 @@
|
||||||
#include <math.h> /* for floor() */
|
#include <math.h> /* for floor() */
|
||||||
#include <stdio.h> /* for FILE etc. */
|
#include <stdio.h> /* for FILE etc. */
|
||||||
#include <string.h> /* for strcmp(), strerror() */
|
#include <string.h> /* for strcmp(), strerror() */
|
||||||
|
#include <time.h> /* for clock() */
|
||||||
#include "FLAC/all.h"
|
#include "FLAC/all.h"
|
||||||
#include "share/grabbag.h"
|
#include "share/grabbag.h"
|
||||||
#include "share/replaygain_synthesis.h"
|
#include "share/replaygain_synthesis.h"
|
||||||
|
@ -91,6 +92,8 @@ typedef struct {
|
||||||
|
|
||||||
foreign_metadata_t *foreign_metadata; /* NULL unless --keep-foreign-metadata requested */
|
foreign_metadata_t *foreign_metadata; /* NULL unless --keep-foreign-metadata requested */
|
||||||
FLAC__off_t fm_offset1, fm_offset2, fm_offset3;
|
FLAC__off_t fm_offset1, fm_offset2, fm_offset3;
|
||||||
|
|
||||||
|
clock_t old_clock_t;
|
||||||
} DecoderSession;
|
} DecoderSession;
|
||||||
|
|
||||||
|
|
||||||
|
@ -247,6 +250,8 @@ FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__
|
||||||
|
|
||||||
d->foreign_metadata = foreign_metadata;
|
d->foreign_metadata = foreign_metadata;
|
||||||
|
|
||||||
|
d->old_clock_t = 0;
|
||||||
|
|
||||||
FLAC__ASSERT(!(d->test_only && d->analysis_mode));
|
FLAC__ASSERT(!(d->test_only && d->analysis_mode));
|
||||||
|
|
||||||
if(!d->test_only) {
|
if(!d->test_only) {
|
||||||
|
@ -1165,8 +1170,16 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder
|
||||||
decoder_session->samples_processed += wide_samples;
|
decoder_session->samples_processed += wide_samples;
|
||||||
decoder_session->frame_counter++;
|
decoder_session->frame_counter++;
|
||||||
|
|
||||||
|
#if 0 /* in case time.h with clock() isn't available for some reason */
|
||||||
if(!(decoder_session->frame_counter & 0x1ff))
|
if(!(decoder_session->frame_counter & 0x1ff))
|
||||||
print_stats(decoder_session);
|
print_stats(decoder_session);
|
||||||
|
#else
|
||||||
|
if((clock() - decoder_session->old_clock_t) > (CLOCKS_PER_SEC/4)) {
|
||||||
|
print_stats(decoder_session);
|
||||||
|
decoder_session->old_clock_t = clock();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if(decoder_session->analysis_mode) {
|
if(decoder_session->analysis_mode) {
|
||||||
flac__analyze_frame(frame, decoder_session->frame_counter-1, decoder_session->decode_position-frame_bytes, frame_bytes, decoder_session->aopts, fout);
|
flac__analyze_frame(frame, decoder_session->frame_counter-1, decoder_session->decode_position-frame_bytes, frame_bytes, decoder_session->aopts, fout);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <stdio.h> /* for FILE etc. */
|
#include <stdio.h> /* for FILE etc. */
|
||||||
#include <stdlib.h> /* for malloc */
|
#include <stdlib.h> /* for malloc */
|
||||||
#include <string.h> /* for strcmp(), strerror() */
|
#include <string.h> /* for strcmp(), strerror() */
|
||||||
|
#include <time.h> /* for clock() */
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "FLAC/all.h"
|
#include "FLAC/all.h"
|
||||||
#include "share/alloc.h"
|
#include "share/alloc.h"
|
||||||
|
@ -89,8 +90,12 @@ typedef struct {
|
||||||
FLAC__uint64 unencoded_size; /* an estimate of the input size, only used in the progress indicator */
|
FLAC__uint64 unencoded_size; /* an estimate of the input size, only used in the progress indicator */
|
||||||
FLAC__uint64 bytes_written;
|
FLAC__uint64 bytes_written;
|
||||||
FLAC__uint64 samples_written;
|
FLAC__uint64 samples_written;
|
||||||
|
#if 0 /* in case time.h with clock() isn't available for some reason */
|
||||||
uint32_t stats_frames_interval;
|
uint32_t stats_frames_interval;
|
||||||
uint32_t old_frames_written;
|
uint32_t old_frames_written;
|
||||||
|
#else
|
||||||
|
clock_t old_clock_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
SampleInfo info;
|
SampleInfo info;
|
||||||
|
|
||||||
|
@ -1544,8 +1549,12 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, encode_options_t options,
|
||||||
e->unencoded_size = 0;
|
e->unencoded_size = 0;
|
||||||
e->bytes_written = 0;
|
e->bytes_written = 0;
|
||||||
e->samples_written = 0;
|
e->samples_written = 0;
|
||||||
|
#if 0 /* in case time.h with clock() isn't available for some reason */
|
||||||
e->stats_frames_interval = 0;
|
e->stats_frames_interval = 0;
|
||||||
e->old_frames_written = 0;
|
e->old_frames_written = 0;
|
||||||
|
#else
|
||||||
|
e->old_clock_t = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
memset(&e->info, 0, sizeof(e->info));
|
memset(&e->info, 0, sizeof(e->info));
|
||||||
|
|
||||||
|
@ -2184,10 +2193,12 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio
|
||||||
else
|
else
|
||||||
e->outputfile_opened = true;
|
e->outputfile_opened = true;
|
||||||
|
|
||||||
|
#if 0 /* in case time.h with clock() isn't available for some reason */
|
||||||
e->stats_frames_interval =
|
e->stats_frames_interval =
|
||||||
(FLAC__stream_encoder_get_do_exhaustive_model_search(e->encoder) && FLAC__stream_encoder_get_do_qlp_coeff_prec_search(e->encoder))? 0x1f :
|
(FLAC__stream_encoder_get_do_exhaustive_model_search(e->encoder) && FLAC__stream_encoder_get_do_qlp_coeff_prec_search(e->encoder))? 0x1f :
|
||||||
(FLAC__stream_encoder_get_do_exhaustive_model_search(e->encoder) || FLAC__stream_encoder_get_do_qlp_coeff_prec_search(e->encoder))? 0x3f :
|
(FLAC__stream_encoder_get_do_exhaustive_model_search(e->encoder) || FLAC__stream_encoder_get_do_qlp_coeff_prec_search(e->encoder))? 0x3f :
|
||||||
0xff;
|
0xff;
|
||||||
|
#endif
|
||||||
|
|
||||||
static_metadata_clear(&static_metadata);
|
static_metadata_clear(&static_metadata);
|
||||||
|
|
||||||
|
@ -2506,7 +2517,7 @@ void encoder_progress_callback(const FLAC__StreamEncoder *encoder, FLAC__uint64
|
||||||
|
|
||||||
const FLAC__uint64 uesize = e->unencoded_size;
|
const FLAC__uint64 uesize = e->unencoded_size;
|
||||||
|
|
||||||
(void)encoder, (void)total_frames_estimate;
|
(void)encoder, (void)total_frames_estimate, (void) frames_written;
|
||||||
|
|
||||||
e->bytes_written = bytes_written;
|
e->bytes_written = bytes_written;
|
||||||
e->samples_written = samples_written;
|
e->samples_written = samples_written;
|
||||||
|
@ -2514,10 +2525,18 @@ void encoder_progress_callback(const FLAC__StreamEncoder *encoder, FLAC__uint64
|
||||||
e->progress = e->total_samples_to_encode ? (double)samples_written / (double)e->total_samples_to_encode : 0;
|
e->progress = e->total_samples_to_encode ? (double)samples_written / (double)e->total_samples_to_encode : 0;
|
||||||
e->compression_ratio = (e->progress && uesize) ? (double)e->bytes_written / ((double)uesize * min(1.0, e->progress)) : 0;
|
e->compression_ratio = (e->progress && uesize) ? (double)e->bytes_written / ((double)uesize * min(1.0, e->progress)) : 0;
|
||||||
|
|
||||||
|
#if 0 /* in case time.h with clock() isn't available for some reason */
|
||||||
if(e->total_samples_to_encode > 0 && frames_written - e->old_frames_written > e->stats_frames_interval) {
|
if(e->total_samples_to_encode > 0 && frames_written - e->old_frames_written > e->stats_frames_interval) {
|
||||||
print_stats(e);
|
print_stats(e);
|
||||||
e->old_frames_written = frames_written;
|
e->old_frames_written = frames_written;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if(e->total_samples_to_encode > 0 && (clock() - e->old_clock_t) > (CLOCKS_PER_SEC/4)) {
|
||||||
|
print_stats(e);
|
||||||
|
e->old_clock_t = clock();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
FLAC__StreamDecoderReadStatus flac_decoder_read_callback(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
|
FLAC__StreamDecoderReadStatus flac_decoder_read_callback(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
|
||||||
|
|
Loading…
Reference in New Issue