Rename SafeStringStream -> locked_stringstream. Bump deps for removal of stringstream.
[dcpomatic.git] / src / lib / encoder.cc
index 9ec817604a34e09ca98dc0c8dfb24a5f1606a441..0c41d8d806a8ec9bf627a54b2ac579315edab074 100644 (file)
@@ -53,7 +53,7 @@ using boost::weak_ptr;
 using boost::optional;
 using dcp::Data;
 
-int const Encoder::_history_size = 25;
+int const Encoder::_history_size = 200;
 
 /** @param f Film that we are encoding */
 Encoder::Encoder (shared_ptr<const Film> film, shared_ptr<Writer> writer)
@@ -78,12 +78,10 @@ Encoder::~Encoder ()
 void
 Encoder::begin ()
 {
-       if (!EncodeServerFinder::instance()->disabled ()) {
-               weak_ptr<Encoder> wp = shared_from_this ();
-               _server_found_connection = EncodeServerFinder::instance()->ServersListChanged.connect (
-                       boost::bind (&Encoder::call_servers_list_changed, wp)
-                       );
-       }
+       weak_ptr<Encoder> wp = shared_from_this ();
+       _server_found_connection = EncodeServerFinder::instance()->ServersListChanged.connect (
+               boost::bind (&Encoder::call_servers_list_changed, wp)
+               );
 }
 
 /* We don't want the servers-list-changed callback trying to do things
@@ -166,6 +164,10 @@ Encoder::current_encoding_rate () const
 int
 Encoder::video_frames_enqueued () const
 {
+       if (!_last_player_video) {
+               return 0;
+       }
+
        return _last_player_video->time().frames_floor (_film->video_frame_rate ());
 }
 
@@ -203,11 +205,13 @@ Encoder::encode (shared_ptr<PlayerVideo> pv)
 
        boost::mutex::scoped_lock queue_lock (_queue_mutex);
 
-       /* Wait until the queue has gone down a bit */
-       while (_queue.size() >= threads * 2) {
-               LOG_TIMING ("decoder-sleep queue=%1", _queue.size());
+       /* Wait until the queue has gone down a bit.  Allow one thing in the queue even
+          when there are no threads.
+       */
+       while (_queue.size() >= (threads * 2) + 1) {
+               LOG_TIMING ("decoder-sleep queue=%1 threads=%2", _queue.size(), threads);
                _full_condition.wait (queue_lock);
-               LOG_TIMING ("decoder-wake queue=%1", _queue.size());
+               LOG_TIMING ("decoder-wake queue=%1 threads=%2", _queue.size(), threads);
        }
 
        _writer->rethrow ();
@@ -360,6 +364,10 @@ try
                _full_condition.notify_all ();
        }
 }
+catch (boost::thread_interrupted& e) {
+       /* Ignore these and just stop the thread */
+       _full_condition.notify_all ();
+}
 catch (...)
 {
        store_current ();