Merge 1.0
[dcpomatic.git] / src / lib / encoder.cc
index 059c4014cf40b2e6be8862f1ea112854c2663096..ca9134c04d29e52400579330eb34d4fa75a5196e 100644 (file)
@@ -34,6 +34,7 @@
 #include "cross.h"
 #include "writer.h"
 #include "server_finder.h"
+#include "player.h"
 
 #include "i18n.h"
 
@@ -95,7 +96,6 @@ Encoder::process_begin ()
        ServerFinder::instance()->connect (boost::bind (&Encoder::server_found, this, _1));
 }
 
-
 void
 Encoder::process_end ()
 {
@@ -181,7 +181,7 @@ Encoder::frame_done ()
 }
 
 void
-Encoder::process_video (shared_ptr<const Image> image, Eyes eyes, ColourConversion conversion, bool same)
+Encoder::process_video (shared_ptr<PlayerImage> image, Eyes eyes, ColourConversion conversion, bool same)
 {
        boost::mutex::scoped_lock lock (_mutex);
 
@@ -198,9 +198,12 @@ Encoder::process_video (shared_ptr<const Image> image, Eyes eyes, ColourConversi
                return;
        }
 
-       if (_writer->thrown ()) {
-               _writer->rethrow ();
-       }
+       _writer->rethrow ();
+       /* Re-throw any exception raised by one of our threads.  If more
+          than one has thrown an exception, only one will be rethrown, I think;
+          but then, if that happens something has gone badly wrong.
+       */
+       rethrow ();
 
        if (_writer->can_fake_write (_video_frames_out)) {
                _writer->fake_write (_video_frames_out, eyes);
@@ -215,8 +218,8 @@ Encoder::process_video (shared_ptr<const Image> image, Eyes eyes, ColourConversi
                TIMING ("adding to queue of %1", _queue.size ());
                _queue.push_back (shared_ptr<DCPVideoFrame> (
                                          new DCPVideoFrame (
-                                                 image, _video_frames_out, eyes, conversion, _film->video_frame_rate(),
-                                                 _film->j2k_bandwidth(), _film->log()
+                                                 image->image(PIX_FMT_RGB24, false), _video_frames_out, eyes, conversion, _film->video_frame_rate(),
+                                                 _film->j2k_bandwidth(), _film->resolution(), _film->log()
                                                  )
                                          ));
                
@@ -256,6 +259,7 @@ Encoder::terminate_threads ()
 
 void
 Encoder::encoder_thread (optional<ServerDescription> server)
+try
 {
        /* Number of seconds that we currently wait between attempts
           to connect to the server; not relevant for localhost
@@ -337,6 +341,10 @@ Encoder::encoder_thread (optional<ServerDescription> server)
                _condition.notify_all ();
        }
 }
+catch (...)
+{
+       store_current ();
+}
 
 void
 Encoder::server_found (ServerDescription s)