From: Carl Hetherington Date: Sat, 24 Apr 2021 20:47:48 +0000 (+0200) Subject: Add content parameter to Piece::content_time_to_dcp(). X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;h=e7924e68c2f213448cdd920dba3bf91a1e019626;hp=4a144b7f777146ff666057caf895ce4fe1c3c2bb;p=dcpomatic.git Add content parameter to Piece::content_time_to_dcp(). --- diff --git a/src/lib/piece.cc b/src/lib/piece.cc index 0e5fd0259..e24db7f40 100644 --- a/src/lib/piece.cc +++ b/src/lib/piece.cc @@ -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 film) const } -DCPTime -Piece::content_time_to_dcp (ContentTime t) const +optional +Piece::content_time_to_dcp (shared_ptr 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_) 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; } diff --git a/src/lib/piece.h b/src/lib/piece.h index 5b80a7fff..50b38b849 100644 --- a/src/lib/piece.h +++ b/src/lib/piece.h @@ -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 film) const; dcpomatic::ContentTime dcp_to_content_time (dcpomatic::DCPTime t, std::shared_ptr film) const; - dcpomatic::DCPTime content_time_to_dcp (dcpomatic::ContentTime t) const; + boost::optional content_time_to_dcp (std::shared_ptr content, dcpomatic::ContentTime t) const; void pass (); diff --git a/src/lib/player.cc b/src/lib/player.cc index 086cfbbbd..e99eb9dae 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -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), weak_ptr((*j)->content()), _1) + bind(&Player::bitmap_text_start, this, weak_ptr(piece), i, weak_ptr((*j)->content()), _1) ); (*j)->PlainStart.connect ( - bind(&Player::plain_text_start, this, weak_ptr(piece), weak_ptr((*j)->content()), _1) + bind(&Player::plain_text_start, this, weak_ptr(piece), i, weak_ptr((*j)->content()), _1) ); (*j)->Stop.connect ( - bind(&Player::subtitle_stop, this, weak_ptr(piece), weak_ptr((*j)->content()), _1) + bind(&Player::subtitle_stop, this, weak_ptr(piece), i, weak_ptr((*j)->content()), _1) ); ++j; @@ -281,6 +281,23 @@ Player::setup_pieces_unlocked () } +optional +Player::content_time_to_dcp (shared_ptr 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 wp, AudioStreamPtr stream, ContentAudio content_a void -Player::bitmap_text_start (weak_ptr wp, weak_ptr wc, ContentBitmapText subtitle) +Player::bitmap_text_start (weak_ptr wp, weak_ptr wc, weak_ptr 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 wp, weak_ptr 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(text->type())].add_from (wc, ps, from); + _active_texts[static_cast(text->type())].add_from (wt, ps, *from); } void -Player::plain_text_start (weak_ptr wp, weak_ptr wc, ContentStringText subtitle) +Player::plain_text_start (weak_ptr wp, weak_ptr wc, weak_ptr 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 wp, weak_ptr 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(text->type())].add_from (wc, ps, from); + _active_texts[static_cast(text->type())].add_from (wt, ps, *from); } void -Player::subtitle_stop (weak_ptr wp, weak_ptr wc, ContentTime to) +Player::subtitle_stop (weak_ptr wp, weak_ptr wc, weak_ptr wt, ContentTime to) { - auto text = wc.lock (); + auto content = wc.lock (); + auto text = wt.lock (); if (!text) { return; } - if (!_active_texts[static_cast(text->type())].have(wc)) { + if (!_active_texts[static_cast(text->type())].have(wt)) { return; } @@ -1025,17 +1047,18 @@ Player::subtitle_stop (weak_ptr wp, weak_ptr 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(text->type())].add_to (wc, dcp_to); + auto from = _active_texts[static_cast(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 reduction) } -optional -Player::content_time_to_dcp (shared_ptr 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 Player::playlist () const { diff --git a/src/lib/player.h b/src/lib/player.h index 229dac91b..9086c4813 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -135,9 +135,9 @@ private: void video (std::weak_ptr, ContentVideo); void audio (std::weak_ptr, AudioStreamPtr, ContentAudio); - void bitmap_text_start (std::weak_ptr, std::weak_ptr, ContentBitmapText); - void plain_text_start (std::weak_ptr, std::weak_ptr, ContentStringText); - void subtitle_stop (std::weak_ptr, std::weak_ptr, dcpomatic::ContentTime); + void bitmap_text_start (std::weak_ptr, std::weak_ptr, std::weak_ptr, ContentBitmapText); + void plain_text_start (std::weak_ptr, std::weak_ptr, std::weak_ptr, ContentStringText); + void subtitle_stop (std::weak_ptr, std::weak_ptr, std::weak_ptr, dcpomatic::ContentTime); void atmos (std::weak_ptr, 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 _suspended; - std::list > _pieces; + std::list> _pieces; /** Size of the image we are rendering to; this may be the DCP frame size, or * the size of preview in a window.