Add -x32/-x64 suffix to boost libraries when building for Windows.
[dcpomatic.git] / test / overlap_video_test.cc
1 /*
2     Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 #include "lib/content.h"
23 #include "lib/content_factory.h"
24 #include "lib/dcpomatic_time.h"
25 #include "lib/film.h"
26 #include "lib/player.h"
27 #include "lib/video_content.h"
28 #include "test.h"
29 #include <dcp/cpl.h>
30 #include <dcp/dcp.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>
35 #include <dcp/reel.h>
36 #include <dcp/reel_mono_picture_asset.h>
37 #include <boost/shared_ptr.hpp>
38 #include <boost/test/unit_test.hpp>
39
40
41 using std::dynamic_pointer_cast;
42 using std::make_shared;
43
44
45 BOOST_AUTO_TEST_CASE (overlap_video_test1)
46 {
47         auto film = new_test_film2 ("overlap_video_test1");
48         film->set_sequence (false);
49         auto A = content_factory("test/data/flat_red.png").front();
50         film->examine_and_add_content (A);
51         auto B = content_factory("test/data/flat_green.png").front();
52         film->examine_and_add_content (B);
53         BOOST_REQUIRE (!wait_for_jobs());
54
55         A->video->set_length (72);
56         B->video->set_length (24);
57         B->set_position (film, dcpomatic::DCPTime::from_seconds(1));
58
59         auto player = make_shared<Player>(film, Image::Alignment::COMPACT);
60         auto pieces = player->_pieces;
61         BOOST_REQUIRE_EQUAL (pieces.size(), 2U);
62         BOOST_CHECK_EQUAL (pieces.front()->content, A);
63         BOOST_CHECK_EQUAL (pieces.back()->content, B);
64         BOOST_CHECK (pieces.front()->ignore_video);
65         BOOST_CHECK (pieces.front()->ignore_video.get() == dcpomatic::DCPTimePeriod(dcpomatic::DCPTime::from_seconds(1), dcpomatic::DCPTime::from_seconds(1) + B->length_after_trim(film)));
66
67         BOOST_CHECK (player->_black.done());
68
69         make_and_verify_dcp (film);
70
71         dcp::DCP back (film->dir(film->dcp_name()));
72         back.read ();
73         BOOST_REQUIRE_EQUAL (back.cpls().size(), 1U);
74         auto cpl = back.cpls()[0];
75         BOOST_REQUIRE_EQUAL (cpl->reels().size(), 1U);
76         auto reel = cpl->reels()[0];
77         BOOST_REQUIRE (reel->main_picture());
78         auto mono_picture = dynamic_pointer_cast<dcp::ReelMonoPictureAsset>(reel->main_picture());
79         BOOST_REQUIRE (mono_picture);
80         auto asset = mono_picture->mono_asset();
81         BOOST_REQUIRE (asset);
82         BOOST_CHECK_EQUAL (asset->intrinsic_duration(), 72);
83         auto reader = asset->start_read ();
84
85         auto close = [](int a, int b, int d) {
86                 BOOST_CHECK (std::abs(a - b) < d);
87         };
88
89         for (int i = 0; i < 24; ++i) {
90                 auto frame = reader->get_frame (i);
91                 auto image = dcp::decompress_j2k(*frame.get(), 0);
92                 close (image->data(0)[0], 2808, 2);
93                 close (image->data(1)[0], 2176, 2);
94                 close (image->data(2)[0], 865, 2);
95         }
96
97         for (int i = 24; i < 48; ++i) {
98                 auto frame = reader->get_frame (i);
99                 auto image = dcp::decompress_j2k(*frame.get(), 0);
100                 close (image->data(0)[0], 2657, 2);
101                 close (image->data(1)[0], 3470, 2);
102                 close (image->data(2)[0], 1742, 2);
103         }
104
105         for (int i = 48; i < 72; ++i) {
106                 auto frame = reader->get_frame (i);
107                 auto image = dcp::decompress_j2k(*frame.get(), 0);
108                 close (image->data(0)[0], 2808, 2);
109                 close (image->data(1)[0], 2176, 2);
110                 close (image->data(2)[0], 865, 2);
111         }
112 }
113