2 Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "lib/content.h"
23 #include "lib/content_factory.h"
24 #include "lib/dcpomatic_time.h"
26 #include "lib/piece.h"
27 #include "lib/player.h"
28 #include "lib/video_content.h"
32 #include <dcp/j2k_transcode.h>
33 #include <dcp/mono_picture_asset.h>
34 #include <dcp/mono_picture_frame.h>
35 #include <dcp/openjpeg_image.h>
37 #include <dcp/reel_mono_picture_asset.h>
38 #include <boost/shared_ptr.hpp>
39 #include <boost/test/unit_test.hpp>
42 using std::dynamic_pointer_cast;
43 using std::make_shared;
46 BOOST_AUTO_TEST_CASE (overlap_video_test1)
48 auto film = new_test_film2 ("overlap_video_test1");
49 film->set_sequence (false);
50 auto A = content_factory("test/data/flat_red.png")[0];
51 film->examine_and_add_content (A);
52 auto B = content_factory("test/data/flat_green.png")[0];
53 film->examine_and_add_content (B);
54 BOOST_REQUIRE (!wait_for_jobs());
56 A->video->set_length (72);
57 B->video->set_length (24);
58 B->set_position (film, dcpomatic::DCPTime::from_seconds(1));
60 auto player = make_shared<Player>(film, Image::Alignment::COMPACT);
61 auto pieces = player->_pieces;
62 BOOST_REQUIRE_EQUAL (pieces.size(), 2U);
63 BOOST_CHECK_EQUAL (pieces.front()->content, A);
64 BOOST_CHECK_EQUAL (pieces.back()->content, B);
65 BOOST_CHECK (pieces.front()->ignore_video);
66 BOOST_CHECK (pieces.front()->ignore_video.get() == dcpomatic::DCPTimePeriod(dcpomatic::DCPTime::from_seconds(1), dcpomatic::DCPTime::from_seconds(1) + B->length_after_trim(film)));
68 BOOST_CHECK (player->_black.done());
70 make_and_verify_dcp (film);
72 dcp::DCP back (film->dir(film->dcp_name()));
74 BOOST_REQUIRE_EQUAL (back.cpls().size(), 1U);
75 auto cpl = back.cpls()[0];
76 BOOST_REQUIRE_EQUAL (cpl->reels().size(), 1U);
77 auto reel = cpl->reels()[0];
78 BOOST_REQUIRE (reel->main_picture());
79 auto mono_picture = dynamic_pointer_cast<dcp::ReelMonoPictureAsset>(reel->main_picture());
80 BOOST_REQUIRE (mono_picture);
81 auto asset = mono_picture->mono_asset();
82 BOOST_REQUIRE (asset);
83 BOOST_CHECK_EQUAL (asset->intrinsic_duration(), 72);
84 auto reader = asset->start_read ();
86 auto close = [](int a, int b, int d) {
87 BOOST_CHECK (std::abs(a - b) < d);
90 for (int i = 0; i < 24; ++i) {
91 auto frame = reader->get_frame (i);
92 auto image = dcp::decompress_j2k(*frame.get(), 0);
93 close (image->data(0)[0], 2808, 2);
94 close (image->data(1)[0], 2176, 2);
95 close (image->data(2)[0], 865, 2);
98 for (int i = 24; i < 48; ++i) {
99 auto frame = reader->get_frame (i);
100 auto image = dcp::decompress_j2k(*frame.get(), 0);
101 close (image->data(0)[0], 2657, 2);
102 close (image->data(1)[0], 3470, 2);
103 close (image->data(2)[0], 1742, 2);
106 for (int i = 48; i < 72; ++i) {
107 auto frame = reader->get_frame (i);
108 auto image = dcp::decompress_j2k(*frame.get(), 0);
109 close (image->data(0)[0], 2808, 2);
110 close (image->data(1)[0], 2176, 2);
111 close (image->data(2)[0], 865, 2);