Comment.
[dcpomatic.git] / src / lib / writer.cc
index 7381d2a904bdf74ae0aebbf250b8e38b8ef53dd4..47c6b838142619a355cab1f0fbc298f84586df9b 100644 (file)
@@ -30,7 +30,6 @@
 #include "cross.h"
 #include "audio_buffers.h"
 #include "md5_digester.h"
-#include "data.h"
 #include "version.h"
 #include "font.h"
 #include "util.h"
@@ -62,6 +61,7 @@ using std::cout;
 using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
+using dcp::Data;
 
 Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j)
        : _film (film)
@@ -448,12 +448,18 @@ Writer::finish ()
                return;
        }
 
+       LOG_GENERAL_NC ("Terminating writer thread");
+
        terminate_thread (true);
 
+       LOG_GENERAL_NC ("Finishing ReelWriters");
+
        BOOST_FOREACH (ReelWriter& i, _reels) {
                i.finish ();
        }
 
+       LOG_GENERAL_NC ("Writing XML");
+
        dcp::DCP dcp (_film->dir (_film->dcp_name()));
 
        shared_ptr<dcp::CPL> cpl (
@@ -467,11 +473,11 @@ Writer::finish ()
 
        BOOST_FOREACH (ReelWriter& i, _reels) {
 
-               cpl->add (i.create_reel (_reel_assets, _fonts));
-
                shared_ptr<Job> job = _job.lock ();
                DCPOMATIC_ASSERT (job);
                i.calculate_digests (job);
+
+               cpl->add (i.create_reel (_reel_assets, _fonts));
        }
 
        dcp::XMLMetadata meta;
@@ -564,7 +570,16 @@ operator== (QueueItem const & a, QueueItem const & b)
 void
 Writer::set_encoder_threads (int threads)
 {
-       _maximum_frames_in_memory = lrint (threads * 1.1);
+       /* I think the scaling factor here should be the ratio of the longest frame
+          encode time to the shortest; if the thread count is T, longest time is L
+          and the shortest time S we could encode L/S frames per thread whilst waiting
+          for the L frame to encode so we might have to store LT/S frames.
+
+          However we don't want to use too much memory, so keep it a bit lower than we'd
+          perhaps like.  A J2K frame is typically about 1Mb so 3 here will mean we could
+          use about 240Mb with 72 encoding threads.
+       */
+       _maximum_frames_in_memory = lrint (threads * 3);
 }
 
 void