bf21e5476d47e807c756e07ef4adc53f77eb4ab0
[dcpomatic.git] / test / time_calculation_test.cc
1 /*
2     Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "lib/film.h"
22 #include "lib/ffmpeg_content.h"
23 #include "lib/video_content.h"
24 #include "lib/player.h"
25 #include "lib/audio_content.h"
26 #include "test.h"
27 #include <boost/test/unit_test.hpp>
28 #include <boost/make_shared.hpp>
29
30 using std::string;
31 using std::list;
32 using boost::shared_ptr;
33 using boost::make_shared;
34
35 static string const xml = "<Content>"
36         "<Type>FFmpeg</Type>"
37         "<BurnSubtitles>0</BurnSubtitles>"
38         "<BitsPerPixel>8</BitsPerPixel>"
39         "<Path>test/data/red_24.mp4</Path>"
40         "<Digest>2760e03c7251480f7f02c01a907792673784335</Digest>"
41         "<Position>0</Position>"
42         "<TrimStart>0</TrimStart>"
43         "<TrimEnd>0</TrimEnd>"
44         "<VideoLength>1353600</VideoLength>"
45         "<VideoWidth>1280</VideoWidth>"
46         "<VideoHeight>720</VideoHeight>"
47         "<VideoFrameRate>25</VideoFrameRate>"
48         "<VideoFrameType>2d</VideoFrameType>"
49         "<LeftCrop>0</LeftCrop>"
50         "<RightCrop>0</RightCrop>"
51         "<TopCrop>0</TopCrop>"
52         "<BottomCrop>0</BottomCrop>"
53         "<Scale>"
54         "<Ratio>178</Ratio>"
55         "</Scale>"
56         "<ColourConversion>"
57         "<InputTransferFunction>"
58         "<Type>ModifiedGamma</Type>"
59         "<Power>2.222222222222222</Power>"
60         "<Threshold>0.081</Threshold>"
61         "<A>0.099</A>"
62         "<B>4.5</B>"
63         "</InputTransferFunction>"
64         "<RedX>0.64</RedX>"
65         "<RedY>0.33</RedY>"
66         "<GreenX>0.3</GreenX>"
67         "<GreenY>0.6</GreenY>"
68         "<BlueX>0.15</BlueX>"
69         "<BlueY>0.06</BlueY>"
70         "<WhiteX>0.3127</WhiteX>"
71         "<WhiteY>0.329</WhiteY>"
72         "<OutputGamma>2.6</OutputGamma>"
73         "</ColourConversion>"
74         "<FadeIn>0</FadeIn>"
75         "<FadeOut>0</FadeOut>"
76         "<AudioGain>0</AudioGain>"
77         "<AudioDelay>0</AudioDelay>"
78         "<UseSubtitles>0</UseSubtitles>"
79         "<SubtitleXOffset>0</SubtitleXOffset>"
80         "<SubtitleYOffset>0</SubtitleYOffset>"
81         "<SubtitleXScale>1</SubtitleXScale>"
82         "<SubtitleYScale>1</SubtitleYScale>"
83         "<SubtitleLanguage></SubtitleLanguage>"
84         "<AudioStream>"
85         "<Selected>1</Selected>"
86         "<Name>und; 2 channels</Name>"
87         "<Id>2</Id>"
88         "<FrameRate>44100</FrameRate>"
89         "<Length>44100</Length>"
90         "<Channels>2</Channels>"
91         "<FirstAudio>0</FirstAudio>"
92         "<Mapping>"
93         "<InputChannels>2</InputChannels>"
94         "<OutputChannels>12</OutputChannels>"
95         "<Gain Input=\"0\" Output=\"0\">1</Gain>"
96         "<Gain Input=\"0\" Output=\"1\">0</Gain>"
97         "<Gain Input=\"0\" Output=\"2\">0</Gain>"
98         "<Gain Input=\"0\" Output=\"3\">0</Gain>"
99         "<Gain Input=\"0\" Output=\"4\">0</Gain>"
100         "<Gain Input=\"0\" Output=\"5\">0</Gain>"
101         "<Gain Input=\"0\" Output=\"6\">0</Gain>"
102         "<Gain Input=\"0\" Output=\"7\">0</Gain>"
103         "<Gain Input=\"0\" Output=\"8\">0</Gain>"
104         "<Gain Input=\"0\" Output=\"9\">0</Gain>"
105         "<Gain Input=\"0\" Output=\"10\">0</Gain>"
106         "<Gain Input=\"0\" Output=\"11\">0</Gain>"
107         "<Gain Input=\"1\" Output=\"0\">0</Gain>"
108         "<Gain Input=\"1\" Output=\"1\">1</Gain>"
109         "<Gain Input=\"1\" Output=\"2\">0</Gain>"
110         "<Gain Input=\"1\" Output=\"3\">0</Gain>"
111         "<Gain Input=\"1\" Output=\"4\">0</Gain>"
112         "<Gain Input=\"1\" Output=\"5\">0</Gain>"
113         "<Gain Input=\"1\" Output=\"6\">0</Gain>"
114         "<Gain Input=\"1\" Output=\"7\">0</Gain>"
115         "<Gain Input=\"1\" Output=\"8\">0</Gain>"
116         "<Gain Input=\"1\" Output=\"9\">0</Gain>"
117         "<Gain Input=\"1\" Output=\"10\">0</Gain>"
118         "<Gain Input=\"1\" Output=\"11\">0</Gain>"
119         "</Mapping>"
120         "</AudioStream>"
121         "<FirstVideo>0</FirstVideo>"
122         "</Content>";
123
124 BOOST_AUTO_TEST_CASE (ffmpeg_time_calculation_test)
125 {
126         shared_ptr<Film> film = new_test_film ("ffmpeg_time_calculation_test");
127
128         shared_ptr<cxml::Document> doc = make_shared<cxml::Document> ();
129         doc->read_string (xml);
130
131         list<string> notes;
132         shared_ptr<FFmpegContent> content = boost::make_shared<FFmpegContent> (film, doc, film->state_version(), notes);
133
134         /* 25fps content, 25fps DCP */
135         film->set_video_frame_rate (25);
136         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video->length() / 25.0));
137         /* 25fps content, 24fps DCP; length should be increased */
138         film->set_video_frame_rate (24);
139         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video->length() / 24.0));
140         /* 25fps content, 30fps DCP; length should be decreased */
141         film->set_video_frame_rate (30);
142         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video->length() / 30.0));
143         /* 25fps content, 50fps DCP; length should be the same */
144         film->set_video_frame_rate (50);
145         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video->length() / 25.0));
146         /* 25fps content, 60fps DCP; length should be decreased */
147         film->set_video_frame_rate (60);
148         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video->length() * (50.0 / 60) / 25.0));
149
150         /* Make the content audio-only */
151         content->video.reset ();
152
153         /* 24fps content, 24fps DCP */
154         film->set_video_frame_rate (24);
155         content->set_video_frame_rate (24);
156         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (1));
157         /* 25fps content, 25fps DCP */
158         film->set_video_frame_rate (25);
159         content->set_video_frame_rate (25);
160         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (1));
161         /* 25fps content, 24fps DCP; length should be increased */
162         film->set_video_frame_rate (24);
163         BOOST_CHECK_SMALL (abs (content->full_length().get() - DCPTime::from_seconds(25.0 / 24).get()), 2);
164         /* 25fps content, 30fps DCP; length should be decreased */
165         film->set_video_frame_rate (30);
166         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (25.0 / 30));
167         /* 25fps content, 50fps DCP; length should be the same */
168         film->set_video_frame_rate (50);
169         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (1));
170         /* 25fps content, 60fps DCP; length should be decreased */
171         film->set_video_frame_rate (60);
172         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (50.0 / 60));
173
174 }
175
176 /** Test Player::dcp_to_content_video */
177 BOOST_AUTO_TEST_CASE (player_time_calculation_test1)
178 {
179         shared_ptr<Film> film = new_test_film ("player_time_calculation_test1");
180
181         shared_ptr<cxml::Document> doc = make_shared<cxml::Document> ();
182         doc->read_string (xml);
183
184         list<string> notes;
185         shared_ptr<FFmpegContent> content = boost::make_shared<FFmpegContent> (film, doc, film->state_version(), notes);
186         film->set_sequence (false);
187         film->add_content (content);
188
189         shared_ptr<Player> player = make_shared<Player> (film, film->playlist ());
190
191         /* Position 0, no trim, content rate = DCP rate */
192         content->set_position (DCPTime ());
193         content->set_trim_start (ContentTime ());
194         content->set_video_frame_rate (24);
195         film->set_video_frame_rate (24);
196         player->setup_pieces ();
197         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
198         shared_ptr<Piece> piece = player->_pieces.front ();
199         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
200         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.5)), 12);
201         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.0)), 72);
202
203         /* Position 3s, no trim, content rate = DCP rate */
204         content->set_position (DCPTime::from_seconds (3));
205         content->set_trim_start (ContentTime ());
206         content->set_video_frame_rate (24);
207         film->set_video_frame_rate (24);
208         player->setup_pieces ();
209         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
210         piece = player->_pieces.front ();
211         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
212         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.50)),   0);
213         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),   0);
214         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)),  36);
215         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 162);
216
217         /* Position 3s, 1.5s trim, content rate = DCP rate */
218         content->set_position (DCPTime::from_seconds (3));
219         content->set_trim_start (ContentTime::from_seconds (1.5));
220         content->set_video_frame_rate (24);
221         film->set_video_frame_rate (24);
222         player->setup_pieces ();
223         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
224         piece = player->_pieces.front ();
225         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
226         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.50)),   0);
227         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),  36);
228         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)),  72);
229         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 198);
230
231         /* Position 0, no trim, content rate 24, DCP rate 25.
232            Now, for example, a DCPTime position of 3s means 3s at 25fps.  Since we run the video
233            fast (at 25fps) in this case, this means 75 frames of content video will be used.
234         */
235         content->set_position (DCPTime ());
236         content->set_trim_start (ContentTime ());
237         content->set_video_frame_rate (24);
238         film->set_video_frame_rate (25);
239         player->setup_pieces ();
240         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
241         piece = player->_pieces.front ();
242         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
243         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.6)), 15);
244         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.0)), 75);
245
246         /* Position 3s, no trim, content rate 24, DCP rate 25 */
247         content->set_position (DCPTime::from_seconds (3));
248         content->set_trim_start (ContentTime ());
249         content->set_video_frame_rate (24);
250         film->set_video_frame_rate (25);
251         player->setup_pieces ();
252         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
253         piece = player->_pieces.front ();
254         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
255         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.60)),   0);
256         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),   0);
257         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.60)),  40);
258         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 168);
259
260         /* Position 3s, 1.6s trim, content rate 24, DCP rate 25.  Here the trim is in ContentTime,
261            so it's 1.6s at 24fps.
262          */
263         content->set_position (DCPTime::from_seconds (3));
264         content->set_trim_start (ContentTime::from_seconds (1.6));
265         content->set_video_frame_rate (24);
266         film->set_video_frame_rate (25);
267         player->setup_pieces ();
268         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
269         piece = player->_pieces.front ();
270         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
271         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.60)),   0);
272         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),  38);
273         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.60)),  78);
274         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 207);
275
276         /* Position 0, no trim, content rate 24, DCP rate 48
277            Now, for example, a DCPTime position of 3s means 3s at 48fps.  Since we run the video
278            with repeated frames in this case, 3 * 24 frames of content video will
279            be used to make 3 * 48 frames of DCP video.  The results should be the same as the
280            content rate = DCP rate case.
281         */
282         content->set_position (DCPTime ());
283         content->set_trim_start (ContentTime ());
284         content->set_video_frame_rate (24);
285         film->set_video_frame_rate (48);
286         player->setup_pieces ();
287         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
288         piece = player->_pieces.front ();
289         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
290         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.5)), 12);
291         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.0)), 72);
292
293         /* Position 3s, no trim, content rate 24, DCP rate 48 */
294         content->set_position (DCPTime::from_seconds (3));
295         content->set_trim_start (ContentTime ());
296         content->set_video_frame_rate (24);
297         film->set_video_frame_rate (48);
298         player->setup_pieces ();
299         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
300         piece = player->_pieces.front ();
301         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
302         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.50)),   0);
303         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),   0);
304         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)),  36);
305         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 162);
306
307         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
308         content->set_position (DCPTime::from_seconds (3));
309         content->set_trim_start (ContentTime::from_seconds (1.5));
310         content->set_video_frame_rate (24);
311         film->set_video_frame_rate (48);
312         player->setup_pieces ();
313         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
314         piece = player->_pieces.front ();
315         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
316         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.50)),   0);
317         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),  36);
318         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)),  72);
319         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 198);
320
321         /* Position 0, no trim, content rate 48, DCP rate 24
322            Now, for example, a DCPTime position of 3s means 3s at 24fps.  Since we run the video
323            with skipped frames in this case, 3 * 48 frames of content video will
324            be used to make 3 * 24 frames of DCP video.
325         */
326         content->set_position (DCPTime ());
327         content->set_trim_start (ContentTime ());
328         content->set_video_frame_rate (48);
329         film->set_video_frame_rate (24);
330         player->setup_pieces ();
331         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
332         piece = player->_pieces.front ();
333         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
334         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.5)), 24);
335         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.0)), 144);
336
337         /* Position 3s, no trim, content rate 24, DCP rate 48 */
338         content->set_position (DCPTime::from_seconds (3));
339         content->set_trim_start (ContentTime ());
340         content->set_video_frame_rate (48);
341         film->set_video_frame_rate (24);
342         player->setup_pieces ();
343         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
344         piece = player->_pieces.front ();
345         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
346         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.50)),   0);
347         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),   0);
348         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)),  72);
349         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 324);
350
351         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
352         content->set_position (DCPTime::from_seconds (3));
353         content->set_trim_start (ContentTime::from_seconds (1.5));
354         content->set_video_frame_rate (48);
355         film->set_video_frame_rate (24);
356         player->setup_pieces ();
357         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
358         piece = player->_pieces.front ();
359         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
360         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.50)),   0);
361         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),  72);
362         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)), 144);
363         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 396);
364
365         /* Position 0s, no trim, content rate 29.9978733, DCP rate 30 */
366         content->set_position (DCPTime::from_seconds (0));
367         content->set_trim_start (ContentTime::from_seconds (0));
368         content->set_video_frame_rate (29.9978733);
369         film->set_video_frame_rate (30);
370         player->setup_pieces ();
371         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
372         piece = player->_pieces.front ();
373         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
374         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (3200)), 1);
375         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (6400)), 2);
376         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (9600)), 3);
377         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (12800)), 4);
378
379 }
380
381 /** Test Player::content_video_to_dcp */
382 BOOST_AUTO_TEST_CASE (player_time_calculation_test2)
383 {
384         shared_ptr<Film> film = new_test_film ("player_time_calculation_test2");
385
386         shared_ptr<cxml::Document> doc = make_shared<cxml::Document> ();
387         doc->read_string (xml);
388
389         list<string> notes;
390         shared_ptr<FFmpegContent> content = boost::make_shared<FFmpegContent> (film, doc, film->state_version(), notes);
391         film->set_sequence (false);
392         film->add_content (content);
393
394         shared_ptr<Player> player = make_shared<Player> (film, film->playlist ());
395
396         /* Position 0, no trim, content rate = DCP rate */
397         content->set_position (DCPTime ());
398         content->set_trim_start (ContentTime ());
399         content->set_video_frame_rate (24);
400         film->set_video_frame_rate (24);
401         player->setup_pieces ();
402         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
403         shared_ptr<Piece> piece = player->_pieces.front ();
404         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime ());
405         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 12), DCPTime::from_seconds (0.5));
406         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 72), DCPTime::from_seconds (3.0));
407
408         /* Position 3s, no trim, content rate = DCP rate */
409         content->set_position (DCPTime::from_seconds (3));
410         content->set_trim_start (ContentTime ());
411         content->set_video_frame_rate (24);
412         film->set_video_frame_rate (24);
413         player->setup_pieces ();
414         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
415         piece = player->_pieces.front ();
416         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime::from_seconds (3.00));
417         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 36), DCPTime::from_seconds (4.50));
418         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 162), DCPTime::from_seconds (9.75));
419
420         /* Position 3s, 1.5s trim, content rate = DCP rate */
421         content->set_position (DCPTime::from_seconds (3));
422         content->set_trim_start (ContentTime::from_seconds (1.5));
423         content->set_video_frame_rate (24);
424         film->set_video_frame_rate (24);
425         player->setup_pieces ();
426         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
427         piece = player->_pieces.front ();
428         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime::from_seconds (1.50));
429         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 36), DCPTime::from_seconds (3.00));
430         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 72), DCPTime::from_seconds (4.50));
431         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 198), DCPTime::from_seconds (9.75));
432
433         /* Position 0, no trim, content rate 24, DCP rate 25.
434            Now, for example, a DCPTime position of 3s means 3s at 25fps.  Since we run the video
435            fast (at 25fps) in this case, this means 75 frames of content video will be used.
436         */
437         content->set_position (DCPTime ());
438         content->set_trim_start (ContentTime ());
439         content->set_video_frame_rate (24);
440         film->set_video_frame_rate (25);
441         player->setup_pieces ();
442         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
443         piece = player->_pieces.front ();
444         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime ());
445         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 15), DCPTime::from_seconds (0.6));
446         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 75), DCPTime::from_seconds (3.0));
447
448         /* Position 3s, no trim, content rate 24, DCP rate 25 */
449         content->set_position (DCPTime::from_seconds (3));
450         content->set_trim_start (ContentTime ());
451         content->set_video_frame_rate (24);
452         film->set_video_frame_rate (25);
453         player->setup_pieces ();
454         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
455         piece = player->_pieces.front ();
456         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime::from_seconds (3.00));
457         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 40), DCPTime::from_seconds (4.60));
458         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 169), DCPTime::from_seconds (9.76));
459
460         /* Position 3s, 1.6s trim, content rate 24, DCP rate 25, so the 1.6s trim is at 24fps */
461         content->set_position (DCPTime::from_seconds (3));
462         content->set_trim_start (ContentTime::from_seconds (1.6));
463         content->set_video_frame_rate (24);
464         film->set_video_frame_rate (25);
465         player->setup_pieces ();
466         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
467         piece = player->_pieces.front ();
468         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime::from_seconds (1.464));
469         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 40), DCPTime::from_seconds (3.064));
470         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 80), DCPTime::from_seconds (4.664));
471         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 209), DCPTime::from_seconds (9.824));
472
473         /* Position 0, no trim, content rate 24, DCP rate 48
474            Now, for example, a DCPTime position of 3s means 3s at 48fps.  Since we run the video
475            with repeated frames in this case, 3 * 24 frames of content video will
476            be used to make 3 * 48 frames of DCP video.  The results should be the same as the
477            content rate = DCP rate case.
478         */
479         content->set_position (DCPTime ());
480         content->set_trim_start (ContentTime ());
481         content->set_video_frame_rate (24);
482         film->set_video_frame_rate (48);
483         player->setup_pieces ();
484         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
485         piece = player->_pieces.front ();
486         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime ());
487         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 12), DCPTime::from_seconds (0.5));
488         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 72), DCPTime::from_seconds (3.0));
489
490         /* Position 3s, no trim, content rate 24, DCP rate 48 */
491         content->set_position (DCPTime::from_seconds (3));
492         content->set_trim_start (ContentTime ());
493         content->set_video_frame_rate (24);
494         film->set_video_frame_rate (48);
495         player->setup_pieces ();
496         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
497         piece = player->_pieces.front ();
498         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime::from_seconds (3.00));
499         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 36), DCPTime::from_seconds (4.50));
500         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 162), DCPTime::from_seconds (9.75));
501
502         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
503         content->set_position (DCPTime::from_seconds (3));
504         content->set_trim_start (ContentTime::from_seconds (1.5));
505         content->set_video_frame_rate (24);
506         film->set_video_frame_rate (48);
507         player->setup_pieces ();
508         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
509         piece = player->_pieces.front ();
510         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime::from_seconds (1.50));
511         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 36), DCPTime::from_seconds (3.00));
512         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 72), DCPTime::from_seconds (4.50));
513         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 198), DCPTime::from_seconds (9.75));
514
515         /* Position 0, no trim, content rate 48, DCP rate 24
516            Now, for example, a DCPTime position of 3s means 3s at 24fps.  Since we run the video
517            with skipped frames in this case, 3 * 48 frames of content video will
518            be used to make 3 * 24 frames of DCP video.
519         */
520         content->set_position (DCPTime ());
521         content->set_trim_start (ContentTime ());
522         content->set_video_frame_rate (48);
523         film->set_video_frame_rate (24);
524         player->setup_pieces ();
525         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
526         piece = player->_pieces.front ();
527         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime ());
528         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 24), DCPTime::from_seconds (0.5));
529         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 144), DCPTime::from_seconds (3.0));
530
531         /* Position 3s, no trim, content rate 24, DCP rate 48 */
532         content->set_position (DCPTime::from_seconds (3));
533         content->set_trim_start (ContentTime ());
534         content->set_video_frame_rate (48);
535         film->set_video_frame_rate (24);
536         player->setup_pieces ();
537         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
538         piece = player->_pieces.front ();
539         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime::from_seconds (3.00));
540         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 72), DCPTime::from_seconds (4.50));
541         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 324), DCPTime::from_seconds (9.75));
542
543         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
544         content->set_position (DCPTime::from_seconds (3));
545         content->set_trim_start (ContentTime::from_seconds (1.5));
546         content->set_video_frame_rate (48);
547         film->set_video_frame_rate (24);
548         player->setup_pieces ();
549         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
550         piece = player->_pieces.front ();
551         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0), DCPTime::from_seconds (1.50));
552         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 72), DCPTime::from_seconds (3.00));
553         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 144), DCPTime::from_seconds (4.50));
554         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 396), DCPTime::from_seconds (9.75));
555 }
556
557 /** Test Player::dcp_to_content_audio */
558 BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
559 {
560         shared_ptr<Film> film = new_test_film ("player_time_calculation_test3");
561
562         shared_ptr<cxml::Document> doc = make_shared<cxml::Document> ();
563         doc->read_string (xml);
564
565         list<string> notes;
566         shared_ptr<FFmpegContent> content = boost::make_shared<FFmpegContent> (film, doc, film->state_version(), notes);
567         AudioStreamPtr stream = content->audio->streams().front();
568         film->set_sequence (false);
569         film->add_content (content);
570
571         shared_ptr<Player> player = make_shared<Player> (film, film->playlist ());
572
573         /* Position 0, no trim, video/audio content rate = video/audio DCP rate */
574         content->set_position (DCPTime ());
575         content->set_trim_start (ContentTime ());
576         content->set_video_frame_rate (24);
577         film->set_video_frame_rate (24);
578         stream->_frame_rate = 48000;
579         player->setup_pieces ();
580         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
581         shared_ptr<Piece> piece = player->_pieces.front ();
582         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
583         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
584         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
585
586         /* Position 3s, no trim, video/audio content rate = video/audio DCP rate */
587         content->set_position (DCPTime::from_seconds (3));
588         content->set_trim_start (ContentTime ());
589         content->set_video_frame_rate (24);
590         film->set_video_frame_rate (24);
591         stream->_frame_rate = 48000;
592         player->setup_pieces ();
593         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
594         piece = player->_pieces.front ();
595         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
596         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
597         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
598         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
599         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
600
601         /* Position 3s, 1.5s trim, video/audio content rate = video/audio DCP rate */
602         content->set_position (DCPTime::from_seconds (3));
603         content->set_trim_start (ContentTime::from_seconds (1.5));
604         content->set_video_frame_rate (24);
605         film->set_video_frame_rate (24);
606         stream->_frame_rate = 48000;
607         player->setup_pieces ();
608         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
609         piece = player->_pieces.front ();
610         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
611         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
612         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
613         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
614         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
615
616         /* Position 0, no trim, content video rate 24, DCP video rate 25, both audio rates still 48k */
617         content->set_position (DCPTime ());
618         content->set_trim_start (ContentTime ());
619         content->set_video_frame_rate (24);
620         film->set_video_frame_rate (25);
621         stream->_frame_rate = 48000;
622         player->setup_pieces ();
623         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
624         piece = player->_pieces.front ();
625         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
626         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.6)),  28800);
627         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
628
629         /* Position 3s, no trim, content video rate 24, DCP rate 25, both audio rates still 48k. */
630         content->set_position (DCPTime::from_seconds (3));
631         content->set_trim_start (ContentTime ());
632         content->set_video_frame_rate (24);
633         film->set_video_frame_rate (25);
634         stream->_frame_rate = 48000;
635         player->setup_pieces ();
636         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
637         piece = player->_pieces.front ();
638         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
639         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.60)),      0);
640         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
641         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.60)),  76800);
642         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
643
644         /* Position 3s, 1.6s trim, content rate 24, DCP rate 25, both audio rates still 48k.
645            1s of content is 46080 samples after resampling.
646         */
647         content->set_position (DCPTime::from_seconds (3));
648         content->set_trim_start (ContentTime::from_seconds (1.6));
649         content->set_video_frame_rate (24);
650         film->set_video_frame_rate (25);
651         stream->_frame_rate = 48000;
652         player->setup_pieces ();
653         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
654         piece = player->_pieces.front ();
655         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
656         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.60)),      0);
657         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  73728);
658         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.60)), 150528);
659         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 397728);
660
661         /* Position 0, no trim, content rate 24, DCP rate 48, both audio rates still 48k.
662            Now, for example, a DCPTime position of 3s means 3s at 48fps.  Since we run the video
663            with repeated frames in this case, audio samples will map straight through.
664            The results should be the same as the content rate = DCP rate case.
665         */
666         content->set_position (DCPTime ());
667         content->set_trim_start (ContentTime ());
668         content->set_video_frame_rate (24);
669         film->set_video_frame_rate (48);
670         stream->_frame_rate = 48000;
671         player->setup_pieces ();
672         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
673         piece = player->_pieces.front ();
674         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
675         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
676         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
677
678         /* Position 3s, no trim, content rate 24, DCP rate 48 */
679         content->set_position (DCPTime::from_seconds (3));
680         content->set_trim_start (ContentTime ());
681         content->set_video_frame_rate (24);
682         film->set_video_frame_rate (24);
683         stream->_frame_rate = 48000;
684         player->setup_pieces ();
685         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
686         piece = player->_pieces.front ();
687         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
688         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
689         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
690         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
691         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
692
693         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
694         content->set_position (DCPTime::from_seconds (3));
695         content->set_trim_start (ContentTime::from_seconds (1.5));
696         content->set_video_frame_rate (24);
697         film->set_video_frame_rate (24);
698         stream->_frame_rate = 48000;
699         player->setup_pieces ();
700         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
701         piece = player->_pieces.front ();
702         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
703         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),   0);
704         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
705         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
706         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
707
708         /* Position 0, no trim, content rate 48, DCP rate 24
709            Now, for example, a DCPTime position of 3s means 3s at 24fps.  Since we run the video
710            with skipped frames in this case, audio samples should map straight through.
711         */
712         content->set_position (DCPTime ());
713         content->set_trim_start (ContentTime ());
714         content->set_video_frame_rate (24);
715         film->set_video_frame_rate (48);
716         stream->_frame_rate = 48000;
717         player->setup_pieces ();
718         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
719         piece = player->_pieces.front ();
720         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
721         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
722         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
723
724         /* Position 3s, no trim, content rate 24, DCP rate 48 */
725         content->set_position (DCPTime::from_seconds (3));
726         content->set_trim_start (ContentTime ());
727         content->set_video_frame_rate (24);
728         film->set_video_frame_rate (24);
729         stream->_frame_rate = 48000;
730         player->setup_pieces ();
731         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
732         piece = player->_pieces.front ();
733         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
734         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
735         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
736         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
737         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
738
739         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
740         content->set_position (DCPTime::from_seconds (3));
741         content->set_trim_start (ContentTime::from_seconds (1.5));
742         content->set_video_frame_rate (24);
743         film->set_video_frame_rate (24);
744         stream->_frame_rate = 48000;
745         player->setup_pieces ();
746         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
747         piece = player->_pieces.front ();
748         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
749         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),   0);
750         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
751         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
752         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
753
754         /* Position 0, no trim, video content rate = video DCP rate, content audio rate = 44.1k */
755         content->set_position (DCPTime ());
756         content->set_trim_start (ContentTime ());
757         content->set_video_frame_rate (24);
758         film->set_video_frame_rate (24);
759         stream->_frame_rate = 44100;
760         player->setup_pieces ();
761         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
762         piece = player->_pieces.front ();
763         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
764         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
765         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
766
767         /* Position 3s, no trim, video content rate = video DCP rate, content audio rate = 44.1k */
768         content->set_position (DCPTime::from_seconds (3));
769         content->set_trim_start (ContentTime ());
770         content->set_video_frame_rate (24);
771         film->set_video_frame_rate (24);
772         stream->_frame_rate = 44100;
773         player->setup_pieces ();
774         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
775         piece = player->_pieces.front ();
776         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
777         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
778         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
779         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
780         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
781
782         /* Position 3s, 1.5s trim, video content rate = video DCP rate, content audio rate = 44.1k */
783         content->set_position (DCPTime::from_seconds (3));
784         content->set_trim_start (ContentTime::from_seconds (1.5));
785         content->set_video_frame_rate (24);
786         film->set_video_frame_rate (24);
787         stream->_frame_rate = 44100;
788         player->setup_pieces ();
789         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
790         piece = player->_pieces.front ();
791         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
792         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
793         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
794         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
795         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
796
797         /* Check with a large start trim */
798         content->set_position (DCPTime::from_seconds (0));
799         content->set_trim_start (ContentTime::from_seconds (54143));
800         content->set_video_frame_rate (24);
801         film->set_video_frame_rate (24);
802         stream->_frame_rate = 48000;
803         player->setup_pieces ();
804         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
805         piece = player->_pieces.front ();
806         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 54143L * 48000);
807 }