Supporters update.
[dcpomatic.git] / src / lib / make_dcp.cc
1 /*
2     Copyright (C) 2021 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
22 #include "config.h"
23 #include "dcp_content.h"
24 #include "dcp_encoder.h"
25 #include "dcp_transcode_job.h"
26 #include "dcpomatic_log.h"
27 #include "environment_info.h"
28 #include "film.h"
29 #include "job_manager.h"
30 #include "make_dcp.h"
31 #include <stdexcept>
32
33 #include "i18n.h"
34
35
36 using std::dynamic_pointer_cast;
37 using std::make_shared;
38 using std::runtime_error;
39 using std::shared_ptr;
40 using std::string;
41
42
43 /** Add suitable Jobs to the JobManager to create a DCP for a Film */
44 void
45 make_dcp (shared_ptr<Film> film, TranscodeJob::ChangedBehaviour behaviour)
46 {
47         if (film->dcp_name().find("/") != string::npos) {
48                 throw BadSettingError (_("name"), _("Cannot contain slashes"));
49         }
50
51         if (film->container() == nullptr) {
52                 throw MissingSettingError (_("container"));
53         }
54
55         if (film->content().empty()) {
56                 throw runtime_error (_("You must add some content to the DCP before creating it"));
57         }
58
59         if (film->length() == dcpomatic::DCPTime()) {
60                 throw runtime_error (_("The DCP is empty, perhaps because all the content has zero length."));
61         }
62
63         if (film->dcp_content_type() == nullptr) {
64                 throw MissingSettingError (_("content type"));
65         }
66
67         if (film->name().empty()) {
68                 film->set_name ("DCP");
69         }
70
71         for (auto i: film->content()) {
72                 if (!i->paths_valid()) {
73                         throw runtime_error (_("Some of your content is missing"));
74                 }
75                 auto dcp = dynamic_pointer_cast<const DCPContent>(i);
76                 if (dcp && dcp->needs_kdm()) {
77                         throw runtime_error (_("Some of your content needs a KDM"));
78                 }
79                 if (dcp && dcp->needs_assets()) {
80                         throw runtime_error (_("Some of your content needs an OV"));
81                 }
82         }
83
84         film->set_isdcf_date_today ();
85
86         for (auto info: environment_info()) {
87                 LOG_GENERAL_NC (info);
88         }
89
90         for (auto content: film->content()) {
91                 LOG_GENERAL ("Content: %1", content->technical_summary());
92         }
93         LOG_GENERAL ("DCP video rate %1 fps", film->video_frame_rate());
94         if (Config::instance()->only_servers_encode()) {
95                 LOG_GENERAL_NC ("0 threads: ONLY SERVERS SET TO ENCODE");
96         } else {
97                 LOG_GENERAL ("%1 threads", Config::instance()->master_encoding_threads());
98         }
99         LOG_GENERAL ("J2K bandwidth %1", film->j2k_bandwidth());
100
101         auto tj = make_shared<DCPTranscodeJob>(film, behaviour);
102         tj->set_encoder (make_shared<DCPEncoder>(film, tj));
103         JobManager::instance()->add (tj);
104 }
105