2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 /* This test needs stuff in Player that is only included in debug mode */
23 #ifdef DCPOMATIC_DEBUG
25 using boost::optional;
29 boost::shared_ptr<Content> content;
30 boost::shared_ptr<const Image> image;
37 PlayerWrapper (shared_ptr<Player> p)
40 _player->Video.connect (bind (&PlayerWrapper::process_video, this, _1, _2, _3));
43 void process_video (shared_ptr<const Image> i, bool, Time t)
46 v.content = _player->_last_video;
49 _queue.push_front (v);
52 optional<Video> get_video ()
54 while (_queue.empty() && !_player->pass ()) {}
55 if (_queue.empty ()) {
56 return optional<Video> ();
59 Video v = _queue.back ();
64 void seek (Time t, bool ac)
66 _player->seek (t, ac);
71 shared_ptr<Player> _player;
72 std::list<Video> _queue;
75 BOOST_AUTO_TEST_CASE (play_test)
77 shared_ptr<Film> film = new_test_film ("play_test");
78 film->set_dcp_content_type (DCPContentType::from_dci_name ("FTR"));
79 film->set_container (Ratio::from_id ("185"));
80 film->set_name ("play_test");
82 shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/red_24.mp4"));
83 film->examine_and_add_content (A);
86 BOOST_CHECK_EQUAL (A->video_length(), 16);
88 shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/red_30.mp4"));
89 film->examine_and_add_content (B);
92 BOOST_CHECK_EQUAL (B->video_length(), 16);
94 /* Film should have been set to 25fps */
95 BOOST_CHECK_EQUAL (film->dcp_video_frame_rate(), 25);
97 BOOST_CHECK_EQUAL (A->start(), 0);
98 /* A is 16 frames long at 25 fps */
99 BOOST_CHECK_EQUAL (B->start(), 16 * TIME_HZ / 25);
101 shared_ptr<Player> player = film->player ();
102 PlayerWrapper wrap (player);
103 /* Seek and audio don't get on at the moment */
104 player->disable_audio ();
106 for (int i = 0; i < 32; ++i) {
107 optional<Video> v = wrap.get_video ();
110 BOOST_CHECK (v.get().content == A);
112 BOOST_CHECK (v.get().content == B);
116 player->seek (10 * TIME_HZ / 25, true);
117 optional<Video> v = wrap.get_video ();
119 cout << (v.get().time * 25 / TIME_HZ) << "\n";
120 BOOST_CHECK_EQUAL (v.get().time, 10 * TIME_HZ / 25);