using std::dynamic_pointer_cast;
using std::function;
using std::list;
+using std::make_pair;
+using std::pair;
using std::shared_ptr;
using namespace dcpomatic;
EmptyVideo::EmptyVideo (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist, DCPTime length)
{
- list<DCPTimePeriod> full;
+ list<DCPTimePeriod> full_left;
+ list<DCPTimePeriod> full_right;
+ list<DCPTimePeriod> full_both;
for (auto i: playlist->content()) {
if (i->video && i->video->use() && i->can_be_played() && i->paths_valid()) {
- full.push_back (DCPTimePeriod(i->position(), i->end(film)));
+ auto period = DCPTimePeriod(i->position(), i->end(film));
+ if (i->video->frame_type() == VideoFrameType::THREE_D_LEFT) {
+ full_left.push_back (period);
+ } else if (i->video->frame_type() == VideoFrameType::THREE_D_RIGHT) {
+ full_right.push_back (period);
+ } else {
+ full_both.push_back (period);
+ }
}
}
- _periods = subtract (DCPTimePeriod(DCPTime(), length), coalesce(full));
+ auto const whole = DCPTimePeriod(DCPTime(), length);
+
+ auto empty_both = subtract(subtract(subtract({whole}, full_left), full_right), full_both);
+ auto empty_left = subtract(subtract(subtract({whole}, full_left), full_both), empty_both);
+ auto empty_right = subtract(subtract(subtract({whole}, full_right), full_both), empty_both);
+
+ for (auto left: empty_left) {
+ _periods.push_back (make_pair(left, Eyes::LEFT));
+ }
+
+ for (auto right: empty_right) {
+ _periods.push_back (make_pair(right, Eyes::RIGHT));
+ }
+
+ for (auto both: empty_both) {
+ _periods.push_back (make_pair(both, Eyes::BOTH));
+ }
+
+ _periods.sort([](std::pair<DCPTimePeriod, Eyes> const& a, std::pair<DCPTimePeriod, Eyes> const& b) {
+ return a.first < b.first;
+ });
if (!_periods.empty()) {
- _position = _periods.front().from;
+ _position = _periods.front().first.from;
}
}
_position = position;
for (auto i: _periods) {
- if (i.contains(_position)) {
+ if (i.first.contains(_position)) {
return;
}
}
for (auto i: _periods) {
- if (i.from > _position) {
- _position = i.from;
+ if (i.first.from > _position) {
+ _position = i.first.from;
return;
}
}
}
-DCPTimePeriod
+pair<DCPTimePeriod, Eyes>
EmptyVideo::period_at_position () const
{
for (auto i: _periods) {
- if (i.contains(_position)) {
- return DCPTimePeriod (_position, i.to);
+ if (i.first.contains(_position)) {
+ return make_pair(DCPTimePeriod(_position, i.first.to), i.second);
}
}
{
DCPTime latest;
for (auto i: _periods) {
- latest = max (latest, i.to);
+ latest = max (latest, i.first.to);
}
return _position >= latest;
EmptyVideo black (film, film->playlist(), film->playlist()->length(film));
BOOST_REQUIRE_EQUAL (black._periods.size(), 2U);
auto i = black._periods.begin();
- BOOST_CHECK (i->from == DCPTime::from_frames(0, vfr));
- BOOST_CHECK (i->to == DCPTime::from_frames(2, vfr));
+ BOOST_CHECK (i->first.from == DCPTime::from_frames(0, vfr));
+ BOOST_CHECK (i->first.to == DCPTime::from_frames(2, vfr));
++i;
- BOOST_CHECK (i->from == DCPTime::from_frames(5, vfr));
- BOOST_CHECK (i->to == DCPTime::from_frames(7, vfr));
+ BOOST_CHECK (i->first.from == DCPTime::from_frames(5, vfr));
+ BOOST_CHECK (i->first.to == DCPTime::from_frames(7, vfr));
}
EmptyVideo black (film, film->playlist(), film->playlist()->length(film));
BOOST_REQUIRE_EQUAL (black._periods.size(), 1U);
- BOOST_CHECK (black._periods.front().from == DCPTime::from_frames(3, vfr));
- BOOST_CHECK (black._periods.front().to == DCPTime::from_frames(7, vfr));
+ BOOST_CHECK (black._periods.front().first.from == DCPTime::from_frames(3, vfr));
+ BOOST_CHECK (black._periods.front().first.to == DCPTime::from_frames(7, vfr));
/* position should initially be the start of the first empty period */
BOOST_CHECK (black.position() == DCPTime::from_frames(3, vfr));
playlist->add (film, contentB);
EmptyVideo black (film, playlist, playlist->length(film));
BOOST_REQUIRE_EQUAL (black._periods.size(), 1U);
- BOOST_CHECK (black._periods.front().from == DCPTime::from_frames(0, vfr));
- BOOST_CHECK (black._periods.front().to == DCPTime::from_frames(7, vfr));
+ BOOST_CHECK (black._periods.front().first.from == DCPTime::from_frames(0, vfr));
+ BOOST_CHECK (black._periods.front().first.to == DCPTime::from_frames(7, vfr));
/* position should initially be the start of the first empty period */
BOOST_CHECK (black.position() == DCPTime::from_frames(0, vfr));
BOOST_REQUIRE (silent._periods.empty());
}
+
+BOOST_AUTO_TEST_CASE (empty_video_test_with_three_d1)
+{
+ auto film = new_test_film2 ("empty_video_test_with_three_d1");
+ film->set_sequence (false);
+
+ auto both1 = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
+ auto left = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
+ auto right = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
+ auto both2 = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
+
+ film->examine_and_add_content (both1);
+ film->examine_and_add_content (left);
+ film->examine_and_add_content (right);
+ film->examine_and_add_content (both2);
+ BOOST_REQUIRE (!wait_for_jobs());
+
+ int const vfr = film->video_frame_rate ();
+
+ both1->video->set_length (vfr * 1);
+ both1->set_position (film, DCPTime(0));
+
+ left->video->set_length (vfr * 2);
+ left->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
+ left->set_position (film, DCPTime::from_seconds(2));
+
+ right->video->set_length (vfr * 2);
+ right->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
+ right->set_position (film, DCPTime::from_seconds(3));
+
+ both2->video->set_length (vfr * 1);
+ both2->set_position (film, DCPTime::from_seconds(6));
+
+ EmptyVideo black(film, film->playlist(), film->playlist()->length(film));
+
+ for (auto i: black._periods) {
+ std::cout << to_string(i.first.from) << " " << to_string(i.first.to) << " " << static_cast<int>(i.second) << "\n";
+ }
+ BOOST_REQUIRE_EQUAL (black._periods.size(), 4U);
+ auto i = black._periods.begin();
+ BOOST_CHECK (i->first.from == DCPTime::from_seconds(1));
+ BOOST_CHECK (i->first.to == DCPTime::from_seconds(2));
+ BOOST_CHECK (i->second == Eyes::BOTH);
+ ++i;
+ BOOST_CHECK (i->first.from == DCPTime::from_seconds(2));
+ BOOST_CHECK (i->first.to == DCPTime::from_seconds(3));
+ BOOST_CHECK (i->second == Eyes::RIGHT);
+ ++i;
+ BOOST_CHECK (i->first.from == DCPTime::from_seconds(4));
+ BOOST_CHECK (i->first.to == DCPTime::from_seconds(5));
+ BOOST_CHECK (i->second == Eyes::LEFT);
+ ++i;
+ BOOST_CHECK (i->first.from == DCPTime::from_seconds(5));
+ BOOST_CHECK (i->first.to == DCPTime::from_seconds(6));
+ BOOST_CHECK (i->second == Eyes::BOTH);
+}
+
+
+BOOST_AUTO_TEST_CASE (empty_video_test_with_three_d2)
+{
+ auto film = new_test_film2 ("empty_video_test_with_three_d2");
+ film->set_sequence (false);
+
+ auto both = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
+ auto right = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
+
+ film->examine_and_add_content (both);
+ film->examine_and_add_content (right);
+ BOOST_REQUIRE (!wait_for_jobs());
+
+ int const vfr = film->video_frame_rate ();
+
+ both->video->set_length (vfr * 1);
+ both->set_position (film, DCPTime(0));
+
+ right->video->set_length (vfr * 1);
+ right->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
+ right->set_position (film, DCPTime::from_seconds(0));
+
+ EmptyVideo black(film, film->playlist(), film->playlist()->length(film));
+ BOOST_REQUIRE (black._periods.empty());
+}
+