Remove debug.
[dcpomatic.git] / test / player_test.cc
1 /*
2     Copyright (C) 2014 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 /** @file  test/player_test.cc
22  *  @brief Test Player class.
23  *  @ingroup selfcontained
24  */
25
26 #include <iostream>
27 #include <boost/test/unit_test.hpp>
28 #include "lib/film.h"
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"
36 #include "test.h"
37
38 using std::cout;
39 using std::list;
40 using boost::shared_ptr;
41 using boost::bind;
42
43 static shared_ptr<AudioBuffers> accumulated;
44
45 static void
46 accumulate (shared_ptr<AudioBuffers> audio, DCPTime t)
47 {
48         BOOST_REQUIRE (accumulated);
49         accumulated->append (audio);
50 }
51
52 /** Check that the Player correctly generates silence when used with a silent FFmpegContent */
53 BOOST_AUTO_TEST_CASE (player_silence_padding_test)
54 {
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);
60
61         film->examine_and_add_content (c);
62         wait_for_jobs ();
63
64         accumulated.reset (new AudioBuffers (film->audio_channels(), 0));
65
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 ());
71
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);
75                 }
76         }
77 }
78
79 /* Test insertion of black frames between separate bits of video content */
80 BOOST_AUTO_TEST_CASE (player_black_fill_test)
81 {
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"));
89
90         film->examine_and_add_content (contentA);
91         film->examine_and_add_content (contentB);
92         wait_for_jobs ();
93
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 ()));
100
101         film->make_dcp ();
102
103         wait_for_jobs ();
104
105         boost::filesystem::path ref;
106         ref = "test";
107         ref /= "data";
108         ref /= "black_fill_test";
109
110         boost::filesystem::path check;
111         check = "build";
112         check /= "test";
113         check /= "black_fill_test";
114         check /= film->dcp_name();
115
116         check_dcp (ref.string(), check.string());
117 }