2 Copyright (C) 2013-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 /** @file test/ffmpeg_audio_test.cc
23 * @brief Test reading audio from an FFmpeg file.
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"
34 #include "lib/player.h"
35 #include "lib/ratio.h"
36 #include "lib/video_content.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>
45 #include <boost/test/unit_test.hpp>
48 using std::make_shared;
52 BOOST_AUTO_TEST_CASE (ffmpeg_audio_test)
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);
59 BOOST_REQUIRE (!wait_for_jobs());
61 int constexpr audio_channels = 6;
63 film->set_container (Ratio::from_id ("185"));
64 film->set_audio_channels(audio_channels);
65 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
66 make_and_verify_dcp (film);
68 boost::filesystem::path path = "build/test";
69 path /= "ffmpeg_audio_test";
70 path /= film->dcp_name ();
71 dcp::DCP check (path.string ());
74 auto sound_asset = check.cpls().front()->reels().front()->main_sound ();
75 BOOST_CHECK (sound_asset);
76 BOOST_REQUIRE_EQUAL(sound_asset->asset()->channels (), audio_channels);
78 /* Sample index in the DCP */
80 /* DCP sound asset frame */
83 while (n < sound_asset->asset()->intrinsic_duration()) {
84 auto sound_frame = sound_asset->asset()->start_read()->get_frame (frame++);
85 uint8_t const * d = sound_frame->data ();
86 for (int offset = 0; offset < sound_frame->size(); offset += (3 * sound_asset->asset()->channels())) {
87 for (auto channel = 0; channel < audio_channels; ++channel) {
88 auto const sample = d[offset + channel * 3 + 1] | (d[offset + channel * 3 + 2] << 8);
90 /* Input should be on centre */
91 BOOST_CHECK_EQUAL(sample, n);
93 /* Everything else should be silent */
94 BOOST_CHECK_EQUAL(sample, 0);
103 /** Decode a file containing truehd so we can profile it; this is with the player set to normal */
104 BOOST_AUTO_TEST_CASE (ffmpeg_audio_test2)
106 auto film = new_test_film2 ("ffmpeg_audio_test2");
107 auto content = content_factory(TestPaths::private_data() / "wayne.mkv")[0];
108 film->examine_and_add_content (content);
109 BOOST_REQUIRE (!wait_for_jobs ());
111 auto player = make_shared<Player>(film, Image::Alignment::COMPACT);
112 while (!player->pass ()) {}
116 /** Decode a file containing truehd so we can profile it; this is with the player set to fast */
117 BOOST_AUTO_TEST_CASE (ffmpeg_audio_test3)
119 auto film = new_test_film2 ("ffmpeg_audio_test3");
120 auto content = content_factory(TestPaths::private_data() / "wayne.mkv")[0];
121 film->examine_and_add_content (content);
122 BOOST_REQUIRE (!wait_for_jobs ());
124 auto player = make_shared<Player>(film, Image::Alignment::COMPACT);
126 while (!player->pass ()) {}
130 /** Decode a file whose audio previously crashed DCP-o-matic (#1857) */
131 BOOST_AUTO_TEST_CASE (ffmpeg_audio_test4)
133 auto film = new_test_film2 ("ffmpeg_audio_test4");
134 auto content = content_factory(TestPaths::private_data() / "Actuellement aout 2020.wmv")[0];
135 film->examine_and_add_content (content);
136 BOOST_REQUIRE (!wait_for_jobs ());
138 auto player = make_shared<Player>(film, Image::Alignment::COMPACT);
140 BOOST_CHECK_NO_THROW (while (!player->pass()) {});