summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-04-26 01:30:10 +0200
committerCarl Hetherington <cth@carlh.net>2021-05-07 09:29:59 +0200
commit904edab223a0bc3b5cf2db1c9eb45623106dc9d9 (patch)
treedf6c595c057176c4162d45d22994d787fe48e918 /src/lib
parent0f54120b78e872ef2a41b716fd25bbedb63d16db (diff)
Put a weak_ptr<Film> into Piece to tidy up calls a lot.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/piece.cc46
-rw-r--r--src/lib/piece.h19
-rw-r--r--src/lib/player.cc32
3 files changed, 57 insertions, 40 deletions
diff --git a/src/lib/piece.cc b/src/lib/piece.cc
index 0dbb7173c..977695824 100644
--- a/src/lib/piece.cc
+++ b/src/lib/piece.cc
@@ -34,12 +34,14 @@ using std::dynamic_pointer_cast;
using std::make_shared;
using std::shared_ptr;
using std::vector;
+using std::weak_ptr;
using boost::optional;
using namespace dcpomatic;
-Piece::Piece (shared_ptr<Content> c, shared_ptr<Decoder> d, FrameRateChange f)
- : _content (c)
+Piece::Piece (weak_ptr<const Film> film, shared_ptr<Content> c, shared_ptr<Decoder> d, FrameRateChange f)
+ : _film (film)
+ , _content (c)
, _decoder (d)
, _frc (f)
{
@@ -83,8 +85,11 @@ Piece::content_video_to_dcp (Frame f) const
DCPTime
-Piece::resampled_audio_to_dcp (Frame f, shared_ptr<const Film> film) const
+Piece::resampled_audio_to_dcp (Frame f) const
{
+ auto film = _film.lock ();
+ DCPOMATIC_ASSERT (film);
+
/* It might seem more logical here to convert s to a ContentTime (using the FrameRateChange)
then convert that ContentTime to frames at the content's rate. However this fails for
situations like content at 29.9978733fps, DCP at 30fps. The accuracy of the Time type is not
@@ -99,8 +104,11 @@ Piece::resampled_audio_to_dcp (Frame f, shared_ptr<const Film> film) const
ContentTime
-Piece::dcp_to_content_time (DCPTime t, shared_ptr<const Film> film) const
+Piece::dcp_to_content_time (DCPTime t) const
{
+ auto film = _film.lock ();
+ DCPOMATIC_ASSERT (film);
+
auto s = t - _content->position ();
s = min (_content->length_after_trim(film), s);
return max (ContentTime(), ContentTime(s, _frc) + _content->trim_start());
@@ -141,15 +149,20 @@ Piece::position () const
dcpomatic::DCPTime
-Piece::end (shared_ptr<const Film> film) const
+Piece::end () const
{
+ auto film = _film.lock ();
+ DCPOMATIC_ASSERT (film);
return _content->end (film);
}
shared_ptr<PlayerVideo>
-Piece::player_video (ContentVideo video, shared_ptr<const Film> film, dcp::Size container_size) const
+Piece::player_video (ContentVideo video, dcp::Size container_size) const
{
+ auto film = _film.lock ();
+ DCPOMATIC_ASSERT (film);
+
return std::make_shared<PlayerVideo>(
video.image,
_content->video->crop (),
@@ -168,8 +181,11 @@ Piece::player_video (ContentVideo video, shared_ptr<const Film> film, dcp::Size
int
-Piece::resampled_audio_frame_rate (shared_ptr<const Film> film) const
+Piece::resampled_audio_frame_rate () const
{
+ auto film = _film.lock ();
+ DCPOMATIC_ASSERT (film);
+
DCPOMATIC_ASSERT (_content->audio);
return _content->audio->resampled_frame_rate (film);
}
@@ -211,7 +227,7 @@ Piece::reference_dcp_audio () const
void
-Piece::seek (shared_ptr<const Film> film, DCPTime time, bool accurate)
+Piece::seek (DCPTime time, bool accurate)
{
if (time < position()) {
/* Before; seek to the start of the content. Even if this request is for an inaccurate seek
@@ -219,11 +235,11 @@ Piece::seek (shared_ptr<const Film> film, DCPTime time, bool accurate)
content we may not start right at the beginning of the next, causing a gap (if the next content has
been trimmed to a point between keyframes, or something).
*/
- _decoder->seek (dcp_to_content_time(position(), film), true);
+ _decoder->seek (dcp_to_content_time(position()), true);
_done = false;
- } else if (position() <= time && time < end(film)) {
+ } else if (position() <= time && time < end()) {
/* During; seek to position */
- _decoder->seek (dcp_to_content_time(time, film), accurate);
+ _decoder->seek (dcp_to_content_time(time), accurate);
_done = false;
} else {
/* After; this piece is done */
@@ -233,7 +249,7 @@ Piece::seek (shared_ptr<const Film> film, DCPTime time, bool accurate)
optional<dcpomatic::DCPTime>
-Piece::decoder_before(shared_ptr<const Film> film, optional<dcpomatic::DCPTime> time)
+Piece::decoder_before(optional<dcpomatic::DCPTime> time)
{
if (_done) {
return {};
@@ -242,7 +258,7 @@ Piece::decoder_before(shared_ptr<const Film> film, optional<dcpomatic::DCPTime>
auto t = content_time_to_dcp(_content, std::max(_decoder->position(), _content->trim_start()));
DCPOMATIC_ASSERT (t);
- if (*t > end(film)) {
+ if (*t > end()) {
_done = true;
} else {
/* Given two choices at the same time, pick the one with texts so we see it before
@@ -271,8 +287,8 @@ Piece::ignore_video_at (DCPTime time) const
DCPTimePeriod
-Piece::period (shared_ptr<const Film> film) const
+Piece::period () const
{
- return DCPTimePeriod(position(), end(film));
+ return DCPTimePeriod(position(), end());
}
diff --git a/src/lib/piece.h b/src/lib/piece.h
index f242ad6bf..493fa6ef8 100644
--- a/src/lib/piece.h
+++ b/src/lib/piece.h
@@ -41,14 +41,14 @@ struct check_reuse_old_data_test;
class Piece
{
public:
- Piece (std::shared_ptr<Content> c, std::shared_ptr<Decoder> d, FrameRateChange f);
+ Piece (std::weak_ptr<const Film> film, std::shared_ptr<Content> c, std::shared_ptr<Decoder> d, FrameRateChange f);
void update_pull_to (dcpomatic::DCPTime& pull_to) const;
void set_last_push_end (AudioStreamPtr stream, dcpomatic::DCPTime last_push_end);
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 resampled_audio_to_dcp (Frame f) const;
+ dcpomatic::ContentTime dcp_to_content_time (dcpomatic::DCPTime t) const;
boost::optional<dcpomatic::DCPTime> content_time_to_dcp (std::shared_ptr<const Content> content, dcpomatic::ContentTime t) const;
void pass ();
@@ -61,19 +61,19 @@ public:
}
dcpomatic::DCPTime position () const;
- dcpomatic::DCPTime end (std::shared_ptr<const Film> film) const;
- dcpomatic::DCPTimePeriod period (std::shared_ptr<const Film> film) const;
+ dcpomatic::DCPTime end () const;
+ dcpomatic::DCPTimePeriod period () const;
- std::shared_ptr<PlayerVideo> player_video (ContentVideo video, std::shared_ptr<const Film> film, dcp::Size container_size) const;
+ std::shared_ptr<PlayerVideo> player_video (ContentVideo video, dcp::Size container_size) const;
- int resampled_audio_frame_rate (std::shared_ptr<const Film> film) const;
+ int resampled_audio_frame_rate () const;
double audio_gain () const;
bool reference_dcp_audio () const;
std::shared_ptr<Decoder> decoder_for (std::shared_ptr<Content> content) const;
- void seek (std::shared_ptr<const Film> film, dcpomatic::DCPTime time, bool accurate);
- boost::optional<dcpomatic::DCPTime> decoder_before(std::shared_ptr<const Film> film, boost::optional<dcpomatic::DCPTime> time);
+ void seek (dcpomatic::DCPTime time, bool accurate);
+ boost::optional<dcpomatic::DCPTime> decoder_before(boost::optional<dcpomatic::DCPTime> time);
std::vector<dcpomatic::FontData> fonts () const;
void set_ignore_video (boost::optional<dcpomatic::DCPTimePeriod> period) {
@@ -86,6 +86,7 @@ private:
friend struct overlap_video_test1;
friend struct check_reuse_old_data_test;
+ std::weak_ptr<const Film> _film;
std::shared_ptr<Content> _content;
std::shared_ptr<Decoder> _decoder;
FrameRateChange _frc;
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 934821449..c6d1e54de 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -221,7 +221,7 @@ Player::setup_pieces_unlocked ()
}
}
- auto piece = make_shared<Piece>(i, decoder, frc);
+ auto piece = make_shared<Piece>(_film, i, decoder, frc);
_pieces.push_back (piece);
if (decoder->video) {
@@ -263,7 +263,7 @@ Player::setup_pieces_unlocked ()
/* Look for content later in the content list with in-use video that overlaps this */
for (auto j = std::next(i); j != _pieces.end(); ++j) {
if ((*j)->use_video()) {
- (*i)->set_ignore_video ((*j)->period(_film).overlap((*i)->period(_film)));
+ (*i)->set_ignore_video ((*j)->period().overlap((*i)->period()));
}
}
}
@@ -595,7 +595,7 @@ Player::pass ()
optional<DCPTime> earliest_time;
for (auto i: _pieces) {
- auto time = i->decoder_before(_film, earliest_time);
+ auto time = i->decoder_before(earliest_time);
if (time) {
earliest_time = *time;
earliest_content = i;
@@ -634,7 +634,7 @@ Player::pass ()
to `hide' the fact that no audio was emitted during the referenced DCP (though
we need to behave as though it was).
*/
- _last_audio_time = earliest_content->end (_film);
+ _last_audio_time = earliest_content->end ();
}
break;
}
@@ -799,7 +799,7 @@ Player::video (weak_ptr<Piece> wp, ContentVideo video)
/* Fill gaps that we discover now that we have some video which needs to be emitted.
This is where we need to fill to.
*/
- DCPTime fill_to = min (time, piece->end(_film));
+ DCPTime fill_to = min (time, piece->end());
if (_last_video_time) {
DCPTime fill_from = max (*_last_video_time, piece->position());
@@ -812,7 +812,7 @@ Player::video (weak_ptr<Piece> wp, ContentVideo video)
if (fill_to_eyes == Eyes::BOTH) {
fill_to_eyes = Eyes::LEFT;
}
- if (fill_to == piece->end(_film)) {
+ if (fill_to == piece->end()) {
/* Don't fill after the end of the content */
fill_to_eyes = Eyes::LEFT;
}
@@ -848,11 +848,11 @@ Player::video (weak_ptr<Piece> wp, ContentVideo video)
}
}
- _last_video[wp] = piece->player_video (video, _film, _video_container_size);
+ _last_video[wp] = piece->player_video (video, _video_container_size);
DCPTime t = time;
for (int i = 0; i < frc.repeat; ++i) {
- if (t < piece->end(_film)) {
+ if (t < piece->end()) {
emit_video (_last_video[wp], t);
}
t += one_video_frame ();
@@ -870,10 +870,10 @@ Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_a
return;
}
- int const rfr = piece->resampled_audio_frame_rate (_film);
+ int const rfr = piece->resampled_audio_frame_rate ();
/* Compute time in the DCP */
- auto time = piece->resampled_audio_to_dcp (content_audio.frame, _film);
+ auto time = piece->resampled_audio_to_dcp (content_audio.frame);
LOG_DEBUG_PLAYER("Received audio frame %1 at %2", content_audio.frame, to_string(time));
/* And the end of this block in the DCP */
@@ -888,11 +888,11 @@ Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_a
}
content_audio.audio = cut.first;
time = cut.second;
- } else if (time > piece->end(_film)) {
+ } else if (time > piece->end()) {
/* Discard it all */
return;
- } else if (end > piece->end(_film)) {
- Frame const remaining_frames = DCPTime(piece->end(_film) - time).frames_round(rfr);
+ } else if (end > piece->end()) {
+ Frame const remaining_frames = DCPTime(piece->end() - time).frames_round(rfr);
if (remaining_frames == 0) {
return;
}
@@ -981,7 +981,7 @@ Player::plain_text_start (weak_ptr<Piece> wp, weak_ptr<const Content> wc, weak_p
auto const from = piece->content_time_to_dcp(content, subtitle.from());
DCPOMATIC_ASSERT (from);
- if (from > piece->end(_film)) {
+ if (from > piece->end()) {
return;
}
@@ -1035,7 +1035,7 @@ Player::subtitle_stop (weak_ptr<Piece> wp, weak_ptr<const Content> wc, weak_ptr<
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()) {
return;
}
@@ -1075,7 +1075,7 @@ Player::seek (DCPTime time, bool accurate)
}
for (auto i: _pieces) {
- i->seek (_film, time, accurate);
+ i->seek (time, accurate);
}
if (accurate) {