Merge master; fix crash on new film.
[dcpomatic.git] / src / lib / encoder.cc
index 3201e6ecb5bd689cd04a4b81013c17a466791357..c1d1041ae539f9cdab1f087291eb2d8d7104abbb 100644 (file)
@@ -93,13 +93,13 @@ Encoder::process_begin ()
                   decide if rematrixing is needed.  It won't be, since
                   input and output layouts are the same.
                */
-                  
+
                _swr_context = swr_alloc_set_opts (
                        0,
-                       av_get_default_channel_layout (_film->audio_channels ()),
+                       av_get_default_channel_layout (_film->audio_mapping().dcp_channels ()),
                        AV_SAMPLE_FMT_FLTP,
                        _film->target_audio_sample_rate(),
-                       av_get_default_channel_layout (_film->audio_channels ()),
+                       av_get_default_channel_layout (_film->audio_mapping().dcp_channels ()),
                        AV_SAMPLE_FMT_FLTP,
                        _film->audio_frame_rate(),
                        0, 0
@@ -240,7 +240,7 @@ Encoder::frame_done ()
 }
 
 void
-Encoder::process_video (shared_ptr<Image> image, bool same, shared_ptr<Subtitle> sub)
+Encoder::process_video (shared_ptr<const Image> image, bool same, shared_ptr<Subtitle> sub)
 {
        FrameRateConversion frc (_film->video_frame_rate(), _film->dcp_frame_rate());
        
@@ -303,7 +303,7 @@ Encoder::process_video (shared_ptr<Image> image, bool same, shared_ptr<Subtitle>
 }
 
 void
-Encoder::process_audio (shared_ptr<AudioBuffers> data)
+Encoder::process_audio (shared_ptr<const AudioBuffers> data)
 {
 #if HAVE_SWRESAMPLE
        /* Maybe sample-rate convert */
@@ -342,7 +342,9 @@ Encoder::terminate_threads ()
        lock.unlock ();
 
        for (list<boost::thread *>::iterator i = _threads.begin(); i != _threads.end(); ++i) {
-               (*i)->join ();
+               if ((*i)->joinable ()) {
+                       (*i)->join ();
+               }
                delete *i;
        }
 }