Add some Changed() emissions so that when a butler is in control
[dcpomatic.git] / src / lib / player.cc
index 408e791cd560952fd0ee673efe660e5138444e6c..782e445e8ad3a3487c409cbbed725e193da12131 100644 (file)
@@ -83,6 +83,9 @@ int const PlayerProperty::PLAYLIST = 701;
 int const PlayerProperty::FILM_CONTAINER = 702;
 int const PlayerProperty::FILM_VIDEO_FRAME_RATE = 703;
 int const PlayerProperty::DCP_DECODE_REDUCTION = 704;
+int const PlayerProperty::IGNORE = 705;
+int const PlayerProperty::FAST = 706;
+int const PlayerProperty::PLAY_REFERENCED = 707;
 
 Player::Player (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist)
        : _film (film)
@@ -465,24 +468,37 @@ Player::get_subtitle_fonts ()
 void
 Player::set_ignore_video ()
 {
-       boost::mutex::scoped_lock lm (_mutex);
-       _ignore_video = true;
-       _have_valid_pieces = false;
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _ignore_video = true;
+               _have_valid_pieces = false;
+       }
+
+       Changed (PlayerProperty::IGNORE, false);
 }
 
 void
 Player::set_ignore_audio ()
 {
-       boost::mutex::scoped_lock lm (_mutex);
-       _ignore_audio = true;
-       _have_valid_pieces = false;
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _ignore_audio = true;
+               _have_valid_pieces = false;
+       }
+
+       Changed (PlayerProperty::IGNORE, false);
 }
 
 void
 Player::set_ignore_text ()
 {
-       boost::mutex::scoped_lock lm (_mutex);
-       _ignore_text = true;
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _ignore_text = true;
+               _have_valid_pieces = false;
+       }
+
+       Changed (PlayerProperty::IGNORE, false);
 }
 
 /** Set the player to always burn open texts into the image regardless of the content settings */
@@ -497,17 +513,25 @@ Player::set_always_burn_open_subtitles ()
 void
 Player::set_fast ()
 {
-       boost::mutex::scoped_lock lm (_mutex);
-       _fast = true;
-       _have_valid_pieces = false;
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _fast = true;
+               _have_valid_pieces = false;
+       }
+
+       Changed (PlayerProperty::FAST, false);
 }
 
 void
 Player::set_play_referenced ()
 {
-       boost::mutex::scoped_lock lm (_mutex);
-       _play_referenced = true;
-       _have_valid_pieces = false;
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _play_referenced = true;
+               _have_valid_pieces = false;
+       }
+
+       Changed (PlayerProperty::PLAY_REFERENCED, false);
 }
 
 list<ReferencedReelAsset>
@@ -594,7 +618,13 @@ Player::pass ()
        boost::mutex::scoped_lock lm (_mutex);
 
        if (!_have_valid_pieces) {
-               setup_pieces ();
+               /* This should only happen when we are under the control of the butler.  In this case, _have_valid_pieces
+                  will be false if something in the Player has changed and we are waiting for the butler to notice
+                  and do a seek back to the place we were at before.  During this time we don't want pass() to do anything,
+                  as just after setup_pieces the new decoders will be back to time 0 until the seek has gone through.  Just do nothing
+                  here and assume that the seek will be forthcoming.
+               */
+               return false;
        }
 
        if (_playlist->length() == DCPTime()) {
@@ -724,15 +754,6 @@ Player::pass ()
        return done;
 }
 
-list<PlayerText>
-Player::closed_captions_for_frame (DCPTime time) const
-{
-       boost::mutex::scoped_lock _lm (_mutex);
-       return _active_texts[TEXT_CLOSED_CAPTION].get (
-               DCPTimePeriod(time, time + DCPTime::from_frames(1, _film->video_frame_rate()))
-               );
-}
-
 /** @return Open subtitles for the frame at the given time, converted to images */
 optional<PositionImage>
 Player::open_subtitles_for_frame (DCPTime time) const
@@ -745,13 +766,13 @@ Player::open_subtitles_for_frame (DCPTime time) const
                _active_texts[TEXT_OPEN_SUBTITLE].get_burnt(DCPTimePeriod(time, time + DCPTime::from_frames(1, vfr)), _always_burn_open_subtitles)
                ) {
 
-               /* Image subtitles */
-               list<PositionImage> c = transform_bitmap_texts (j.image);
+               /* Bitmap subtitles */
+               list<PositionImage> c = transform_bitmap_texts (j.bitmap);
                copy (c.begin(), c.end(), back_inserter (captions));
 
-               /* Text subtitles (rendered to an image) */
-               if (!j.text.empty ()) {
-                       list<PositionImage> s = render_text (j.text, j.fonts, _video_container_size, time, vfr);
+               /* String subtitles (rendered to an image) */
+               if (!j.string.empty ()) {
+                       list<PositionImage> s = render_text (j.string, j.fonts, _video_container_size, time, vfr);
                        copy (s.begin(), s.end(), back_inserter (captions));
                }
        }
@@ -796,12 +817,17 @@ Player::video (weak_ptr<Piece> wp, ContentVideo video)
                DCPTime fill_from = max (*_last_video_time, piece->content->position());
                LastVideoMap::const_iterator last = _last_video.find (wp);
                if (_film->three_d()) {
+                       Eyes fill_to_eyes = video.eyes;
+                       if (fill_to == piece->content->end()) {
+                               /* Don't fill after the end of the content */
+                               fill_to_eyes = EYES_LEFT;
+                       }
                        DCPTime j = fill_from;
                        Eyes eyes = _last_video_eyes.get_value_or(EYES_LEFT);
                        if (eyes == EYES_BOTH) {
                                eyes = EYES_LEFT;
                        }
-                       while (j < fill_to || eyes != video.eyes) {
+                       while (j < fill_to || eyes != fill_to_eyes) {
                                if (last != _last_video.end()) {
                                        shared_ptr<PlayerVideo> copy = last->second->shallow_copy();
                                        copy->set_eyes (eyes);
@@ -940,7 +966,7 @@ Player::bitmap_text_start (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, C
        subtitle.sub.rectangle.height *= text->y_scale ();
 
        PlayerText ps;
-       ps.image.push_back (subtitle.sub);
+       ps.bitmap.push_back (subtitle.sub);
        DCPTime from (content_time_to_dcp (piece, subtitle.from()));
 
        _active_texts[subtitle.type()].add_from (wc, ps, from);
@@ -983,7 +1009,7 @@ Player::plain_text_start (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, Co
                }
 
                s.set_in (dcp::Time(from.seconds(), 1000));
-               ps.text.push_back (StringText (s, text->outline_width()));
+               ps.string.push_back (StringText (s, text->outline_width()));
                ps.add_fonts (text->fonts ());
        }