Some attempts to block referencing of DCPs when it is not possible.
[dcpomatic.git] / test / reels_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/ratio.h"
22 #include "lib/ffmpeg_content.h"
23 #include "lib/image_content.h"
24 #include "lib/dcp_content_type.h"
25 #include "lib/dcp_content.h"
26 #include "test.h"
27 #include <boost/test/unit_test.hpp>
28
29 using std::list;
30 using boost::shared_ptr;
31
32 /** Test Film::reels() */
33 BOOST_AUTO_TEST_CASE (reels_test1)
34 {
35         shared_ptr<Film> film = new_test_film ("reels_test1");
36         film->set_container (Ratio::from_id ("185"));
37         shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/test.mp4"));
38         film->examine_and_add_content (A);
39         shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/test.mp4"));
40         film->examine_and_add_content (B);
41         wait_for_jobs ();
42         BOOST_CHECK_EQUAL (A->full_length(), DCPTime (288000));
43
44         film->set_reel_type (REELTYPE_SINGLE);
45         list<DCPTimePeriod> r = film->reels ();
46         BOOST_CHECK_EQUAL (r.size(), 1);
47         BOOST_CHECK_EQUAL (r.front().from, DCPTime (0));
48         BOOST_CHECK_EQUAL (r.front().to, DCPTime (288000 * 2));
49
50         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
51         r = film->reels ();
52         BOOST_CHECK_EQUAL (r.size(), 2);
53         BOOST_CHECK_EQUAL (r.front().from, DCPTime (0));
54         BOOST_CHECK_EQUAL (r.front().to, DCPTime (288000));
55         BOOST_CHECK_EQUAL (r.back().from, DCPTime (288000));
56         BOOST_CHECK_EQUAL (r.back().to, DCPTime (288000 * 2));
57
58         film->set_j2k_bandwidth (100000000);
59         film->set_reel_type (REELTYPE_BY_LENGTH);
60         /* This is just over 2.5s at 100Mbit/s; should correspond to 60 frames */
61         film->set_reel_length (31253154);
62         r = film->reels ();
63         BOOST_CHECK_EQUAL (r.size(), 3);
64         list<DCPTimePeriod>::const_iterator i = r.begin ();
65         BOOST_CHECK_EQUAL (i->from, DCPTime (0));
66         BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (60, 24));
67         ++i;
68         BOOST_CHECK_EQUAL (i->from, DCPTime::from_frames (60, 24));
69         BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (120, 24));
70         ++i;
71         BOOST_CHECK_EQUAL (i->from, DCPTime::from_frames (120, 24));
72         BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (144, 24));
73 }
74
75 /** Make a short DCP with multi reels split by video content, then import
76  *  this into a new project and make a new DCP referencing it.
77  */
78 BOOST_AUTO_TEST_CASE (reels_test2)
79 {
80         shared_ptr<Film> film = new_test_film ("reels_test2");
81         film->set_name ("reels_test2");
82         film->set_container (Ratio::from_id ("185"));
83         film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
84
85         {
86                 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_red.png"));
87                 film->examine_and_add_content (c);
88                 wait_for_jobs ();
89                 c->set_video_length (24);
90         }
91
92         {
93                 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_green.png"));
94                 film->examine_and_add_content (c);
95                 wait_for_jobs ();
96                 c->set_video_length (24);
97         }
98
99         {
100                 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_blue.png"));
101                 film->examine_and_add_content (c);
102                 wait_for_jobs ();
103                 c->set_video_length (24);
104         }
105
106         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
107         wait_for_jobs ();
108
109         film->make_dcp ();
110         wait_for_jobs ();
111
112         check_dcp ("test/data/reels_test2", film->dir (film->dcp_name()));
113
114         shared_ptr<Film> film2 = new_test_film ("reels_test3");
115         film2->set_name ("reels_test3");
116         film2->set_container (Ratio::from_id ("185"));
117         film2->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
118         film2->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
119
120         shared_ptr<DCPContent> c (new DCPContent (film2, film->dir (film->dcp_name ())));
121         film2->examine_and_add_content (c);
122         wait_for_jobs ();
123
124         list<DCPTimePeriod> r = film2->reels ();
125         BOOST_CHECK_EQUAL (r.size(), 3);
126         list<DCPTimePeriod>::const_iterator i = r.begin ();
127         BOOST_CHECK_EQUAL (i->from, DCPTime (0));
128         BOOST_CHECK_EQUAL (i->to, DCPTime (96000));
129         ++i;
130         BOOST_CHECK_EQUAL (i->from, DCPTime (96000));
131         BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 2));
132         ++i;
133         BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 2));
134         BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 3));
135
136         c->set_reference_video (true);
137         c->set_reference_audio (true);
138
139         film2->make_dcp ();
140         wait_for_jobs ();
141 }