From: Carl Hetherington Date: Sun, 6 Dec 2015 23:43:42 +0000 (+0000) Subject: Basics of send-to-batch-converter; not tested on Windows nor OS X. X-Git-Tag: v2.6.6~3 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=9af73fe2b9ea2ef82d641d44a995c110f8e61693 Basics of send-to-batch-converter; not tested on Windows nor OS X. --- diff --git a/ChangeLog b/ChangeLog index a528350be..561c2bd68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-12-06 Carl Hetherington + + * Add menu option to send a project to the + batch converter (#770). + 2015-12-10 Carl Hetherington * Put ISDCF name subtitle language in lower case if all subs are diff --git a/src/lib/config.h b/src/lib/config.h index 7cc3cf7e4..664020a2a 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -471,7 +471,7 @@ private: /** default directory to put new films in */ boost::filesystem::path _default_directory; /** base port number to use for J2K encoding servers; - * this port and the one above it will be used. + * this port and the two above it will be used. */ int _server_port_base; /** true to broadcast on the `any' address to look for servers */ diff --git a/src/lib/cross.cc b/src/lib/cross.cc index 24abf2c0a..6398e3676 100644 --- a/src/lib/cross.cc +++ b/src/lib/cross.cc @@ -353,3 +353,29 @@ Waker::~Waker () IOPMAssertionRelease (_assertion_id); #endif } + +void +start_batch_converter (boost::filesystem::path dcpomatic) +{ +#if defined(DCPOMATIC_LINUX) || defined(DCPOMATIC_WINDOWS) + boost::filesystem::path batch = dcpomatic.parent_path() / "dcpomatic2_batch"; +#endif + +#ifdef DCPOMATIC_OSX + boost::filesystem::patch batch = dcpomatic.parent_path (); + batch = batch.parent_path (); // MacOS + batch = batch.parent_path (); // Contents + batch = batch.parent_path (); // DCP-o-matic.app + batch = batch.parent_path (); // Applications + batch /= "DCP-o-matic 2 Batch Converter.app" / "Contents" / "MacOS" / "dcpomatic2_batch"; +#endif + +#ifdef DCPOMATIC_LINUX + pid_t pid = fork (); + if (pid == 0) { + int const r = system (batch.string().c_str ()); + exit (WEXITSTATUS (r)); + } +#endif + +} diff --git a/src/lib/cross.h b/src/lib/cross.h index fee68cedc..4c9b93fde 100644 --- a/src/lib/cross.h +++ b/src/lib/cross.h @@ -46,6 +46,7 @@ extern boost::filesystem::path app_contents (); extern boost::filesystem::path shared_path (); extern FILE * fopen_boost (boost::filesystem::path, std::string); extern int dcpomatic_fseek (FILE *, int64_t, int); +extern void start_batch_converter (boost::filesystem::path dcpomatic); /** @class Waker * @brief A class which tries to keep the computer awake on various operating systems. diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index 0cd0bac33..16c7a08e5 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -55,7 +55,9 @@ #include "lib/content_factory.h" #include "lib/compose.hpp" #include "lib/cinema_kdms.h" +#include "lib/dcpomatic_socket.h" #include +#include #include #include #include @@ -88,6 +90,7 @@ using std::list; using std::exception; using boost::shared_ptr; using boost::dynamic_pointer_cast; +using dcp::raw_convert; class FilmChangedDialog { @@ -138,6 +141,7 @@ enum { ID_content_scale_to_fit_width = 100, ID_content_scale_to_fit_height, ID_jobs_make_dcp, + ID_jobs_make_dcp_batch, ID_jobs_make_kdms, ID_jobs_make_self_dkdm, ID_jobs_send_dcp_to_tms, @@ -204,6 +208,7 @@ public: Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::content_scale_to_fit_height, this), ID_content_scale_to_fit_height); Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_make_dcp, this), ID_jobs_make_dcp); Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_make_kdms, this), ID_jobs_make_kdms); + Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_make_dcp_batch, this), ID_jobs_make_dcp_batch); Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_make_self_dkdm, this), ID_jobs_make_self_dkdm); Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_send_dcp_to_tms, this), ID_jobs_send_dcp_to_tms); Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_show_dcp, this), ID_jobs_show_dcp); @@ -482,6 +487,44 @@ private: d->Destroy (); } + void jobs_make_dcp_batch () + { + if (!_film) { + return; + } + + _film->write_metadata (); + + /* i = 0; try to connect via socket + i = 1; try again, and then try to start the batch converter + i = 2; try again. + i = 3; try again. + */ + for (int i = 0; i < 4; ++i) { + try { + boost::asio::io_service io_service; + boost::asio::ip::tcp::resolver resolver (io_service); + boost::asio::ip::tcp::resolver::query query ("localhost", raw_convert (Config::instance()->server_port_base() + 2)); + boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve (query); + Socket socket (1); + socket.connect (*endpoint_iterator); + string s = _film->directory().string (); + socket.write (s.length() + 1); + socket.write ((uint8_t *) s.c_str(), s.length() + 1); + return; + } catch (...) { + } + + if (i == 1) { + start_batch_converter (wx_to_std (wxStandardPaths::Get().GetExecutablePath())); + } + + dcpomatic_sleep (1); + } + + error_dialog (this, _("Could not find batch converter.")); + } + void jobs_make_self_dkdm () { if (!_film) { @@ -750,6 +793,7 @@ private: wxMenu* jobs_menu = new wxMenu; add_item (jobs_menu, _("&Make DCP\tCtrl-M"), ID_jobs_make_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION); + add_item (jobs_menu, _("Make DCP in &batch converter\tCtrl-B"), ID_jobs_make_dcp_batch, NEEDS_FILM | NOT_DURING_DCP_CREATION); add_item (jobs_menu, _("Make &KDMs...\tCtrl-K"), ID_jobs_make_kdms, NEEDS_FILM); add_item (jobs_menu, _("Make DKDM for DCP-o-matic..."), ID_jobs_make_self_dkdm, NEEDS_FILM); add_item (jobs_menu, _("&Send DCP to TMS"), ID_jobs_send_dcp_to_tms, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL); diff --git a/src/tools/dcpomatic_batch.cc b/src/tools/dcpomatic_batch.cc index 7db05c0dd..677861c3d 100644 --- a/src/tools/dcpomatic_batch.cc +++ b/src/tools/dcpomatic_batch.cc @@ -29,14 +29,20 @@ #include "lib/util.h" #include "lib/film.h" #include "lib/job_manager.h" +#include "lib/dcpomatic_socket.h" #include #include #include #include #include +#include using std::exception; +using std::string; +using std::cout; using boost::shared_ptr; +using boost::thread; +using boost::scoped_array; static std::string film_to_load; @@ -118,6 +124,19 @@ public: Bind (wxEVT_SIZE, boost::bind (&DOMFrame::sized, this, _1)); } + void start_job (boost::filesystem::path path) + { + try { + shared_ptr film (new Film (path)); + film->read_metadata (); + film->make_dcp (); + } catch (std::exception& e) { + wxString p = std_to_wx (path.string ()); + wxCharBuffer b = p.ToUTF8 (); + error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), std_to_wx (e.what()).data())); + } + } + private: void sized (wxSizeEvent& ev) { @@ -207,15 +226,7 @@ private: } if (r == wxID_OK) { - try { - shared_ptr film (new Film (wx_to_std (c->GetPath ()))); - film->read_metadata (); - film->make_dcp (); - } catch (std::exception& e) { - wxString p = c->GetPath (); - wxCharBuffer b = p.ToUTF8 (); - error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), std_to_wx (e.what()).data())); - } + start_job (wx_to_std (c->GetPath ())); } _last_parent = boost::filesystem::path (wx_to_std (c->GetPath ())).parent_path (); @@ -234,6 +245,32 @@ static const wxCmdLineEntryDesc command_line_description[] = { { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 } }; +class JobServer : public Server +{ +public: + JobServer (DOMFrame* frame) + : Server (Config::instance()->server_port_base() + 2) + , _frame (frame) + {} + + void handle (shared_ptr socket) + { + try { + int const length = socket->read_uint32 (); + cout << "len=" << length << "\n"; + scoped_array buffer (new char[length]); + socket->read (reinterpret_cast (buffer.get()), length); + string s (buffer.get()); + _frame->start_job (s); + } catch (...) { + + } + } + +private: + DOMFrame* _frame; +}; + class App : public wxApp { bool OnInit () @@ -273,6 +310,9 @@ class App : public wxApp f->Maximize (); f->Show (); + JobServer* server = new JobServer (f); + new thread (boost::bind (&JobServer::run, server)); + signal_manager = new wxSignalManager (this); this->Bind (wxEVT_IDLE, boost::bind (&App::idle, this));