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.
20 #include <boost/test/unit_test.hpp>
21 #include "lib/player.h"
22 #include "lib/ratio.h"
23 #include "lib/dcp_content_type.h"
26 /* This test needs stuff in Player that is only included in debug mode */
27 #ifdef DCPOMATIC_DEBUG
30 using boost::optional;
31 using boost::shared_ptr;
35 boost::shared_ptr<Content> content;
36 boost::shared_ptr<const Image> image;
43 PlayerWrapper (shared_ptr<Player> p)
46 _player->Video.connect (bind (&PlayerWrapper::process_video, this, _1, _2, _5));
49 void process_video (shared_ptr<PlayerImage> i, bool, DCPTime t)
52 v.content = _player->_last_video;
53 v.image = i->image (PIX_FMT_RGB24, false);
55 _queue.push_front (v);
58 optional<Video> get_video ()
60 while (_queue.empty() && !_player->pass ()) {}
61 if (_queue.empty ()) {
62 return optional<Video> ();
65 Video v = _queue.back ();
70 void seek (DCPTime t, bool ac)
72 _player->seek (t, ac);
77 shared_ptr<Player> _player;
78 std::list<Video> _queue;
81 BOOST_AUTO_TEST_CASE (play_test)
83 shared_ptr<Film> film = new_test_film ("play_test");
84 film->set_dcp_content_type (DCPContentType::from_dci_name ("FTR"));
85 film->set_container (Ratio::from_id ("185"));
86 film->set_name ("play_test");
88 shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/red_24.mp4"));
89 film->examine_and_add_content (A);
92 BOOST_CHECK_EQUAL (A->video_length_after_3d_combine().frames (24), 16);
94 shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/red_30.mp4"));
95 film->examine_and_add_content (B);
98 BOOST_CHECK_EQUAL (B->video_length_after_3d_combine().frames (30), 16);
100 /* Film should have been set to 25fps */
101 BOOST_CHECK_EQUAL (film->video_frame_rate(), 25);
103 BOOST_CHECK_EQUAL (A->position(), DCPTime ());
104 /* A is 16 frames long at 25 fps */
105 BOOST_CHECK_EQUAL (B->position(), DCPTime::from_frames (16, 25));
107 shared_ptr<Player> player = film->make_player ();
108 PlayerWrapper wrap (player);
110 for (int i = 0; i < 32; ++i) {
111 optional<Video> v = wrap.get_video ();
114 BOOST_CHECK (v.get().content == A);
116 BOOST_CHECK (v.get().content == B);
120 player->seek (DCPTime::from_frames (6, 25), true);
121 optional<Video> v = wrap.get_video ();
123 BOOST_CHECK_EQUAL (v.get().time, DCPTime::from_frames (6, 25));