Don't set up Writer etc. until the job is run. This means that
authorCarl Hetherington <cth@carlh.net>
Tue, 18 Jul 2017 15:06:14 +0000 (16:06 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 18 Jul 2017 15:06:14 +0000 (16:06 +0100)
jobs queued in the batch converter don't start too early; e.g.
if you add the same job twice the check of the existing video
won't start on the second job until the first is complete.

src/lib/dcp_encoder.cc
src/lib/dcp_encoder.h

index a3708040596c3c3aa9173f5e7e317fc03b094560..67235e5968e419c3c08a70c5301afeef5c955587 100644 (file)
@@ -56,12 +56,12 @@ using boost::dynamic_pointer_cast;
  */
 DCPEncoder::DCPEncoder (shared_ptr<const Film> film, weak_ptr<Job> job)
        : Encoder (film, job)
-       , _writer (new Writer (film, job))
-       , _j2k_encoder (new J2KEncoder (film, _writer))
+       , _film (film)
+       , _job (job)
        , _finishing (false)
        , _non_burnt_subtitles (false)
 {
-       BOOST_FOREACH (shared_ptr<const Content> c, _film->content ()) {
+       BOOST_FOREACH (shared_ptr<const Content> c, film->content ()) {
                if (c->subtitle && c->subtitle->use() && !c->subtitle->burn()) {
                        _non_burnt_subtitles = true;
                }
@@ -79,7 +79,10 @@ DCPEncoder::~DCPEncoder ()
 void
 DCPEncoder::go ()
 {
+       _writer.reset (new Writer (_film, _job));
        _writer->start ();
+
+       _j2k_encoder.reset (new J2KEncoder (_film, _writer));
        _j2k_encoder->begin ();
 
        {
@@ -135,11 +138,19 @@ DCPEncoder::subtitle (PlayerSubtitles data, DCPTimePeriod period)
 float
 DCPEncoder::current_rate () const
 {
+       if (!_j2k_encoder) {
+               return 0;
+       }
+
        return _j2k_encoder->current_encoding_rate ();
 }
 
 Frame
 DCPEncoder::frames_done () const
 {
+       if (!_j2k_encoder) {
+               return 0;
+       }
+
        return _j2k_encoder->video_frames_enqueued ();
 }
index d35b06184547b415d58e3f22871ae3a444416493..b1514efdc7d0715070c76445dee8ecae32ec528b 100644 (file)
@@ -54,6 +54,8 @@ private:
        void audio (boost::shared_ptr<AudioBuffers>, DCPTime);
        void subtitle (PlayerSubtitles, DCPTimePeriod);
 
+       boost::shared_ptr<const Film> _film;
+       boost::weak_ptr<Job> _job;
        boost::shared_ptr<Writer> _writer;
        boost::shared_ptr<J2KEncoder> _j2k_encoder;
        bool _finishing;