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