Store subtitle language(s) in Film, and allow setup of those
[dcpomatic.git] / src / lib / butler.cc
index df23580863a800e41c2f5c2561719822605966a3..d27778b70b0a909b1d8aae0626dece75d8d41108 100644 (file)
@@ -39,6 +39,9 @@ using boost::bind;
 using boost::optional;
 using boost::function;
 using namespace dcpomatic;
+#if BOOST_VERSION >= 106100
+using namespace boost::placeholders;
+#endif
 
 /** Minimum video readahead in frames */
 #define MINIMUM_VIDEO_READAHEAD 10
@@ -59,6 +62,7 @@ Butler::Butler (
        AudioMapping audio_mapping,
        int audio_channels,
        function<AVPixelFormat (AVPixelFormat)> pixel_format,
+       VideoRange video_range,
        bool aligned,
        bool fast
        )
@@ -73,6 +77,7 @@ Butler::Butler (
        , _audio_channels (audio_channels)
        , _disable_audio (false)
        , _pixel_format (pixel_format)
+       , _video_range (video_range)
        , _aligned (aligned)
        , _fast (fast)
 {
@@ -208,6 +213,12 @@ try
        boost::mutex::scoped_lock lm (_mutex);
        _finished = true;
        _arrived.notify_all ();
+} catch (std::exception& e) {
+       store_current ();
+       boost::mutex::scoped_lock lm (_mutex);
+       _died = true;
+       _died_message = e.what ();
+       _arrived.notify_all ();
 } catch (...) {
        store_current ();
        boost::mutex::scoped_lock lm (_mutex);
@@ -226,7 +237,7 @@ Butler::get_video (bool blocking, Error* e)
 
        if (_suspended || (_video.empty() && !blocking)) {
                if (e) {
-                       *e = AGAIN;
+                       e->code = Error::AGAIN;
                }
                return make_pair(shared_ptr<PlayerVideo>(), DCPTime());
        }
@@ -239,11 +250,12 @@ Butler::get_video (bool blocking, Error* e)
        if (_video.empty()) {
                if (e) {
                        if (_died) {
-                               *e = DIED;
+                               e->code = Error::DIED;
+                               e->message = _died_message;
                        } else if (_finished) {
-                               *e = FINISHED;
+                               e->code = Error::FINISHED;
                        } else {
-                               *e = NONE;
+                               e->code = Error::NONE;
                        }
                }
                return make_pair(shared_ptr<PlayerVideo>(), DCPTime());
@@ -295,10 +307,17 @@ try
        /* If the weak_ptr cannot be locked the video obviously no longer requires any work */
        if (video) {
                LOG_TIMING("start-prepare in %1", thread_id());
-               video->prepare (_pixel_format, _aligned, _fast);
+               video->prepare (_pixel_format, _video_range, _aligned, _fast);
                LOG_TIMING("finish-prepare in %1", thread_id());
        }
 }
+catch (std::exception& e)
+{
+       store_current ();
+       boost::mutex::scoped_lock lm (_mutex);
+       _died = true;
+       _died_message = e.what ();
+}
 catch (...)
 {
        store_current ();
@@ -406,3 +425,22 @@ Butler::text (PlayerText pt, TextType type, optional<DCPTextTrack> track, DCPTim
 
        _closed_caption.put (pt, *track, period);
 }
+
+string
+Butler::Error::summary () const
+{
+       switch (code)
+       {
+               case Error::NONE:
+                       return "No error registered";
+               case Error::AGAIN:
+                       return "Butler not ready";
+               case Error::DIED:
+                       return String::compose("Butler died (%1)", message);
+               case Error::FINISHED:
+                       return "Butler finished";
+       }
+
+       return "";
+}
+