summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-04-24 22:47:48 +0200
committerCarl Hetherington <cth@carlh.net>2021-05-07 09:29:59 +0200
commite7924e68c2f213448cdd920dba3bf91a1e019626 (patch)
treea2d315f7a273d5fe2b3f044b446a713109817378
parent4a144b7f777146ff666057caf895ce4fe1c3c2bb (diff)
Add content parameter to Piece::content_time_to_dcp().
-rw-r--r--src/lib/piece.cc13
-rw-r--r--src/lib/piece.h2
-rw-r--r--src/lib/player.cc81
-rw-r--r--src/lib/player.h8
4 files changed, 59 insertions, 45 deletions
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<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;
}
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<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 ();
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>(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
{
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<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.