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_j2k_picture_asset.h>
34 #include <dcp/mono_j2k_picture_frame.h>
35 #include <dcp/openjpeg_image.h>
37 #include <dcp/reel_mono_picture_asset.h>
38 #include <boost/test/unit_test.hpp>
41 using std::dynamic_pointer_cast;
42 using std::make_shared;
43 using std::shared_ptr;
47 BOOST_AUTO_TEST_CASE (overlap_video_test1)
49 auto A = content_factory("test/data/flat_red.png")[0];
50 auto B = content_factory("test/data/flat_green.png")[0];
51 auto C = content_factory("test/data/flat_blue.png")[0];
52 auto film = new_test_film2("overlap_video_test1", { A, B, C });
53 film->set_sequence (false);
62 A->video->set_length(5 * fps);
63 B->video->set_length(1 * fps);
64 C->video->set_length(1 * fps);
66 B->set_position(film, dcpomatic::DCPTime::from_seconds(1));
67 C->set_position(film, dcpomatic::DCPTime::from_seconds(3));
69 auto player = make_shared<Player>(film, Image::Alignment::COMPACT);
70 auto pieces = player->_pieces;
71 BOOST_REQUIRE_EQUAL (pieces.size(), 3U);
72 BOOST_CHECK_EQUAL(pieces[0]->content, A);
73 BOOST_CHECK_EQUAL(pieces[1]->content, B);
74 BOOST_CHECK_EQUAL(pieces[2]->content, C);
75 BOOST_CHECK_EQUAL(pieces[0]->ignore_video.size(), 2U);
76 BOOST_CHECK(pieces[0]->ignore_video[0] == dcpomatic::DCPTimePeriod(dcpomatic::DCPTime::from_seconds(1), dcpomatic::DCPTime::from_seconds(1) + B->length_after_trim(film)));
77 BOOST_CHECK(pieces[0]->ignore_video[1] == dcpomatic::DCPTimePeriod(dcpomatic::DCPTime::from_seconds(3), dcpomatic::DCPTime::from_seconds(3) + C->length_after_trim(film)));
79 BOOST_CHECK (player->_black.done());
81 make_and_verify_dcp (film);
83 dcp::DCP back (film->dir(film->dcp_name()));
85 BOOST_REQUIRE_EQUAL (back.cpls().size(), 1U);
86 auto cpl = back.cpls()[0];
87 BOOST_REQUIRE_EQUAL (cpl->reels().size(), 1U);
88 auto reel = cpl->reels()[0];
89 BOOST_REQUIRE (reel->main_picture());
90 auto mono_picture = dynamic_pointer_cast<dcp::ReelMonoPictureAsset>(reel->main_picture());
91 BOOST_REQUIRE (mono_picture);
92 auto asset = mono_picture->mono_j2k_asset();
93 BOOST_REQUIRE (asset);
94 BOOST_CHECK_EQUAL (asset->intrinsic_duration(), fps * 5);
95 auto reader = asset->start_read ();
97 auto close = [](shared_ptr<const dcp::OpenJPEGImage> image, vector<int> rgb) {
98 for (int component = 0; component < 3; ++component) {
99 BOOST_REQUIRE(std::abs(image->data(component)[0] - rgb[component]) < 2);
103 vector<int> const red = { 2808, 2176, 865 };
104 vector<int> const blue = { 2657, 3470, 1742 };
105 vector<int> const green = { 2044, 1437, 3871 };
107 for (int i = 0; i < 5 * fps; ++i) {
108 auto frame = reader->get_frame (i);
109 auto image = dcp::decompress_j2k(*frame.get(), 0);
112 } else if (i < 2 * fps) {
114 } else if (i < 3 * fps) {
116 } else if (i < 4 * fps) {
118 } else if (i < 5 * fps) {