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 Various tests of Player.
26 #include <boost/test/unit_test.hpp>
28 #include "lib/ffmpeg_content.h"
29 #include "lib/dcp_content_type.h"
30 #include "lib/ratio.h"
31 #include "lib/audio_buffers.h"
32 #include "lib/player.h"
37 using boost::shared_ptr;
40 valid (Content const *)
45 /** Player::overlaps */
46 BOOST_AUTO_TEST_CASE (player_overlaps_test)
48 shared_ptr<Film> film = new_test_film ("player_overlaps_test");
49 film->set_container (Ratio::from_id ("185"));
51 /* This content is 3s long */
52 shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/test.mp4"));
53 shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/test.mp4"));
54 shared_ptr<FFmpegContent> C (new FFmpegContent (film, "test/data/test.mp4"));
56 film->examine_and_add_content (A);
57 film->examine_and_add_content (B);
58 film->examine_and_add_content (C);
61 BOOST_CHECK_EQUAL (A->full_length(), DCPTime (288000));
63 A->set_position (DCPTime::from_seconds (0));
64 B->set_position (DCPTime::from_seconds (10));
65 C->set_position (DCPTime::from_seconds (20));
67 shared_ptr<Player> player (new Player (film, film->playlist ()));
69 list<shared_ptr<Piece> > o = player->overlaps (DCPTime::from_seconds (0), DCPTime::from_seconds (5), &valid);
70 BOOST_CHECK_EQUAL (o.size(), 1U);
71 BOOST_CHECK_EQUAL (o.front()->content, A);
73 o = player->overlaps (DCPTime::from_seconds (5), DCPTime::from_seconds (8), &valid);
74 BOOST_CHECK_EQUAL (o.size(), 0U);
76 o = player->overlaps (DCPTime::from_seconds (8), DCPTime::from_seconds (12), &valid);
77 BOOST_CHECK_EQUAL (o.size(), 1U);
78 BOOST_CHECK_EQUAL (o.front()->content, B);
80 o = player->overlaps (DCPTime::from_seconds (2), DCPTime::from_seconds (12), &valid);
81 BOOST_CHECK_EQUAL (o.size(), 2U);
82 BOOST_CHECK_EQUAL (o.front()->content, A);
83 BOOST_CHECK_EQUAL (o.back()->content, B);
85 o = player->overlaps (DCPTime::from_seconds (8), DCPTime::from_seconds (11), &valid);
86 BOOST_CHECK_EQUAL (o.size(), 1U);
87 BOOST_CHECK_EQUAL (o.front()->content, B);
90 /** Check that the Player correctly generates silence when used with a silent FFmpegContent */
91 BOOST_AUTO_TEST_CASE (player_silence_padding_test)
93 shared_ptr<Film> film = new_test_film ("player_silence_padding_test");
94 film->set_name ("player_silence_padding_test");
95 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
96 film->set_container (Ratio::from_id ("185"));
97 film->set_audio_channels (6);
99 film->examine_and_add_content (c);
102 shared_ptr<Player> player (new Player (film, film->playlist ()));
103 shared_ptr<AudioBuffers> test = player->get_audio (DCPTime (0), DCPTime::from_seconds (1), true);
104 BOOST_CHECK_EQUAL (test->frames(), 48000);
105 BOOST_CHECK_EQUAL (test->channels(), film->audio_channels ());
107 for (int i = 0; i < test->frames(); ++i) {
108 for (int c = 0; c < test->channels(); ++c) {
109 BOOST_CHECK_EQUAL (test->data()[c][i], 0);