Speculative fix for reel length errors when some trimmed content comes in the 2nd...
[dcpomatic.git] / src / lib / player.cc
index bd194c3733dfb05cb267d9af3632d2b542f9245e..c94e0b549602eff985ff1318208f60471ffe7bee 100644 (file)
@@ -283,6 +283,8 @@ Player::film_changed (Film::Property p)
                if (_film->audio_processor ()) {
                        _audio_processor = _film->audio_processor()->clone (_film->audio_frame_rate ());
                }
+       } else if (p == Film::AUDIO_CHANNELS) {
+               _audio_merger.clear ();
        }
 }
 
@@ -555,7 +557,11 @@ Player::pass ()
                        continue;
                }
 
-               DCPTime const t = content_time_to_dcp (i, i->decoder->position());
+               /** decoder position may need to be trimmed like the
+                   content (but the decoder does not know it yet);
+                   check for that and fake it here if necessary.
+               */
+               DCPTime const t = content_time_to_dcp (i, min(i->decoder->position(), i->content->trim_start()));
                if (t > i->content->end()) {
                        i->done = true;
                } else {
@@ -886,6 +892,10 @@ Player::text_subtitle_start (weak_ptr<Piece> wp, ContentTextSubtitle subtitle)
        PlayerSubtitles ps;
        DCPTime const from (content_time_to_dcp (piece, subtitle.from()));
 
+       if (from > piece->content->end()) {
+               return;
+       }
+
        BOOST_FOREACH (dcp::SubtitleString s, subtitle.subs) {
                s.set_h_position (s.h_position() + piece->content->subtitle->x_offset ());
                s.set_v_position (s.v_position() + piece->content->subtitle->y_offset ());
@@ -928,6 +938,10 @@ Player::subtitle_stop (weak_ptr<Piece> wp, ContentTime to)
 
        DCPTime const dcp_to = content_time_to_dcp (piece, to);
 
+       if (dcp_to > piece->content->end()) {
+               return;
+       }
+
        pair<PlayerSubtitles, DCPTime> from = _active_subtitles.add_to (wp, dcp_to);
 
        if (piece->content->subtitle->use() && !_always_burn_subtitles && !piece->content->subtitle->burn()) {
@@ -957,8 +971,8 @@ Player::seek (DCPTime time, bool accurate)
 
        BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
                if (time < i->content->position()) {
-                       /* Before; seek to 0 */
-                       i->decoder->seek (ContentTime(), accurate);
+                       /* Before; seek to the start of the content */
+                       i->decoder->seek (dcp_to_content_time (i, i->content->position()), accurate);
                        i->done = false;
                } else if (i->content->position() <= time && time < i->content->end()) {
                        /* During; seek to position */
@@ -1031,8 +1045,8 @@ Player::emit_audio (shared_ptr<AudioBuffers> data, DCPTime time)
                _film->log()->log(String::compose("Out-of-sequence emit %1 vs %2", to_string(time), to_string(*_last_audio_time)), LogEntry::TYPE_WARNING);
        }
 
-       /* This audio must follow on from the previous */
-       DCPOMATIC_ASSERT (!_last_audio_time || time == *_last_audio_time);
+       /* This audio must follow on from the previous, but I'll remove this check for the 2.12.x release */
+       // DCPOMATIC_ASSERT (!_last_audio_time || time == *_last_audio_time);
        Audio (data, time);
        _last_audio_time = time + DCPTime::from_frames (data->frames(), _film->audio_frame_rate());
 }