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 "lib/ffmpeg_content.h"
27 #include "lib/dcp_content_type.h"
28 #include "lib/ratio.h"
29 #include "lib/audio_buffers.h"
30 #include "lib/player.h"
32 #include <boost/test/unit_test.hpp>
33 #include <boost/make_shared.hpp>
38 using boost::shared_ptr;
39 using boost::make_shared;
42 valid (Content const *)
47 /** Player::overlaps */
48 BOOST_AUTO_TEST_CASE (player_overlaps_test)
50 shared_ptr<Film> film = new_test_film ("player_overlaps_test");
51 film->set_container (Ratio::from_id ("185"));
53 /* This content is 3s long */
54 shared_ptr<FFmpegContent> A = make_shared<FFmpegContent> (film, "test/data/test.mp4");
55 shared_ptr<FFmpegContent> B = make_shared<FFmpegContent> (film, "test/data/test.mp4");
56 shared_ptr<FFmpegContent> C = make_shared<FFmpegContent> (film, "test/data/test.mp4");
58 film->examine_and_add_content (A);
59 film->examine_and_add_content (B);
60 film->examine_and_add_content (C);
63 BOOST_CHECK_EQUAL (A->full_length(), DCPTime (288000));
65 A->set_position (DCPTime::from_seconds (0));
66 B->set_position (DCPTime::from_seconds (10));
67 C->set_position (DCPTime::from_seconds (20));
69 shared_ptr<Player> player = make_shared<Player> (film, film->playlist ());
71 list<shared_ptr<Piece> > o = player->overlaps (DCPTime::from_seconds (0), DCPTime::from_seconds (5), &valid);
72 BOOST_CHECK_EQUAL (o.size(), 1U);
73 BOOST_CHECK_EQUAL (o.front()->content, A);
75 o = player->overlaps (DCPTime::from_seconds (5), DCPTime::from_seconds (8), &valid);
76 BOOST_CHECK_EQUAL (o.size(), 0U);
78 o = player->overlaps (DCPTime::from_seconds (8), DCPTime::from_seconds (12), &valid);
79 BOOST_CHECK_EQUAL (o.size(), 1U);
80 BOOST_CHECK_EQUAL (o.front()->content, B);
82 o = player->overlaps (DCPTime::from_seconds (2), DCPTime::from_seconds (12), &valid);
83 BOOST_CHECK_EQUAL (o.size(), 2U);
84 BOOST_CHECK_EQUAL (o.front()->content, A);
85 BOOST_CHECK_EQUAL (o.back()->content, B);
87 o = player->overlaps (DCPTime::from_seconds (8), DCPTime::from_seconds (11), &valid);
88 BOOST_CHECK_EQUAL (o.size(), 1U);
89 BOOST_CHECK_EQUAL (o.front()->content, B);
92 /** Check that the Player correctly generates silence when used with a silent FFmpegContent */
93 BOOST_AUTO_TEST_CASE (player_silence_padding_test)
95 shared_ptr<Film> film = new_test_film ("player_silence_padding_test");
96 film->set_name ("player_silence_padding_test");
97 shared_ptr<FFmpegContent> c = make_shared<FFmpegContent> (film, "test/data/test.mp4");
98 film->set_container (Ratio::from_id ("185"));
99 film->set_audio_channels (6);
101 film->examine_and_add_content (c);
104 shared_ptr<Player> player = make_shared<Player> (film, film->playlist ());
105 shared_ptr<AudioBuffers> test = player->get_audio (DCPTime (0), DCPTime::from_seconds (1), true);
106 BOOST_CHECK_EQUAL (test->frames(), 48000);
107 BOOST_CHECK_EQUAL (test->channels(), film->audio_channels ());
109 for (int i = 0; i < test->frames(); ++i) {
110 for (int c = 0; c < test->channels(); ++c) {
111 BOOST_CHECK_EQUAL (test->data()[c][i], 0);