Merge master.
[dcpomatic.git] / src / lib / util.cc
index 9063b46d49b3514ecf43ebdfe7fbc7f21e996fab..eda0d0236767300f349c146660d29a1f24a24595 100644 (file)
@@ -39,6 +39,7 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/thread.hpp>
 #include <boost/filesystem.hpp>
+#include <glib.h>
 #include <openjpeg.h>
 #include <openssl/md5.h>
 #include <magick/MagickCore.h>
@@ -55,11 +56,14 @@ extern "C" {
 #include "util.h"
 #include "exceptions.h"
 #include "scaler.h"
-#include "format.h"
 #include "dcp_content_type.h"
 #include "filter.h"
 #include "sound_processor.h"
 #include "config.h"
+#include "ratio.h"
+#ifdef DCPOMATIC_WINDOWS
+#include "stack.hpp"
+#endif
 
 #include "i18n.h"
 
@@ -80,6 +84,7 @@ using std::multimap;
 using std::istream;
 using std::numeric_limits;
 using std::pair;
+using std::ofstream;
 using boost::shared_ptr;
 using boost::thread;
 using boost::lexical_cast;
@@ -87,6 +92,7 @@ using boost::optional;
 using libdcp::Size;
 
 boost::thread::id ui_thread;
+boost::filesystem::path backtrace_file;
 
 /** Convert some number of seconds to a string representation
  *  in hours, minutes and seconds.
@@ -254,15 +260,31 @@ seconds (struct timeval t)
        return t.tv_sec + (double (t.tv_usec) / 1e6);
 }
 
-/** Call the required functions to set up DCP-o-matic's static arrays, etc.
+#ifdef DCPOMATIC_WINDOWS
+LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *)
+{
+       dbg::stack s;
+       ofstream f (backtrace_file.string().c_str());
+       std::copy(s.begin(), s.end(), std::ostream_iterator<dbg::stack_frame>(f, "\n"));
+       return EXCEPTION_CONTINUE_SEARCH;
+}
+#endif
+
+/** Call the required functions to set up DVD-o-matic's static arrays, etc.
  *  Must be called from the UI thread, if there is one.
  */
 void
 dcpomatic_setup ()
 {
+#ifdef DCPOMATIC_WINDOWS
+       backtrace_file /= g_get_user_config_dir ();
+       backtrace_file /= "backtrace.txt";
+       SetUnhandledExceptionFilter(exception_handler);
+#endif 
+       
        avfilter_register_all ();
        
-       Format::setup_formats ();
+       Ratio::setup_ratios ();
        DCPContentType::setup_dcp_content_types ();
        Scaler::setup_scalers ();
        Filter::setup_filters ();
@@ -693,32 +715,6 @@ video_frames_to_audio_frames (ContentVideoFrame v, float audio_sample_rate, floa
        return ((int64_t) v * audio_sample_rate / frames_per_second);
 }
 
-/** @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 DCPOMATIC_POSIX
-       ifstream f (N_("/proc/cpuinfo"));
-       while (f.good ()) {
-               string l;
-               getline (f, l);
-               if (boost::algorithm::starts_with (l, N_("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, N_("processor"))) {
-                       ++info.second;
-               }
-       }
-#endif 
-
-       return info;
-}
-
 string
 audio_channel_name (int c)
 {
@@ -775,8 +771,8 @@ LocaleGuard::LocaleGuard ()
 
         if (old) {
                 _old = strdup (old);
-                if (strcmp (_old, "POSIX")) {
-                        setlocale (LC_NUMERIC, "POSIX");
+                if (strcmp (_old, "C")) {
+                        setlocale (LC_NUMERIC, "C");
                 }
         }
 }