Allow content factory to return multiple content.
[dcpomatic.git] / test / burnt_subtitle_test.cc
1 /*
2     Copyright (C) 2014-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/burnt_subtitle_test.cc
22  *  @brief Test the burning of subtitles into the DCP.
23  */
24
25 #include "lib/text_subtitle_content.h"
26 #include "lib/dcp_subtitle_content.h"
27 #include "lib/film.h"
28 #include "lib/ratio.h"
29 #include "lib/dcp_content_type.h"
30 #include "lib/subtitle_content.h"
31 #include "lib/content_factory.h"
32 #include "test.h"
33 #include <dcp/dcp.h>
34 #include <dcp/cpl.h>
35 #include <dcp/reel.h>
36 #include <dcp/j2k.h>
37 #include <dcp/mono_picture_asset.h>
38 #include <dcp/mono_picture_asset_reader.h>
39 #include <dcp/mono_picture_frame.h>
40 #include <dcp/openjpeg_image.h>
41 #include <dcp/reel_picture_asset.h>
42 #include <dcp/reel_mono_picture_asset.h>
43 #include <boost/test/unit_test.hpp>
44 #include <iostream>
45
46 using std::cout;
47 using std::map;
48 using boost::shared_ptr;
49 using boost::dynamic_pointer_cast;
50
51 /** Build a small DCP with no picture and a single subtitle overlaid onto it from a SubRip file */
52 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_subrip)
53 {
54         shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_subrip");
55         film->set_container (Ratio::from_id ("185"));
56         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
57         film->set_name ("frobozz");
58         shared_ptr<TextSubtitleContent> content (new TextSubtitleContent (film, "test/data/subrip2.srt"));
59         content->set_use_subtitles (true);
60         content->set_burn_subtitles (true);
61         film->examine_and_add_content (content, true);
62         wait_for_jobs ();
63         film->make_dcp ();
64         wait_for_jobs ();
65
66         check_dcp ("test/data/burnt_subtitle_test_subrip", film->dir (film->dcp_name ()));
67 }
68
69 /** Build a small DCP with no picture and a single subtitle overlaid onto it from a DCP XML file */
70 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_dcp)
71 {
72         shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_dcp");
73         film->set_container (Ratio::from_id ("185"));
74         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
75         film->set_name ("frobozz");
76         film->set_burn_subtitles (true);
77         shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent (film, "test/data/dcp_sub.xml"));
78         content->set_use_subtitles (true);
79         film->examine_and_add_content (content, true);
80         wait_for_jobs ();
81         film->make_dcp ();
82         wait_for_jobs ();
83
84         check_dcp ("test/data/burnt_subtitle_test_dcp", film->dir (film->dcp_name ()));
85 }
86
87 /** Burn some subtitles into an existing DCP to check the colour conversion */
88 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_onto_dcp)
89 {
90         shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_onto_dcp");
91         film->set_container (Ratio::from_id ("185"));
92         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
93         film->set_name ("frobozz");
94         film->examine_and_add_content (content_factory(film, "test/data/flat_white.png").front());
95         wait_for_jobs ();
96         film->make_dcp ();
97         wait_for_jobs ();
98
99         shared_ptr<Film> film2 = new_test_film ("burnt_subtitle_test_onto_dcp2");
100         film2->set_container (Ratio::from_id ("185"));
101         film2->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
102         film2->set_name ("frobozz");
103         film2->examine_and_add_content (content_factory(film2, film->dir (film->dcp_name ())).front());
104         shared_ptr<TextSubtitleContent> sub = dynamic_pointer_cast<TextSubtitleContent> (
105                 content_factory (film2, "test/data/subrip2.srt")
106                 );
107         sub->subtitle->set_burn (true);
108         sub->subtitle->set_outline (true);
109         film2->examine_and_add_content (sub);
110         wait_for_jobs ();
111         film2->make_dcp ();
112         wait_for_jobs ();
113
114         dcp::DCP dcp (film2->dir (film2->dcp_name ()));
115         dcp.read ();
116         BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1);
117         BOOST_REQUIRE_EQUAL (dcp.cpls().front()->reels().size(), 1);
118         BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture());
119         BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture()->asset());
120         shared_ptr<const dcp::MonoPictureAsset> pic = dynamic_pointer_cast<dcp::ReelMonoPictureAsset> (
121                 dcp.cpls().front()->reels().front()->main_picture()
122                 )->mono_asset();
123         BOOST_REQUIRE (pic);
124         shared_ptr<const dcp::MonoPictureFrame> frame = pic->start_read()->get_frame (12);
125         shared_ptr<dcp::OpenJPEGImage> xyz = frame->xyz_image ();
126         BOOST_CHECK_EQUAL (xyz->size().width, 1998);
127         BOOST_CHECK_EQUAL (xyz->size().height, 1080);
128
129         /* XXX: check the output ... */
130 }