Merge branch 'content-burn-subs' into 2.0
[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                 "<BurnSubtitles>0</BurnSubtitles>"
36                 "<Path>/home/c.hetherington/DCP/clapperboard.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                 "<Channels>2</Channels>"
87                 "<FirstAudio>0</FirstAudio>"
88                 "<Mapping>"
89                 "<InputChannels>2</InputChannels>"
90                 "<OutputChannels>12</OutputChannels>"
91                 "<Gain Input=\"0\" Output=\"0\">1</Gain>"
92                 "<Gain Input=\"0\" Output=\"1\">0</Gain>"
93                 "<Gain Input=\"0\" Output=\"2\">0</Gain>"
94                 "<Gain Input=\"0\" Output=\"3\">0</Gain>"
95                 "<Gain Input=\"0\" Output=\"4\">0</Gain>"
96                 "<Gain Input=\"0\" Output=\"5\">0</Gain>"
97                 "<Gain Input=\"0\" Output=\"6\">0</Gain>"
98                 "<Gain Input=\"0\" Output=\"7\">0</Gain>"
99                 "<Gain Input=\"0\" Output=\"8\">0</Gain>"
100                 "<Gain Input=\"0\" Output=\"9\">0</Gain>"
101                 "<Gain Input=\"0\" Output=\"10\">0</Gain>"
102                 "<Gain Input=\"0\" Output=\"11\">0</Gain>"
103                 "<Gain Input=\"1\" Output=\"0\">0</Gain>"
104                 "<Gain Input=\"1\" Output=\"1\">1</Gain>"
105                 "<Gain Input=\"1\" Output=\"2\">0</Gain>"
106                 "<Gain Input=\"1\" Output=\"3\">0</Gain>"
107                 "<Gain Input=\"1\" Output=\"4\">0</Gain>"
108                 "<Gain Input=\"1\" Output=\"5\">0</Gain>"
109                 "<Gain Input=\"1\" Output=\"6\">0</Gain>"
110                 "<Gain Input=\"1\" Output=\"7\">0</Gain>"
111                 "<Gain Input=\"1\" Output=\"8\">0</Gain>"
112                 "<Gain Input=\"1\" Output=\"9\">0</Gain>"
113                 "<Gain Input=\"1\" Output=\"10\">0</Gain>"
114                 "<Gain Input=\"1\" Output=\"11\">0</Gain>"
115                 "</Mapping>"
116                 "</AudioStream>"
117                 "<FirstVideo>0</FirstVideo>"
118                 "</Content>";
119
120         shared_ptr<cxml::Document> doc (new cxml::Document);
121         doc->read_string (xml);
122
123         list<string> notes;
124         shared_ptr<FFmpegContent> content (new FFmpegContent (film, doc, film->state_version(), notes));
125
126         /* 25fps content, 25fps DCP */
127         film->set_video_frame_rate (25);
128         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 25.0));
129         /* 25fps content, 24fps DCP; length should be increased */
130         film->set_video_frame_rate (24);
131         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 24.0));
132         /* 25fps content, 30fps DCP; length should be decreased */
133         film->set_video_frame_rate (30);
134         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 30.0));
135         /* 25fps content, 50fps DCP; length should be the same */
136         film->set_video_frame_rate (50);
137         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 25.0));
138         /* 25fps content, 60fps DCP; length should be decreased */
139         film->set_video_frame_rate (60);
140         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() * (50.0 / 60) / 25.0));
141 }
142
143 /* XXX much more stuff to test */