From ded71cffd18962ebb6b9611a5eb6dfafe9e8e4ec Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 23 Jul 2018 01:21:07 +0100 Subject: Get ccaps by asking the Player, rather than by listening to its emissions, which is slightly cleaner and works when subtitles are emitted with an unknown end time. Also add CCAPs to the player. --- src/lib/active_captions.cc | 40 ++++++++++++++++++++++++++++++++-------- src/lib/active_captions.h | 3 +++ src/lib/caption_content.cc | 2 +- src/lib/player.cc | 43 ++++++++++++++++++++++++------------------- src/lib/player.h | 4 +++- 5 files changed, 63 insertions(+), 29 deletions(-) (limited to 'src/lib') diff --git a/src/lib/active_captions.cc b/src/lib/active_captions.cc index b4252e0c3..1d3a53609 100644 --- a/src/lib/active_captions.cc +++ b/src/lib/active_captions.cc @@ -30,7 +30,37 @@ using boost::weak_ptr; using boost::shared_ptr; using boost::optional; -/** Get the subtitles that should be burnt into a given period. +void +ActiveCaptions::add (DCPTimePeriod period, list& pc, list p) const +{ + BOOST_FOREACH (Period i, p) { + DCPTimePeriod test (i.from, i.to.get_value_or(DCPTime::max())); + optional overlap = period.overlap (test); + if (overlap && overlap->duration() > DCPTime(period.duration().get() / 2)) { + pc.push_back (i.subs); + } + } +} + +list +ActiveCaptions::get (DCPTimePeriod period) const +{ + list ps; + + for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) { + + shared_ptr caption = i->first.lock (); + if (!caption || !caption->use()) { + continue; + } + + add (period, ps, i->second); + } + + return ps; +} + +/** Get the open captions that should be burnt into a given period. * @param period Period of interest. * @param always_burn_captions Always burn captions even if their content is not set to burn. */ @@ -51,13 +81,7 @@ ActiveCaptions::get_burnt (DCPTimePeriod period, bool always_burn_captions) cons continue; } - BOOST_FOREACH (Period j, i->second) { - DCPTimePeriod test (j.from, j.to.get_value_or(DCPTime::max())); - optional overlap = period.overlap (test); - if (overlap && overlap->duration() > DCPTime(period.duration().get() / 2)) { - ps.push_back (j.subs); - } - } + add (period, ps, i->second); } return ps; diff --git a/src/lib/active_captions.h b/src/lib/active_captions.h index 10b0b5da9..8e38564f5 100644 --- a/src/lib/active_captions.h +++ b/src/lib/active_captions.h @@ -36,6 +36,7 @@ class CaptionContent; class ActiveCaptions : public boost::noncopyable { public: + std::list get (DCPTimePeriod period) const; std::list get_burnt (DCPTimePeriod period, bool always_burn_captions) const; void clear_before (DCPTime time); void clear (); @@ -61,5 +62,7 @@ private: typedef std::map, std::list > Map; + void add (DCPTimePeriod period, std::list& pc, std::list p) const; + Map _data; }; diff --git a/src/lib/caption_content.cc b/src/lib/caption_content.cc index 37a3e7c70..bbb1bacf3 100644 --- a/src/lib/caption_content.cc +++ b/src/lib/caption_content.cc @@ -67,7 +67,7 @@ CaptionContent::CaptionContent (Content* parent, CaptionType original_type) , _y_scale (1) , _line_spacing (1) , _outline_width (2) - , _type (CAPTION_OPEN) + , _type (original_type) , _original_type (original_type) { diff --git a/src/lib/player.cc b/src/lib/player.cc index dfd309774..4635233ff 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -676,29 +676,34 @@ Player::pass () return done; } +list +Player::closed_captions_for_frame (DCPTime time) const +{ + return _active_captions[CAPTION_CLOSED].get ( + DCPTimePeriod(time, time + DCPTime::from_frames(1, _film->video_frame_rate())) + ); +} + +/** @return Open captions for the frame at the given time, converted to images */ optional -Player::captions_for_frame (DCPTime time) const +Player::open_captions_for_frame (DCPTime time) const { list captions; - int const vfr = _film->video_frame_rate(); - for (int i = 0; i < CAPTION_COUNT; ++i) { - bool const always = i == CAPTION_OPEN && _always_burn_open_captions; - BOOST_FOREACH ( - PlayerCaption j, - _active_captions[i].get_burnt(DCPTimePeriod(time, time + DCPTime::from_frames(1, vfr)), always) - ) { - - /* Image subtitles */ - list c = transform_bitmap_captions (j.image); - copy (c.begin(), c.end(), back_inserter (captions)); - - /* Text subtitles (rendered to an image) */ - if (!j.text.empty ()) { - list s = render_text (j.text, j.fonts, _video_container_size, time, vfr); - copy (s.begin(), s.end(), back_inserter (captions)); - } + BOOST_FOREACH ( + PlayerCaption j, + _active_captions[CAPTION_OPEN].get_burnt(DCPTimePeriod(time, time + DCPTime::from_frames(1, vfr)), _always_burn_open_captions) + ) { + + /* Image subtitles */ + list c = transform_bitmap_captions (j.image); + copy (c.begin(), c.end(), back_inserter (captions)); + + /* Text subtitles (rendered to an image) */ + if (!j.text.empty ()) { + list s = render_text (j.text, j.fonts, _video_container_size, time, vfr); + copy (s.begin(), s.end(), back_inserter (captions)); } } @@ -1047,7 +1052,7 @@ Player::do_emit_video (shared_ptr pv, DCPTime time) } } - optional captions = captions_for_frame (time); + optional captions = open_captions_for_frame (time); if (captions) { pv->set_caption (captions.get ()); } diff --git a/src/lib/player.h b/src/lib/player.h index d54d927cd..8b85a011f 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -86,6 +86,8 @@ public: DCPTime content_time_to_dcp (boost::shared_ptr content, ContentTime t); + std::list closed_captions_for_frame (DCPTime time) const; + /** Emitted when something has changed such that if we went back and emitted * the last frame again it would look different. This is not emitted after * a seek. @@ -134,7 +136,7 @@ private: std::pair, DCPTime> discard_audio ( boost::shared_ptr audio, DCPTime time, DCPTime discard_to ) const; - boost::optional captions_for_frame (DCPTime time) const; + boost::optional open_captions_for_frame (DCPTime time) const; void emit_video (boost::shared_ptr pv, DCPTime time); void do_emit_video (boost::shared_ptr pv, DCPTime time); void emit_audio (boost::shared_ptr data, DCPTime time); -- cgit v1.2.3