2 Copyright (C) 2012 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>
22 #include "lib/config.h"
25 using boost::shared_ptr;
27 /* Test Playlist::best_dcp_frame_rate and FrameRateConversion
28 with a single piece of content.
30 BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single)
32 shared_ptr<Film> film = new_test_film ("best_dcp_frame_rate_test_single");
33 /* Get any piece of content, it doesn't matter what */
34 shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/test.mp4"));
35 film->add_content (content);
38 /* Run some tests with a limited range of allowed rates */
44 Config::instance()->set_allowed_dcp_frame_rates (afr);
46 content->_video_frame_rate = 60;
47 int best = film->playlist()->best_dcp_frame_rate ();
48 FrameRateConversion frc = FrameRateConversion (60, best);
49 BOOST_CHECK_EQUAL (best, 30);
50 BOOST_CHECK_EQUAL (frc.skip, true);
51 BOOST_CHECK_EQUAL (frc.repeat, false);
52 BOOST_CHECK_EQUAL (frc.change_speed, false);
54 content->_video_frame_rate = 50;
55 best = film->playlist()->best_dcp_frame_rate ();
56 frc = FrameRateConversion (50, best);
57 BOOST_CHECK_EQUAL (best, 25);
58 BOOST_CHECK_EQUAL (frc.skip, true);
59 BOOST_CHECK_EQUAL (frc.repeat, false);
60 BOOST_CHECK_EQUAL (frc.change_speed, false);
62 content->_video_frame_rate = 48;
63 best = film->playlist()->best_dcp_frame_rate ();
64 frc = FrameRateConversion (48, best);
65 BOOST_CHECK_EQUAL (best, 24);
66 BOOST_CHECK_EQUAL (frc.skip, true);
67 BOOST_CHECK_EQUAL (frc.repeat, false);
68 BOOST_CHECK_EQUAL (frc.change_speed, false);
70 content->_video_frame_rate = 30;
71 best = film->playlist()->best_dcp_frame_rate ();
72 frc = FrameRateConversion (30, best);
73 BOOST_CHECK_EQUAL (best, 30);
74 BOOST_CHECK_EQUAL (frc.skip, false);
75 BOOST_CHECK_EQUAL (frc.repeat, false);
76 BOOST_CHECK_EQUAL (frc.change_speed, false);
78 content->_video_frame_rate = 29.97;
79 best = film->playlist()->best_dcp_frame_rate ();
80 frc = FrameRateConversion (29.97, best);
81 BOOST_CHECK_EQUAL (best, 30);
82 BOOST_CHECK_EQUAL (frc.skip, false);
83 BOOST_CHECK_EQUAL (frc.repeat, false);
84 BOOST_CHECK_EQUAL (frc.change_speed, true);
86 content->_video_frame_rate = 25;
87 best = film->playlist()->best_dcp_frame_rate ();
88 frc = FrameRateConversion (25, best);
89 BOOST_CHECK_EQUAL (best, 25);
90 BOOST_CHECK_EQUAL (frc.skip, false);
91 BOOST_CHECK_EQUAL (frc.repeat, false);
92 BOOST_CHECK_EQUAL (frc.change_speed, false);
94 content->_video_frame_rate = 24;
95 best = film->playlist()->best_dcp_frame_rate ();
96 frc = FrameRateConversion (24, best);
97 BOOST_CHECK_EQUAL (best, 24);
98 BOOST_CHECK_EQUAL (frc.skip, false);
99 BOOST_CHECK_EQUAL (frc.repeat, false);
100 BOOST_CHECK_EQUAL (frc.change_speed, false);
102 content->_video_frame_rate = 14.5;
103 best = film->playlist()->best_dcp_frame_rate ();
104 frc = FrameRateConversion (14.5, best);
105 BOOST_CHECK_EQUAL (best, 30);
106 BOOST_CHECK_EQUAL (frc.skip, false);
107 BOOST_CHECK_EQUAL (frc.repeat, true);
108 BOOST_CHECK_EQUAL (frc.change_speed, true);
110 content->_video_frame_rate = 12.6;
111 best = film->playlist()->best_dcp_frame_rate ();
112 frc = FrameRateConversion (12.6, best);
113 BOOST_CHECK_EQUAL (best, 25);
114 BOOST_CHECK_EQUAL (frc.skip, false);
115 BOOST_CHECK_EQUAL (frc.repeat, true);
116 BOOST_CHECK_EQUAL (frc.change_speed, true);
118 content->_video_frame_rate = 12.4;
119 best = film->playlist()->best_dcp_frame_rate ();
120 frc = FrameRateConversion (12.4, best);
121 BOOST_CHECK_EQUAL (best, 25);
122 BOOST_CHECK_EQUAL (frc.skip, false);
123 BOOST_CHECK_EQUAL (frc.repeat, true);
124 BOOST_CHECK_EQUAL (frc.change_speed, true);
126 content->_video_frame_rate = 12;
127 best = film->playlist()->best_dcp_frame_rate ();
128 frc = FrameRateConversion (12, best);
129 BOOST_CHECK_EQUAL (best, 24);
130 BOOST_CHECK_EQUAL (frc.skip, false);
131 BOOST_CHECK_EQUAL (frc.repeat, true);
132 BOOST_CHECK_EQUAL (frc.change_speed, false);
134 /* Now add some more rates and see if it will use them
135 in preference to skip/repeat.
141 Config::instance()->set_allowed_dcp_frame_rates (afr);
143 content->_video_frame_rate = 60;
144 best = film->playlist()->best_dcp_frame_rate ();
145 frc = FrameRateConversion (60, best);
146 BOOST_CHECK_EQUAL (best, 60);
147 BOOST_CHECK_EQUAL (frc.skip, false);
148 BOOST_CHECK_EQUAL (frc.repeat, false);
149 BOOST_CHECK_EQUAL (frc.change_speed, false);
151 content->_video_frame_rate = 50;
152 best = film->playlist()->best_dcp_frame_rate ();
153 frc = FrameRateConversion (50, best);
154 BOOST_CHECK_EQUAL (best, 50);
155 BOOST_CHECK_EQUAL (frc.skip, false);
156 BOOST_CHECK_EQUAL (frc.repeat, false);
157 BOOST_CHECK_EQUAL (frc.change_speed, false);
159 content->_video_frame_rate = 48;
160 best = film->playlist()->best_dcp_frame_rate ();
161 frc = FrameRateConversion (48, best);
162 BOOST_CHECK_EQUAL (best, 48);
163 BOOST_CHECK_EQUAL (frc.skip, false);
164 BOOST_CHECK_EQUAL (frc.repeat, false);
165 BOOST_CHECK_EQUAL (frc.change_speed, false);
167 /* Check some out-there conversions (not the best) */
169 frc = FrameRateConversion (14.99, 24);
170 BOOST_CHECK_EQUAL (frc.skip, false);
171 BOOST_CHECK_EQUAL (frc.repeat, true);
172 BOOST_CHECK_EQUAL (frc.change_speed, true);
174 /* Check some conversions with limited DCP targets */
178 Config::instance()->set_allowed_dcp_frame_rates (afr);
180 content->_video_frame_rate = 25;
181 best = film->playlist()->best_dcp_frame_rate ();
182 frc = FrameRateConversion (25, best);
183 BOOST_CHECK_EQUAL (best, 24);
184 BOOST_CHECK_EQUAL (frc.skip, false);
185 BOOST_CHECK_EQUAL (frc.repeat, false);
186 BOOST_CHECK_EQUAL (frc.change_speed, true);
189 /* Test Playlist::best_dcp_frame_rate and FrameRateConversion
190 with two pieces of content.
192 BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_double)
194 shared_ptr<Film> film = new_test_film ("best_dcp_frame_rate_test_double");
195 /* Get any old content, it doesn't matter what */
196 shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/test.mp4"));
197 film->add_content (A);
198 shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/test.mp4"));
199 film->add_content (B);
202 /* Run some tests with a limited range of allowed rates */
208 Config::instance()->set_allowed_dcp_frame_rates (afr);
210 A->_video_frame_rate = 30;
211 B->_video_frame_rate = 24;
212 BOOST_CHECK_EQUAL (film->playlist()->best_dcp_frame_rate(), 25);
216 BOOST_AUTO_TEST_CASE (audio_sampling_rate_test)
218 shared_ptr<Film> film = new_test_film ("audio_sampling_rate_test");
219 /* Get any piece of content, it doesn't matter what */
220 shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/test.mp4"));
221 film->add_content (content);
228 Config::instance()->set_allowed_dcp_frame_rates (afr);
230 content->_video_frame_rate = 24;
231 film->set_dcp_video_frame_rate (24);
232 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
233 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 48000);
235 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 44100, 0)));
236 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 48000);
238 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 80000, 0)));
239 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 96000);
241 content->_video_frame_rate = 23.976;
242 film->set_dcp_video_frame_rate (24);
243 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
244 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 47952);
246 content->_video_frame_rate = 29.97;
247 film->set_dcp_video_frame_rate (30);
248 BOOST_CHECK_EQUAL (film->dcp_video_frame_rate (), 30);
249 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
250 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 47952);
252 content->_video_frame_rate = 25;
253 film->set_dcp_video_frame_rate (24);
254 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
255 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 50000);
257 content->_video_frame_rate = 25;
258 film->set_dcp_video_frame_rate (24);
259 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 44100, 0)));
260 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 50000);
262 /* Check some out-there conversions (not the best) */
264 content->_video_frame_rate = 14.99;
265 film->set_dcp_video_frame_rate (25);
266 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 16000, 0)));
267 /* The FrameRateConversion within output_audio_frame_rate should choose to double-up
268 the 14.99 fps video to 30 and then run it slow at 25.
270 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), rint (48000 * 2 * 14.99 / 25));