Take Film pointer out of Content.
[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(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(film).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(film).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(film).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(film).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(film).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(film).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(film).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(film).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(film).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(film).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(film).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(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 (film, 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 (film, 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 (film, 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 (film, 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 (film, 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.  Note that trims are rounded to the nearest video frame, so
265            some of these results are not quite what you'd perhaps expect.
266          */
267         content->set_position (film, DCPTime::from_seconds(3));
268         content->set_trim_start (ContentTime::from_seconds (1.6));
269         content->set_video_frame_rate (24);
270         film->set_video_frame_rate (25);
271         player->setup_pieces ();
272         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
273         piece = player->_pieces.front ();
274         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
275         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.60)),   0);
276         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),  38);
277         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.60)),  78);
278         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 206);
279
280         /* Position 0, no trim, content rate 24, DCP rate 48
281            Now, for example, a DCPTime position of 3s means 3s at 48fps.  Since we run the video
282            with repeated frames in this case, 3 * 24 frames of content video will
283            be used to make 3 * 48 frames of DCP video.  The results should be the same as the
284            content rate = DCP rate case.
285         */
286         content->set_position (film, DCPTime());
287         content->set_trim_start (ContentTime ());
288         content->set_video_frame_rate (24);
289         film->set_video_frame_rate (48);
290         player->setup_pieces ();
291         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
292         piece = player->_pieces.front ();
293         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
294         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.5)), 12);
295         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.0)), 72);
296
297         /* Position 3s, no trim, content rate 24, DCP rate 48 */
298         content->set_position (film, DCPTime::from_seconds(3));
299         content->set_trim_start (ContentTime ());
300         content->set_video_frame_rate (24);
301         film->set_video_frame_rate (48);
302         player->setup_pieces ();
303         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
304         piece = player->_pieces.front ();
305         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
306         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.50)),   0);
307         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),   0);
308         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)),  36);
309         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 162);
310
311         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
312         content->set_position (film, DCPTime::from_seconds(3));
313         content->set_trim_start (ContentTime::from_seconds (1.5));
314         content->set_video_frame_rate (24);
315         film->set_video_frame_rate (48);
316         player->setup_pieces ();
317         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
318         piece = player->_pieces.front ();
319         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
320         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.50)),   0);
321         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),  36);
322         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)),  72);
323         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 198);
324
325         /* Position 0, no trim, content rate 48, DCP rate 24
326            Now, for example, a DCPTime position of 3s means 3s at 24fps.  Since we run the video
327            with skipped frames in this case, 3 * 48 frames of content video will
328            be used to make 3 * 24 frames of DCP video.
329         */
330         content->set_position (film, DCPTime());
331         content->set_trim_start (ContentTime ());
332         content->set_video_frame_rate (48);
333         film->set_video_frame_rate (24);
334         player->setup_pieces ();
335         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
336         piece = player->_pieces.front ();
337         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
338         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.5)), 24);
339         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.0)), 144);
340
341         /* Position 3s, no trim, content rate 24, DCP rate 48 */
342         content->set_position (film, DCPTime::from_seconds(3));
343         content->set_trim_start (ContentTime ());
344         content->set_video_frame_rate (48);
345         film->set_video_frame_rate (24);
346         player->setup_pieces ();
347         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
348         piece = player->_pieces.front ();
349         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
350         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.50)),   0);
351         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),   0);
352         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)),  72);
353         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 324);
354
355         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
356         content->set_position (film, DCPTime::from_seconds(3));
357         content->set_trim_start (ContentTime::from_seconds (1.5));
358         content->set_video_frame_rate (48);
359         film->set_video_frame_rate (24);
360         player->setup_pieces ();
361         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
362         piece = player->_pieces.front ();
363         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
364         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (0.50)),   0);
365         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),  72);
366         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)), 144);
367         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 396);
368
369         /* Position 0s, no trim, content rate 29.9978733, DCP rate 30 */
370         content->set_position (film, DCPTime::from_seconds(0));
371         content->set_trim_start (ContentTime::from_seconds (0));
372         content->set_video_frame_rate (29.9978733);
373         film->set_video_frame_rate (30);
374         player->setup_pieces ();
375         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
376         piece = player->_pieces.front ();
377         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
378         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (3200)), 1);
379         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (6400)), 2);
380         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (9600)), 3);
381         BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (12800)), 4);
382
383 }
384
385 /** Test Player::content_video_to_dcp */
386 BOOST_AUTO_TEST_CASE (player_time_calculation_test2)
387 {
388         shared_ptr<Film> film = new_test_film ("player_time_calculation_test2");
389
390         shared_ptr<cxml::Document> doc (new cxml::Document);
391         doc->read_string (xml);
392
393         list<string> notes;
394         shared_ptr<FFmpegContent> content (new FFmpegContent(doc, film->state_version(), notes));
395         film->set_sequence (false);
396         film->add_content (content);
397
398         shared_ptr<Player> player (new Player (film, film->playlist ()));
399
400         /* Position 0, no trim, content rate = DCP rate */
401         content->set_position (film, DCPTime());
402         content->set_trim_start (ContentTime ());
403         content->set_video_frame_rate (24);
404         film->set_video_frame_rate (24);
405         player->setup_pieces ();
406         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
407         shared_ptr<Piece> piece = player->_pieces.front ();
408         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 0).get(), 0);
409         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 12).get(), DCPTime::from_seconds(0.5).get());
410         BOOST_CHECK_EQUAL (player->content_video_to_dcp (piece, 72).get(), DCPTime::from_seconds(3.0).get());
411
412         /* Position 3s, no trim, content rate = DCP rate */
413         content->set_position (film, DCPTime::from_seconds(3));
414         content->set_trim_start (ContentTime ());
415         content->set_video_frame_rate (24);
416         film->set_video_frame_rate (24);
417         player->setup_pieces ();
418         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
419         piece = player->_pieces.front ();
420         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 0).get(), DCPTime::from_seconds(3.00).get());
421         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 36).get(), DCPTime::from_seconds(4.50).get());
422         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 162).get(), DCPTime::from_seconds(9.75).get());
423
424         /* Position 3s, 1.5s trim, content rate = DCP rate */
425         content->set_position (film, DCPTime::from_seconds(3));
426         content->set_trim_start (ContentTime::from_seconds (1.5));
427         content->set_video_frame_rate (24);
428         film->set_video_frame_rate (24);
429         player->setup_pieces ();
430         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
431         piece = player->_pieces.front ();
432         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 0).get(), DCPTime::from_seconds(1.50).get());
433         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 36).get(), DCPTime::from_seconds(3.00).get());
434         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 72).get(), DCPTime::from_seconds(4.50).get());
435         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 198).get(), DCPTime::from_seconds(9.75).get());
436
437         /* Position 0, no trim, content rate 24, DCP rate 25.
438            Now, for example, a DCPTime position of 3s means 3s at 25fps.  Since we run the video
439            fast (at 25fps) in this case, this means 75 frames of content video will be used.
440         */
441         content->set_position (film, DCPTime());
442         content->set_trim_start (ContentTime ());
443         content->set_video_frame_rate (24);
444         film->set_video_frame_rate (25);
445         player->setup_pieces ();
446         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
447         piece = player->_pieces.front ();
448         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 0).get(), 0);
449         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 15).get(), DCPTime::from_seconds(0.6).get());
450         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 75).get(), DCPTime::from_seconds(3.0).get());
451
452         /* Position 3s, no trim, content rate 24, DCP rate 25 */
453         content->set_position (film, DCPTime::from_seconds(3));
454         content->set_trim_start (ContentTime ());
455         content->set_video_frame_rate (24);
456         film->set_video_frame_rate (25);
457         player->setup_pieces ();
458         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
459         piece = player->_pieces.front ();
460         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 0).get(), DCPTime::from_seconds(3.00).get());
461         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 40).get(), DCPTime::from_seconds(4.60).get());
462         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 169).get(), DCPTime::from_seconds(9.76).get());
463
464         /* Position 3s, 1.6s trim, content rate 24, DCP rate 25, so the 1.6s trim is at 24fps */
465         content->set_position (film, DCPTime::from_seconds(3));
466         content->set_trim_start (ContentTime::from_seconds (1.6));
467         content->set_video_frame_rate (24);
468         film->set_video_frame_rate (25);
469         player->setup_pieces ();
470         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
471         piece = player->_pieces.front ();
472         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 0).get(), 142080);
473         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 40).get(), 295680);
474         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 80).get(), 449280);
475         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 209).get(), 944640);
476
477         /* Position 0, no trim, content rate 24, DCP rate 48
478            Now, for example, a DCPTime position of 3s means 3s at 48fps.  Since we run the video
479            with repeated frames in this case, 3 * 24 frames of content video will
480            be used to make 3 * 48 frames of DCP video.  The results should be the same as the
481            content rate = DCP rate case.
482         */
483         content->set_position (film, DCPTime());
484         content->set_trim_start (ContentTime ());
485         content->set_video_frame_rate (24);
486         film->set_video_frame_rate (48);
487         player->setup_pieces ();
488         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
489         piece = player->_pieces.front ();
490         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 0).get(), 0);
491         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 12).get(), DCPTime::from_seconds(0.5).get());
492         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 72).get(), DCPTime::from_seconds(3.0).get());
493
494         /* Position 3s, no trim, content rate 24, DCP rate 48 */
495         content->set_position (film, DCPTime::from_seconds(3));
496         content->set_trim_start (ContentTime ());
497         content->set_video_frame_rate (24);
498         film->set_video_frame_rate (48);
499         player->setup_pieces ();
500         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
501         piece = player->_pieces.front ();
502         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 0).get(), DCPTime::from_seconds(3.00).get());
503         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 36).get(), DCPTime::from_seconds(4.50).get());
504         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 162).get(), DCPTime::from_seconds(9.75).get());
505
506         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
507         content->set_position (film, DCPTime::from_seconds(3));
508         content->set_trim_start (ContentTime::from_seconds (1.5));
509         content->set_video_frame_rate (24);
510         film->set_video_frame_rate (48);
511         player->setup_pieces ();
512         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
513         piece = player->_pieces.front ();
514         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 0).get(), DCPTime::from_seconds(1.50).get());
515         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 36).get(), DCPTime::from_seconds(3.00).get());
516         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 72).get(), DCPTime::from_seconds(4.50).get());
517         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 198).get(), DCPTime::from_seconds(9.75).get());
518
519         /* Position 0, no trim, content rate 48, DCP rate 24
520            Now, for example, a DCPTime position of 3s means 3s at 24fps.  Since we run the video
521            with skipped frames in this case, 3 * 48 frames of content video will
522            be used to make 3 * 24 frames of DCP video.
523         */
524         content->set_position (film, DCPTime());
525         content->set_trim_start (ContentTime ());
526         content->set_video_frame_rate (48);
527         film->set_video_frame_rate (24);
528         player->setup_pieces ();
529         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
530         piece = player->_pieces.front ();
531         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 0).get(), 0);
532         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 24).get(), DCPTime::from_seconds(0.5).get());
533         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 144).get(), DCPTime::from_seconds(3.0).get());
534
535         /* Position 3s, no trim, content rate 24, DCP rate 48 */
536         content->set_position (film, DCPTime::from_seconds(3));
537         content->set_trim_start (ContentTime ());
538         content->set_video_frame_rate (48);
539         film->set_video_frame_rate (24);
540         player->setup_pieces ();
541         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
542         piece = player->_pieces.front ();
543         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 0).get(), DCPTime::from_seconds(3.00).get());
544         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 72).get(), DCPTime::from_seconds(4.50).get());
545         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 324).get(), DCPTime::from_seconds(9.75).get());
546
547         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
548         content->set_position (film, DCPTime::from_seconds(3));
549         content->set_trim_start (ContentTime::from_seconds (1.5));
550         content->set_video_frame_rate (48);
551         film->set_video_frame_rate (24);
552         player->setup_pieces ();
553         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
554         piece = player->_pieces.front ();
555         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 0).get(), DCPTime::from_seconds(1.50).get());
556         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 72).get(), DCPTime::from_seconds(3.00).get());
557         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 144).get(), DCPTime::from_seconds(4.50).get());
558         BOOST_CHECK_EQUAL (player->content_video_to_dcp(piece, 396).get(), DCPTime::from_seconds(9.75).get());
559 }
560
561 /** Test Player::dcp_to_content_audio */
562 BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
563 {
564         shared_ptr<Film> film = new_test_film ("player_time_calculation_test3");
565
566         shared_ptr<cxml::Document> doc (new cxml::Document);
567         doc->read_string (xml);
568
569         list<string> notes;
570         shared_ptr<FFmpegContent> content (new FFmpegContent(doc, film->state_version(), notes));
571         AudioStreamPtr stream = content->audio->streams().front();
572         film->set_sequence (false);
573         film->add_content (content);
574
575         shared_ptr<Player> player (new Player (film, film->playlist ()));
576
577         /* Position 0, no trim, video/audio content rate = video/audio DCP rate */
578         content->set_position (film, DCPTime());
579         content->set_trim_start (ContentTime ());
580         content->set_video_frame_rate (24);
581         film->set_video_frame_rate (24);
582         stream->_frame_rate = 48000;
583         player->setup_pieces ();
584         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
585         shared_ptr<Piece> piece = player->_pieces.front ();
586         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
587         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
588         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
589
590         /* Position 3s, no trim, video/audio content rate = video/audio DCP rate */
591         content->set_position (film, DCPTime::from_seconds (3));
592         content->set_trim_start (ContentTime ());
593         content->set_video_frame_rate (24);
594         film->set_video_frame_rate (24);
595         stream->_frame_rate = 48000;
596         player->setup_pieces ();
597         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
598         piece = player->_pieces.front ();
599         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
600         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
601         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
602         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
603         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
604
605         /* Position 3s, 1.5s trim, video/audio content rate = video/audio DCP rate */
606         content->set_position (film, DCPTime::from_seconds (3));
607         content->set_trim_start (ContentTime::from_seconds (1.5));
608         content->set_video_frame_rate (24);
609         film->set_video_frame_rate (24);
610         stream->_frame_rate = 48000;
611         player->setup_pieces ();
612         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
613         piece = player->_pieces.front ();
614         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
615         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
616         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
617         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
618         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
619
620         /* Position 0, no trim, content video rate 24, DCP video rate 25, both audio rates still 48k */
621         content->set_position (film, DCPTime());
622         content->set_trim_start (ContentTime ());
623         content->set_video_frame_rate (24);
624         film->set_video_frame_rate (25);
625         stream->_frame_rate = 48000;
626         player->setup_pieces ();
627         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
628         piece = player->_pieces.front ();
629         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
630         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.6)),  28800);
631         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
632
633         /* Position 3s, no trim, content video rate 24, DCP rate 25, both audio rates still 48k. */
634         content->set_position (film, DCPTime::from_seconds(3));
635         content->set_trim_start (ContentTime ());
636         content->set_video_frame_rate (24);
637         film->set_video_frame_rate (25);
638         stream->_frame_rate = 48000;
639         player->setup_pieces ();
640         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
641         piece = player->_pieces.front ();
642         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
643         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.60)),      0);
644         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
645         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.60)),  76800);
646         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
647
648         /* Position 3s, 1.6s trim, content rate 24, DCP rate 25, both audio rates still 48k.
649            1s of content is 46080 samples after resampling.
650         */
651         content->set_position (film, DCPTime::from_seconds(3));
652         content->set_trim_start (ContentTime::from_seconds (1.6));
653         content->set_video_frame_rate (24);
654         film->set_video_frame_rate (25);
655         stream->_frame_rate = 48000;
656         player->setup_pieces ();
657         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
658         piece = player->_pieces.front ();
659         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
660         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.60)),      0);
661         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72960);
662         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.60)), 149760);
663         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396960);
664
665         /* Position 0, no trim, content rate 24, DCP rate 48, both audio rates still 48k.
666            Now, for example, a DCPTime position of 3s means 3s at 48fps.  Since we run the video
667            with repeated frames in this case, audio samples will map straight through.
668            The results should be the same as the content rate = DCP rate case.
669         */
670         content->set_position (film, DCPTime());
671         content->set_trim_start (ContentTime ());
672         content->set_video_frame_rate (24);
673         film->set_video_frame_rate (48);
674         stream->_frame_rate = 48000;
675         player->setup_pieces ();
676         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
677         piece = player->_pieces.front ();
678         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
679         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
680         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
681
682         /* Position 3s, no trim, content rate 24, DCP rate 48 */
683         content->set_position (film, DCPTime::from_seconds(3));
684         content->set_trim_start (ContentTime ());
685         content->set_video_frame_rate (24);
686         film->set_video_frame_rate (24);
687         stream->_frame_rate = 48000;
688         player->setup_pieces ();
689         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
690         piece = player->_pieces.front ();
691         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
692         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
693         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
694         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
695         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
696
697         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
698         content->set_position (film, DCPTime::from_seconds(3));
699         content->set_trim_start (ContentTime::from_seconds (1.5));
700         content->set_video_frame_rate (24);
701         film->set_video_frame_rate (24);
702         stream->_frame_rate = 48000;
703         player->setup_pieces ();
704         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
705         piece = player->_pieces.front ();
706         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
707         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),   0);
708         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
709         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
710         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
711
712         /* Position 0, no trim, content rate 48, DCP rate 24
713            Now, for example, a DCPTime position of 3s means 3s at 24fps.  Since we run the video
714            with skipped frames in this case, audio samples should map straight through.
715         */
716         content->set_position (film, DCPTime());
717         content->set_trim_start (ContentTime ());
718         content->set_video_frame_rate (24);
719         film->set_video_frame_rate (48);
720         stream->_frame_rate = 48000;
721         player->setup_pieces ();
722         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
723         piece = player->_pieces.front ();
724         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
725         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
726         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
727
728         /* Position 3s, no trim, content rate 24, DCP rate 48 */
729         content->set_position (film, DCPTime::from_seconds(3));
730         content->set_trim_start (ContentTime ());
731         content->set_video_frame_rate (24);
732         film->set_video_frame_rate (24);
733         stream->_frame_rate = 48000;
734         player->setup_pieces ();
735         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
736         piece = player->_pieces.front ();
737         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
738         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
739         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
740         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
741         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
742
743         /* Position 3s, 1.5s trim, content rate 24, DCP rate 48 */
744         content->set_position (film, DCPTime::from_seconds(3));
745         content->set_trim_start (ContentTime::from_seconds (1.5));
746         content->set_video_frame_rate (24);
747         film->set_video_frame_rate (24);
748         stream->_frame_rate = 48000;
749         player->setup_pieces ();
750         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
751         piece = player->_pieces.front ();
752         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
753         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),   0);
754         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
755         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
756         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
757
758         /* Position 0, no trim, video content rate = video DCP rate, content audio rate = 44.1k */
759         content->set_position (film, DCPTime());
760         content->set_trim_start (ContentTime ());
761         content->set_video_frame_rate (24);
762         film->set_video_frame_rate (24);
763         stream->_frame_rate = 44100;
764         player->setup_pieces ();
765         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
766         piece = player->_pieces.front ();
767         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
768         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.5)),  24000);
769         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.0)), 144000);
770
771         /* Position 3s, no trim, video content rate = video DCP rate, content audio rate = 44.1k */
772         content->set_position (film, DCPTime::from_seconds(3));
773         content->set_trim_start (ContentTime ());
774         content->set_video_frame_rate (24);
775         film->set_video_frame_rate (24);
776         stream->_frame_rate = 44100;
777         player->setup_pieces ();
778         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
779         piece = player->_pieces.front ();
780         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
781         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
782         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),      0);
783         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)),  72000);
784         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
785
786         /* Position 3s, 1.5s trim, video content rate = video DCP rate, content audio rate = 44.1k */
787         content->set_position (film, DCPTime::from_seconds(3));
788         content->set_trim_start (ContentTime::from_seconds (1.5));
789         content->set_video_frame_rate (24);
790         film->set_video_frame_rate (24);
791         stream->_frame_rate = 44100;
792         player->setup_pieces ();
793         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
794         piece = player->_pieces.front ();
795         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
796         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
797         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
798         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
799         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
800
801         /* Check with a large start trim */
802         content->set_position (film, DCPTime::from_seconds(0));
803         content->set_trim_start (ContentTime::from_seconds (54143));
804         content->set_video_frame_rate (24);
805         film->set_video_frame_rate (24);
806         stream->_frame_rate = 48000;
807         player->setup_pieces ();
808         BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
809         piece = player->_pieces.front ();
810         BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 54143L * 48000);
811 }