Merge master.
[dcpomatic.git] / src / lib / util.cc
index 395c53e31ebf0500b255a81c7e6edb4b007fcf1a..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 ();
@@ -367,7 +370,7 @@ dcp_audio_sample_rate (int fs)
 int
 dcp_audio_channels (int f)
 {
-       if (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.
                */
@@ -875,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;
+}