Always make 16-channel MXFs.
[dcpomatic.git] / test / ffmpeg_audio_test.cc
1 /*
2     Copyright (C) 2013-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 /** @file  test/ffmpeg_audio_test.cc
23  *  @brief Test reading audio from an FFmpeg file.
24  *  @ingroup feature
25  */
26
27
28 #include "lib/constants.h"
29 #include "lib/content_factory.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/ffmpeg_content.h"
32 #include "lib/ffmpeg_content.h"
33 #include "lib/film.h"
34 #include "lib/player.h"
35 #include "lib/ratio.h"
36 #include "lib/video_content.h"
37 #include "test.h"
38 #include <dcp/cpl.h>
39 #include <dcp/dcp.h>
40 #include <dcp/sound_asset.h>
41 #include <dcp/sound_frame.h>
42 #include <dcp/reel_sound_asset.h>
43 #include <dcp/sound_asset_reader.h>
44 #include <dcp/reel.h>
45 #include <boost/test/unit_test.hpp>
46
47
48 using std::make_shared;
49 using std::string;
50
51
52 BOOST_AUTO_TEST_CASE (ffmpeg_audio_test)
53 {
54         auto film = new_test_film ("ffmpeg_audio_test");
55         film->set_name ("ffmpeg_audio_test");
56         auto c = make_shared<FFmpegContent> ("test/data/staircase.mov");
57         film->examine_and_add_content (c);
58
59         BOOST_REQUIRE (!wait_for_jobs());
60
61         film->set_container (Ratio::from_id ("185"));
62         film->set_audio_channels (6);
63         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
64         make_and_verify_dcp (film);
65
66         boost::filesystem::path path = "build/test";
67         path /= "ffmpeg_audio_test";
68         path /= film->dcp_name ();
69         dcp::DCP check (path.string ());
70         check.read ();
71
72         auto sound_asset = check.cpls().front()->reels().front()->main_sound ();
73         BOOST_CHECK (sound_asset);
74         BOOST_CHECK_EQUAL(sound_asset->asset()->channels (), 16);
75
76         /* Sample index in the DCP */
77         int n = 0;
78         /* DCP sound asset frame */
79         int frame = 0;
80
81         while (n < sound_asset->asset()->intrinsic_duration()) {
82                 auto sound_frame = sound_asset->asset()->start_read()->get_frame (frame++);
83                 uint8_t const * d = sound_frame->data ();
84                 for (int offset = 0; offset < sound_frame->size(); offset += (3 * sound_asset->asset()->channels())) {
85                         for (auto channel = 0; channel < MAX_DCP_AUDIO_CHANNELS; ++channel) {
86                                 auto const sample = d[offset + channel * 3 + 1] | (d[offset + channel * 3 + 2] << 8);
87                                 if (channel == 2) {
88                                         /* Input should be on centre */
89                                         BOOST_CHECK_EQUAL(sample, n);
90                                 } else {
91                                         /* Everything else should be silent */
92                                         BOOST_CHECK_EQUAL(sample, 0);
93                                 }
94                         }
95                         ++n;
96                 }
97         }
98 }
99
100
101 /** Decode a file containing truehd so we can profile it; this is with the player set to normal */
102 BOOST_AUTO_TEST_CASE (ffmpeg_audio_test2)
103 {
104         auto film = new_test_film2 ("ffmpeg_audio_test2");
105         auto content = content_factory(TestPaths::private_data() / "wayne.mkv")[0];
106         film->examine_and_add_content (content);
107         BOOST_REQUIRE (!wait_for_jobs ());
108
109         auto player = make_shared<Player>(film, Image::Alignment::COMPACT);
110         while (!player->pass ()) {}
111 }
112
113
114 /** Decode a file containing truehd so we can profile it; this is with the player set to fast */
115 BOOST_AUTO_TEST_CASE (ffmpeg_audio_test3)
116 {
117         auto film = new_test_film2 ("ffmpeg_audio_test3");
118         auto content = content_factory(TestPaths::private_data() / "wayne.mkv")[0];
119         film->examine_and_add_content (content);
120         BOOST_REQUIRE (!wait_for_jobs ());
121
122         auto player = make_shared<Player>(film, Image::Alignment::COMPACT);
123         player->set_fast ();
124         while (!player->pass ()) {}
125 }
126
127
128 /** Decode a file whose audio previously crashed DCP-o-matic (#1857) */
129 BOOST_AUTO_TEST_CASE (ffmpeg_audio_test4)
130 {
131         auto film = new_test_film2 ("ffmpeg_audio_test4");
132         auto content = content_factory(TestPaths::private_data() / "Actuellement aout 2020.wmv")[0];
133         film->examine_and_add_content (content);
134         BOOST_REQUIRE (!wait_for_jobs ());
135
136         auto player = make_shared<Player>(film, Image::Alignment::COMPACT);
137         player->set_fast ();
138         BOOST_CHECK_NO_THROW (while (!player->pass()) {});
139 }
140