2 Copyright (C) 2013-2014 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"
24 #include "lib/player_video_frame.h"
28 /* This test needs stuff in Player that is only included in debug mode */
29 #ifdef DCPOMATIC_DEBUG
32 using boost::optional;
33 using boost::shared_ptr;
37 boost::shared_ptr<Content> content;
38 boost::shared_ptr<const Image> image;
45 PlayerWrapper (shared_ptr<Player> p)
48 _player->Video.connect (bind (&PlayerWrapper::process_video, this, _1, _3));
51 void process_video (shared_ptr<PlayerVideoFrame> i, Time t)
54 v.content = _player->_last_video;
55 v.image = i->image (PIX_FMT_RGB24);
57 _queue.push_front (v);
60 optional<Video> get_video ()
62 while (_queue.empty() && !_player->pass ()) {}
63 if (_queue.empty ()) {
64 return optional<Video> ();
67 Video v = _queue.back ();
72 void seek (Time t, bool ac)
74 _player->seek (t, ac);
79 shared_ptr<Player> _player;
80 std::list<Video> _queue;
83 BOOST_AUTO_TEST_CASE (play_test)
85 shared_ptr<Film> film = new_test_film ("play_test");
86 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
87 film->set_container (Ratio::from_id ("185"));
88 film->set_name ("play_test");
90 shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/red_24.mp4"));
91 film->examine_and_add_content (A);
94 BOOST_CHECK_EQUAL (A->video_length_after_3d_combine(), 16);
96 shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/red_30.mp4"));
97 film->examine_and_add_content (B);
100 BOOST_CHECK_EQUAL (B->video_length_after_3d_combine(), 16);
102 /* Film should have been set to 25fps */
103 BOOST_CHECK_EQUAL (film->video_frame_rate(), 25);
105 BOOST_CHECK_EQUAL (A->position(), 0);
106 /* A is 16 frames long at 25 fps */
107 BOOST_CHECK_EQUAL (B->position(), 16 * TIME_HZ / 25);
109 shared_ptr<Player> player (new Player (film));
110 PlayerWrapper wrap (player);
111 /* Seek and audio don't get on at the moment */
112 player->disable_audio ();
114 for (int i = 0; i < 32; ++i) {
115 optional<Video> v = wrap.get_video ();
118 BOOST_CHECK (v.get().content == A);
120 BOOST_CHECK (v.get().content == B);
124 wrap.seek (10 * TIME_HZ / 25, true);
125 optional<Video> v = wrap.get_video ();
127 BOOST_CHECK_EQUAL (v.get().time, 10 * TIME_HZ / 25);