diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-07-20 23:16:40 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-07-20 23:16:40 +0100 |
| commit | 1013175d5f6adfa0e6a7442e4c9aebb893787748 (patch) | |
| tree | 039939d2e10efec2708d8f42a2946ed838eb39b8 /src | |
| parent | aa0c63e482b63d7e85407ca72fa0ba5e5e1259ad (diff) | |
Key ActiveCaptions on a CaptionContent rather than a Piece.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/active_captions.cc | 43 | ||||
| -rw-r--r-- | src/lib/active_captions.h | 10 | ||||
| -rw-r--r-- | src/lib/player.cc | 61 | ||||
| -rw-r--r-- | src/lib/player.h | 6 |
4 files changed, 64 insertions, 56 deletions
diff --git a/src/lib/active_captions.cc b/src/lib/active_captions.cc index bb64f995d..b84c75a7c 100644 --- a/src/lib/active_captions.cc +++ b/src/lib/active_captions.cc @@ -19,7 +19,6 @@ */ #include "active_captions.h" -#include "piece.h" #include "caption_content.h" #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> @@ -42,13 +41,13 @@ ActiveCaptions::get_burnt (DCPTimePeriod period, bool always_burn_captions) cons for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) { - shared_ptr<Piece> piece = i->first.lock (); - if (!piece) { + shared_ptr<CaptionContent> caption = i->first.lock (); + if (!caption) { continue; } - if (!piece->content->caption->use() || (!always_burn_captions && !piece->content->caption->burn())) { - /* Not burning this piece */ + if (!caption->use() || (!always_burn_captions && !caption->burn())) { + /* Not burning this content */ continue; } @@ -86,45 +85,45 @@ ActiveCaptions::clear_before (DCPTime time) } /** Add a new subtitle with a from time. - * @param piece Piece that the subtitle is from. + * @param content Content that the subtitle is from. * @param ps Subtitles. * @param from From time for these subtitles. */ void -ActiveCaptions::add_from (weak_ptr<Piece> piece, PlayerCaption ps, DCPTime from) +ActiveCaptions::add_from (weak_ptr<CaptionContent> content, PlayerCaption ps, DCPTime from) { - if (_data.find(piece) == _data.end()) { - _data[piece] = list<Period>(); + if (_data.find(content) == _data.end()) { + _data[content] = list<Period>(); } - _data[piece].push_back (Period (ps, from)); + _data[content].push_back (Period (ps, from)); } -/** Add the to time for the last subtitle added from a piece. - * @param piece Piece that the subtitle is from. - * @param to To time for the last subtitle submitted to add_from for this piece. +/** Add the to time for the last subtitle added from a piece of content. + * @param content Content that the subtitle is from. + * @param to To time for the last subtitle submitted to add_from for this content. * @return Return the corresponding subtitles and their from time. */ pair<PlayerCaption, DCPTime> -ActiveCaptions::add_to (weak_ptr<Piece> piece, DCPTime to) +ActiveCaptions::add_to (weak_ptr<CaptionContent> content, DCPTime to) { - DCPOMATIC_ASSERT (_data.find(piece) != _data.end()); + DCPOMATIC_ASSERT (_data.find(content) != _data.end()); - _data[piece].back().to = to; + _data[content].back().to = to; - BOOST_FOREACH (TextCaption& i, _data[piece].back().subs.text) { + BOOST_FOREACH (TextCaption& i, _data[content].back().subs.text) { i.set_out (dcp::Time(to.seconds(), 1000)); } - return make_pair (_data[piece].back().subs, _data[piece].back().from); + return make_pair (_data[content].back().subs, _data[content].back().from); } -/** @param piece A piece. - * @return true if we have any active subtitles from this piece. +/** @param content Some content. + * @return true if we have any active subtitles from this content. */ bool -ActiveCaptions::have (weak_ptr<Piece> piece) const +ActiveCaptions::have (weak_ptr<CaptionContent> content) const { - Map::const_iterator i = _data.find(piece); + Map::const_iterator i = _data.find(content); if (i == _data.end()) { return false; } diff --git a/src/lib/active_captions.h b/src/lib/active_captions.h index e0e8acf8e..28ddcad52 100644 --- a/src/lib/active_captions.h +++ b/src/lib/active_captions.h @@ -28,7 +28,7 @@ #include <list> #include <map> -class Piece; +class CaptionContent; /** @class ActiveCaptions * @brief A class to maintain information on active subtitles for Player. @@ -39,9 +39,9 @@ public: std::list<PlayerCaption> get_burnt (DCPTimePeriod period, bool always_burn_captions) const; void clear_before (DCPTime time); void clear (); - void add_from (boost::weak_ptr<Piece> piece, PlayerCaption ps, DCPTime from); - std::pair<PlayerCaption, DCPTime> add_to (boost::weak_ptr<Piece> piece, DCPTime to); - bool have (boost::weak_ptr<Piece> piece) const; + void add_from (boost::weak_ptr<CaptionContent> content, PlayerCaption ps, DCPTime from); + std::pair<PlayerCaption, DCPTime> add_to (boost::weak_ptr<CaptionContent> content, DCPTime to); + bool have (boost::weak_ptr<CaptionContent> content) const; private: class Period @@ -59,7 +59,7 @@ private: boost::optional<DCPTime> to; }; - typedef std::map<boost::weak_ptr<Piece>, std::list<Period> > Map; + typedef std::map<boost::weak_ptr<CaptionContent>, std::list<Period> > Map; Map _data; }; diff --git a/src/lib/player.cc b/src/lib/player.cc index 72c0519c6..78928af26 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -165,9 +165,15 @@ Player::setup_pieces () } if (decoder->caption) { - decoder->caption->BitmapStart.connect (bind (&Player::bitmap_text_start, this, weak_ptr<Piece> (piece), _1)); - decoder->caption->PlainStart.connect (bind (&Player::plain_text_start, this, weak_ptr<Piece> (piece), _1)); - decoder->caption->Stop.connect (bind (&Player::subtitle_stop, this, weak_ptr<Piece> (piece), _1, _2)); + decoder->caption->BitmapStart.connect ( + bind(&Player::bitmap_text_start, this, weak_ptr<Piece>(piece), weak_ptr<CaptionContent>(piece->content->caption), _1) + ); + decoder->caption->PlainStart.connect ( + bind(&Player::plain_text_start, this, weak_ptr<Piece>(piece), weak_ptr<CaptionContent>(piece->content->caption), _1) + ); + decoder->caption->Stop.connect ( + bind(&Player::subtitle_stop, this, weak_ptr<Piece>(piece), weak_ptr<CaptionContent>(piece->content->caption), _1, _2) + ); } } @@ -845,37 +851,39 @@ Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_a } void -Player::bitmap_text_start (weak_ptr<Piece> wp, ContentBitmapCaption subtitle) +Player::bitmap_text_start (weak_ptr<Piece> wp, weak_ptr<CaptionContent> wc, ContentBitmapCaption subtitle) { shared_ptr<Piece> piece = wp.lock (); - if (!piece) { + shared_ptr<CaptionContent> caption = wc.lock (); + if (!piece || !caption) { return; } /* Apply content's subtitle offsets */ - subtitle.sub.rectangle.x += piece->content->caption->x_offset (); - subtitle.sub.rectangle.y += piece->content->caption->y_offset (); + subtitle.sub.rectangle.x += caption->x_offset (); + subtitle.sub.rectangle.y += caption->y_offset (); /* Apply a corrective translation to keep the subtitle centred after the scale that is coming up */ - subtitle.sub.rectangle.x -= subtitle.sub.rectangle.width * ((piece->content->caption->x_scale() - 1) / 2); - subtitle.sub.rectangle.y -= subtitle.sub.rectangle.height * ((piece->content->caption->y_scale() - 1) / 2); + subtitle.sub.rectangle.x -= subtitle.sub.rectangle.width * ((caption->x_scale() - 1) / 2); + subtitle.sub.rectangle.y -= subtitle.sub.rectangle.height * ((caption->y_scale() - 1) / 2); /* Apply content's subtitle scale */ - subtitle.sub.rectangle.width *= piece->content->caption->x_scale (); - subtitle.sub.rectangle.height *= piece->content->caption->y_scale (); + subtitle.sub.rectangle.width *= caption->x_scale (); + subtitle.sub.rectangle.height *= caption->y_scale (); PlayerCaption ps; ps.image.push_back (subtitle.sub); DCPTime from (content_time_to_dcp (piece, subtitle.from())); - _active_captions[subtitle.type()].add_from (wp, ps, from); + _active_captions[subtitle.type()].add_from (wc, ps, from); } void -Player::plain_text_start (weak_ptr<Piece> wp, ContentTextCaption subtitle) +Player::plain_text_start (weak_ptr<Piece> wp, weak_ptr<CaptionContent> wc, ContentTextCaption subtitle) { shared_ptr<Piece> piece = wp.lock (); - if (!piece) { + shared_ptr<CaptionContent> caption = wc.lock (); + if (!piece || !caption) { return; } @@ -887,10 +895,10 @@ Player::plain_text_start (weak_ptr<Piece> wp, ContentTextCaption subtitle) } BOOST_FOREACH (dcp::SubtitleString s, subtitle.subs) { - s.set_h_position (s.h_position() + piece->content->caption->x_offset ()); - s.set_v_position (s.v_position() + piece->content->caption->y_offset ()); - float const xs = piece->content->caption->x_scale(); - float const ys = piece->content->caption->y_scale(); + s.set_h_position (s.h_position() + caption->x_offset ()); + s.set_v_position (s.v_position() + caption->y_offset ()); + float const xs = caption->x_scale(); + float const ys = caption->y_scale(); float size = s.size(); /* Adjust size to express the common part of the scaling; @@ -907,22 +915,23 @@ Player::plain_text_start (weak_ptr<Piece> wp, ContentTextCaption subtitle) } s.set_in (dcp::Time(from.seconds(), 1000)); - ps.text.push_back (TextCaption (s, piece->content->caption->outline_width())); - ps.add_fonts (piece->content->caption->fonts ()); + ps.text.push_back (TextCaption (s, caption->outline_width())); + ps.add_fonts (caption->fonts ()); } - _active_captions[subtitle.type()].add_from (wp, ps, from); + _active_captions[subtitle.type()].add_from (wc, ps, from); } void -Player::subtitle_stop (weak_ptr<Piece> wp, ContentTime to, CaptionType type) +Player::subtitle_stop (weak_ptr<Piece> wp, weak_ptr<CaptionContent> wc, ContentTime to, CaptionType type) { - if (!_active_captions[type].have (wp)) { + if (!_active_captions[type].have (wc)) { return; } shared_ptr<Piece> piece = wp.lock (); - if (!piece) { + shared_ptr<CaptionContent> caption = wc.lock (); + if (!piece || !caption) { return; } @@ -932,10 +941,10 @@ Player::subtitle_stop (weak_ptr<Piece> wp, ContentTime to, CaptionType type) return; } - pair<PlayerCaption, DCPTime> from = _active_captions[type].add_to (wp, dcp_to); + pair<PlayerCaption, DCPTime> from = _active_captions[type].add_to (wc, dcp_to); bool const always = _always_burn_captions && *_always_burn_captions == type; - if (piece->content->caption->use() && !always && !piece->content->caption->burn()) { + if (caption->use() && !always && !caption->burn()) { Caption (from.first, type, DCPTimePeriod (from.second, dcp_to)); } } diff --git a/src/lib/player.h b/src/lib/player.h index cbadb11f6..d0f1eec6d 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -126,9 +126,9 @@ private: boost::shared_ptr<PlayerVideo> black_player_video_frame (Eyes eyes) const; void video (boost::weak_ptr<Piece>, ContentVideo); void audio (boost::weak_ptr<Piece>, AudioStreamPtr, ContentAudio); - void bitmap_text_start (boost::weak_ptr<Piece>, ContentBitmapCaption); - void plain_text_start (boost::weak_ptr<Piece>, ContentTextCaption); - void subtitle_stop (boost::weak_ptr<Piece>, ContentTime, CaptionType); + void bitmap_text_start (boost::weak_ptr<Piece>, boost::weak_ptr<CaptionContent>, ContentBitmapCaption); + void plain_text_start (boost::weak_ptr<Piece>, boost::weak_ptr<CaptionContent>, ContentTextCaption); + void subtitle_stop (boost::weak_ptr<Piece>, boost::weak_ptr<CaptionContent>, ContentTime, CaptionType); DCPTime one_video_frame () const; void fill_audio (DCPTimePeriod period); std::pair<boost::shared_ptr<AudioBuffers>, DCPTime> discard_audio ( |
