Fix test.
[dcpomatic.git] / test / time_calculation_test.cc
1 /*
2     Copyright (C) 2015 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 "test.h"
23 #include <boost/test/unit_test.hpp>
24
25 using std::string;
26 using std::list;
27 using boost::shared_ptr;
28
29 BOOST_AUTO_TEST_CASE (ffmpeg_time_calculation_test)
30 {
31         shared_ptr<Film> film = new_test_film ("ffmpeg_time_calculation_test");
32
33         string const xml = "<Content>"
34                 "<Type>FFmpeg</Type>"
35                 "<Path>/home/c.hetherington/DCP/clapperboard.mp4</Path>"
36                 "<Digest>2760e03c7251480f7f02c01a907792673784335</Digest>"
37                 "<Position>0</Position>"
38                 "<TrimStart>0</TrimStart>"
39                 "<TrimEnd>0</TrimEnd>"
40                 "<VideoLength>1353600</VideoLength>"
41                 "<VideoWidth>1280</VideoWidth>"
42                 "<VideoHeight>720</VideoHeight>"
43                 "<VideoFrameRate>25</VideoFrameRate>"
44                 "<VideoFrameType>0</VideoFrameType>"
45                 "<LeftCrop>0</LeftCrop>"
46                 "<RightCrop>0</RightCrop>"
47                 "<TopCrop>0</TopCrop>"
48                 "<BottomCrop>0</BottomCrop>"
49                 "<Scale>"
50                 "<Ratio>178</Ratio>"
51                 "</Scale>"
52                 "<ColourConversion>"
53                 "<InputTransferFunction>"
54                 "<Type>ModifiedGamma</Type>"
55                 "<Power>2.222222222222222</Power>"
56                 "<Threshold>0.081</Threshold>"
57                 "<A>0.099</A>"
58                 "<B>4.5</B>"
59                 "</InputTransferFunction>"
60                 "<RedX>0.64</RedX>"
61                 "<RedY>0.33</RedY>"
62                 "<GreenX>0.3</GreenX>"
63                 "<GreenY>0.6</GreenY>"
64                 "<BlueX>0.15</BlueX>"
65                 "<BlueY>0.06</BlueY>"
66                 "<WhiteX>0.3127</WhiteX>"
67                 "<WhiteY>0.329</WhiteY>"
68                 "<OutputGamma>2.6</OutputGamma>"
69                 "</ColourConversion>"
70                 "<FadeIn>0</FadeIn>"
71                 "<FadeOut>0</FadeOut>"
72                 "<AudioGain>0</AudioGain>"
73                 "<AudioDelay>0</AudioDelay>"
74                 "<UseSubtitles>0</UseSubtitles>"
75                 "<SubtitleXOffset>0</SubtitleXOffset>"
76                 "<SubtitleYOffset>0</SubtitleYOffset>"
77                 "<SubtitleXScale>1</SubtitleXScale>"
78                 "<SubtitleYScale>1</SubtitleYScale>"
79                 "<SubtitleLanguage></SubtitleLanguage>"
80                 "<AudioStream>"
81                 "<Selected>1</Selected>"
82                 "<Name>und; 2 channels</Name>"
83                 "<Id>2</Id>"
84                 "<FrameRate>44100</FrameRate>"
85                 "<Channels>2</Channels>"
86                 "<FirstAudio>0</FirstAudio>"
87                 "<Mapping>"
88                 "<InputChannels>2</InputChannels>"
89                 "<OutputChannels>12</OutputChannels>"
90                 "<Gain Content=\"0\" DCP=\"0\">1</Gain>"
91                 "<Gain Content=\"0\" DCP=\"1\">0</Gain>"
92                 "<Gain Content=\"0\" DCP=\"2\">0</Gain>"
93                 "<Gain Content=\"0\" DCP=\"3\">0</Gain>"
94                 "<Gain Content=\"0\" DCP=\"4\">0</Gain>"
95                 "<Gain Content=\"0\" DCP=\"5\">0</Gain>"
96                 "<Gain Content=\"0\" DCP=\"6\">0</Gain>"
97                 "<Gain Content=\"0\" DCP=\"7\">0</Gain>"
98                 "<Gain Content=\"0\" DCP=\"8\">0</Gain>"
99                 "<Gain Content=\"0\" DCP=\"9\">0</Gain>"
100                 "<Gain Content=\"0\" DCP=\"10\">0</Gain>"
101                 "<Gain Content=\"0\" DCP=\"11\">0</Gain>"
102                 "<Gain Content=\"1\" DCP=\"0\">0</Gain>"
103                 "<Gain Content=\"1\" DCP=\"1\">1</Gain>"
104                 "<Gain Content=\"1\" DCP=\"2\">0</Gain>"
105                 "<Gain Content=\"1\" DCP=\"3\">0</Gain>"
106                 "<Gain Content=\"1\" DCP=\"4\">0</Gain>"
107                 "<Gain Content=\"1\" DCP=\"5\">0</Gain>"
108                 "<Gain Content=\"1\" DCP=\"6\">0</Gain>"
109                 "<Gain Content=\"1\" DCP=\"7\">0</Gain>"
110                 "<Gain Content=\"1\" DCP=\"8\">0</Gain>"
111                 "<Gain Content=\"1\" DCP=\"9\">0</Gain>"
112                 "<Gain Content=\"1\" DCP=\"10\">0</Gain>"
113                 "<Gain Content=\"1\" DCP=\"11\">0</Gain>"
114                 "</Mapping>"
115                 "</AudioStream>"
116                 "<FirstVideo>0</FirstVideo>"
117                 "</Content>";
118
119         shared_ptr<cxml::Document> doc (new cxml::Document);
120         doc->read_string (xml);
121
122         list<string> notes;
123         shared_ptr<FFmpegContent> content (new FFmpegContent (film, doc, film->state_version(), notes));
124
125         /* 25fps content, 25fps DCP */
126         film->set_video_frame_rate (25);
127         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 25.0));
128         /* 25fps content, 24fps DCP; length should be increased */
129         film->set_video_frame_rate (24);
130         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 24.0));
131         /* 25fps content, 30fps DCP; length should be decreased */
132         film->set_video_frame_rate (30);
133         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 30.0));
134         /* 25fps content, 50fps DCP; length should be the same */
135         film->set_video_frame_rate (50);
136         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 25.0));
137         /* 25fps content, 60fps DCP; length should be decreased */
138         film->set_video_frame_rate (60);
139         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() * (50.0 / 60) / 25.0));
140 }
141
142 /* XXX much more stuff to test */