Fix some coverity-reported stuff.
[dcpomatic.git] / src / lib / player.cc
index 9f859969341fa65a1eacc22d0c3da9b7002387c0..42551889b03563f2dbea0f8e779ddbcddfdd767e 100644 (file)
@@ -62,6 +62,8 @@ public:
                , decoder (d)
                , video_position (c->position ())
                , audio_position (c->position ())
+               , repeat_to_do (0)
+               , repeat_done (0)
        {}
 
        /** Set this piece to repeat a video frame a given number of times */
@@ -224,7 +226,8 @@ Player::pass ()
                                continue;
                        }
 
-                       if (dynamic_pointer_cast<AudioDecoder> ((*i)->decoder)) {
+                       shared_ptr<AudioDecoder> ad = dynamic_pointer_cast<AudioDecoder> ((*i)->decoder);
+                       if (ad && ad->has_audio ()) {
                                audio_done_up_to = min (audio_done_up_to.get_value_or (TIME_MAX), (*i)->audio_position);
                        }
                }
@@ -292,6 +295,7 @@ Player::process_video (weak_ptr<Piece> weak_piece, shared_ptr<const Image> image
 
                pi->set_subtitle (_out_subtitle.image, _out_subtitle.position + container_offset);
        }
+               
                                            
 #ifdef DCPOMATIC_DEBUG
        _last_video = piece->content;
@@ -519,7 +523,11 @@ Player::content_changed (weak_ptr<Content> w, int property, bool frequent)
                _have_valid_pieces = false;
                Changed (frequent);
 
-       } else if (property == SubtitleContentProperty::SUBTITLE_OFFSET || property == SubtitleContentProperty::SUBTITLE_SCALE) {
+       } else if (
+               property == SubtitleContentProperty::SUBTITLE_X_OFFSET ||
+               property == SubtitleContentProperty::SUBTITLE_Y_OFFSET ||
+               property == SubtitleContentProperty::SUBTITLE_SCALE
+               ) {
 
                update_subtitle ();
                Changed (frequent);
@@ -656,7 +664,8 @@ Player::update_subtitle ()
        dcpomatic::Rect<double> in_rect = _in_subtitle.rect;
        libdcp::Size scaled_size;
 
-       in_rect.y += sc->subtitle_offset ();
+       in_rect.x += sc->subtitle_x_offset ();
+       in_rect.y += sc->subtitle_y_offset ();
 
        /* We will scale the subtitle up to fit _video_container_size, and also by the additional subtitle_scale */
        scaled_size.width = in_rect.width * _video_container_size.width * sc->subtitle_scale ();
@@ -683,8 +692,18 @@ Player::update_subtitle ()
                _in_subtitle.image->pixel_format (),
                true
                );
-       _out_subtitle.from = _in_subtitle.from + piece->content->position ();
-       _out_subtitle.to = _in_subtitle.to + piece->content->position ();
+
+       /* XXX: hack */
+       Time from = _in_subtitle.from;
+       Time to = _in_subtitle.to;
+       shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (piece->content);
+       if (vc) {
+               from = rint (from * vc->video_frame_rate() / _film->video_frame_rate());
+               to = rint (to * vc->video_frame_rate() / _film->video_frame_rate());
+       }
+       
+       _out_subtitle.from = from + piece->content->position ();
+       _out_subtitle.to = to + piece->content->position ();
 }
 
 /** Re-emit the last frame that was emitted, using current settings for crop, ratio, scaler and subtitles.