Re-transcode and re-check J2Ks after a bad one is found.
authorCarl Hetherington <cth@carlh.net>
Tue, 25 Sep 2012 00:36:53 +0000 (01:36 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 25 Sep 2012 00:36:53 +0000 (01:36 +0100)
src/lib/check_hashes_job.cc
src/lib/job.h
src/lib/job_manager.cc
src/lib/job_manager.h
src/lib/transcode_job.cc

index 87eb40d144a0a4926155b48b7aeab869d7f767a8..5a927f752bb5815517dfb488787545849884dbe3 100644 (file)
@@ -24,6 +24,9 @@
 #include "film_state.h"
 #include "options.h"
 #include "log.h"
+#include "job_manager.h"
+#include "ab_transcode_job.h"
+#include "transcode_job.h"
 
 using namespace std;
 using namespace boost;
@@ -66,6 +69,19 @@ CheckHashesJob::run ()
                set_progress (float (i) / _fs->length);
        }
 
+       if (_bad) {
+               shared_ptr<Job> tc;
+
+               if (_fs->dcp_ab) {
+                       tc.reset (new ABTranscodeJob (_fs, _opt, _log));
+               } else {
+                       tc.reset (new TranscodeJob (_fs, _opt, _log));
+               }
+               
+               JobManager::instance()->add_after (shared_from_this(), tc);
+               JobManager::instance()->add_after (tc, shared_ptr<Job> (new CheckHashesJob (_fs, _opt, _log)));
+       }
+               
        set_progress (1);
        set_state (FINISHED_OK);
 }
@@ -74,6 +90,15 @@ string
 CheckHashesJob::status () const
 {
        stringstream s;
-       s << Job::status () << "; " << _bad << " bad frames found";
+       s << Job::status ();
+       if (overall_progress() > 0) {
+               if (_bad == 0) {
+                       s << "; no bad frames found";
+               } else if (_bad == 1) {
+                       s << "; 1 bad frame found";
+               } else {
+                       s << "; " << _bad << " bad frames found";
+               }
+       }
        return s.str ();
 }
index fee887b428673d3501112bc613408a76e4fab2e7..b391304792e0a3e9ab0a926ae440b3dfcf806e8d 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <string>
 #include <boost/thread/mutex.hpp>
+#include <boost/enable_shared_from_this.hpp>
 #include <sigc++/sigc++.h>
 
 class Log;
@@ -35,7 +36,7 @@ class Options;
 /** @class Job
  *  @brief A parent class to represent long-running tasks which are run in their own thread.
  */
-class Job
+class Job : public boost::enable_shared_from_this<Job>
 {
 public:
        Job (boost::shared_ptr<const FilmState> s, boost::shared_ptr<const Options> o, Log* l);
index 93fdbd27a8d43472a1a93b64aad2a05b4a978c67..a166b5924dd0e3c472c89bdcc24bdd378c07797a 100644 (file)
@@ -41,15 +41,23 @@ void
 JobManager::add (shared_ptr<Job> j)
 {
        boost::mutex::scoped_lock lm (_mutex);
-       
        _jobs.push_back (j);
 }
 
+void
+JobManager::add_after (shared_ptr<Job> after, shared_ptr<Job> j)
+{
+       boost::mutex::scoped_lock lm (_mutex);
+       list<shared_ptr<Job> >::iterator i = find (_jobs.begin(), _jobs.end(), after);
+       assert (i != _jobs.end ());
+       ++i;
+       _jobs.insert (i, j);
+}
+
 list<shared_ptr<Job> >
 JobManager::get () const
 {
        boost::mutex::scoped_lock lm (_mutex);
-       
        return _jobs;
 }
 
index f2f5e0057c946c6bc02e767bc755252d7f5adb2e..d1d33cfc2ce7e7dc3ac4693d579d7309e0ec30e5 100644 (file)
@@ -38,6 +38,7 @@ class JobManager
 public:
 
        void add (boost::shared_ptr<Job>);
+       void add_after (boost::shared_ptr<Job> after, boost::shared_ptr<Job> j);
        std::list<boost::shared_ptr<Job> > get () const;
        bool work_to_do () const;
 
index 2de6e90ca850e76769f5907c6839d4a955b63846..9113593f0c1976c4967df5df7e9c7bea509d38d4 100644 (file)
@@ -89,7 +89,7 @@ TranscodeJob::status () const
        }
 
        if (_encoder->skipping () && !finished ()) {
-               return "skipping frames already encoded";
+               return "skipping already-encoded frames";
        }