Key ActiveCaptions on a CaptionContent rather than a Piece.
authorCarl Hetherington <cth@carlh.net>
Fri, 20 Jul 2018 22:16:40 +0000 (23:16 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 20 Jul 2018 22:16:40 +0000 (23:16 +0100)
src/lib/active_captions.cc
src/lib/active_captions.h
src/lib/player.cc
src/lib/player.h

index bb64f995dbd96cdbda6320509faa45b63c5c11f6..b84c75a7cda99325f8ed39c3de7df307018db8e7 100644 (file)
@@ -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;
        }
index e0e8acf8ebea9daf33e0a951ea05cc8df9d2c666..28ddcad52c5939867be6cda3fad77b282073e8f7 100644 (file)
@@ -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;
 };
index 72c0519c6512cc3e0d8f0ce8103383308aec22a5..78928af26bc0954288952014c902e573c711fb74 100644 (file)
@@ -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));
        }
 }
index cbadb11f658f5a82f509c04304241fe4a703f604..d0f1eec6d4d31b0bb5de76498a8ed875d58aef20 100644 (file)
@@ -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 (