Basics of send-to-batch-converter; not tested on Windows nor OS X.
authorCarl Hetherington <cth@carlh.net>
Sun, 6 Dec 2015 23:43:42 +0000 (23:43 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 11 Dec 2015 11:56:50 +0000 (11:56 +0000)
ChangeLog
src/lib/config.h
src/lib/cross.cc
src/lib/cross.h
src/tools/dcpomatic.cc
src/tools/dcpomatic_batch.cc

index a528350be766d3c93e3d34c7bc058f6ebef9537c..561c2bd68dc52b9d6358b4fc196717bafd9552f6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-12-06  Carl Hetherington  <cth@carlh.net>
+
+       * Add menu option to send a project to the
+       batch converter (#770).
+
 2015-12-10  Carl Hetherington  <cth@carlh.net>
 
        * Put ISDCF name subtitle language in lower case if all subs are
index 7cc3cf7e4968ed7755b78c5dd5e553ca7c937778..664020a2a2fef500a257476bf0825d92375a02bc 100644 (file)
@@ -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 */
index 24abf2c0a99a64a74df01f814394f7417148a7cc..6398e36764be282f60b355fa06613f79c810f7bc 100644 (file)
@@ -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
+
+}
index fee68cedc6f05bf220d11b7b1307f43ed16e9b48..4c9b93fde2fed04feeed9edca6048c3927a9d3a4 100644 (file)
@@ -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.
index 0cd0bac330c85796ef1c00743aab78e4276eba00..16c7a08e5e1ef5100c39df55162f6a8fdce43fc1 100644 (file)
@@ -55,7 +55,9 @@
 #include "lib/content_factory.h"
 #include "lib/compose.hpp"
 #include "lib/cinema_kdms.h"
+#include "lib/dcpomatic_socket.h"
 #include <dcp/exceptions.h>
+#include <dcp/raw_convert.h>
 #include <wx/generic/aboutdlgg.h>
 #include <wx/stdpaths.h>
 #include <wx/cmdline.h>
@@ -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<string> (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);
index 7db05c0ddde0182489b889bdb88a99a64d3e0719..677861c3d4ae688dd58da8d759ae38c6583f3f4d 100644 (file)
 #include "lib/util.h"
 #include "lib/film.h"
 #include "lib/job_manager.h"
+#include "lib/dcpomatic_socket.h"
 #include <wx/aboutdlg.h>
 #include <wx/stdpaths.h>
 #include <wx/cmdline.h>
 #include <wx/preferences.h>
 #include <wx/wx.h>
+#include <iostream>
 
 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> 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> 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> socket)
+       {
+               try {
+                       int const length = socket->read_uint32 ();
+                       cout << "len=" << length << "\n";
+                       scoped_array<char> buffer (new char[length]);
+                       socket->read (reinterpret_cast<uint8_t*> (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));