2 Copyright (C) 2015 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.
21 #include "lib/ratio.h"
22 #include "lib/ffmpeg_content.h"
23 #include "lib/image_content.h"
24 #include "lib/dcp_content_type.h"
25 #include "lib/dcp_content.h"
26 #include "lib/subrip_content.h"
28 #include <boost/test/unit_test.hpp>
29 #include <boost/foreach.hpp>
32 using boost::shared_ptr;
34 /** Test Film::reels() */
35 BOOST_AUTO_TEST_CASE (reels_test1)
37 shared_ptr<Film> film = new_test_film ("reels_test1");
38 film->set_container (Ratio::from_id ("185"));
39 shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/test.mp4"));
40 film->examine_and_add_content (A);
41 shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/test.mp4"));
42 film->examine_and_add_content (B);
44 BOOST_CHECK_EQUAL (A->full_length(), DCPTime (288000));
46 film->set_reel_type (REELTYPE_SINGLE);
47 list<DCPTimePeriod> r = film->reels ();
48 BOOST_CHECK_EQUAL (r.size(), 1);
49 BOOST_CHECK_EQUAL (r.front().from, DCPTime (0));
50 BOOST_CHECK_EQUAL (r.front().to, DCPTime (288000 * 2));
52 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
54 BOOST_CHECK_EQUAL (r.size(), 2);
55 BOOST_CHECK_EQUAL (r.front().from, DCPTime (0));
56 BOOST_CHECK_EQUAL (r.front().to, DCPTime (288000));
57 BOOST_CHECK_EQUAL (r.back().from, DCPTime (288000));
58 BOOST_CHECK_EQUAL (r.back().to, DCPTime (288000 * 2));
60 film->set_j2k_bandwidth (100000000);
61 film->set_reel_type (REELTYPE_BY_LENGTH);
62 /* This is just over 2.5s at 100Mbit/s; should correspond to 60 frames */
63 film->set_reel_length (31253154);
65 BOOST_CHECK_EQUAL (r.size(), 3);
66 list<DCPTimePeriod>::const_iterator i = r.begin ();
67 BOOST_CHECK_EQUAL (i->from, DCPTime (0));
68 BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (60, 24));
70 BOOST_CHECK_EQUAL (i->from, DCPTime::from_frames (60, 24));
71 BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (120, 24));
73 BOOST_CHECK_EQUAL (i->from, DCPTime::from_frames (120, 24));
74 BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (144, 24));
77 /** Make a short DCP with multi reels split by video content, then import
78 * this into a new project and make a new DCP referencing it.
80 BOOST_AUTO_TEST_CASE (reels_test2)
82 shared_ptr<Film> film = new_test_film ("reels_test2");
83 film->set_name ("reels_test2");
84 film->set_container (Ratio::from_id ("185"));
85 film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
88 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_red.png"));
89 film->examine_and_add_content (c);
91 c->set_video_length (24);
95 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_green.png"));
96 film->examine_and_add_content (c);
98 c->set_video_length (24);
102 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_blue.png"));
103 film->examine_and_add_content (c);
105 c->set_video_length (24);
108 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
114 check_dcp ("test/data/reels_test2", film->dir (film->dcp_name()));
116 shared_ptr<Film> film2 = new_test_film ("reels_test2b");
117 film2->set_name ("reels_test2b");
118 film2->set_container (Ratio::from_id ("185"));
119 film2->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
120 film2->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
122 shared_ptr<DCPContent> c (new DCPContent (film2, film->dir (film->dcp_name ())));
123 film2->examine_and_add_content (c);
126 list<DCPTimePeriod> r = film2->reels ();
127 BOOST_CHECK_EQUAL (r.size(), 3);
128 list<DCPTimePeriod>::const_iterator i = r.begin ();
129 BOOST_CHECK_EQUAL (i->from, DCPTime (0));
130 BOOST_CHECK_EQUAL (i->to, DCPTime (96000));
132 BOOST_CHECK_EQUAL (i->from, DCPTime (96000));
133 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 2));
135 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 2));
136 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 3));
138 c->set_reference_video (true);
139 c->set_reference_audio (true);
145 /** Check that REELTYPE_BY_VIDEO_CONTENT adds an extra reel, if necessary, at the end
146 * of all the video content to mop up anything afterward.
148 BOOST_AUTO_TEST_CASE (reels_test3)
150 shared_ptr<Film> film = new_test_film ("reels_test3");
151 film->set_name ("reels_test3");
152 film->set_container (Ratio::from_id ("185"));
153 film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
154 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
156 shared_ptr<Content> dcp (new DCPContent (film, "test/data/reels_test2"));
157 film->examine_and_add_content (dcp);
158 shared_ptr<Content> sub (new SubRipContent (film, "test/data/subrip.srt"));
159 film->examine_and_add_content (sub);
162 std::cout << dcp->position() << " " << dcp->full_length() << "\n";
163 std::cout << sub->position() << " " << sub->full_length() << "\n";
165 list<DCPTimePeriod> reels = film->reels();
166 BOOST_REQUIRE_EQUAL (reels.size(), 4);
167 list<DCPTimePeriod>::const_iterator i = reels.begin ();
168 BOOST_CHECK_EQUAL (i->from, DCPTime (0));
169 BOOST_CHECK_EQUAL (i->to, DCPTime (96000));
171 BOOST_CHECK_EQUAL (i->from, DCPTime (96000));
172 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 2));
174 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 2));
175 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 3));
177 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 3));
178 BOOST_CHECK_EQUAL (i->to, sub->full_length());