Trim referred-to DCPs correctly using CPL entry point / duration.
[dcpomatic.git] / src / lib / player.cc
index 20a3e14533557997117cfd9fb0c9a91ae017a700..c17cdfdc0166d04fd376024e40a7494aa85215e0 100644 (file)
@@ -172,26 +172,43 @@ Player::playlist_content_changed (weak_ptr<Content> w, int property, bool freque
                property == DCPContentProperty::CAN_BE_PLAYED ||
                property == SubtitleContentProperty::COLOUR ||
                property == SubtitleContentProperty::OUTLINE ||
-               property == SubtitleContentProperty::OUTLINE_COLOUR ||
-               property == FFmpegContentProperty::SUBTITLE_STREAM
+               property == SubtitleContentProperty::SHADOW ||
+               property == SubtitleContentProperty::EFFECT_COLOUR ||
+               property == FFmpegContentProperty::SUBTITLE_STREAM ||
+               property == VideoContentProperty::COLOUR_CONVERSION
                ) {
 
                _have_valid_pieces = false;
                Changed (frequent);
 
+       } else if (
+               property == SubtitleContentProperty::LINE_SPACING ||
+               property == SubtitleContentProperty::OUTLINE_WIDTH ||
+               property == SubtitleContentProperty::Y_SCALE ||
+               property == SubtitleContentProperty::FADE_IN ||
+               property == SubtitleContentProperty::FADE_OUT
+               ) {
+
+               /* These changes just need the pieces' decoders to be reset.
+                  It's quite possible that other changes could be handled by
+                  this branch rather than the _have_valid_pieces = false branch
+                  above.  This would make things a lot faster.
+               */
+
+               reset_pieces ();
+               Changed (frequent);
+
        } else if (
                property == ContentProperty::VIDEO_FRAME_RATE ||
                property == SubtitleContentProperty::USE ||
                property == SubtitleContentProperty::X_OFFSET ||
                property == SubtitleContentProperty::Y_OFFSET ||
                property == SubtitleContentProperty::X_SCALE ||
-               property == SubtitleContentProperty::Y_SCALE ||
                property == SubtitleContentProperty::FONTS ||
                property == VideoContentProperty::CROP ||
                property == VideoContentProperty::SCALE ||
                property == VideoContentProperty::FADE_IN ||
-               property == VideoContentProperty::FADE_OUT ||
-               property == VideoContentProperty::COLOUR_CONVERSION
+               property == VideoContentProperty::FADE_OUT
                ) {
 
                Changed (frequent);
@@ -323,7 +340,7 @@ Player::get_video (DCPTime time, bool accurate)
 
        /* Text subtitles (rendered to an image) */
        if (!ps.text.empty ()) {
-               list<PositionImage> s = render_subtitles (ps.text, ps.fonts, _video_container_size);
+               list<PositionImage> s = render_subtitles (ps.text, ps.fonts, _video_container_size, time);
                copy (s.begin (), s.end (), back_inserter (sub_images));
        }
 
@@ -576,7 +593,7 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt,
 {
        list<shared_ptr<Piece> > subs = overlaps (time, time + length, has_subtitle);
 
-       PlayerSubtitles ps (time, length);
+       PlayerSubtitles ps (time);
 
        for (list<shared_ptr<Piece> >::const_iterator j = subs.begin(); j != subs.end(); ++j) {
                if (!(*j)->content->subtitle->use () || (!_always_burn_subtitles && (burnt != (*j)->content->subtitle->burn ()))) {
@@ -634,7 +651,7 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt,
                                }
                                s.set_in (dcp::Time(content_subtitle_to_dcp (*j, ts.period().from).seconds(), 1000));
                                s.set_out (dcp::Time(content_subtitle_to_dcp (*j, ts.period().to).seconds(), 1000));
-                               ps.text.push_back (s);
+                               ps.text.push_back (SubtitleString (s, (*j)->content->subtitle->outline_width()));
                                ps.add_fonts ((*j)->content->subtitle->fonts ());
                        }
                }
@@ -722,8 +739,17 @@ Player::get_reel_assets ()
 
                int64_t offset = 0;
                BOOST_FOREACH (shared_ptr<dcp::Reel> k, decoder->reels()) {
+
+                       DCPOMATIC_ASSERT (j->video_frame_rate ());
+                       double const cfr = j->video_frame_rate().get();
+                       Frame const trim_start = j->trim_start().frames_round (cfr);
+                       Frame const trim_end = j->trim_end().frames_round (cfr);
+
                        DCPTime const from = i->position() + DCPTime::from_frames (offset, _film->video_frame_rate());
                        if (j->reference_video ()) {
+                               DCPOMATIC_ASSERT (k->main_picture ());
+                               k->main_picture()->set_entry_point (trim_start);
+                               k->main_picture()->set_duration (k->main_picture()->intrinsic_duration() - trim_start - trim_end);
                                a.push_back (
                                        ReferencedReelAsset (
                                                k->main_picture (),
@@ -733,6 +759,9 @@ Player::get_reel_assets ()
                        }
 
                        if (j->reference_audio ()) {
+                               DCPOMATIC_ASSERT (k->main_sound ());
+                               k->main_sound()->set_entry_point (trim_start);
+                               k->main_sound()->set_duration (k->main_sound()->intrinsic_duration() - trim_start - trim_end);
                                a.push_back (
                                        ReferencedReelAsset (
                                                k->main_sound (),
@@ -743,6 +772,8 @@ Player::get_reel_assets ()
 
                        if (j->reference_subtitle ()) {
                                DCPOMATIC_ASSERT (k->main_subtitle ());
+                               k->main_subtitle()->set_entry_point (trim_start);
+                               k->main_subtitle()->set_duration (k->main_subtitle()->intrinsic_duration() - trim_start - trim_end);
                                a.push_back (
                                        ReferencedReelAsset (
                                                k->main_subtitle (),
@@ -775,3 +806,11 @@ Player::overlaps (DCPTime from, DCPTime to, boost::function<bool (Content *)> va
 
        return overlaps;
 }
+
+void
+Player::reset_pieces ()
+{
+       BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+               i->decoder->reset ();
+       }
+}