X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ftranscode_job.cc;h=fb9a5917956109a8bbe1dcfd57df7d93fa322890;hb=71d8cf20889a3c419c9a3e485f461236e5317423;hp=74b425c1e6a3fd5b9f5340b10371c1050049a7a3;hpb=11325f810e214935e4115248223c186a6e4cc184;p=dcpomatic.git diff --git a/src/lib/transcode_job.cc b/src/lib/transcode_job.cc index 74b425c1e..fb9a59179 100644 --- a/src/lib/transcode_job.cc +++ b/src/lib/transcode_job.cc @@ -30,6 +30,9 @@ #include "i18n.h" +#define LOG_GENERAL_NC(...) _film->log()->microsecond_log (__VA_ARGS__, Log::GENERAL); +#define LOG_ERROR_NC(...) _film->log()->microsecond_log (__VA_ARGS__, Log::ERROR); + using std::string; using std::stringstream; using std::fixed; @@ -50,26 +53,32 @@ TranscodeJob::name () const return String::compose (_("Transcode %1"), _film->name()); } +string +TranscodeJob::json_name () const +{ + return N_("transcode"); +} + void TranscodeJob::run () { try { - _film->log()->log (N_("Transcode job starting")); + LOG_GENERAL_NC (N_("Transcode job starting")); _transcoder.reset (new Transcoder (_film, shared_from_this ())); _transcoder->go (); set_progress (1); set_state (FINISHED_OK); - _film->log()->log (N_("Transcode job completed successfully")); - - } catch (std::exception& e) { + LOG_GENERAL_NC (N_("Transcode job completed successfully")); + _transcoder.reset (); + } catch (...) { set_progress (1); set_state (FINISHED_ERROR); - _film->log()->log (String::compose (N_("Transcode job failed (%1)"), e.what())); - + LOG_ERROR_NC (N_("Transcode job failed or cancelled")); + _transcoder.reset (); throw; } } @@ -78,7 +87,7 @@ string TranscodeJob::status () const { if (!_transcoder) { - return _("0%"); + return Job::status (); } float const fps = _transcoder->current_encoding_rate (); @@ -90,8 +99,8 @@ TranscodeJob::status () const s << Job::status (); - if (!finished ()) { - s << "; " << fixed << setprecision (1) << fps << N_(" ") << _("frames per second"); + if (!finished () && !_transcoder->finishing ()) { + s << "; " << fixed << setprecision (1) << fps << " " << _("frames per second"); } return s.str (); @@ -100,17 +109,20 @@ TranscodeJob::status () const int TranscodeJob::remaining_time () const { - if (!_transcoder) { + /* _transcoder might be destroyed by the job-runner thread */ + shared_ptr t = _transcoder; + + if (!t) { return 0; } - float fps = _transcoder->current_encoding_rate (); + float fps = t->current_encoding_rate (); if (fps == 0) { return 0; } /* Compute approximate proposed length here, as it's only here that we need it */ - OutputVideoFrame const left = _film->time_to_video_frames (_film->length ()) - _transcoder->video_frames_out(); + OutputVideoFrame const left = _film->time_to_video_frames (_film->length ()) - t->video_frames_out(); return left / fps; }