Merge branch 'master' into plot-audio
[dcpomatic.git] / src / lib / writer.cc
index 1df8a430102c454376e06ac01865ebd86d9dac5e..1dad4357d9381f02f5a9b9e3382c22c0a6a71153 100644 (file)
@@ -72,20 +72,22 @@ Writer::Writer (shared_ptr<Film> f)
 
        _picture_asset_writer = _picture_asset->start_write (_first_nonexistant_frame > 0);
 
-       if (_film->audio_channels() > 0) {
+       AudioMapping m (_film->audio_channels ());
+       
+       if (m.dcp_channels() > 0) {
                _sound_asset.reset (
                        new libdcp::SoundAsset (
                                _film->dir (_film->dcp_name()),
                                "audio.mxf",
                                DCPFrameRate (_film->frames_per_second()).frames_per_second,
-                               _film->audio_channels(),
+                               m.dcp_channels (),
                                dcp_audio_sample_rate (_film->audio_stream()->sample_rate())
                                )
                        );
 
                _sound_asset_writer = _sound_asset->start_write ();
        }
-       
+
        _thread = new boost::thread (boost::bind (&Writer::thread, this));
 }
 
@@ -130,6 +132,7 @@ Writer::write (shared_ptr<const AudioBuffers> audio)
 
 void
 Writer::thread ()
+try
 {
        while (1)
        {
@@ -221,7 +224,10 @@ Writer::thread ()
                        --_queued_full_in_memory;
                }
        }
-
+}
+catch (...)
+{
+       store_current ();
 }
 
 void
@@ -237,6 +243,10 @@ Writer::finish ()
        lock.unlock ();
 
        _thread->join ();
+       if (thrown ()) {
+               rethrow ();
+       }
+       
        delete _thread;
        _thread = 0;
 
@@ -361,7 +371,6 @@ Writer::can_fake_write (int frame) const
        return (frame != 0 && frame < _first_nonexistant_frame);
 }
 
-
 bool
 operator< (QueueItem const & a, QueueItem const & b)
 {