Add content parameter to Piece::content_time_to_dcp().
authorCarl Hetherington <cth@carlh.net>
Sat, 24 Apr 2021 20:47:48 +0000 (22:47 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 7 May 2021 07:29:59 +0000 (09:29 +0200)
src/lib/piece.cc
src/lib/piece.h
src/lib/player.cc
src/lib/player.h

index 0e5fd0259d8549ad3a9a6b1c97775f35df9d1052..e24db7f4097c0a4235100ab7fe8f7a0a89a93873 100644 (file)
@@ -33,6 +33,7 @@
 using std::dynamic_pointer_cast;
 using std::make_shared;
 using std::shared_ptr;
+using boost::optional;
 using namespace dcpomatic;
 
 
@@ -105,9 +106,13 @@ Piece::dcp_to_content_time (DCPTime t, shared_ptr<const Film> film) const
 }
 
 
-DCPTime
-Piece::content_time_to_dcp (ContentTime t) const
+optional<DCPTime>
+Piece::content_time_to_dcp (shared_ptr<const Content> content_, ContentTime t) const
 {
+       if (content != content_) {
+               return {};
+       }
+
        return max (DCPTime(), DCPTime(t - content->trim_start(), frc) + content->position());
 }
 
@@ -191,7 +196,9 @@ Piece::decoder_for (shared_ptr<Content> content_) const
 DCPTime
 Piece::decoder_position () const
 {
-       return content_time_to_dcp(std::max(decoder->position(), content->trim_start()));
+       auto t = content_time_to_dcp(content, std::max(decoder->position(), content->trim_start()));
+       DCPOMATIC_ASSERT (t);
+       return *t;
 }
 
 
index 5b80a7fff2060cd1f6bb1de480464231da4e0948..50b38b849ca25453698d1d811098fe076316f2b9 100644 (file)
@@ -47,7 +47,7 @@ public:
        dcpomatic::DCPTime content_video_to_dcp (Frame f) const;
        dcpomatic::DCPTime resampled_audio_to_dcp (Frame f, std::shared_ptr<const Film> film) const;
        dcpomatic::ContentTime dcp_to_content_time (dcpomatic::DCPTime t, std::shared_ptr<const Film> film) const;
-       dcpomatic::DCPTime content_time_to_dcp (dcpomatic::ContentTime t) const;
+       boost::optional<dcpomatic::DCPTime> content_time_to_dcp (std::shared_ptr<const Content> content, dcpomatic::ContentTime t) const;
 
        void pass ();
 
index 086cfbbbd7b259d447a5e68d01abe364b5b8d8c6..e99eb9daee2c87285af5b1ba83e8ec384ba527d5 100644 (file)
@@ -241,13 +241,13 @@ Player::setup_pieces_unlocked ()
 
                while (j != decoder->text.end()) {
                        (*j)->BitmapStart.connect (
-                               bind(&Player::bitmap_text_start, this, weak_ptr<Piece>(piece), weak_ptr<const TextContent>((*j)->content()), _1)
+                               bind(&Player::bitmap_text_start, this, weak_ptr<Piece>(piece), i, weak_ptr<const TextContent>((*j)->content()), _1)
                                );
                        (*j)->PlainStart.connect (
-                               bind(&Player::plain_text_start, this, weak_ptr<Piece>(piece), weak_ptr<const TextContent>((*j)->content()), _1)
+                               bind(&Player::plain_text_start, this, weak_ptr<Piece>(piece), i, weak_ptr<const TextContent>((*j)->content()), _1)
                                );
                        (*j)->Stop.connect (
-                               bind(&Player::subtitle_stop, this, weak_ptr<Piece>(piece), weak_ptr<const TextContent>((*j)->content()), _1)
+                               bind(&Player::subtitle_stop, this, weak_ptr<Piece>(piece), i, weak_ptr<const TextContent>((*j)->content()), _1)
                                );
 
                        ++j;
@@ -281,6 +281,23 @@ Player::setup_pieces_unlocked ()
 }
 
 
+optional<DCPTime>
+Player::content_time_to_dcp (shared_ptr<Content> content, ContentTime t)
+{
+       boost::mutex::scoped_lock lm (_mutex);
+
+       for (auto i: _pieces) {
+               auto dcp = i->content_time_to_dcp(content, t);
+               if (dcp) {
+                       return *dcp;
+               }
+       }
+
+       /* We couldn't find this content; perhaps things are being changed over */
+       return {};
+}
+
+
 void
 Player::playlist_content_change (ChangeType type, int property, bool frequent)
 {
@@ -925,11 +942,12 @@ Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_a
 
 
 void
-Player::bitmap_text_start (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, ContentBitmapText subtitle)
+Player::bitmap_text_start (weak_ptr<Piece> wp, weak_ptr<const Content> wc, weak_ptr<const TextContent> wt, ContentBitmapText subtitle)
 {
        auto piece = wp.lock ();
-       auto text = wc.lock ();
-       if (!piece || !text) {
+       auto content = wc.lock ();
+       auto text = wt.lock ();
+       if (!piece || !content || !text) {
                return;
        }
 
@@ -957,23 +975,26 @@ Player::bitmap_text_start (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, C
 
        dcp::Size scaled_size (width, height);
        ps.bitmap.push_back (BitmapText(image->scale(scaled_size, dcp::YUVToRGB::REC601, image->pixel_format(), true, _fast), subtitle.sub.rectangle));
-       DCPTime from (piece->content_time_to_dcp(subtitle.from()));
+       auto from = piece->content_time_to_dcp(content, subtitle.from());
+       DCPOMATIC_ASSERT (from);
 
-       _active_texts[static_cast<int>(text->type())].add_from (wc, ps, from);
+       _active_texts[static_cast<int>(text->type())].add_from (wt, ps, *from);
 }
 
 
 void
-Player::plain_text_start (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, ContentStringText subtitle)
+Player::plain_text_start (weak_ptr<Piece> wp, weak_ptr<const Content> wc, weak_ptr<const TextContent> wt, ContentStringText subtitle)
 {
        auto piece = wp.lock ();
-       auto text = wc.lock ();
-       if (!piece || !text) {
+       auto content = wc.lock ();
+       auto text = wt.lock ();
+       if (!piece || !content || !text) {
                return;
        }
 
        PlayerText ps;
-       DCPTime const from (piece->content_time_to_dcp(subtitle.from()));
+       auto const from = piece->content_time_to_dcp(content, subtitle.from());
+       DCPOMATIC_ASSERT (from);
 
        if (from > piece->end(_film)) {
                return;
@@ -999,24 +1020,25 @@ Player::plain_text_start (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, Co
                        s.set_aspect_adjust (xs / ys);
                }
 
-               s.set_in (dcp::Time(from.seconds(), 1000));
+               s.set_in (dcp::Time(from->seconds(), 1000));
                ps.string.push_back (StringText (s, text->outline_width()));
                ps.add_fonts (text->fonts ());
        }
 
-       _active_texts[static_cast<int>(text->type())].add_from (wc, ps, from);
+       _active_texts[static_cast<int>(text->type())].add_from (wt, ps, *from);
 }
 
 
 void
-Player::subtitle_stop (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, ContentTime to)
+Player::subtitle_stop (weak_ptr<Piece> wp, weak_ptr<const Content> wc, weak_ptr<const TextContent> wt, ContentTime to)
 {
-       auto text = wc.lock ();
+       auto content = wc.lock ();
+       auto text = wt.lock ();
        if (!text) {
                return;
        }
 
-       if (!_active_texts[static_cast<int>(text->type())].have(wc)) {
+       if (!_active_texts[static_cast<int>(text->type())].have(wt)) {
                return;
        }
 
@@ -1025,17 +1047,18 @@ Player::subtitle_stop (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, Conte
                return;
        }
 
-       auto const dcp_to = piece->content_time_to_dcp(to);
+       auto const dcp_to = piece->content_time_to_dcp(content, to);
+       DCPOMATIC_ASSERT (dcp_to);
 
-       if (dcp_to > piece->end(_film)) {
+       if (*dcp_to > piece->end(_film)) {
                return;
        }
 
-       auto from = _active_texts[static_cast<int>(text->type())].add_to (wc, dcp_to);
+       auto from = _active_texts[static_cast<int>(text->type())].add_to(wt, *dcp_to);
 
        bool const always = (text->type() == TextType::OPEN_SUBTITLE && _always_burn_open_subtitles);
        if (text->use() && !always && !text->burn()) {
-               Text (from.first, text->type(), text->dcp_track().get_value_or(DCPTextTrack()), DCPTimePeriod (from.second, dcp_to));
+               Text (from.first, text->type(), text->dcp_track().get_value_or(DCPTextTrack()), DCPTimePeriod (from.second, *dcp_to));
        }
 }
 
@@ -1234,22 +1257,6 @@ Player::set_dcp_decode_reduction (optional<int> reduction)
 }
 
 
-optional<DCPTime>
-Player::content_time_to_dcp (shared_ptr<Content> content, ContentTime t)
-{
-       boost::mutex::scoped_lock lm (_mutex);
-
-       for (auto i: _pieces) {
-               if (i->content == content) {
-                       return i->content_time_to_dcp(t);
-               }
-       }
-
-       /* We couldn't find this content; perhaps things are being changed over */
-       return {};
-}
-
-
 shared_ptr<const Playlist>
 Player::playlist () const
 {
index 229dac91b602145f6cfb0b33723e7dbc52b91139..9086c48137f85f8b9112290c08f3b252f3eb34b9 100644 (file)
@@ -135,9 +135,9 @@ private:
 
        void video (std::weak_ptr<Piece>, ContentVideo);
        void audio (std::weak_ptr<Piece>, AudioStreamPtr, ContentAudio);
-       void bitmap_text_start (std::weak_ptr<Piece>, std::weak_ptr<const TextContent>, ContentBitmapText);
-       void plain_text_start (std::weak_ptr<Piece>, std::weak_ptr<const TextContent>, ContentStringText);
-       void subtitle_stop (std::weak_ptr<Piece>, std::weak_ptr<const TextContent>, dcpomatic::ContentTime);
+       void bitmap_text_start (std::weak_ptr<Piece>, std::weak_ptr<const Content>, std::weak_ptr<const TextContent>, ContentBitmapText);
+       void plain_text_start (std::weak_ptr<Piece>, std::weak_ptr<const Content>, std::weak_ptr<const TextContent>, ContentStringText);
+       void subtitle_stop (std::weak_ptr<Piece>, std::weak_ptr<const Content>, std::weak_ptr<const TextContent>, dcpomatic::ContentTime);
        void atmos (std::weak_ptr<Piece>, ContentAtmos);
 
        dcpomatic::DCPTime one_video_frame () const;
@@ -163,7 +163,7 @@ private:
 
        /** > 0 if we are suspended (i.e. pass() and seek() do nothing) */
        boost::atomic<int> _suspended;
-       std::list<std::shared_ptr<Piece> > _pieces;
+       std::list<std::shared_ptr<Piece>> _pieces;
 
        /** Size of the image we are rendering to; this may be the DCP frame size, or
         *  the size of preview in a window.