Merge master.
[dcpomatic.git] / src / lib / util.cc
index 66eaea39e21258328693570609926c475117cffb..ef6f46575f32ada59bb6a7923d0fa56277db5cbf 100644 (file)
@@ -43,6 +43,7 @@
 #include <magick/MagickCore.h>
 #include <magick/version.h>
 #include <libdcp/version.h>
+#include <libdcp/util.h>
 extern "C" {
 #include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
@@ -230,6 +231,8 @@ seconds (struct timeval t)
 void
 dvdomatic_setup ()
 {
+       libdcp::init ();
+       
        Format::setup_formats ();
        DCPContentType::setup_dcp_content_types ();
        Scaler::setup_scalers ();
@@ -364,11 +367,30 @@ dcp_audio_sample_rate (int fs)
        return 96000;
 }
 
+int
+dcp_audio_channels (int f)
+{
+       if (f == 1) {
+               /* The source is mono, so to put the mono channel into
+                  the centre we need to generate a 5.1 soundtrack.
+               */
+               return 6;
+       }
+
+       return f;
+}
+
+
 bool operator== (Size const & a, Size const & b)
 {
        return (a.width == b.width && a.height == b.height);
 }
 
+bool operator!= (Size const & a, Size const & b)
+{
+       return !(a == b);
+}
+
 bool operator== (Crop const & a, Crop const & b)
 {
        return (a.left == b.left && a.right == b.right && a.top == b.top && a.bottom == b.bottom);
@@ -423,6 +445,7 @@ Socket::check ()
 void
 Socket::connect (asio::ip::basic_resolver_entry<asio::ip::tcp> const & endpoint, int timeout)
 {
+       _deadline.expires_from_now (posix_time::seconds (timeout));
        system::error_code ec = asio::error::would_block;
        _socket.async_connect (endpoint, lambda::var(ec) = lambda::_1);
        do {
@@ -855,3 +878,29 @@ still_image_file (string f)
        
        return (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png");
 }
+
+/** @return A pair containing CPU model name and the number of processors */
+pair<string, int>
+cpu_info ()
+{
+       pair<string, int> info;
+       info.second = 0;
+       
+#ifdef DVDOMATIC_POSIX
+       ifstream f ("/proc/cpuinfo");
+       while (f.good ()) {
+               string l;
+               getline (f, l);
+               if (boost::algorithm::starts_with (l, "model name")) {
+                       string::size_type const c = l.find (':');
+                       if (c != string::npos) {
+                               info.first = l.substr (c + 2);
+                       }
+               } else if (boost::algorithm::starts_with (l, "processor")) {
+                       ++info.second;
+               }
+       }
+#endif 
+
+       return info;
+}