Don't keep returning AGAIN from the butler when it is already dead/finished.
authorCarl Hetherington <cth@carlh.net>
Mon, 15 Feb 2021 01:50:03 +0000 (02:50 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 15 Feb 2021 09:56:14 +0000 (10:56 +0100)
This causes, for example, player UI hangs when trying to play
something unplayable (e.g. a DCP with no KDM).

src/lib/butler.cc

index 56acbd8a0817aa4809741aea234a3589a9d9162c..d4da787ddfb741595fdaa5ddae803203b0b15394 100644 (file)
@@ -237,10 +237,21 @@ Butler::get_video (bool blocking, Error* e)
 {
        boost::mutex::scoped_lock lm (_mutex);
 
 {
        boost::mutex::scoped_lock lm (_mutex);
 
-       if (_suspended || (_video.empty() && !blocking)) {
+       auto setup_error = [this](Error* e, Error::Code fallback) {
                if (e) {
                if (e) {
-                       e->code = Error::AGAIN;
+                       if (_died) {
+                               e->code = Error::DIED;
+                               e->message = _died_message;
+                       } else if (_finished) {
+                               e->code = Error::FINISHED;
+                       } else {
+                               e->code = fallback;
+                       }
                }
                }
+       };
+
+       if (_video.empty() && (_finished || _died || (_suspended && !blocking))) {
+               setup_error (e, Error::AGAIN);
                return make_pair(shared_ptr<PlayerVideo>(), DCPTime());
        }
 
                return make_pair(shared_ptr<PlayerVideo>(), DCPTime());
        }
 
@@ -250,20 +261,11 @@ Butler::get_video (bool blocking, Error* e)
        }
 
        if (_video.empty()) {
        }
 
        if (_video.empty()) {
-               if (e) {
-                       if (_died) {
-                               e->code = Error::DIED;
-                               e->message = _died_message;
-                       } else if (_finished) {
-                               e->code = Error::FINISHED;
-                       } else {
-                               e->code = Error::NONE;
-                       }
-               }
+               setup_error (e, Error::NONE);
                return make_pair(shared_ptr<PlayerVideo>(), DCPTime());
        }
 
                return make_pair(shared_ptr<PlayerVideo>(), DCPTime());
        }
 
-       pair<shared_ptr<PlayerVideo>, DCPTime> const r = _video.get ();
+       auto const r = _video.get ();
        _summon.notify_all ();
        return r;
 }
        _summon.notify_all ();
        return r;
 }