Extract simple_digest().
[dcpomatic.git] / src / lib / util.cc
index ccd505e57d8ee263eee8c20b484f9b0e55760d32..6e2a1ad642c9d2b7a945abf32314879438b233c2 100644 (file)
 #include "text_decoder.h"
 #include "util.h"
 #include "video_content.h"
-#include "warnings.h"
+#include <dcp/atmos_asset.h>
 #include <dcp/decrypted_kdm.h>
 #include <dcp/locale_convert.h>
-#include <dcp/util.h>
-#include <dcp/raw_convert.h>
 #include <dcp/picture_asset.h>
+#include <dcp/raw_convert.h>
 #include <dcp/sound_asset.h>
 #include <dcp/subtitle_asset.h>
-#include <dcp/atmos_asset.h>
-DCPOMATIC_DISABLE_WARNINGS
+#include <dcp/util.h>
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 extern "C" {
 #include <libavfilter/avfilter.h>
 #include <libavformat/avformat.h>
 #include <libavcodec/avcodec.h>
 }
-DCPOMATIC_ENABLE_WARNINGS
+LIBDCP_ENABLE_WARNINGS
 #include <curl/curl.h>
 #include <glib.h>
 #include <pangomm/init.h>
@@ -75,9 +75,9 @@ DCPOMATIC_ENABLE_WARNINGS
 #include <boost/range/algorithm/replace_if.hpp>
 #include <boost/thread.hpp>
 #include <boost/filesystem.hpp>
-DCPOMATIC_DISABLE_WARNINGS
+LIBDCP_DISABLE_WARNINGS
 #include <boost/locale.hpp>
-DCPOMATIC_ENABLE_WARNINGS
+LIBDCP_ENABLE_WARNINGS
 #ifdef DCPOMATIC_WINDOWS
 #include <boost/locale.hpp>
 #include <dbghelp.h>
@@ -242,7 +242,7 @@ addr2line (void const * const addr)
        return system(addr2line_cmd);
 }
 
-DCPOMATIC_DISABLE_WARNINGS
+LIBDCP_DISABLE_WARNINGS
 /** This is called when C signals occur on Windows (e.g. SIGSEGV)
  *  (NOT C++ exceptions!).  We write a backtrace to backtrace_file by dark means.
  *  Adapted from code here: http://spin.atomicobject.com/2013/01/13/exceptions-stack-traces-c/
@@ -299,7 +299,7 @@ exception_handler(struct _EXCEPTION_POINTERS * info)
 
        return EXCEPTION_CONTINUE_SEARCH;
 }
-DCPOMATIC_ENABLE_WARNINGS
+LIBDCP_ENABLE_WARNINGS
 #endif
 
 void
@@ -371,10 +371,10 @@ dcpomatic_setup ()
 #endif
 
 #ifdef DCPOMATIC_HAVE_AVREGISTER
-DCPOMATIC_DISABLE_WARNINGS
+LIBDCP_DISABLE_WARNINGS
        av_register_all ();
        avfilter_register_all ();
-DCPOMATIC_ENABLE_WARNINGS
+LIBDCP_ENABLE_WARNINGS
 #endif
 
 #ifdef DCPOMATIC_OSX
@@ -529,19 +529,14 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
        return digester.get ();
 }
 
-/** Round a number up to the nearest multiple of another number.
- *  @param c Index.
- *  @param stride Array of numbers to round, indexed by c.
- *  @param t Multiple to round to.
- *  @return Rounded number.
- */
-int
-stride_round_up (int c, int const * stride, int t)
+
+string
+simple_digest (vector<boost::filesystem::path> paths)
 {
-       int const a = stride[c] + (t - 1);
-       return a - (a % t);
+       return digest_head_tail(paths, 1000000) + raw_convert<string>(boost::filesystem::file_size(paths.front()));
 }
 
+
 /** Trip an assert if the caller is not in the UI thread */
 void
 ensure_ui_thread ()
@@ -664,16 +659,6 @@ fit_ratio_within (float ratio, dcp::Size full_frame)
        return dcp::Size (full_frame.width, lrintf (full_frame.width / ratio));
 }
 
-void *
-wrapped_av_malloc (size_t s)
-{
-       auto p = av_malloc (s);
-       if (!p) {
-               throw bad_alloc ();
-       }
-       return p;
-}
-
 map<string, string>
 split_get_request (string url)
 {
@@ -1097,18 +1082,6 @@ copy_in_bits (boost::filesystem::path from, boost::filesystem::path to, std::fun
        free (buffer);
 }
 
-double
-db_to_linear (double db)
-{
-       return pow(10, db / 20);
-}
-
-double
-linear_to_db (double linear)
-{
-       return 20 * log10(linear);
-}
-
 
 dcp::Size
 scale_for_display (dcp::Size s, dcp::Size display_container, dcp::Size film_container, PixelQuanta quanta)