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)
48 BOOST_REQUIRE (accumulated);
49 accumulated->append (audio);
52 /** Check that the Player correctly generates silence when used with a silent FFmpegContent */
53 BOOST_AUTO_TEST_CASE (player_silence_padding_test)
55 shared_ptr<Film> film = new_test_film ("player_silence_padding_test");
56 film->set_name ("player_silence_padding_test");
57 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
58 film->set_container (Ratio::from_id ("185"));
59 film->set_audio_channels (6);
61 film->examine_and_add_content (c);
64 accumulated.reset (new AudioBuffers (film->audio_channels(), 0));
66 shared_ptr<Player> player (new Player (film, film->playlist ()));
67 player->Audio.connect (bind (&accumulate, _1, _2));
68 while (!player->pass ()) {}
69 BOOST_REQUIRE (accumulated->frames() >= 48000);
70 BOOST_CHECK_EQUAL (accumulated->channels(), film->audio_channels ());
72 for (int i = 0; i < 48000; ++i) {
73 for (int c = 0; c < accumulated->channels(); ++c) {
74 BOOST_CHECK_EQUAL (accumulated->data()[c][i], 0);
79 /* Test insertion of black frames between separate bits of video content */
80 BOOST_AUTO_TEST_CASE (player_black_fill_test)
82 shared_ptr<Film> film = new_test_film ("black_fill_test");
83 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
84 film->set_name ("black_fill_test");
85 film->set_container (Ratio::from_id ("185"));
86 film->set_sequence (false);
87 shared_ptr<ImageContent> contentA (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
88 shared_ptr<ImageContent> contentB (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
90 film->examine_and_add_content (contentA);
91 film->examine_and_add_content (contentB);
94 contentA->video->set_scale (VideoContentScale (Ratio::from_id ("185")));
95 contentA->video->set_length (3);
96 contentA->set_position (DCPTime::from_frames (2, film->video_frame_rate ()));
97 contentB->video->set_scale (VideoContentScale (Ratio::from_id ("185")));
98 contentB->video->set_length (1);
99 contentB->set_position (DCPTime::from_frames (7, film->video_frame_rate ()));
105 boost::filesystem::path ref;
108 ref /= "black_fill_test";
110 boost::filesystem::path check;
113 check /= "black_fill_test";
114 check /= film->dcp_name();
116 check_dcp (ref.string(), check.string());