Fix silent stereo mixdown exports when the project audio channel count is > 6.
[dcpomatic.git] / test / remake_video_test.cc
1 /*
2     Copyright (C) 2024 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_factory.h"
23 #include "lib/film.h"
24 #include "lib/video_content.h"
25 #include "test.h"
26 #include <dcp/colour_conversion.h>
27 #include <dcp/cpl.h>
28 #include <dcp/dcp.h>
29 #include <dcp/mono_picture_asset_reader.h>
30 #include <dcp/reel.h>
31 #include <dcp/reel_mono_picture_asset.h>
32 #include <boost/test/unit_test.hpp>
33
34
35 using std::dynamic_pointer_cast;
36 using std::shared_ptr;
37 using std::string;
38 using std::vector;
39
40
41 BOOST_AUTO_TEST_CASE(remake_video_after_yub_rgb_matrix_changed)
42 {
43         auto content = content_factory("test/data/rgb_grey_testcard.mp4")[0];
44         auto film = new_test_film2("remake_video_after_yub_rgb_matrix_changed", { content });
45
46         auto conversion = content->video->colour_conversion();
47         BOOST_REQUIRE(static_cast<bool>(conversion));
48         conversion->set_yuv_to_rgb(dcp::YUVToRGB::REC709);
49         content->video->set_colour_conversion(*conversion);
50
51         auto calculate_picture_hashes = [](shared_ptr<Film> film) {
52                 /* >1 CPLs in the DCP raises an error in ClairMeta */
53                 make_and_verify_dcp(film, {}, true, false);
54                 dcp::DCP dcp(film->dir(film->dcp_name()));
55                 dcp.read();
56                 BOOST_REQUIRE(!dcp.cpls().empty());
57                 auto cpl = dcp.cpls()[0];
58                 BOOST_REQUIRE(!cpl->reels().empty());
59                 auto reel = cpl->reels()[0];
60                 BOOST_REQUIRE(reel->main_picture());
61                 auto mono = dynamic_pointer_cast<dcp::MonoPictureAsset>(reel->main_picture()->asset());
62                 BOOST_REQUIRE(mono);
63                 auto reader = mono->start_read();
64
65                 vector<string> hashes;
66                 for (auto i = 0; i < reel->main_picture()->intrinsic_duration(); ++i) {
67                         auto frame = reader->get_frame(i);
68                         hashes.push_back(dcp::make_digest(dcp::ArrayData(frame->data(), frame->size())));
69                 }
70                 return hashes;
71         };
72
73         auto before = calculate_picture_hashes(film);
74         conversion->set_yuv_to_rgb(dcp::YUVToRGB::REC601);
75         content->video->set_colour_conversion(*conversion);
76         auto after = calculate_picture_hashes(film);
77
78         BOOST_CHECK(before != after);
79 }
80