Distinguish master DoM encode threads count from the server count.
[dcpomatic.git] / src / lib / encoder.cc
index 32af746a583a0cdae5f2e3b65123e7b8c619ee55..276ef8d3adccf1578223231e79c0818020f2bab0 100644 (file)
@@ -56,7 +56,9 @@ using dcp::Data;
 
 int const Encoder::_history_size = 200;
 
-/** @param f Film that we are encoding */
+/** @param film Film that we are encoding.
+ *  @param writer Writer that we are using.
+ */
 Encoder::Encoder (shared_ptr<const Film> film, shared_ptr<Writer> writer)
        : _film (film)
        , _writer (writer)
@@ -165,16 +167,14 @@ Encoder::current_encoding_rate () const
 int
 Encoder::video_frames_enqueued () const
 {
-       if (!_last_player_video) {
+       if (!_last_player_video_time) {
                return 0;
        }
 
-       return _last_player_video->time().frames_floor (_film->video_frame_rate ());
+       return _last_player_video_time->frames_floor (_film->video_frame_rate ());
 }
 
-/** Should be called when a frame has been encoded successfully.
- *  @param n Source frame index.
- */
+/** Should be called when a frame has been encoded successfully */
 void
 Encoder::frame_done ()
 {
@@ -188,13 +188,16 @@ Encoder::frame_done ()
        }
 }
 
-/** Called to start encoding of the next video frame in the DCP.  This is called in order,
+/** Called to request encoding of the next video frame in the DCP.  This is called in order,
  *  so each time the supplied frame is the one after the previous one.
  *  pv represents one video frame, and could be empty if there is nothing to encode
  *  for this DCP frame.
+ *
+ *  @param pv PlayerVideo to encode.
+ *  @param time Time of \p pv within the DCP.
  */
 void
-Encoder::encode (shared_ptr<PlayerVideo> pv)
+Encoder::encode (shared_ptr<PlayerVideo> pv, DCPTime time)
 {
        _waker.nudge ();
 
@@ -222,22 +225,22 @@ Encoder::encode (shared_ptr<PlayerVideo> pv)
        */
        rethrow ();
 
-       Frame const position = pv->time().frames_floor(_film->video_frame_rate());
+       Frame const position = time.frames_floor(_film->video_frame_rate());
 
        if (_writer->can_fake_write (position)) {
                /* We can fake-write this frame */
-               LOG_DEBUG_ENCODE("Frame @ %1 FAKE", to_string(pv->time()));
+               LOG_DEBUG_ENCODE("Frame @ %1 FAKE", to_string(time));
                _writer->fake_write (position, pv->eyes ());
                frame_done ();
        } else if (pv->has_j2k ()) {
-               LOG_DEBUG_ENCODE("Frame @ %1 J2K", to_string(pv->time()));
+               LOG_DEBUG_ENCODE("Frame @ %1 J2K", to_string(time));
                /* This frame already has JPEG2000 data, so just write it */
                _writer->write (pv->j2k(), position, pv->eyes ());
        } else if (_last_player_video && _writer->can_repeat(position) && pv->same (_last_player_video)) {
-               LOG_DEBUG_ENCODE("Frame @ %1 REPEAT", to_string(pv->time()));
+               LOG_DEBUG_ENCODE("Frame @ %1 REPEAT", to_string(time));
                _writer->repeat (position, pv->eyes ());
        } else {
-               LOG_DEBUG_ENCODE("Frame @ %1 ENCODE", to_string(pv->time()));
+               LOG_DEBUG_ENCODE("Frame @ %1 ENCODE", to_string(time));
                /* Queue this new frame for encoding */
                LOG_TIMING ("add-frame-to-queue queue=%1", _queue.size ());
                _queue.push_back (shared_ptr<DCPVideo> (
@@ -258,6 +261,7 @@ Encoder::encode (shared_ptr<PlayerVideo> pv)
        }
 
        _last_player_video = pv;
+       _last_player_video_time = time;
 }
 
 void
@@ -410,7 +414,7 @@ Encoder::servers_list_changed ()
 #endif
 
        if (!Config::instance()->only_servers_encode ()) {
-               for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) {
+               for (int i = 0; i < Config::instance()->master_encoding_threads (); ++i) {
                        boost::thread* t = new boost::thread (boost::bind (&Encoder::encoder_thread, this, optional<EncodeServerDescription> ()));
                        _threads.push_back (t);
 #ifdef BOOST_THREAD_PLATFORM_WIN32