diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-04-14 02:54:33 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-05-18 11:50:29 +0100 |
| commit | a4ad6395a27e8ccb25af3b05f815d318312ae1b7 (patch) | |
| tree | c2a8d4e8da5fe538cae5ca27aa9204a89412a5e3 /src/lib | |
| parent | a4c215fa859ed7826b3c12eadc2da75c93875f4f (diff) | |
Fix Player::overlaps for the new world order.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/player.cc | 44 | ||||
| -rw-r--r-- | src/lib/player.h | 24 |
2 files changed, 41 insertions, 27 deletions
diff --git a/src/lib/player.cc b/src/lib/player.cc index d37910ad8..617085a7b 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -77,6 +77,24 @@ using boost::dynamic_pointer_cast; using boost::optional; using boost::scoped_ptr; +static bool +has_video (Content* c) +{ + return c->video; +} + +static bool +has_audio (Content* c) +{ + return c->audio; +} + +static bool +has_subtitle (Content* c) +{ + return c->subtitle; +} + Player::Player (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist) : _film (film) , _playlist (playlist) @@ -384,9 +402,10 @@ Player::get_video (DCPTime time, bool accurate) /* Find pieces containing video which is happening now */ - list<shared_ptr<Piece> > ov = overlaps<VideoContent> ( + list<shared_ptr<Piece> > ov = overlaps ( time, - time + DCPTime::from_frames (1, _film->video_frame_rate ()) + time + DCPTime::from_frames (1, _film->video_frame_rate ()), + &has_video ); list<shared_ptr<PlayerVideo> > pvf; @@ -474,7 +493,7 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate) shared_ptr<AudioBuffers> audio (new AudioBuffers (_film->audio_channels(), length_frames)); audio->make_silent (); - list<shared_ptr<Piece> > ov = overlaps<AudioContent> (time, time + length); + list<shared_ptr<Piece> > ov = overlaps (time, time + length, has_audio); if (ov.empty ()) { return audio; } @@ -623,7 +642,7 @@ Player::content_subtitle_to_dcp (shared_ptr<const Piece> piece, ContentTime t) c PlayerSubtitles Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt, bool accurate) { - list<shared_ptr<Piece> > subs = overlaps<SubtitleContent> (time, time + length); + list<shared_ptr<Piece> > subs = overlaps (time, time + length, has_subtitle); PlayerSubtitles ps (time, length); @@ -807,3 +826,20 @@ Player::get_reel_assets () return a; } + +list<shared_ptr<Piece> > +Player::overlaps (DCPTime from, DCPTime to, boost::function<bool (Content *)> valid) +{ + if (!_have_valid_pieces) { + setup_pieces (); + } + + list<shared_ptr<Piece> > overlaps; + BOOST_FOREACH (shared_ptr<Piece> i, _pieces) { + if (valid (i->content.get ()) && i->content->position() < to && i->content->end() > from) { + overlaps.push_back (i); + } + } + + return overlaps; +} diff --git a/src/lib/player.h b/src/lib/player.h index bfb21abba..696c0c857 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -90,29 +90,7 @@ private: ContentTime dcp_to_content_subtitle (boost::shared_ptr<const Piece> piece, DCPTime t) const; DCPTime content_subtitle_to_dcp (boost::shared_ptr<const Piece> piece, ContentTime t) const; boost::shared_ptr<PlayerVideo> black_player_video_frame (DCPTime) const; - - /** @return Pieces of content type C that overlap a specified time range in the DCP */ - template<class C> - std::list<boost::shared_ptr<Piece> > - overlaps (DCPTime from, DCPTime to) - { - if (!_have_valid_pieces) { - setup_pieces (); - } - - std::list<boost::shared_ptr<Piece> > overlaps; - for (typename std::list<boost::shared_ptr<Piece> >::const_iterator i = _pieces.begin(); i != _pieces.end(); ++i) { - if (!boost::dynamic_pointer_cast<C> ((*i)->content)) { - continue; - } - - if ((*i)->content->position() < to && (*i)->content->end() > from) { - overlaps.push_back (*i); - } - } - - return overlaps; - } + std::list<boost::shared_ptr<Piece> > overlaps (DCPTime from, DCPTime to, boost::function<bool (Content *)> valid); boost::shared_ptr<const Film> _film; boost::shared_ptr<const Playlist> _playlist; |
