2 Copyright (C) 2014 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/>.
21 /** @file test/player_test.cc
22 * @brief Test Player class.
23 * @ingroup selfcontained
27 #include <boost/test/unit_test.hpp>
29 #include "lib/ffmpeg_content.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/ratio.h"
32 #include "lib/audio_buffers.h"
33 #include "lib/player.h"
34 #include "lib/video_content.h"
35 #include "lib/image_content.h"
40 using boost::shared_ptr;
43 static shared_ptr<AudioBuffers> accumulated;
46 accumulate (shared_ptr<AudioBuffers> audio, DCPTime t)
48 cout << "got " << audio->frames() << " @ " << to_string(t) << "\n";
49 BOOST_REQUIRE (accumulated);
50 accumulated->append (audio);
53 /** Check that the Player correctly generates silence when used with a silent FFmpegContent */
54 BOOST_AUTO_TEST_CASE (player_silence_padding_test)
56 shared_ptr<Film> film = new_test_film ("player_silence_padding_test");
57 film->set_name ("player_silence_padding_test");
58 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
59 film->set_container (Ratio::from_id ("185"));
60 film->set_audio_channels (6);
62 film->examine_and_add_content (c);
65 accumulated.reset (new AudioBuffers (film->audio_channels(), 0));
67 shared_ptr<Player> player (new Player (film, film->playlist ()));
68 player->Audio.connect (bind (&accumulate, _1, _2));
69 while (!player->pass ()) {}
70 BOOST_REQUIRE (accumulated->frames() >= 48000);
71 BOOST_CHECK_EQUAL (accumulated->channels(), film->audio_channels ());
73 for (int i = 0; i < 48000; ++i) {
74 for (int c = 0; c < accumulated->channels(); ++c) {
75 BOOST_CHECK_EQUAL (accumulated->data()[c][i], 0);
80 /* Test insertion of black frames between separate bits of video content */
81 BOOST_AUTO_TEST_CASE (player_black_fill_test)
83 shared_ptr<Film> film = new_test_film ("black_fill_test");
84 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
85 film->set_name ("black_fill_test");
86 film->set_container (Ratio::from_id ("185"));
87 film->set_sequence (false);
88 shared_ptr<ImageContent> contentA (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
89 shared_ptr<ImageContent> contentB (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
91 film->examine_and_add_content (contentA);
92 film->examine_and_add_content (contentB);
95 contentA->video->set_scale (VideoContentScale (Ratio::from_id ("185")));
96 contentA->video->set_length (3);
97 contentA->set_position (DCPTime::from_frames (2, film->video_frame_rate ()));
98 contentB->video->set_scale (VideoContentScale (Ratio::from_id ("185")));
99 contentB->video->set_length (1);
100 contentB->set_position (DCPTime::from_frames (7, film->video_frame_rate ()));
106 boost::filesystem::path ref;
109 ref /= "black_fill_test";
111 boost::filesystem::path check;
114 check /= "black_fill_test";
115 check /= film->dcp_name();
117 check_dcp (ref.string(), check.string());