2 Copyright (C) 2013-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 #include <boost/test/unit_test.hpp>
22 #include "lib/player.h"
23 #include "lib/ratio.h"
24 #include "lib/dcp_content_type.h"
25 #include "lib/player_video_frame.h"
29 /* This test needs stuff in Player that is only included in debug mode */
30 #ifdef DCPOMATIC_DEBUG
33 using boost::optional;
34 using boost::shared_ptr;
38 boost::shared_ptr<Content> content;
39 boost::shared_ptr<const Image> image;
46 PlayerWrapper (shared_ptr<Player> p)
49 _player->Video.connect (bind (&PlayerWrapper::process_video, this, _1, _3));
52 void process_video (shared_ptr<PlayerVideoFrame> i, Time t)
55 v.content = _player->_last_video;
56 v.image = i->image (PIX_FMT_RGB24);
58 _queue.push_front (v);
61 optional<Video> get_video ()
63 while (_queue.empty() && !_player->pass ()) {}
64 if (_queue.empty ()) {
65 return optional<Video> ();
68 Video v = _queue.back ();
73 void seek (Time t, bool ac)
75 _player->seek (t, ac);
80 shared_ptr<Player> _player;
81 std::list<Video> _queue;
84 BOOST_AUTO_TEST_CASE (play_test)
86 shared_ptr<Film> film = new_test_film ("play_test");
87 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
88 film->set_container (Ratio::from_id ("185"));
89 film->set_name ("play_test");
91 shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/red_24.mp4"));
92 film->examine_and_add_content (A);
95 BOOST_CHECK_EQUAL (A->video_length_after_3d_combine(), 16);
97 shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/red_30.mp4"));
98 film->examine_and_add_content (B);
101 BOOST_CHECK_EQUAL (B->video_length_after_3d_combine(), 16);
103 /* Film should have been set to 25fps */
104 BOOST_CHECK_EQUAL (film->video_frame_rate(), 25);
106 BOOST_CHECK_EQUAL (A->position(), 0);
107 /* A is 16 frames long at 25 fps */
108 BOOST_CHECK_EQUAL (B->position(), 16 * TIME_HZ / 25);
110 shared_ptr<Player> player (new Player (film));
111 PlayerWrapper wrap (player);
112 /* Seek and audio don't get on at the moment */
113 player->disable_audio ();
115 for (int i = 0; i < 32; ++i) {
116 optional<Video> v = wrap.get_video ();
119 BOOST_CHECK (v.get().content == A);
121 BOOST_CHECK (v.get().content == B);
125 wrap.seek (10 * TIME_HZ / 25, true);
126 optional<Video> v = wrap.get_video ();
128 BOOST_CHECK_EQUAL (v.get().time, 10 * TIME_HZ / 25);