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/player.h"
27 #include "lib/video_content.h"
31 #include <dcp/j2k_transcode.h>
32 #include <dcp/mono_picture_asset.h>
33 #include <dcp/mono_picture_frame.h>
34 #include <dcp/openjpeg_image.h>
36 #include <dcp/reel_mono_picture_asset.h>
37 #include <boost/shared_ptr.hpp>
38 #include <boost/test/unit_test.hpp>
41 using std::dynamic_pointer_cast;
42 using std::make_shared;
43 using std::shared_ptr;
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").front();
51 film->examine_and_add_content (A);
52 auto B = content_factory("test/data/flat_green.png").front();
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);
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());
71 BOOST_REQUIRE (!wait_for_jobs());
73 dcp::DCP back (film->dir(film->dcp_name()));
75 BOOST_REQUIRE_EQUAL (back.cpls().size(), 1U);
76 auto cpl = back.cpls()[0];
77 BOOST_REQUIRE_EQUAL (cpl->reels().size(), 1U);
78 auto reel = cpl->reels()[0];
79 BOOST_REQUIRE (reel->main_picture());
80 auto mono_picture = dynamic_pointer_cast<dcp::ReelMonoPictureAsset>(reel->main_picture());
81 BOOST_REQUIRE (mono_picture);
82 auto asset = mono_picture->mono_asset();
83 BOOST_REQUIRE (asset);
84 BOOST_CHECK_EQUAL (asset->intrinsic_duration(), 72);
85 auto reader = asset->start_read ();
87 for (int i = 0; i < 24; ++i) {
88 auto frame = reader->get_frame (i);
89 auto image = dcp::decompress_j2k(*frame.get(), 0);
90 BOOST_CHECK_EQUAL (image->data(0)[0], 2808);
91 BOOST_CHECK_EQUAL (image->data(1)[0], 2176);
92 BOOST_CHECK_EQUAL (image->data(2)[0], 865);
95 for (int i = 24; i < 48; ++i) {
96 auto frame = reader->get_frame (i);
97 auto image = dcp::decompress_j2k(*frame.get(), 0);
98 BOOST_CHECK_EQUAL (image->data(0)[0], 2657);
99 BOOST_CHECK_EQUAL (image->data(1)[0], 3470);
100 BOOST_CHECK_EQUAL (image->data(2)[0], 1742);
103 for (int i = 48; i < 72; ++i) {
104 auto frame = reader->get_frame (i);
105 auto image = dcp::decompress_j2k(*frame.get(), 0);
106 BOOST_CHECK_EQUAL (image->data(0)[0], 2808);
107 BOOST_CHECK_EQUAL (image->data(1)[0], 2176);
108 BOOST_CHECK_EQUAL (image->data(2)[0], 865);