From 9f8bdc77426b15f1f89110118ccb5c9903228351 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 5 May 2017 14:06:47 +0100 Subject: [PATCH] Keep active subtitles around until the video they are on has been emitted. --- src/lib/player.cc | 33 ++++++++++++++++++++++++--------- src/lib/player.h | 21 ++++++++++++++++++--- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/lib/player.cc b/src/lib/player.cc index 3de26ec90..06a1b008d 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -626,7 +626,7 @@ Player::video (weak_ptr wp, ContentVideo video) optional subtitles; - for (ActiveSubtitles::const_iterator i = _active_subtitles.begin(); i != _active_subtitles.end(); ++i) { + for (ActiveSubtitlesMap::const_iterator i = _active_subtitles.begin(); i != _active_subtitles.end(); ++i) { shared_ptr sub_piece = i->first.lock (); if (!sub_piece) { @@ -637,17 +637,21 @@ Player::video (weak_ptr wp, ContentVideo video) continue; } - pair sub = i->second; + ActiveSubtitles sub = i->second; + + if (sub.from > time || (sub.to && sub.to.get() <= time)) { + continue; + } list sub_images; /* Image subtitles */ - list c = transform_image_subtitles (sub.first.image); + list c = transform_image_subtitles (sub.subs.image); copy (c.begin(), c.end(), back_inserter (sub_images)); /* Text subtitles (rendered to an image) */ - if (!sub.first.text.empty ()) { - list s = render_subtitles (sub.first.text, sub.first.fonts, _video_container_size, time); + if (!sub.subs.text.empty ()) { + list s = render_subtitles (sub.subs.text, sub.subs.fonts, _video_container_size, time); copy (s.begin (), s.end (), back_inserter (sub_images)); } @@ -684,6 +688,15 @@ Player::video (weak_ptr wp, ContentVideo video) Video (_last_video, time); _last_video_time = time + one_video_frame (); + + /* Clear any finished _active_subtitles */ + ActiveSubtitlesMap updated; + for (ActiveSubtitlesMap::const_iterator i = _active_subtitles.begin(); i != _active_subtitles.end(); ++i) { + if (!i->second.to || i->second.to.get() >= time) { + updated[i->first] = i->second; + } + } + _active_subtitles = updated; } void @@ -836,7 +849,7 @@ Player::image_subtitle_start (weak_ptr wp, ContentImageSubtitle subtitle) ps.image.push_back (subtitle.sub); DCPTime from (content_time_to_dcp (piece, subtitle.from())); - _active_subtitles[wp] = make_pair (ps, from); + _active_subtitles[wp] = ActiveSubtitles (ps, from); } void @@ -875,7 +888,7 @@ Player::text_subtitle_start (weak_ptr wp, ContentTextSubtitle subtitle) ps.add_fonts (piece->content->subtitle->fonts ()); } - _active_subtitles[wp] = make_pair (ps, from); + _active_subtitles[wp] = ActiveSubtitles (ps, from); } void @@ -890,11 +903,13 @@ Player::subtitle_stop (weak_ptr wp, ContentTime to) return; } + DCPTime const dcp_to = content_time_to_dcp (piece, to); + if (piece->content->subtitle->use() && !_always_burn_subtitles && !piece->content->subtitle->burn()) { - Subtitle (_active_subtitles[wp].first, DCPTimePeriod (_active_subtitles[wp].second, content_time_to_dcp (piece, to))); + Subtitle (_active_subtitles[wp].subs, DCPTimePeriod (_active_subtitles[wp].from, dcp_to)); } - _active_subtitles.erase (wp); + _active_subtitles[wp].to = dcp_to; } void diff --git a/src/lib/player.h b/src/lib/player.h index 719e42895..18b47043a 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -152,7 +152,8 @@ private: AudioMerger _audio_merger; - class StreamState { + class StreamState + { public: StreamState () {} @@ -169,8 +170,22 @@ private: std::list _no_video; std::list _no_audio; - typedef std::map, std::pair > ActiveSubtitles; - ActiveSubtitles _active_subtitles; + class ActiveSubtitles + { + public: + ActiveSubtitles () {} + + ActiveSubtitles (PlayerSubtitles s, DCPTime f) + : subs (s) + , from (f) + {} + + PlayerSubtitles subs; + DCPTime from; + boost::optional to; + }; + typedef std::map, ActiveSubtitles> ActiveSubtitlesMap; + ActiveSubtitlesMap _active_subtitles; boost::shared_ptr _audio_processor; typedef std::map, AudioStreamPtr>, boost::shared_ptr > ResamplerMap; -- 2.30.2