Basic jump to selected subtitle (#1200).
[dcpomatic.git] / src / lib / player.cc
index 44fe770ff0812a338ce2c251942a7fa385b31b01..df58ed223af0ea043322f5a2e42262dc0466656a 100644 (file)
@@ -206,14 +206,15 @@ Player::playlist_content_changed (weak_ptr<Content> w, int property, bool freque
                property == ContentProperty::TRIM_END ||
                property == ContentProperty::PATH ||
                property == VideoContentProperty::FRAME_TYPE ||
+               property == VideoContentProperty::COLOUR_CONVERSION ||
+               property == AudioContentProperty::STREAMS ||
                property == DCPContentProperty::NEEDS_ASSETS ||
                property == DCPContentProperty::NEEDS_KDM ||
                property == SubtitleContentProperty::COLOUR ||
                property == SubtitleContentProperty::EFFECT ||
                property == SubtitleContentProperty::EFFECT_COLOUR ||
                property == FFmpegContentProperty::SUBTITLE_STREAM ||
-               property == FFmpegContentProperty::FILTERS ||
-               property == VideoContentProperty::COLOUR_CONVERSION
+               property == FFmpegContentProperty::FILTERS
                ) {
 
                _have_valid_pieces = false;
@@ -301,18 +302,6 @@ Player::transform_image_subtitles (list<ImageSubtitle> subs) const
                /* We will scale the subtitle up to fit _video_container_size */
                dcp::Size scaled_size (i->rectangle.width * _video_container_size.width, i->rectangle.height * _video_container_size.height);
 
-               /* Then we need a corrective translation, consisting of two parts:
-                *
-                * 1.  that which is the result of the scaling of the subtitle by _video_container_size; this will be
-                *     rect.x * _video_container_size.width and rect.y * _video_container_size.height.
-                *
-                * 2.  that to shift the origin of the scale by subtitle_scale to the centre of the subtitle; this will be
-                *     (width_before_subtitle_scale * (1 - subtitle_x_scale) / 2) and
-                *     (height_before_subtitle_scale * (1 - subtitle_y_scale) / 2).
-                *
-                * Combining these two translations gives these expressions.
-                */
-
                all.push_back (
                        PositionImage (
                                i->image->scale (
@@ -557,7 +546,7 @@ Player::pass ()
                        continue;
                }
 
-               DCPTime const t = content_time_to_dcp (i, i->decoder->position());
+               DCPTime const t = content_time_to_dcp (i, max(i->decoder->position(), i->content->trim_start()));
                if (t > i->content->end()) {
                        i->done = true;
                } else {
@@ -888,6 +877,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 ());
@@ -930,6 +923,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()) {
@@ -959,8 +956,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 */
@@ -1092,3 +1089,20 @@ Player::set_dcp_decode_reduction (optional<int> reduction)
        _have_valid_pieces = false;
        Changed (PlayerProperty::DCP_DECODE_REDUCTION, false);
 }
+
+DCPTime
+Player::content_time_to_dcp (shared_ptr<Content> content, ContentTime t)
+{
+       if (_have_valid_pieces) {
+               setup_pieces ();
+       }
+
+       BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+               if (i->content == content) {
+                       return content_time_to_dcp (i, t);
+               }
+       }
+
+       DCPOMATIC_ASSERT (false);
+       return DCPTime ();
+}