summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-12-31 15:44:51 +0000
committerCarl Hetherington <cth@carlh.net>2013-12-31 15:44:51 +0000
commitad49361b303d1ceff7048fa0e89ba609ca9ce376 (patch)
treebe6413325604b0d403add54a8de6ea861ec90772 /src/lib
parentb2a9271256e09fcfedff3beea5fc73c04e7c0e14 (diff)
parent5625ba9542e38504e87799dd655be5071161fb1f (diff)
Merge 1.0
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/encoder.cc15
-rw-r--r--src/lib/encoder.h2
-rw-r--r--src/lib/exceptions.h25
-rw-r--r--src/lib/player.cc6
-rw-r--r--src/lib/server_finder.cc10
-rw-r--r--src/lib/server_finder.h2
-rw-r--r--src/lib/writer.cc4
7 files changed, 46 insertions, 18 deletions
diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc
index 475c230da..ca9134c04 100644
--- a/src/lib/encoder.cc
+++ b/src/lib/encoder.cc
@@ -96,7 +96,6 @@ Encoder::process_begin ()
ServerFinder::instance()->connect (boost::bind (&Encoder::server_found, this, _1));
}
-
void
Encoder::process_end ()
{
@@ -199,9 +198,12 @@ Encoder::process_video (shared_ptr<PlayerImage> 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);
@@ -257,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
@@ -338,6 +341,10 @@ Encoder::encoder_thread (optional<ServerDescription> server)
_condition.notify_all ();
}
}
+catch (...)
+{
+ store_current ();
+}
void
Encoder::server_found (ServerDescription s)
diff --git a/src/lib/encoder.h b/src/lib/encoder.h
index d43e4e1d3..079174f89 100644
--- a/src/lib/encoder.h
+++ b/src/lib/encoder.h
@@ -56,7 +56,7 @@ class PlayerImage;
* is supplied as uncompressed PCM in blocks of various sizes.
*/
-class Encoder : public boost::noncopyable
+class Encoder : public boost::noncopyable, public ExceptionStore
{
public:
Encoder (boost::shared_ptr<const Film> f, boost::weak_ptr<Job>);
diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h
index f4631c09b..c1240538f 100644
--- a/src/lib/exceptions.h
+++ b/src/lib/exceptions.h
@@ -230,17 +230,30 @@ public:
PixelFormatError (std::string o, AVPixelFormat f);
};
+/** A parent class for classes which have a need to catch and
+ * re-throw exceptions. This is intended for classes
+ * which run their own thread; they should do something like
+ *
+ * void my_thread ()
+ * try {
+ * // do things which might throw exceptions
+ * } catch (...) {
+ * store_current ();
+ * }
+ *
+ * and then in another thread call rethrow(). If any
+ * exception was thrown by my_thread it will be stored by
+ * store_current() and then rethrow() will re-throw it where
+ * it can be handled.
+ */
class ExceptionStore
{
public:
- bool thrown () const {
- boost::mutex::scoped_lock lm (_mutex);
- return _exception;
- }
-
void rethrow () {
boost::mutex::scoped_lock lm (_mutex);
- boost::rethrow_exception (_exception);
+ if (_exception) {
+ boost::rethrow_exception (_exception);
+ }
}
protected:
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 96d23a82b..c9f9acd94 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -343,16 +343,16 @@ void
Player::flush ()
{
TimedAudioBuffers<DCPTime> tb = _audio_merger.flush ();
- if (tb.audio) {
+ if (_audio && tb.audio) {
Audio (tb.audio, tb.time);
_audio_position += _film->audio_frames_to_time (tb.audio->frames ());
}
- while (_video_position < _audio_position) {
+ while (_video && _video_position < _audio_position) {
emit_black ();
}
- while (_audio_position < _video_position) {
+ while (_audio && _audio_position < _video_position) {
emit_silence (_video_position - _audio_position);
}
diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc
index de90e0d5c..5b67d8048 100644
--- a/src/lib/server_finder.cc
+++ b/src/lib/server_finder.cc
@@ -47,6 +47,7 @@ ServerFinder::ServerFinder ()
void
ServerFinder::broadcast_thread ()
+try
{
boost::system::error_code error;
boost::asio::io_service io_service;
@@ -88,9 +89,14 @@ ServerFinder::broadcast_thread ()
dcpomatic_sleep (10);
}
}
+catch (...)
+{
+ store_current ();
+}
void
ServerFinder::listen_thread ()
+try
{
while (1) {
shared_ptr<Socket> sock (new Socket (10));
@@ -117,6 +123,10 @@ ServerFinder::listen_thread ()
}
}
}
+catch (...)
+{
+ store_current ();
+}
bool
ServerFinder::server_found (string ip) const
diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h
index 01e26f7df..202bee8f9 100644
--- a/src/lib/server_finder.h
+++ b/src/lib/server_finder.h
@@ -20,7 +20,7 @@
#include <boost/signals2.hpp>
#include "server.h"
-class ServerFinder
+class ServerFinder : public ExceptionStore
{
public:
void connect (boost::function<void (ServerDescription)>);
diff --git a/src/lib/writer.cc b/src/lib/writer.cc
index 4129b7a82..414ea72eb 100644
--- a/src/lib/writer.cc
+++ b/src/lib/writer.cc
@@ -335,9 +335,7 @@ Writer::finish ()
lock.unlock ();
_thread->join ();
- if (thrown ()) {
- rethrow ();
- }
+ rethrow ();
delete _thread;
_thread = 0;