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 /* Test Playlist::best_dcp_frame_rate and FrameRateConversion
21 with a single piece of content.
23 BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single)
25 shared_ptr<Film> film = new_test_film ("best_dcp_frame_rate_test_single");
26 /* Get any piece of content, it doesn't matter what */
27 shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/test.mp4"));
28 film->add_content (content);
31 /* Run some tests with a limited range of allowed rates */
37 Config::instance()->set_allowed_dcp_frame_rates (afr);
39 content->_video_frame_rate = 60;
40 int best = film->playlist()->best_dcp_frame_rate ();
41 FrameRateConversion frc = FrameRateConversion (60, best);
42 BOOST_CHECK_EQUAL (best, 30);
43 BOOST_CHECK_EQUAL (frc.skip, true);
44 BOOST_CHECK_EQUAL (frc.repeat, false);
45 BOOST_CHECK_EQUAL (frc.change_speed, false);
47 content->_video_frame_rate = 50;
48 best = film->playlist()->best_dcp_frame_rate ();
49 frc = FrameRateConversion (50, best);
50 BOOST_CHECK_EQUAL (best, 25);
51 BOOST_CHECK_EQUAL (frc.skip, true);
52 BOOST_CHECK_EQUAL (frc.repeat, false);
53 BOOST_CHECK_EQUAL (frc.change_speed, false);
55 content->_video_frame_rate = 48;
56 best = film->playlist()->best_dcp_frame_rate ();
57 frc = FrameRateConversion (48, best);
58 BOOST_CHECK_EQUAL (best, 24);
59 BOOST_CHECK_EQUAL (frc.skip, true);
60 BOOST_CHECK_EQUAL (frc.repeat, false);
61 BOOST_CHECK_EQUAL (frc.change_speed, false);
63 content->_video_frame_rate = 30;
64 best = film->playlist()->best_dcp_frame_rate ();
65 frc = FrameRateConversion (30, best);
66 BOOST_CHECK_EQUAL (best, 30);
67 BOOST_CHECK_EQUAL (frc.skip, false);
68 BOOST_CHECK_EQUAL (frc.repeat, false);
69 BOOST_CHECK_EQUAL (frc.change_speed, false);
71 content->_video_frame_rate = 29.97;
72 best = film->playlist()->best_dcp_frame_rate ();
73 frc = FrameRateConversion (29.97, best);
74 BOOST_CHECK_EQUAL (best, 30);
75 BOOST_CHECK_EQUAL (frc.skip, false);
76 BOOST_CHECK_EQUAL (frc.repeat, false);
77 BOOST_CHECK_EQUAL (frc.change_speed, true);
79 content->_video_frame_rate = 25;
80 best = film->playlist()->best_dcp_frame_rate ();
81 frc = FrameRateConversion (25, best);
82 BOOST_CHECK_EQUAL (best, 25);
83 BOOST_CHECK_EQUAL (frc.skip, false);
84 BOOST_CHECK_EQUAL (frc.repeat, false);
85 BOOST_CHECK_EQUAL (frc.change_speed, false);
87 content->_video_frame_rate = 24;
88 best = film->playlist()->best_dcp_frame_rate ();
89 frc = FrameRateConversion (24, best);
90 BOOST_CHECK_EQUAL (best, 24);
91 BOOST_CHECK_EQUAL (frc.skip, false);
92 BOOST_CHECK_EQUAL (frc.repeat, false);
93 BOOST_CHECK_EQUAL (frc.change_speed, false);
95 content->_video_frame_rate = 14.5;
96 best = film->playlist()->best_dcp_frame_rate ();
97 frc = FrameRateConversion (14.5, best);
98 BOOST_CHECK_EQUAL (best, 30);
99 BOOST_CHECK_EQUAL (frc.skip, false);
100 BOOST_CHECK_EQUAL (frc.repeat, true);
101 BOOST_CHECK_EQUAL (frc.change_speed, true);
103 content->_video_frame_rate = 12.6;
104 best = film->playlist()->best_dcp_frame_rate ();
105 frc = FrameRateConversion (12.6, best);
106 BOOST_CHECK_EQUAL (best, 25);
107 BOOST_CHECK_EQUAL (frc.skip, false);
108 BOOST_CHECK_EQUAL (frc.repeat, true);
109 BOOST_CHECK_EQUAL (frc.change_speed, true);
111 content->_video_frame_rate = 12.4;
112 best = film->playlist()->best_dcp_frame_rate ();
113 frc = FrameRateConversion (12.4, best);
114 BOOST_CHECK_EQUAL (best, 25);
115 BOOST_CHECK_EQUAL (frc.skip, false);
116 BOOST_CHECK_EQUAL (frc.repeat, true);
117 BOOST_CHECK_EQUAL (frc.change_speed, true);
119 content->_video_frame_rate = 12;
120 best = film->playlist()->best_dcp_frame_rate ();
121 frc = FrameRateConversion (12, best);
122 BOOST_CHECK_EQUAL (best, 24);
123 BOOST_CHECK_EQUAL (frc.skip, false);
124 BOOST_CHECK_EQUAL (frc.repeat, true);
125 BOOST_CHECK_EQUAL (frc.change_speed, false);
127 /* Now add some more rates and see if it will use them
128 in preference to skip/repeat.
134 Config::instance()->set_allowed_dcp_frame_rates (afr);
136 content->_video_frame_rate = 60;
137 best = film->playlist()->best_dcp_frame_rate ();
138 frc = FrameRateConversion (60, best);
139 BOOST_CHECK_EQUAL (best, 60);
140 BOOST_CHECK_EQUAL (frc.skip, false);
141 BOOST_CHECK_EQUAL (frc.repeat, false);
142 BOOST_CHECK_EQUAL (frc.change_speed, false);
144 content->_video_frame_rate = 50;
145 best = film->playlist()->best_dcp_frame_rate ();
146 frc = FrameRateConversion (50, best);
147 BOOST_CHECK_EQUAL (best, 50);
148 BOOST_CHECK_EQUAL (frc.skip, false);
149 BOOST_CHECK_EQUAL (frc.repeat, false);
150 BOOST_CHECK_EQUAL (frc.change_speed, false);
152 content->_video_frame_rate = 48;
153 best = film->playlist()->best_dcp_frame_rate ();
154 frc = FrameRateConversion (48, best);
155 BOOST_CHECK_EQUAL (best, 48);
156 BOOST_CHECK_EQUAL (frc.skip, false);
157 BOOST_CHECK_EQUAL (frc.repeat, false);
158 BOOST_CHECK_EQUAL (frc.change_speed, false);
160 /* Check some out-there conversions (not the best) */
162 frc = FrameRateConversion (14.99, 24);
163 BOOST_CHECK_EQUAL (frc.skip, false);
164 BOOST_CHECK_EQUAL (frc.repeat, true);
165 BOOST_CHECK_EQUAL (frc.change_speed, true);
167 /* Check some conversions with limited DCP targets */
171 Config::instance()->set_allowed_dcp_frame_rates (afr);
173 content->_video_frame_rate = 25;
174 best = film->playlist()->best_dcp_frame_rate ();
175 frc = FrameRateConversion (25, best);
176 BOOST_CHECK_EQUAL (best, 24);
177 BOOST_CHECK_EQUAL (frc.skip, false);
178 BOOST_CHECK_EQUAL (frc.repeat, false);
179 BOOST_CHECK_EQUAL (frc.change_speed, true);
182 /* Test Playlist::best_dcp_frame_rate and FrameRateConversion
183 with two pieces of content.
185 BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_double)
187 shared_ptr<Film> film = new_test_film ("best_dcp_frame_rate_test_double");
188 /* Get any old content, it doesn't matter what */
189 shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/test.mp4"));
190 film->add_content (A);
191 shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/test.mp4"));
192 film->add_content (B);
195 /* Run some tests with a limited range of allowed rates */
201 Config::instance()->set_allowed_dcp_frame_rates (afr);
203 A->_video_frame_rate = 30;
204 B->_video_frame_rate = 24;
205 BOOST_CHECK_EQUAL (film->playlist()->best_dcp_frame_rate(), 25);
209 BOOST_AUTO_TEST_CASE (audio_sampling_rate_test)
211 shared_ptr<Film> film = new_test_film ("audio_sampling_rate_test");
212 /* Get any piece of content, it doesn't matter what */
213 shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/test.mp4"));
214 film->add_content (content);
221 Config::instance()->set_allowed_dcp_frame_rates (afr);
223 content->_video_frame_rate = 24;
224 film->set_dcp_video_frame_rate (24);
225 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
226 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 48000);
228 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 44100, 0)));
229 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 48000);
231 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 80000, 0)));
232 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 96000);
234 content->_video_frame_rate = 23.976;
235 film->set_dcp_video_frame_rate (24);
236 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
237 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 47952);
239 content->_video_frame_rate = 29.97;
240 film->set_dcp_video_frame_rate (30);
241 BOOST_CHECK_EQUAL (film->dcp_video_frame_rate (), 30);
242 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
243 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 47952);
245 content->_video_frame_rate = 25;
246 film->set_dcp_video_frame_rate (24);
247 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
248 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 50000);
250 content->_video_frame_rate = 25;
251 film->set_dcp_video_frame_rate (24);
252 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 44100, 0)));
253 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 50000);
255 /* Check some out-there conversions (not the best) */
257 content->_video_frame_rate = 14.99;
258 film->set_dcp_video_frame_rate (25);
259 content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 16000, 0)));
260 /* The FrameRateConversion within output_audio_frame_rate should choose to double-up
261 the 14.99 fps video to 30 and then run it slow at 25.
263 BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), rint (48000 * 2 * 14.99 / 25));