Merge master.
[dcpomatic.git] / src / lib / util.cc
index 78e7b480c9c91f3c07485e886644fc864a66d7dd..40e9d9c2eed730795a8f8476533ae16290c403c0 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
     Copyright (C) 2000-2007 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
@@ -46,9 +46,9 @@
 #include <glib.h>
 #include <openjpeg.h>
 #include <openssl/md5.h>
+#include <pangomm/init.h>
 #include <magick/MagickCore.h>
 #include <magick/version.h>
-#include <pangomm/init.h>
 #include <dcp/version.h>
 #include <dcp/util.h>
 #include <dcp/signer_chain.h>
@@ -58,7 +58,6 @@ extern "C" {
 #include <libavformat/avformat.h>
 #include <libswscale/swscale.h>
 #include <libavfilter/avfiltergraph.h>
-#include <libpostproc/postprocess.h>
 #include <libavutil/pixfmt.h>
 }
 #include "util.h"
@@ -71,6 +70,8 @@ extern "C" {
 #include "ratio.h"
 #include "job.h"
 #include "cross.h"
+#include "video_content.h"
+#include "rect.h"
 #ifdef DCPOMATIC_WINDOWS
 #include "stack.hpp"
 #endif
@@ -238,25 +239,6 @@ ffmpeg_version_to_string (int v)
        return s.str ();
 }
 
-/** Return a user-readable string summarising the versions of our dependencies */
-string
-dependency_version_summary ()
-{
-       stringstream s;
-       s << N_("libopenjpeg ") << opj_version () << N_(", ")
-         << N_("libavcodec ") << ffmpeg_version_to_string (avcodec_version()) << N_(", ")
-         << N_("libavfilter ") << ffmpeg_version_to_string (avfilter_version()) << N_(", ")
-         << N_("libavformat ") << ffmpeg_version_to_string (avformat_version()) << N_(", ")
-         << N_("libavutil ") << ffmpeg_version_to_string (avutil_version()) << N_(", ")
-         << N_("libpostproc ") << ffmpeg_version_to_string (postproc_version()) << N_(", ")
-         << N_("libswscale ") << ffmpeg_version_to_string (swscale_version()) << N_(", ")
-         << MagickVersion << N_(", ")
-         << N_("libssh ") << ssh_version (0) << N_(", ")
-         << N_("libdcp ") << dcp::version << N_(" git ") << dcp::git_commit;
-
-       return s.str ();
-}
-
 double
 seconds (struct timeval t)
 {
@@ -347,6 +329,7 @@ dcpomatic_setup ()
        dcp::init ();
        
        Ratio::setup_ratios ();
+       VideoContentScale::setup_scales ();
        DCPContentType::setup_dcp_content_types ();
        Scaler::setup_scalers ();
        Filter::setup_filters ();
@@ -754,7 +737,7 @@ ensure_ui_thread ()
 string
 audio_channel_name (int c)
 {
-       assert (MAX_AUDIO_CHANNELS == 8);
+       assert (MAX_AUDIO_CHANNELS == 12);
 
        /* TRANSLATORS: these are the names of audio channels; Lfe (sub) is the low-frequency
           enhancement channel (sub-woofer).  HI is the hearing-impaired audio track and
@@ -767,8 +750,12 @@ audio_channel_name (int c)
                _("Lfe (sub)"),
                _("Left surround"),
                _("Right surround"),
-               _("HI"),
-               _("VI")
+               _("Hearing impaired"),
+               _("Visually impaired"),
+               _("Left centre"),
+               _("Right centre"),
+               _("Left rear surround"),
+               _("Right rear surround"),
        };
 
        return channels[c];
@@ -952,3 +939,56 @@ divide_with_round (int64_t a, int64_t b)
                return a / b;
        }
 }
+
+/** Return a user-readable string summarising the versions of our dependencies */
+string
+dependency_version_summary ()
+{
+       stringstream s;
+       s << N_("libopenjpeg ") << opj_version () << N_(", ")
+         << N_("libavcodec ") << ffmpeg_version_to_string (avcodec_version()) << N_(", ")
+         << N_("libavfilter ") << ffmpeg_version_to_string (avfilter_version()) << N_(", ")
+         << N_("libavformat ") << ffmpeg_version_to_string (avformat_version()) << N_(", ")
+         << N_("libavutil ") << ffmpeg_version_to_string (avutil_version()) << N_(", ")
+         << N_("libswscale ") << ffmpeg_version_to_string (swscale_version()) << N_(", ")
+         << MagickVersion << N_(", ")
+         << N_("libssh ") << ssh_version (0) << N_(", ")
+         << N_("libdcp ") << dcp::version << N_(" git ") << dcp::git_commit;
+
+       return s.str ();
+}
+
+ScopedTemporary::ScopedTemporary ()
+       : _open (0)
+{
+       _file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path ();
+}
+
+ScopedTemporary::~ScopedTemporary ()
+{
+       close ();       
+       boost::system::error_code ec;
+       boost::filesystem::remove (_file, ec);
+}
+
+char const *
+ScopedTemporary::c_str () const
+{
+       return _file.string().c_str ();
+}
+
+FILE*
+ScopedTemporary::open (char const * params)
+{
+       _open = fopen (c_str(), params);
+       return _open;
+}
+
+void
+ScopedTemporary::close ()
+{
+       if (_open) {
+               fclose (_open);
+               _open = 0;
+       }
+}