+2012-09-22 Carl Hetherington <cth@carlh.net>
+
+ * Improve transcode job progress reporting.
+
2012-09-22 Carl Hetherington <cth@carlh.net>
* Version 0.50 released.
: _fs (s)
, _opt (o)
, _log (l)
+ , _just_skipped (false)
+ , _last_frame (0)
{
}
return _history_size / (seconds (now) - seconds (_time_history.back ()));
}
+bool
+Encoder::skipping () const
+{
+ boost::mutex::scoped_lock (_history_mutex);
+ return _just_skipped;
+}
+
+int
+Encoder::last_frame () const
+{
+ boost::mutex::scoped_lock (_history_mutex);
+ return _last_frame;
+}
+
void
-Encoder::frame_done ()
+Encoder::frame_done (int n)
{
boost::mutex::scoped_lock lock (_history_mutex);
+ _just_skipped = false;
+ _last_frame = n;
+
struct timeval tv;
gettimeofday (&tv, 0);
_time_history.push_front (tv);
_time_history.pop_back ();
}
}
+
+/** Called by a subclass when it has just skipped the processing
+ of a frame because it has already been done.
+*/
+void
+Encoder::frame_skipped ()
+{
+ boost::mutex::scoped_lock lock (_history_mutex);
+ _just_skipped = true;
+}
virtual void process_end () = 0;
float current_frames_per_second () const;
+ bool skipping () const;
+ int last_frame () const;
protected:
- void frame_done ();
+ void frame_done (int n);
+ void frame_skipped ();
/** FilmState of the film that we are encoding */
boost::shared_ptr<const FilmState> _fs;
/** Log */
Log* _log;
+ /** Mutex for _time_history, _just_skipped and _last_frame */
mutable boost::mutex _history_mutex;
std::list<struct timeval> _time_history;
static int const _history_size;
+ /** true if the last frame we processed was skipped (because it was already done) */
+ bool _just_skipped;
+ int _last_frame;
};
#endif
filesystem::copy_file (real, link);
#endif
}
- frame_done ();
+ frame_done (0);
}
}
));
_worker_condition.notify_all ();
+ } else {
+ frame_skipped ();
}
}
if (encoded) {
encoded->write (_opt, vf->frame ());
- frame_done ();
+ frame_done (vf->frame ());
} else {
lock.lock ();
_queue.push_front (vf);
try {
shared_ptr<EncodedData> e = (*i)->encode_locally ();
e->write (_opt, (*i)->frame ());
- frame_done ();
+ frame_done ((*i)->frame ());
} catch (std::exception& e) {
stringstream s;
s << "Local encode failed " << e.what() << ".";
{
float const p = overall_progress ();
int const t = elapsed_time ();
+ int const r = remaining_time ();
stringstream s;
- if (!finished () && p >= 0 && t > 10) {
- s << rint (p * 100) << "%; about " << seconds_to_approximate_hms (t / p - t) << " remaining";
- } else if (!finished () && t <= 10) {
+ if (!finished () && p >= 0 && t > 10 && r > 0) {
+ s << rint (p * 100) << "%; " << seconds_to_approximate_hms (r) << " remaining";
+ } else if (!finished () && (t <= 10 || r == 0)) {
s << rint (p * 100) << "%";
} else if (finished_ok ()) {
s << "OK (ran for " << seconds_to_hms (t) << ")";
return s.str ();
}
+
+int
+Job::remaining_time () const
+{
+ return elapsed_time() / overall_progress() - elapsed_time();
+}
protected:
+ virtual int remaining_time () const;
+
enum State {
NEW, ///< the job hasn't been started yet
RUNNING, ///< the job is running
TIFFClose (output);
boost::filesystem::rename (tmp_file, _opt->frame_out_path (frame, false));
- frame_done ();
+ frame_done (frame);
}
if (!_encoder) {
return "0%";
}
+
+ if (_encoder->skipping ()) {
+ return "skipping frames already encoded";
+ }
+
float const fps = _encoder->current_frames_per_second ();
if (fps == 0) {
return Job::status ();
}
-
+
stringstream s;
- s << Job::status () << "; about " << fixed << setprecision (1) << fps << " frames per second.";
+
+ s << Job::status () << "; " << fixed << setprecision (1) << fps << " frames per second";
return s.str ();
}
+
+int
+TranscodeJob::remaining_time () const
+{
+ float fps = _encoder->current_frames_per_second ();
+ if (fps == 0) {
+ return 0;
+ }
+
+ return ((_fs->length - _encoder->last_frame()) / fps);
+}
void run ();
std::string status () const;
+protected:
+ int remaining_time () const;
+
private:
boost::shared_ptr<Encoder> _encoder;
};