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)
/* 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;
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;
}
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);
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;
+}
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;
using std::list;
using boost::shared_ptr;
+static bool
+valid (Content const *)
+{
+ return true;
+}
+
/** Player::overlaps */
BOOST_AUTO_TEST_CASE (player_overlaps_test)
{
shared_ptr<Player> player (new Player (film, film->playlist ()));
- list<shared_ptr<Piece> > o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (0), DCPTime::from_seconds (5));
+ list<shared_ptr<Piece> > o = player->overlaps (DCPTime::from_seconds (0), DCPTime::from_seconds (5), &valid);
BOOST_CHECK_EQUAL (o.size(), 1U);
BOOST_CHECK_EQUAL (o.front()->content, A);
- o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (5), DCPTime::from_seconds (8));
+ o = player->overlaps (DCPTime::from_seconds (5), DCPTime::from_seconds (8), &valid);
BOOST_CHECK_EQUAL (o.size(), 0U);
- o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (8), DCPTime::from_seconds (12));
+ o = player->overlaps (DCPTime::from_seconds (8), DCPTime::from_seconds (12), &valid);
BOOST_CHECK_EQUAL (o.size(), 1U);
BOOST_CHECK_EQUAL (o.front()->content, B);
- o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (2), DCPTime::from_seconds (12));
+ o = player->overlaps (DCPTime::from_seconds (2), DCPTime::from_seconds (12), &valid);
BOOST_CHECK_EQUAL (o.size(), 2U);
BOOST_CHECK_EQUAL (o.front()->content, A);
BOOST_CHECK_EQUAL (o.back()->content, B);
- o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (8), DCPTime::from_seconds (11));
+ o = player->overlaps (DCPTime::from_seconds (8), DCPTime::from_seconds (11), &valid);
BOOST_CHECK_EQUAL (o.size(), 1U);
BOOST_CHECK_EQUAL (o.front()->content, B);
}