From b446636faaec7b3f10044f5ee6d237991c45fff9 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 10 Sep 2003 15:21:16 +0000 Subject: [PATCH] Better progress report at the end, always going to 100%. --- src/mkvmerge.cpp | 23 +++++++++++++---------- src/pr_generic.h | 2 +- src/r_aac.cpp | 11 ++++++----- src/r_aac.h | 2 +- src/r_ac3.cpp | 10 ++++++---- src/r_ac3.h | 2 +- src/r_avi.cpp | 16 ++++++++++------ src/r_avi.h | 2 +- src/r_dts.cpp | 11 ++++++----- src/r_dts.h | 2 +- src/r_matroska.cpp | 12 ++++++++---- src/r_matroska.h | 2 +- src/r_microdvd.h | 2 +- src/r_mp3.cpp | 11 ++++++----- src/r_mp3.h | 2 +- src/r_ogm.cpp | 11 ++++++----- src/r_ogm.h | 2 +- src/r_qtmp4.cpp | 9 ++++++--- src/r_qtmp4.h | 2 +- src/r_real.cpp | 10 +++++++--- src/r_real.h | 2 +- src/r_srt.cpp | 2 +- src/r_srt.h | 2 +- src/r_ssa.cpp | 2 +- src/r_ssa.h | 2 +- src/r_vobsub.cpp | 3 +-- src/r_wav.cpp | 13 ++++++++----- src/r_wav.h | 2 +- 28 files changed, 99 insertions(+), 73 deletions(-) diff --git a/src/mkvmerge.cpp b/src/mkvmerge.cpp index 5c6812c73..afd5e4847 100644 --- a/src/mkvmerge.cpp +++ b/src/mkvmerge.cpp @@ -395,19 +395,22 @@ static void sighandler(int signum) { #endif static int display_counter = 1; +static generic_reader_c *display_reader = NULL; -static void display_progress(int force) { - filelist_t *winner; +static void display_progress(bool force) { + generic_reader_c *winner; int i; if (((display_counter % 500) == 0) || force) { display_counter = 0; - winner = files[0]; - for (i = 1; i < files.size(); i++) - if (files[i]->reader->display_priority() > - winner->reader->display_priority()) - winner = files[i]; - winner->reader->display_progress(); + if (display_reader == NULL) { + winner = files[0]->reader; + for (i = 1; i < files.size(); i++) + if (files[i]->reader->display_priority() > winner->display_priority()) + winner = files[i]->reader; + display_reader = winner; + } + display_reader->display_progress(force); } display_counter++; } @@ -1958,7 +1961,7 @@ void main_loop() { // display some progress information if (verbose >= 1) - display_progress(0); + display_progress(false); } // Render all remaining packets (if there are any). @@ -1966,7 +1969,7 @@ void main_loop() { cluster_helper->render(); if (verbose >= 1) - display_progress(1); + display_progress(true); } // }}} diff --git a/src/pr_generic.h b/src/pr_generic.h index 662e62ba1..b9c67ca27 100644 --- a/src/pr_generic.h +++ b/src/pr_generic.h @@ -220,7 +220,7 @@ public: virtual ~generic_reader_c(); virtual int read(generic_packetizer_c *ptzr) = 0; virtual int display_priority() = 0; - virtual void display_progress() = 0; + virtual void display_progress(bool final = false) = 0; virtual void set_headers() = 0; virtual void identify() = 0; diff --git a/src/r_aac.cpp b/src/r_aac.cpp index 6ae5af1c5..1ef27af1f 100644 --- a/src/r_aac.cpp +++ b/src/r_aac.cpp @@ -160,11 +160,12 @@ int aac_reader_c::display_priority() { return DISPLAYPRIORITY_HIGH - 1; } -void aac_reader_c::display_progress() { - mxinfo("progress: %lld/%lld bytes (%d%%)\r", - bytes_processed, size, - (int)(bytes_processed * 100L / size)); - fflush(stdout); +void aac_reader_c::display_progress(bool final) { + if (final) + mxinfo("progress: %lld/%lld bytes (100%%)\r", size, size); + else + mxinfo("progress: %lld/%lld bytes (%d%%)\r", bytes_processed, size, + (int)(bytes_processed * 100L / size)); } void aac_reader_c::set_headers() { diff --git a/src/r_aac.h b/src/r_aac.h index e7d49533c..a862303cc 100644 --- a/src/r_aac.h +++ b/src/r_aac.h @@ -46,7 +46,7 @@ public: virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); virtual void set_headers(); virtual void identify(); diff --git a/src/r_ac3.cpp b/src/r_ac3.cpp index 0f4b30704..4ffcd088e 100644 --- a/src/r_ac3.cpp +++ b/src/r_ac3.cpp @@ -111,10 +111,12 @@ int ac3_reader_c::display_priority() { return DISPLAYPRIORITY_HIGH - 1; } -void ac3_reader_c::display_progress() { - mxinfo("progress: %lld/%lld bytes (%d%%)\r", - bytes_processed, size, - (int)(bytes_processed * 100L / size)); +void ac3_reader_c::display_progress(bool final) { + if (final) + mxinfo("progress: %lld/%lld bytes (100%%)\r", size, size); + else + mxinfo("progress: %lld/%lld bytes (%d%%)\r", bytes_processed, size, + (int)(bytes_processed * 100L / size)); } void ac3_reader_c::set_headers() { diff --git a/src/r_ac3.h b/src/r_ac3.h index d1f4a99da..6f4bd66e2 100644 --- a/src/r_ac3.h +++ b/src/r_ac3.h @@ -45,7 +45,7 @@ public: virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); virtual void set_headers(); virtual void identify(); diff --git a/src/r_avi.cpp b/src/r_avi.cpp index 2e3f77936..990580891 100644 --- a/src/r_avi.cpp +++ b/src/r_avi.cpp @@ -439,21 +439,25 @@ int avi_reader_c::display_priority() { static char wchar[] = "-\\|/-\\|/-"; -void avi_reader_c::display_progress() { +void avi_reader_c::display_progress(bool final) { + int myframes; + if (vpacketizer != NULL) { - int myframes = frames; + myframes = frames; if (frames == (maxframes + 1)) myframes--; - mxinfo("progress: %d/%ld frames (%ld%%)\r", - myframes, AVI_video_frames(avi), - myframes * 100 / AVI_video_frames(avi)); + if (final) + mxinfo("progress: %ld/%ld frames (100%%)\r", AVI_video_frames(avi), + AVI_video_frames(avi)); + else + mxinfo("progress: %d/%ld frames (%ld%%)\r", myframes, + AVI_video_frames(avi), myframes * 100 / AVI_video_frames(avi)); } else { mxinfo("Working... %c\r", wchar[act_wchar]); act_wchar++; if (act_wchar == strlen(wchar)) act_wchar = 0; } - fflush(stdout); } // }}} diff --git a/src/r_avi.h b/src/r_avi.h index 4401ac0d2..da43be958 100644 --- a/src/r_avi.h +++ b/src/r_avi.h @@ -65,7 +65,7 @@ public: virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); virtual void set_headers(); virtual void identify(); diff --git a/src/r_dts.cpp b/src/r_dts.cpp index 042e95956..2678273fd 100644 --- a/src/r_dts.cpp +++ b/src/r_dts.cpp @@ -112,11 +112,12 @@ int dts_reader_c::display_priority() { return DISPLAYPRIORITY_HIGH - 1; } -void dts_reader_c::display_progress() { - mxinfo("progress: %lld/%lld bytes (%d%%)\r", - bytes_processed, size, - (int)(bytes_processed * 100L / size)); - fflush(stdout); +void dts_reader_c::display_progress(bool final) { + if (final) + mxinfo("progress: %lld/%lld bytes (100%%)\r", size, size); + else + mxinfo("progress: %lld/%lld bytes (%d%%)\r", bytes_processed, size, + (int)(bytes_processed * 100L / size)); } void dts_reader_c::set_headers() { diff --git a/src/r_dts.h b/src/r_dts.h index 447ae51d9..fa87f2658 100644 --- a/src/r_dts.h +++ b/src/r_dts.h @@ -45,7 +45,7 @@ public: virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); virtual void set_headers(); virtual void identify(); diff --git a/src/r_matroska.cpp b/src/r_matroska.cpp index d78d8879f..3fdce6a1d 100644 --- a/src/r_matroska.cpp +++ b/src/r_matroska.cpp @@ -1441,13 +1441,17 @@ int kax_reader_c::display_priority() { static char wchar[] = "-\\|/-\\|/-"; -void kax_reader_c::display_progress() { +void kax_reader_c::display_progress(bool final) { int i; if (segment_duration != 0.0) { - mxinfo("progress: %.3fs/%.3fs (%d%%)\r", - (last_timecode - first_timecode) / 1000.0, segment_duration, - (int)((last_timecode - first_timecode) / 10 / segment_duration)); + if (final) + mxinfo("progress: %.3fs/%.3fs (100%%)\r", segment_duration, + segment_duration); + else + mxinfo("progress: %.3fs/%.3fs (%d%%)\r", + (last_timecode - first_timecode) / 1000.0, segment_duration, + (int)((last_timecode - first_timecode) / 10 / segment_duration)); return; } diff --git a/src/r_matroska.h b/src/r_matroska.h index 7634afe97..ea15e2ff7 100644 --- a/src/r_matroska.h +++ b/src/r_matroska.h @@ -112,7 +112,7 @@ public: virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); virtual void set_headers(); virtual void identify(); diff --git a/src/r_microdvd.h b/src/r_microdvd.h index 6401a487f..e7c778c74 100644 --- a/src/r_microdvd.h +++ b/src/r_microdvd.h @@ -45,7 +45,7 @@ public: PACKET_TYPE_HEADER); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); virtual void set_headers(); static int probe_file(mm_io_c *mm_io, int64_t size); diff --git a/src/r_mp3.cpp b/src/r_mp3.cpp index 833bf57b6..dbc50f961 100644 --- a/src/r_mp3.cpp +++ b/src/r_mp3.cpp @@ -121,11 +121,12 @@ int mp3_reader_c::display_priority() { return DISPLAYPRIORITY_HIGH - 1; } -void mp3_reader_c::display_progress() { - mxinfo("progress: %lld/%lld bytes (%d%%)\r", - bytes_processed, size, - (int)(bytes_processed * 100L / size)); - fflush(stdout); +void mp3_reader_c::display_progress(bool final) { + if (final) + mxinfo("progress: %lld/%lld bytes (100%%)\r", size, size); + else + mxinfo("progress: %lld/%lld bytes (%d%%)\r", bytes_processed, size, + (int)(bytes_processed * 100L / size)); } void mp3_reader_c::set_headers() { diff --git a/src/r_mp3.h b/src/r_mp3.h index be027514f..d90b8f452 100644 --- a/src/r_mp3.h +++ b/src/r_mp3.h @@ -47,7 +47,7 @@ public: virtual void identify(); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); static int probe_file(mm_io_c *mm_io, int64_t size); }; diff --git a/src/r_ogm.cpp b/src/r_ogm.cpp index 1cc237254..5be92bc11 100644 --- a/src/r_ogm.cpp +++ b/src/r_ogm.cpp @@ -697,15 +697,16 @@ int ogm_reader_c::display_priority() { static char wchar[] = "-\\|/-\\|/-"; -void ogm_reader_c::display_progress() { +void ogm_reader_c::display_progress(bool final) { int i; for (i = 0; i < num_sdemuxers; i++) if (sdemuxers[i]->stype == OGM_STREAM_TYPE_VIDEO) { - mxinfo("progress: %d frames (%d%%)\r", - sdemuxers[i]->units_processed, (int)(mm_io->getFilePointer() * - 100 / file_size)); - fflush(stdout); + if (final) + mxinfo("progress: %d frames (100%%)\r", sdemuxers[i]->units_processed); + else + mxinfo("progress: %d frames (%d%%)\r", sdemuxers[i]->units_processed, + (int)(mm_io->getFilePointer() * 100 / file_size)); return; } diff --git a/src/r_ogm.h b/src/r_ogm.h index dfb6d3a2d..d5586dabc 100644 --- a/src/r_ogm.h +++ b/src/r_ogm.h @@ -68,7 +68,7 @@ public: virtual void identify(); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); static int probe_file(mm_io_c *mm_io, int64_t size); diff --git a/src/r_qtmp4.cpp b/src/r_qtmp4.cpp index 8350bd870..9af0d1850 100644 --- a/src/r_qtmp4.cpp +++ b/src/r_qtmp4.cpp @@ -1107,7 +1107,7 @@ int qtmp4_reader_c::display_priority() { return DISPLAYPRIORITY_MEDIUM; } -void qtmp4_reader_c::display_progress() { +void qtmp4_reader_c::display_progress(bool final) { uint32_t max_chunks; qtmp4_demuxer_t *dmx; @@ -1116,8 +1116,11 @@ void qtmp4_reader_c::display_progress() { max_chunks = dmx->sample_table_len; else max_chunks = dmx->chunk_table_len; - mxinfo("progress: %d/%d chunks (%d%%)\r", dmx->pos, max_chunks, - dmx->pos * 100 / max_chunks); + if (final) + mxinfo("progress: %d/%d chunks (100%%)\r", max_chunks, max_chunks); + else + mxinfo("progress: %d/%d chunks (%d%%)\r", dmx->pos, max_chunks, + dmx->pos * 100 / max_chunks); } void qtmp4_reader_c::identify() { diff --git a/src/r_qtmp4.h b/src/r_qtmp4.h index a79694032..04275a3d3 100644 --- a/src/r_qtmp4.h +++ b/src/r_qtmp4.h @@ -125,7 +125,7 @@ public: virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); virtual void set_headers(); virtual void identify(); diff --git a/src/r_real.cpp b/src/r_real.cpp index 51aed0294..f45d6bfed 100644 --- a/src/r_real.cpp +++ b/src/r_real.cpp @@ -638,9 +638,13 @@ int real_reader_c::display_priority() { return DISPLAYPRIORITY_MEDIUM; } -void real_reader_c::display_progress() { - mxinfo("progress: %lld/%lld packets (%lld%%)\r", num_packets, - num_packets_in_chunk, num_packets * 100 / num_packets_in_chunk); +void real_reader_c::display_progress(bool final) { + if (final) + mxinfo("progress: %lld/%lld packets (100%%)\r", num_packets_in_chunk, + num_packets_in_chunk); + else + mxinfo("progress: %lld/%lld packets (%lld%%)\r", num_packets, + num_packets_in_chunk, num_packets * 100 / num_packets_in_chunk); } void real_reader_c::set_headers() { diff --git a/src/r_real.h b/src/r_real.h index bf2269f36..390ceacd9 100644 --- a/src/r_real.h +++ b/src/r_real.h @@ -77,7 +77,7 @@ public: virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); virtual void set_headers(); virtual void identify(); diff --git a/src/r_srt.cpp b/src/r_srt.cpp index 6ffdbe572..4cc9eee2c 100644 --- a/src/r_srt.cpp +++ b/src/r_srt.cpp @@ -154,7 +154,7 @@ int srt_reader_c::display_priority() { static char wchar[] = "-\\|/-\\|/-"; -void srt_reader_c::display_progress() { +void srt_reader_c::display_progress(bool) { mxinfo("working... %c\r", wchar[act_wchar]); act_wchar++; if (act_wchar == strlen(wchar)) diff --git a/src/r_srt.h b/src/r_srt.h index b8fc80676..73344683a 100644 --- a/src/r_srt.h +++ b/src/r_srt.h @@ -46,7 +46,7 @@ public: virtual void identify(); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); static int probe_file(mm_text_io_c *mm_io, int64_t size); }; diff --git a/src/r_ssa.cpp b/src/r_ssa.cpp index 4a71d6890..be0219f1b 100644 --- a/src/r_ssa.cpp +++ b/src/r_ssa.cpp @@ -296,7 +296,7 @@ int ssa_reader_c::display_priority() { static char wchar[] = "-\\|/-\\|/-"; -void ssa_reader_c::display_progress() { +void ssa_reader_c::display_progress(bool) { mxinfo("working... %c\r", wchar[act_wchar]); act_wchar++; if (act_wchar == strlen(wchar)) diff --git a/src/r_ssa.h b/src/r_ssa.h index 06022a91a..80177346a 100644 --- a/src/r_ssa.h +++ b/src/r_ssa.h @@ -53,7 +53,7 @@ public: virtual void identify(); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); static int probe_file(mm_text_io_c *mm_io, int64_t size); diff --git a/src/r_vobsub.cpp b/src/r_vobsub.cpp index e79f5286d..d344c2c88 100644 --- a/src/r_vobsub.cpp +++ b/src/r_vobsub.cpp @@ -331,10 +331,9 @@ void vobsub_reader_c::reset() { static char wchar[] = "-\\|/-\\|/-"; -void vobsub_reader_c::display_progress() { +void vobsub_reader_c::display_progress(bool final) { mxprint(stdout, "working... %c\r", wchar[act_wchar]); act_wchar++; if (act_wchar == strlen(wchar)) act_wchar = 0; - fflush(stdout); } diff --git a/src/r_wav.cpp b/src/r_wav.cpp index 552658554..82d620b5f 100644 --- a/src/r_wav.cpp +++ b/src/r_wav.cpp @@ -270,12 +270,15 @@ int wav_reader_c::display_priority() { return DISPLAYPRIORITY_HIGH - 1; } -void wav_reader_c::display_progress() { +void wav_reader_c::display_progress(bool final) { int samples = (wheader.riff.len - sizeof(wheader) + 8) / bps; - mxinfo("progress: %d/%d seconds (%d%%)\r", - (int)(bytes_processed / bps), (int)samples, - (int)(bytes_processed * 100L / bps / samples)); - fflush(stdout); + + if (final) + mxinfo("progress: %d/%d seconds (100%%)\r", (int)samples, (int)samples); + else + mxinfo("progress: %d/%d seconds (%d%%)\r", + (int)(bytes_processed / bps), (int)samples, + (int)(bytes_processed * 100L / bps / samples)); } void wav_reader_c::set_headers() { diff --git a/src/r_wav.h b/src/r_wav.h index 0c57aab46..0fdbb652e 100644 --- a/src/r_wav.h +++ b/src/r_wav.h @@ -58,7 +58,7 @@ public: virtual void identify(); virtual int display_priority(); - virtual void display_progress(); + virtual void display_progress(bool final = false); static int probe_file(mm_io_c *mm_io, int64_t size); };