Merge branch '1.0' of /home/carl/git/dvdomatic into 1.0
authorCarl Hetherington <cth@carlh.net>
Wed, 6 Nov 2013 16:38:00 +0000 (16:38 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 6 Nov 2013 16:38:00 +0000 (16:38 +0000)
src/lib/encoder.cc
src/lib/encoder.h
src/lib/server_finder.cc [new file with mode: 0644]
src/lib/server_finder.h [new file with mode: 0644]
src/lib/wscript
src/tools/dcpomatic.cc
src/tools/dcpomatic_cli.cc
src/wx/servers_list_dialog.cc [new file with mode: 0644]
src/wx/servers_list_dialog.h [new file with mode: 0644]
src/wx/wscript

index a442e64d07fffdea9efbb8320d537a3f4a8908e6..2ec32deb72e037bdb9d55dd2a2c35a9785787731 100644 (file)
@@ -33,6 +33,7 @@
 #include "server.h"
 #include "cross.h"
 #include "writer.h"
+#include "server_finder.h"
 
 #include "i18n.h"
 
@@ -56,8 +57,6 @@ Encoder::Encoder (shared_ptr<const Film> f, shared_ptr<Job> j)
        , _job (j)
        , _video_frames_out (0)
        , _terminate (false)
-       , _broadcast_thread (0)
-       , _listen_thread (0)
 {
        _have_a_real_frame[EYES_BOTH] = false;
        _have_a_real_frame[EYES_LEFT] = false;
@@ -104,10 +103,9 @@ Encoder::process_begin ()
                add_worker_threads (*i);
        }
 
-       _broadcast_thread = new boost::thread (boost::bind (&Encoder::broadcast_thread, this));
-       _listen_thread = new boost::thread (boost::bind (&Encoder::listen_thread, this));
-
        _writer.reset (new Writer (_film, _job));
+       _server_finder.reset (new ServerFinder ());
+       _server_finder->ServerFound.connect (boost::bind (&Encoder::server_found, this, _1));
 }
 
 
@@ -267,16 +265,6 @@ Encoder::terminate_threads ()
        }
 
        _threads.clear ();
-                    
-       if (_broadcast_thread && _broadcast_thread->joinable ()) {
-               _broadcast_thread->join ();
-       }
-       delete _broadcast_thread;
-
-       if (_listen_thread && _listen_thread->joinable ()) {
-               _listen_thread->join ();
-       }
-       delete _listen_thread;
 }
 
 void
@@ -364,76 +352,16 @@ Encoder::encoder_thread (optional<ServerDescription> server)
 }
 
 void
-Encoder::broadcast_thread ()
+Encoder::server_found (ServerDescription s)
 {
-       boost::system::error_code error;
-       boost::asio::io_service io_service;
-       boost::asio::ip::udp::socket socket (io_service);
-       socket.open (boost::asio::ip::udp::v4(), error);
-       if (error) {
-               throw NetworkError ("failed to set up broadcast socket");
+       /* See if we already know about this server */
+       boost::mutex::scoped_lock lm (_mutex);
+       ThreadList::iterator i = _threads.begin();
+       while (i != _threads.end() && (!i->first || i->first.get().host_name() != s.host_name())) {
+               ++i;
        }
-
-        socket.set_option (boost::asio::ip::udp::socket::reuse_address (true));
-        socket.set_option (boost::asio::socket_base::broadcast (true));
        
-        boost::asio::ip::udp::endpoint end_point (boost::asio::ip::address_v4::broadcast(), Config::instance()->server_port_base() + 1);            
-
-       while (1) {
-               boost::mutex::scoped_lock lm (_mutex);
-               if (_terminate) {
-                       socket.close (error);
-                       return;
-               }
-               
-               string data = DCPOMATIC_HELLO;
-               socket.send_to (boost::asio::buffer (data.c_str(), data.size() + 1), end_point);
-
-               lm.unlock ();
-               dcpomatic_sleep (10);
-       }
-}
-
-void
-Encoder::listen_thread ()
-{
-       while (1) {
-               {
-                       /* See if we need to stop */
-                       boost::mutex::scoped_lock lm (_mutex);
-                       if (_terminate) {
-                               return;
-                       }
-               }
-
-               shared_ptr<Socket> sock (new Socket (10));
-
-               try {
-                       sock->accept (Config::instance()->server_port_base() + 1);
-               } catch (std::exception& e) {
-                       continue;
-               }
-
-               uint32_t length = sock->read_uint32 ();
-               scoped_array<char> buffer (new char[length]);
-               sock->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
-               
-               stringstream s (buffer.get());
-               shared_ptr<cxml::Document> xml (new cxml::Document ("ServerAvailable"));
-               xml->read_stream (s);
-
-               {
-                       /* See if we already know about this server */
-                       string const ip = sock->socket().remote_endpoint().address().to_string ();
-                       boost::mutex::scoped_lock lm (_mutex);
-                       ThreadList::iterator i = _threads.begin();
-                       while (i != _threads.end() && (!i->first || i->first->host_name() != ip)) {
-                               ++i;
-                       }
-
-                       if (i == _threads.end ()) {
-                               add_worker_threads (ServerDescription (ip, xml->number_child<int> ("Threads")));
-                       }
-               }
+       if (i == _threads.end ()) {
+               add_worker_threads (s);
        }
 }
index 9fcba560f23085988ec4ca9ce8c51b8906ec5d68..902dae2d5e1f113ea8ebdaa0e9e4cb40a30a8779 100644 (file)
@@ -46,6 +46,7 @@ class DCPVideoFrame;
 class EncodedData;
 class Writer;
 class Job;
+class ServerFinder;
 
 /** @class Encoder
  *  @brief Encoder to J2K and WAV for DCP.
@@ -84,9 +85,8 @@ private:
        
        void encoder_thread (boost::optional<ServerDescription>);
        void terminate_threads ();
-       void broadcast_thread ();
-       void listen_thread ();
        void add_worker_threads (ServerDescription);
+       void server_found (ServerDescription);
 
        /** Film that we are encoding */
        boost::shared_ptr<const Film> _film;
@@ -113,10 +113,7 @@ private:
        boost::condition _condition;
 
        boost::shared_ptr<Writer> _writer;
-
-       /** A thread to periodically issue broadcasts to find encoding servers */
-       boost::thread* _broadcast_thread;
-       boost::thread* _listen_thread;
+       boost::shared_ptr<ServerFinder> _server_finder;
 };
 
 #endif
diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc
new file mode 100644 (file)
index 0000000..c0b554e
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <libcxml/cxml.h>
+#include "server_finder.h"
+#include "exceptions.h"
+#include "util.h"
+#include "config.h"
+#include "cross.h"
+#include "ui_signaller.h"
+
+using std::string;
+using std::stringstream;
+using boost::shared_ptr;
+using boost::scoped_array;
+
+ServerFinder::ServerFinder ()
+       : _broadcast_thread (0)
+       , _listen_thread (0)
+       , _terminate (false)
+{
+       _broadcast_thread = new boost::thread (boost::bind (&ServerFinder::broadcast_thread, this));
+       _listen_thread = new boost::thread (boost::bind (&ServerFinder::listen_thread, this));
+}
+
+ServerFinder::~ServerFinder ()
+{
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _terminate = true;
+       }
+       
+       if (_broadcast_thread && _broadcast_thread->joinable ()) {
+               _broadcast_thread->join ();
+       }
+       delete _broadcast_thread;
+
+       if (_listen_thread && _listen_thread->joinable ()) {
+               _listen_thread->join ();
+       }
+       delete _listen_thread;
+}
+
+void
+ServerFinder::broadcast_thread ()
+{
+       boost::system::error_code error;
+       boost::asio::io_service io_service;
+       boost::asio::ip::udp::socket socket (io_service);
+       socket.open (boost::asio::ip::udp::v4(), error);
+       if (error) {
+               throw NetworkError ("failed to set up broadcast socket");
+       }
+
+        socket.set_option (boost::asio::ip::udp::socket::reuse_address (true));
+        socket.set_option (boost::asio::socket_base::broadcast (true));
+       
+        boost::asio::ip::udp::endpoint end_point (boost::asio::ip::address_v4::broadcast(), Config::instance()->server_port_base() + 1);            
+
+       while (1) {
+               boost::mutex::scoped_lock lm (_mutex);
+               if (_terminate) {
+                       socket.close (error);
+                       return;
+               }
+               
+               string data = DCPOMATIC_HELLO;
+               socket.send_to (boost::asio::buffer (data.c_str(), data.size() + 1), end_point);
+
+               lm.unlock ();
+               dcpomatic_sleep (10);
+       }
+}
+
+void
+ServerFinder::listen_thread ()
+{
+       while (1) {
+               {
+                       /* See if we need to stop */
+                       boost::mutex::scoped_lock lm (_mutex);
+                       if (_terminate) {
+                               return;
+                       }
+               }
+
+               shared_ptr<Socket> sock (new Socket (10));
+
+               try {
+                       sock->accept (Config::instance()->server_port_base() + 1);
+               } catch (std::exception& e) {
+                       continue;
+               }
+
+               uint32_t length = sock->read_uint32 ();
+               scoped_array<char> buffer (new char[length]);
+               sock->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
+               
+               stringstream s (buffer.get());
+               shared_ptr<cxml::Document> xml (new cxml::Document ("ServerAvailable"));
+               xml->read_stream (s);
+
+               ui_signaller->emit (boost::bind (boost::ref (ServerFound), ServerDescription (
+                                                        sock->socket().remote_endpoint().address().to_string (),
+                                                        xml->number_child<int> ("Threads")
+                                                        )));
+       }
+}
diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h
new file mode 100644 (file)
index 0000000..8b56022
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/signals2.hpp>
+#include "server.h"
+
+class ServerFinder
+{
+public:
+       ServerFinder ();
+       ~ServerFinder ();
+
+       boost::signals2::signal<void (ServerDescription)> ServerFound;
+
+private:
+       void broadcast_thread ();
+       void listen_thread ();
+       
+       /** A thread to periodically issue broadcasts to find encoding servers */
+       boost::thread* _broadcast_thread;
+       boost::thread* _listen_thread;
+
+       bool _terminate;
+       boost::mutex _mutex;
+};
index f731795c760175b61354239ad5297410e38df0a2..852bb1aed57e60240b3b15adf0a578c5609b1f8b 100644 (file)
@@ -44,6 +44,7 @@ sources = """
           scp_dcp_job.cc
           scaler.cc
           server.cc
+          server_finder.cc
           sndfile_content.cc
           sndfile_decoder.cc
           sound_processor.cc
index 4972654b27aabd28ed39674c0f672f2575f7c914..af620c5a2e93c487a10c1d5c3a6b922526abfe3c 100644 (file)
@@ -40,6 +40,7 @@
 #include "wx/wx_ui_signaller.h"
 #include "wx/about_dialog.h"
 #include "wx/kdm_dialog.h"
+#include "wx/servers_list_dialog.h"
 #include "lib/film.h"
 #include "lib/config.h"
 #include "lib/util.h"
@@ -180,6 +181,7 @@ enum {
        ID_jobs_make_kdms,
        ID_jobs_send_dcp_to_tms,
        ID_jobs_show_dcp,
+       ID_tools_encoding_servers,
 };
 
 void
@@ -216,6 +218,9 @@ setup_menu (wxMenuBar* m)
        add_item (jobs_menu, _("&Send DCP to TMS"), ID_jobs_send_dcp_to_tms, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_DCP);
        add_item (jobs_menu, _("S&how DCP"), ID_jobs_show_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_DCP);
 
+       wxMenu* tools = new wxMenu;
+       add_item (tools, _("Encoding Servers..."), ID_tools_encoding_servers, 0);
+
        wxMenu* help = new wxMenu;
 #ifdef __WXOSX__       
        add_item (help, _("About DCP-o-matic"), wxID_ABOUT, ALWAYS);
@@ -228,6 +233,7 @@ setup_menu (wxMenuBar* m)
        m->Append (edit, _("&Edit"));
 #endif 
        m->Append (jobs_menu, _("&Jobs"));
+       m->Append (tools, _("&Tools"));
        m->Append (help, _("&Help"));
 }
 
@@ -236,22 +242,24 @@ class Frame : public wxFrame
 public:
        Frame (wxString const & title)
                : wxFrame (NULL, -1, title)
+               , _servers_list_dialog (0)
        {
                wxMenuBar* bar = new wxMenuBar;
                setup_menu (bar);
                SetMenuBar (bar);
 
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_new, this),             ID_file_new);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_open, this),            ID_file_open);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_save, this),            ID_file_save);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_properties, this),      ID_file_properties);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_exit, this),            wxID_EXIT);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::edit_preferences, this),     wxID_PREFERENCES);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_dcp, this),        ID_jobs_make_dcp);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_kdms, this),       ID_jobs_make_kdms);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_send_dcp_to_tms, this), ID_jobs_send_dcp_to_tms);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_show_dcp, this),        ID_jobs_show_dcp);
-               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::help_about, this),           wxID_ABOUT);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_new, this),               ID_file_new);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_open, this),              ID_file_open);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_save, this),              ID_file_save);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_properties, this),        ID_file_properties);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::file_exit, this),              wxID_EXIT);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::edit_preferences, this),       wxID_PREFERENCES);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_dcp, this),          ID_jobs_make_dcp);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_kdms, this),         ID_jobs_make_kdms);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_send_dcp_to_tms, this),   ID_jobs_send_dcp_to_tms);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_show_dcp, this),          ID_jobs_show_dcp);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::tools_encoding_servers, this), ID_tools_encoding_servers);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::help_about, this),             wxID_ABOUT);
 
                Bind (wxEVT_CLOSE_WINDOW, boost::bind (&Frame::close, this, _1));
 
@@ -465,6 +473,15 @@ private:
 #endif         
        }
 
+       void tools_encoding_servers ()
+       {
+               if (!_servers_list_dialog) {
+                       _servers_list_dialog = new ServersListDialog (this);
+               }
+
+               _servers_list_dialog->Show ();
+       }
+
        void help_about ()
        {
                AboutDialog* d = new AboutDialog (this);
@@ -498,7 +515,9 @@ private:
                }
 
                ev.Skip ();
-       }       
+       }
+
+       ServersListDialog* _servers_list_dialog;
 };
 
 static const wxCmdLineEntryDesc command_line_description[] = {
index 01e08858ab95d73052f673533b1c7eb89e97a562..51248fde7f613c543db955ca60ca30eb75dbb4fa 100644 (file)
@@ -31,6 +31,7 @@
 #include "lib/cross.h"
 #include "lib/config.h"
 #include "lib/log.h"
+#include "lib/ui_signaller.h"
 
 using std::string;
 using std::cerr;
@@ -114,6 +115,7 @@ main (int argc, char* argv[])
        film_dir = argv[optind];
                        
        dcpomatic_setup ();
+       ui_signaller = new UISignaller ();
 
        if (no_remote) {
                Config::instance()->set_servers (vector<ServerDescription> ());
diff --git a/src/wx/servers_list_dialog.cc b/src/wx/servers_list_dialog.cc
new file mode 100644 (file)
index 0000000..49d91fc
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/lexical_cast.hpp>
+#include "servers_list_dialog.h"
+#include "wx_util.h"
+
+using std::list;
+using std::string;
+using boost::lexical_cast;
+
+ServersListDialog::ServersListDialog (wxWindow* parent)
+       : wxDialog (parent, wxID_ANY, _("Encoding Servers"))
+{
+       wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
+       SetSizer (s);
+       
+       _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (400, 200), wxLC_REPORT | wxLC_SINGLE_SEL);
+
+       {
+               wxListItem ip;
+               ip.SetId (0);
+               ip.SetText (_("Host"));
+               ip.SetWidth (300);
+               _list->InsertColumn (0, ip);
+       }
+
+       {
+               wxListItem ip;
+               ip.SetId (1);
+               ip.SetText (_("Threads"));
+               ip.SetWidth (100);
+               _list->InsertColumn (1, ip);
+       }
+
+       s->Add (_list, 1, wxEXPAND | wxALL, 12);
+
+       wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
+       if (buttons) {
+               s->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
+       }
+
+       SetSizer (s);
+       s->Layout ();
+       s->SetSizeHints (this);
+       
+       _server_finder.ServerFound.connect (boost::bind (&ServersListDialog::server_found, this, _1));
+}
+
+void
+ServersListDialog::server_found (ServerDescription s)
+{
+       list<ServerDescription>::const_iterator i = _servers.begin();
+       while (i != _servers.end() && i->host_name() != s.host_name()) {
+               ++i;
+       }
+
+       if (i != _servers.end ()) {
+               return;
+       }
+
+       wxListItem list_item;
+       int const n = _list->GetItemCount ();
+       list_item.SetId (n);
+       _list->InsertItem (list_item);
+
+       _list->SetItem (n, 0, std_to_wx (s.host_name ()));
+       _list->SetItem (n, 1, std_to_wx (lexical_cast<string> (s.threads ())));
+
+       _servers.push_back (s);
+}
diff --git a/src/wx/servers_list_dialog.h b/src/wx/servers_list_dialog.h
new file mode 100644 (file)
index 0000000..0662a14
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <wx/wx.h>
+#include <wx/listctrl.h>
+#include "lib/server_finder.h"
+
+class ServersListDialog : public wxDialog
+{
+public:
+       ServersListDialog (wxWindow *);
+
+private:
+       void server_found (ServerDescription);
+
+       ServerFinder _server_finder;
+       std::list<ServerDescription> _servers;
+       wxListCtrl* _list;
+};
index 09e78316158d5b2fc464918dd4a89d49c6ad6133..c86188c6aded9c93ffe2c1ac68ce44a5227401a0 100644 (file)
@@ -31,6 +31,7 @@ sources = """
           repeat_dialog.cc
           screen_dialog.cc
           server_dialog.cc
+          servers_list_dialog.cc
           subtitle_panel.cc
           timecode.cc
           timeline.cc