Make terminate_threads() less likely to leave _threads containing invalid pointers.
[dcpomatic.git] / src / lib / player.cc
index 96c963e7093ec166c8f392de4e41120fac9fdc2b..baf9b20680b10da6f439c189459569da2b5b2a18 100644 (file)
@@ -517,8 +517,8 @@ Player::get_reel_assets ()
                        int64_t const reel_duration = k->main_picture()->duration();
 
                        /* See doc/design/trim_reels.svg */
-                       Frame const reel_trim_start = min(reel_duration, max(0L, trim_start - offset_from_start));
-                       Frame const reel_trim_end =   min(reel_duration, max(0L, reel_duration - (offset_from_end - trim_end)));
+                       Frame const reel_trim_start = min(reel_duration, max(int64_t(0), trim_start - offset_from_start));
+                       Frame const reel_trim_end =   min(reel_duration, max(int64_t(0), reel_duration - (offset_from_end - trim_end)));
 
                        DCPTime const from = i->position() + DCPTime::from_frames (offset_from_start, _film->video_frame_rate());
                        if (j->reference_video ()) {
@@ -613,8 +613,18 @@ Player::pass ()
 
        switch (which) {
        case CONTENT:
+       {
                earliest_content->done = earliest_content->decoder->pass ();
+               shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(earliest_content->content);
+               if (dcp && !_play_referenced && dcp->reference_audio()) {
+                       /* We are skipping some referenced DCP audio content, so we need to update _last_audio_time
+                          to `hide' the fact that no audio was emitted during the referenced DCP (though
+                          we need to behave as though it was).
+                       */
+                       _last_audio_time = dcp->end (_film);
+               }
                break;
+       }
        case BLACK:
                emit_video (black_player_video_frame(EYES_BOTH), _black.position());
                _black.set_position (_black.position() + one_video_frame());
@@ -625,8 +635,15 @@ Player::pass ()
                if (_last_audio_time) {
                        /* Sometimes the thing that happened last finishes fractionally before
                           or after this silence.  Bodge the start time of the silence to fix it.
+                          I think this is nothing to worry about since we will just add or
+                          remove a little silence at the end of some content.
                        */
-                       DCPOMATIC_ASSERT (labs(period.from.get() - _last_audio_time->get()) < 2);
+                       int64_t const error = labs(period.from.get() - _last_audio_time->get());
+                       int64_t const too_much_error = 4;
+                       if (error >= too_much_error) {
+                               _film->log()->log(String::compose("Silence starting before or after last audio by %1", error), LogEntry::TYPE_ERROR);
+                       }
+                       DCPOMATIC_ASSERT (error < too_much_error);
                        period.from = *_last_audio_time;
                }
                if (period.duration() > one_video_frame()) {