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