diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-07-23 01:21:07 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-07-23 01:21:07 +0100 |
| commit | ded71cffd18962ebb6b9611a5eb6dfafe9e8e4ec (patch) | |
| tree | 6da7f5da15b7b4cdeb82f7099b549abf537bf4fa /src/lib | |
| parent | 07d75f41aed77e340d927cc092dc4e7d74d03897 (diff) | |
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.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/active_captions.cc | 40 | ||||
| -rw-r--r-- | src/lib/active_captions.h | 3 | ||||
| -rw-r--r-- | src/lib/caption_content.cc | 2 | ||||
| -rw-r--r-- | src/lib/player.cc | 43 | ||||
| -rw-r--r-- | src/lib/player.h | 4 |
5 files changed, 63 insertions, 29 deletions
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<PlayerCaption>& pc, list<Period> p) const +{ + BOOST_FOREACH (Period i, p) { + DCPTimePeriod test (i.from, i.to.get_value_or(DCPTime::max())); + optional<DCPTimePeriod> overlap = period.overlap (test); + if (overlap && overlap->duration() > DCPTime(period.duration().get() / 2)) { + pc.push_back (i.subs); + } + } +} + +list<PlayerCaption> +ActiveCaptions::get (DCPTimePeriod period) const +{ + list<PlayerCaption> ps; + + for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) { + + shared_ptr<const CaptionContent> 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<DCPTimePeriod> 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<PlayerCaption> get (DCPTimePeriod period) const; std::list<PlayerCaption> get_burnt (DCPTimePeriod period, bool always_burn_captions) const; void clear_before (DCPTime time); void clear (); @@ -61,5 +62,7 @@ private: typedef std::map<boost::weak_ptr<const CaptionContent>, std::list<Period> > Map; + void add (DCPTimePeriod period, std::list<PlayerCaption>& pc, std::list<Period> 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<PlayerCaption> +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<PositionImage> -Player::captions_for_frame (DCPTime time) const +Player::open_captions_for_frame (DCPTime time) const { list<PositionImage> 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<PositionImage> 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<PositionImage> 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<PositionImage> 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<PositionImage> 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<PlayerVideo> pv, DCPTime time) } } - optional<PositionImage> captions = captions_for_frame (time); + optional<PositionImage> 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> content, ContentTime t); + std::list<PlayerCaption> 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<boost::shared_ptr<AudioBuffers>, DCPTime> discard_audio ( boost::shared_ptr<const AudioBuffers> audio, DCPTime time, DCPTime discard_to ) const; - boost::optional<PositionImage> captions_for_frame (DCPTime time) const; + boost::optional<PositionImage> open_captions_for_frame (DCPTime time) const; void emit_video (boost::shared_ptr<PlayerVideo> pv, DCPTime time); void do_emit_video (boost::shared_ptr<PlayerVideo> pv, DCPTime time); void emit_audio (boost::shared_ptr<AudioBuffers> data, DCPTime time); |
