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