Move make_dcp() out of Film (#2132).
authorCarl Hetherington <cth@carlh.net>
Sat, 18 Dec 2021 13:23:50 +0000 (14:23 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 18 Dec 2021 13:23:50 +0000 (14:23 +0100)
12 files changed:
src/lib/film.cc
src/lib/film.h
src/lib/make_dcp.cc [new file with mode: 0644]
src/lib/make_dcp.h [new file with mode: 0644]
src/lib/wscript
src/tools/dcpomatic.cc
src/tools/dcpomatic_batch.cc
src/tools/dcpomatic_cli.cc
test/interrupt_encoder_test.cc
test/reels_test.cc
test/test.cc
test/threed_test.cc

index d0f0106c49b6fb0e2906b53468d76e3e71190e25..b58c530098f8ad82f05da1b11c6b9390c61a679d 100644 (file)
@@ -377,69 +377,6 @@ Film::subtitle_analysis_path (shared_ptr<const Content> content) const
 }
 
 
-/** Add suitable Jobs to the JobManager to create a DCP for this Film */
-void
-Film::make_dcp (TranscodeJob::ChangedBehaviour behaviour)
-{
-       if (dcp_name().find ("/") != string::npos) {
-               throw BadSettingError (_("name"), _("Cannot contain slashes"));
-       }
-
-       if (container() == nullptr) {
-               throw MissingSettingError (_("container"));
-       }
-
-       if (content().empty()) {
-               throw runtime_error (_("You must add some content to the DCP before creating it"));
-       }
-
-       if (length() == DCPTime()) {
-               throw runtime_error (_("The DCP is empty, perhaps because all the content has zero length."));
-       }
-
-       if (dcp_content_type() == nullptr) {
-               throw MissingSettingError (_("content type"));
-       }
-
-       if (name().empty()) {
-               set_name ("DCP");
-       }
-
-       for (auto i: content ()) {
-               if (!i->paths_valid()) {
-                       throw runtime_error (_("some of your content is missing"));
-               }
-               auto dcp = dynamic_pointer_cast<const DCPContent>(i);
-               if (dcp && dcp->needs_kdm()) {
-                       throw runtime_error (_("Some of your content needs a KDM"));
-               }
-               if (dcp && dcp->needs_assets()) {
-                       throw runtime_error (_("Some of your content needs an OV"));
-               }
-       }
-
-       set_isdcf_date_today ();
-
-       for (auto i: environment_info ()) {
-               LOG_GENERAL_NC (i);
-       }
-
-       for (auto i: content ()) {
-               LOG_GENERAL ("Content: %1", i->technical_summary());
-       }
-       LOG_GENERAL ("DCP video rate %1 fps", video_frame_rate());
-       if (Config::instance()->only_servers_encode ()) {
-               LOG_GENERAL_NC ("0 threads: ONLY SERVERS SET TO ENCODE");
-       } else {
-               LOG_GENERAL ("%1 threads", Config::instance()->master_encoding_threads());
-       }
-       LOG_GENERAL ("J2K bandwidth %1", j2k_bandwidth());
-
-       auto tj = make_shared<TranscodeJob>(shared_from_this(), behaviour);
-       tj->set_encoder (make_shared<DCPEncoder>(shared_from_this(), tj));
-       JobManager::instance()->add (tj);
-}
-
 /** Start a job to send our DCP to the configured TMS */
 void
 Film::send_dcp_to_tms ()
index 78a66e17f24d9903e65afcde30a259681bf2a77b..16f7d7f7907214cd05a699bca82fb6d6d95882dd 100644 (file)
@@ -112,7 +112,6 @@ public:
        boost::filesystem::path subtitle_analysis_path (std::shared_ptr<const Content>) const;
 
        void send_dcp_to_tms ();
-       void make_dcp (TranscodeJob::ChangedBehaviour behaviour);
 
        /** @return Logger.
         *  It is safe to call this from any thread.
diff --git a/src/lib/make_dcp.cc b/src/lib/make_dcp.cc
new file mode 100644 (file)
index 0000000..934387f
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+    Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "config.h"
+#include "dcp_content.h"
+#include "dcp_encoder.h"
+#include "dcpomatic_log.h"
+#include "environment_info.h"
+#include "film.h"
+#include "job_manager.h"
+#include "make_dcp.h"
+#include "transcode_job.h"
+#include <stdexcept>
+
+#include "i18n.h"
+
+
+using std::dynamic_pointer_cast;
+using std::make_shared;
+using std::runtime_error;
+using std::shared_ptr;
+using std::string;
+
+
+/** Add suitable Jobs to the JobManager to create a DCP for a Film */
+void
+make_dcp (shared_ptr<Film> film, TranscodeJob::ChangedBehaviour behaviour)
+{
+       if (film->dcp_name().find("/") != string::npos) {
+               throw BadSettingError (_("name"), _("Cannot contain slashes"));
+       }
+
+       if (film->container() == nullptr) {
+               throw MissingSettingError (_("container"));
+       }
+
+       if (film->content().empty()) {
+               throw runtime_error (_("You must add some content to the DCP before creating it"));
+       }
+
+       if (film->length() == dcpomatic::DCPTime()) {
+               throw runtime_error (_("The DCP is empty, perhaps because all the content has zero length."));
+       }
+
+       if (film->dcp_content_type() == nullptr) {
+               throw MissingSettingError (_("content type"));
+       }
+
+       if (film->name().empty()) {
+               film->set_name ("DCP");
+       }
+
+       for (auto i: film->content()) {
+               if (!i->paths_valid()) {
+                       throw runtime_error (_("Some of your content is missing"));
+               }
+               auto dcp = dynamic_pointer_cast<const DCPContent>(i);
+               if (dcp && dcp->needs_kdm()) {
+                       throw runtime_error (_("Some of your content needs a KDM"));
+               }
+               if (dcp && dcp->needs_assets()) {
+                       throw runtime_error (_("Some of your content needs an OV"));
+               }
+       }
+
+       film->set_isdcf_date_today ();
+
+       for (auto info: environment_info()) {
+               LOG_GENERAL_NC (info);
+       }
+
+       for (auto content: film->content()) {
+               LOG_GENERAL ("Content: %1", content->technical_summary());
+       }
+       LOG_GENERAL ("DCP video rate %1 fps", film->video_frame_rate());
+       if (Config::instance()->only_servers_encode()) {
+               LOG_GENERAL_NC ("0 threads: ONLY SERVERS SET TO ENCODE");
+       } else {
+               LOG_GENERAL ("%1 threads", Config::instance()->master_encoding_threads());
+       }
+       LOG_GENERAL ("J2K bandwidth %1", film->j2k_bandwidth());
+
+       auto tj = make_shared<TranscodeJob>(film, behaviour);
+       tj->set_encoder (make_shared<DCPEncoder>(film, tj));
+       JobManager::instance()->add (tj);
+}
+
diff --git a/src/lib/make_dcp.h b/src/lib/make_dcp.h
new file mode 100644 (file)
index 0000000..9f50727
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+    Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "transcode_job.h"
+
+
+class Film;
+
+
+void make_dcp (std::shared_ptr<Film> film, TranscodeJob::ChangedBehaviour behaviour);
+
index fd243db689afb0fef910ea73e1d7a42f0803fb06..7bc30e865d506736010e369102369e9a8014e68c 100644 (file)
@@ -131,6 +131,7 @@ sources = """
           kdm_recipient.cc
           log.cc
           log_entry.cc
+          make_dcp.cc
           mid_side_decoder.cc
           overlaps.cc
           pixel_quanta.cc
index e03b63400cba8f57ac8d72a4c0dfd1925697f1de..27df23ef03692ca049c46c73350ba191a5b3b91b 100644 (file)
  */
 
 
-#include "wx/standard_controls.h"
-#include "wx/film_viewer.h"
-#include "wx/film_editor.h"
-#include "wx/job_manager_view.h"
-#include "wx/full_config_dialog.h"
-#include "wx/wx_util.h"
-#include "wx/film_name_location_dialog.h"
-#include "wx/wx_signal_manager.h"
-#include "wx/recreate_chain_dialog.h"
 #include "wx/about_dialog.h"
-#include "wx/kdm_dialog.h"
-#include "wx/dkdm_dialog.h"
-#include "wx/self_dkdm_dialog.h"
-#include "wx/servers_list_dialog.h"
-#include "wx/hints_dialog.h"
-#include "wx/update_dialog.h"
 #include "wx/content_panel.h"
-#include "wx/report_problem_dialog.h"
-#include "wx/video_waveform_dialog.h"
-#include "wx/system_information_dialog.h"
-#include "wx/save_template_dialog.h"
-#include "wx/templates_dialog.h"
-#include "wx/nag_dialog.h"
+#include "wx/dkdm_dialog.h"
 #include "wx/export_subtitles_dialog.h"
 #include "wx/export_video_file_dialog.h"
-#include "wx/paste_dialog.h"
+#include "wx/film_editor.h"
+#include "wx/film_name_location_dialog.h"
+#include "wx/film_viewer.h"
 #include "wx/focus_manager.h"
+#include "wx/full_config_dialog.h"
+#include "wx/hints_dialog.h"
 #include "wx/html_dialog.h"
-#include "wx/send_i18n_dialog.h"
 #include "wx/i18n_hook.h"
-#include "lib/film.h"
+#include "wx/job_manager_view.h"
+#include "wx/kdm_dialog.h"
+#include "wx/nag_dialog.h"
+#include "wx/paste_dialog.h"
+#include "wx/recreate_chain_dialog.h"
+#include "wx/report_problem_dialog.h"
+#include "wx/save_template_dialog.h"
+#include "wx/self_dkdm_dialog.h"
+#include "wx/send_i18n_dialog.h"
+#include "wx/servers_list_dialog.h"
+#include "wx/standard_controls.h"
+#include "wx/system_information_dialog.h"
+#include "wx/templates_dialog.h"
+#include "wx/update_dialog.h"
+#include "wx/video_waveform_dialog.h"
+#include "wx/wx_signal_manager.h"
+#include "wx/wx_util.h"
 #include "lib/analytics.h"
-#include "lib/emailer.h"
+#include "lib/audio_content.h"
+#include "lib/check_content_change_job.h"
+#include "lib/cinema.h"
+#include "lib/compose.hpp"
 #include "lib/config.h"
-#include "lib/cross.h"
-#include "lib/util.h"
-#include "lib/video_content.h"
 #include "lib/content.h"
-#include "lib/version.h"
-#include "lib/signal_manager.h"
-#include "lib/log.h"
-#include "lib/screen.h"
-#include "lib/job_manager.h"
-#include "lib/exceptions.h"
-#include "lib/cinema.h"
-#include "lib/kdm_with_metadata.h"
-#include "lib/send_kdm_email_job.h"
-#include "lib/encode_server_finder.h"
-#include "lib/update_checker.h"
-#include "lib/cross.h"
 #include "lib/content_factory.h"
-#include "lib/compose.hpp"
-#include "lib/dcpomatic_socket.h"
-#include "lib/hints.h"
+#include "lib/cross.h"
+#include "lib/cross.h"
 #include "lib/dcp_content.h"
-#include "lib/ffmpeg_encoder.h"
-#include "lib/transcode_job.h"
-#include "lib/dkdm_wrapper.h"
-#include "lib/audio_content.h"
-#include "lib/check_content_change_job.h"
-#include "lib/text_content.h"
 #include "lib/dcpomatic_log.h"
+#include "lib/dcpomatic_socket.h"
+#include "lib/dkdm_wrapper.h"
+#include "lib/emailer.h"
+#include "lib/encode_server_finder.h"
+#include "lib/exceptions.h"
+#include "lib/ffmpeg_encoder.h"
+#include "lib/film.h"
+#include "lib/hints.h"
+#include "lib/job_manager.h"
+#include "lib/kdm_with_metadata.h"
+#include "lib/log.h"
+#include "lib/make_dcp.h"
+#include "lib/screen.h"
+#include "lib/send_kdm_email_job.h"
+#include "lib/signal_manager.h"
 #include "lib/subtitle_encoder.h"
+#include "lib/text_content.h"
+#include "lib/transcode_job.h"
+#include "lib/update_checker.h"
+#include "lib/util.h"
+#include "lib/version.h"
+#include "lib/video_content.h"
 #include "lib/warnings.h"
 #include <dcp/exceptions.h>
 #include <dcp/raw_convert.h>
 DCPOMATIC_DISABLE_WARNINGS
-#include <wx/generic/aboutdlgg.h>
-#include <wx/stdpaths.h>
 #include <wx/cmdline.h>
+#include <wx/generic/aboutdlgg.h>
 #include <wx/preferences.h>
 #include <wx/splash.h>
+#include <wx/stdpaths.h>
 #include <wx/wxhtml.h>
 DCPOMATIC_ENABLE_WARNINGS
 #ifdef __WXGTK__
@@ -104,8 +105,8 @@ DCPOMATIC_ENABLE_WARNINGS
 #ifdef __WXMSW__
 #include <shellapi.h>
 #endif
-#include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
+#include <boost/filesystem.hpp>
 #include <iostream>
 #include <fstream>
 /* This is OK as it's only used with DCPOMATIC_WINDOWS */
@@ -798,7 +799,7 @@ private:
                           a long time, and crashes/power failures are moderately likely.
                        */
                        _film->write_metadata ();
-                       _film->make_dcp (TranscodeJob::ChangedBehaviour::EXAMINE_THEN_STOP);
+                       make_dcp (_film, TranscodeJob::ChangedBehaviour::EXAMINE_THEN_STOP);
                } catch (BadSettingError& e) {
                        error_dialog (this, wxString::Format (_("Bad setting for %s."), std_to_wx(e.setting()).data()), std_to_wx(e.what()));
                } catch (std::exception& e) {
index 29f79ff080bf840276773c1159c12f3078c21fc1..2df60dd1d9e8158460bfc56c8e732f59f2a5ab9f 100644 (file)
@@ -32,6 +32,7 @@
 #include "lib/film.h"
 #include "lib/job.h"
 #include "lib/job_manager.h"
+#include "lib/make_dcp.h"
 #include "lib/transcode_job.h"
 #include "lib/util.h"
 #include "lib/version.h"
@@ -211,7 +212,7 @@ public:
                                }
                        }
 
-                       film->make_dcp (TranscodeJob::ChangedBehaviour::STOP);
+                       make_dcp (film, TranscodeJob::ChangedBehaviour::STOP);
                } catch (std::exception& e) {
                        auto p = std_to_wx (path.string ());
                        auto b = p.ToUTF8 ();
@@ -450,7 +451,7 @@ class App : public wxApp
                                try {
                                        film = make_shared<Film>(i);
                                        film->read_metadata ();
-                                       film->make_dcp (TranscodeJob::ChangedBehaviour::EXAMINE_THEN_STOP);
+                                       make_dcp (film, TranscodeJob::ChangedBehaviour::EXAMINE_THEN_STOP);
                                } catch (exception& e) {
                                        error_dialog (
                                                0,
index 95f2f40397ecf95c0d763948b784123f68d18a9b..96568f73babb35e4d0f45fde96af264066338d50 100644 (file)
 
 */
 
+#include "lib/audio_content.h"
+#include "lib/config.h"
+#include "lib/cross.h"
+#include "lib/dcpomatic_log.h"
+#include "lib/encode_server_finder.h"
 #include "lib/film.h"
 #include "lib/filter.h"
-#include "lib/transcode_job.h"
 #include "lib/job_manager.h"
-#include "lib/util.h"
-#include "lib/version.h"
-#include "lib/cross.h"
-#include "lib/config.h"
-#include "lib/log.h"
-#include "lib/signal_manager.h"
-#include "lib/encode_server_finder.h"
 #include "lib/json_server.h"
+#include "lib/log.h"
+#include "lib/make_dcp.h"
 #include "lib/ratio.h"
+#include "lib/signal_manager.h"
+#include "lib/transcode_job.h"
+#include "lib/util.h"
+#include "lib/version.h"
 #include "lib/video_content.h"
-#include "lib/audio_content.h"
-#include "lib/dcpomatic_log.h"
 #include <dcp/version.h>
 #include <getopt.h>
 #include <iostream>
@@ -355,7 +356,7 @@ main (int argc, char* argv[])
                cout << "\nMaking DCP for " << film->name() << "\n";
        }
 
-       film->make_dcp (check ? TranscodeJob::ChangedBehaviour::STOP : TranscodeJob::ChangedBehaviour::IGNORE);
+       make_dcp (film, check ? TranscodeJob::ChangedBehaviour::STOP : TranscodeJob::ChangedBehaviour::IGNORE);
        bool const error = show_jobs_on_console (progress);
 
        if (keep_going) {
index 5b76e67d357d44b347d4b347fdff954eb4e2f0c3..2e839336d9ec8458e8384922ff394d2a5e727d1c 100644 (file)
@@ -31,6 +31,7 @@
 #include "lib/ffmpeg_content.h"
 #include "lib/film.h"
 #include "lib/job_manager.h"
+#include "lib/make_dcp.h"
 #include "lib/ratio.h"
 #include "test.h"
 #include <boost/test/unit_test.hpp>
@@ -54,7 +55,7 @@ BOOST_AUTO_TEST_CASE (interrupt_encoder_test)
        film->examine_and_add_content (content);
        BOOST_REQUIRE (!wait_for_jobs());
 
-       film->make_dcp (TranscodeJob::ChangedBehaviour::IGNORE);
+       make_dcp (film, TranscodeJob::ChangedBehaviour::IGNORE);
 
        dcpomatic_sleep_seconds (10);
 
index db974d38463cb452148416fb81b6063b341e409e..82123b3e178d9680dd60c3b954236ef2d18a1094 100644 (file)
  */
 
 
-#include "lib/film.h"
-#include "lib/ratio.h"
+#include "lib/content_factory.h"
+#include "lib/dcp_content.h"
+#include "lib/dcp_content_type.h"
 #include "lib/ffmpeg_content.h"
+#include "lib/film.h"
 #include "lib/image_content.h"
-#include "lib/dcp_content_type.h"
-#include "lib/dcp_content.h"
-#include "lib/video_content.h"
+#include "lib/make_dcp.h"
+#include "lib/ratio.h"
 #include "lib/string_text_file_content.h"
-#include "lib/content_factory.h"
+#include "lib/video_content.h"
 #include "test.h"
 #include <boost/test/unit_test.hpp>
 #include <iostream>
 
 
-using std::list;
 using std::cout;
-using std::vector;
-using std::string;
-using std::shared_ptr;
-using std::make_shared;
 using std::function;
+using std::list;
+using std::make_shared;
+using std::shared_ptr;
+using std::string;
+using std::vector;
 using namespace dcpomatic;
 
 
@@ -564,7 +565,7 @@ BOOST_AUTO_TEST_CASE (reels_should_not_be_short4)
        BOOST_CHECK (film->reels().front() == dcpomatic::DCPTimePeriod(dcpomatic::DCPTime(), dcpomatic::DCPTime::from_frames(263, 24)));
 
        film->write_metadata ();
-       film->make_dcp (TranscodeJob::ChangedBehaviour::IGNORE);
+       make_dcp (film, TranscodeJob::ChangedBehaviour::IGNORE);
        BOOST_REQUIRE (!wait_for_jobs());
 
        vector<boost::filesystem::path> dirs = { film->dir(film->dcp_name(false)) };
index 7f868179067dde1893bd040d2a47acab10df3421..ae1453a9d3e6b3e309bafb0100788eedf8e99039 100644 (file)
@@ -38,6 +38,7 @@
 #include "lib/job.h"
 #include "lib/job_manager.h"
 #include "lib/log_entry.h"
+#include "lib/make_dcp.h"
 #include "lib/ratio.h"
 #include "lib/signal_manager.h"
 #include "lib/util.h"
@@ -887,7 +888,7 @@ void
 make_and_verify_dcp (shared_ptr<Film> film, vector<dcp::VerificationNote::Code> ignore)
 {
        film->write_metadata ();
-       film->make_dcp (TranscodeJob::ChangedBehaviour::IGNORE);
+       make_dcp (film, TranscodeJob::ChangedBehaviour::IGNORE);
        BOOST_REQUIRE (!wait_for_jobs());
        auto notes = dcp::verify ({film->dir(film->dcp_name())}, &stage, &progress, TestPaths::xsd());
        bool ok = true;
index bceb6700fe1d7bad834626dba3ea5569e1b73f1f..8523b56250d00cabe9d3c1e8523541d28db6372b 100644 (file)
@@ -33,6 +33,7 @@
 #include "lib/film.h"
 #include "lib/job.h"
 #include "lib/job_manager.h"
+#include "lib/make_dcp.h"
 #include "lib/ratio.h"
 #include "lib/video_content.h"
 #include "test.h"
@@ -186,7 +187,7 @@ BOOST_AUTO_TEST_CASE (threed_test7)
        c->video->set_length (24);
 
        film->set_three_d (true);
-       film->make_dcp (TranscodeJob::ChangedBehaviour::IGNORE);
+       make_dcp (film, TranscodeJob::ChangedBehaviour::IGNORE);
        film->write_metadata ();
 
        auto jm = JobManager::instance ();