X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Futil.cc;h=f98e5960bb20e807f8bf2c9df0c0594a38f54926;hp=c298a1946be278847e905693e4f9f663eeb13a86;hb=a5e87b6f0f496f4ed71d9129d40a5baebb68495f;hpb=bfe277e664a03ec47cd6bee7e1b1e4aca6eb38e6 diff --git a/src/lib/util.cc b/src/lib/util.cc index c298a1946..f98e5960b 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington + Copyright (C) 2012-2015 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,7 +23,6 @@ #include "util.h" #include "exceptions.h" -#include "scaler.h" #include "dcp_content_type.h" #include "filter.h" #include "cinema_sound_processor.h" @@ -36,28 +35,10 @@ #include "md5_digester.h" #include "audio_processor.h" #include "safe_stringstream.h" -#include #include #include -#include -extern "C" { -#include -#include -#include -#include -#include -} #include -#include #include -#ifdef DCPOMATIC_IMAGE_MAGICK -#include -#else -#include -#include -#endif -#include -#include #include #include #include @@ -87,6 +68,7 @@ using std::endl; using std::vector; using std::min; using std::max; +using std::map; using std::list; using std::multimap; using std::istream; @@ -98,7 +80,6 @@ using boost::shared_ptr; using boost::thread; using boost::optional; using dcp::Size; -using dcp::raw_convert; /** Path to our executable, required by the stacktrace stuff and filled * in during App::onInit(). @@ -187,17 +168,6 @@ seconds_to_approximate_hms (int s) return ap.str (); } -/** @param v Version as used by FFmpeg. - * @return A string representation of v. - */ -static string -ffmpeg_version_to_string (int v) -{ - SafeStringStream s; - s << ((v & 0xff0000) >> 16) << N_(".") << ((v & 0xff00) >> 8) << N_(".") << (v & 0xff); - return s.str (); -} - double seconds (struct timeval t) { @@ -354,7 +324,6 @@ dcpomatic_setup () Ratio::setup_ratios (); VideoContentScale::setup_scales (); DCPContentType::setup_dcp_content_types (); - Scaler::setup_scalers (); Filter::setup_filters (); CinemaSoundProcessor::setup_cinema_sound_processors (); AudioProcessor::setup_audio_processors (); @@ -412,7 +381,7 @@ dcpomatic_setup_gettext_i18n (string lang) #endif #ifdef DCPOMATIC_LINUX - bindtextdomain ("libdcpomatic", POSIX_LOCALE_PREFIX); + bindtextdomain ("libdcpomatic", LINUX_LOCALE_PREFIX); #endif } @@ -454,7 +423,7 @@ md5_digest_head_tail (vector files, boost::uintmax_t si } boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i])); - fseek (f, -this_time, SEEK_END); + dcpomatic_fseek (f, -this_time, SEEK_END); fread (p, 1, this_time, f); p += this_time; to_do -= this_time; @@ -592,24 +561,6 @@ wrapped_av_malloc (size_t s) return p; } -/** Return a user-readable string summarising the versions of our dependencies */ -string -dependency_version_summary () -{ - SafeStringStream 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 (); -} - ContentTimePeriod subtitle_period (AVSubtitle const & sub) { @@ -622,3 +573,93 @@ subtitle_period (AVSubtitle const & sub) return period; } + +map +split_get_request (string url) +{ + enum { + AWAITING_QUESTION_MARK, + KEY, + VALUE + } state = AWAITING_QUESTION_MARK; + + map r; + string k; + string v; + for (size_t i = 0; i < url.length(); ++i) { + switch (state) { + case AWAITING_QUESTION_MARK: + if (url[i] == '?') { + state = KEY; + } + break; + case KEY: + if (url[i] == '=') { + v.clear (); + state = VALUE; + } else { + k += url[i]; + } + break; + case VALUE: + if (url[i] == '&') { + r.insert (make_pair (k, v)); + k.clear (); + state = KEY; + } else { + v += url[i]; + } + break; + } + } + + if (state == VALUE) { + r.insert (make_pair (k, v)); + } + + return r; +} + +long +frame_info_position (int frame, Eyes eyes) +{ + static int const info_size = 48; + + switch (eyes) { + case EYES_BOTH: + return frame * info_size; + case EYES_LEFT: + return frame * info_size * 2; + case EYES_RIGHT: + return frame * info_size * 2 + info_size; + default: + DCPOMATIC_ASSERT (false); + } + + DCPOMATIC_ASSERT (false); +} + +dcp::FrameInfo +read_frame_info (FILE* file, int frame, Eyes eyes) +{ + dcp::FrameInfo info; + dcpomatic_fseek (file, frame_info_position (frame, eyes), SEEK_SET); + fread (&info.offset, sizeof (info.offset), 1, file); + fread (&info.size, sizeof (info.size), 1, file); + + char hash_buffer[33]; + fread (hash_buffer, 1, 32, file); + hash_buffer[32] = '\0'; + info.hash = hash_buffer; + + return info; +} + +void +write_frame_info (FILE* file, int frame, Eyes eyes, dcp::FrameInfo info) +{ + dcpomatic_fseek (file, frame_info_position (frame, eyes), SEEK_SET); + fwrite (&info.offset, sizeof (info.offset), 1, file); + fwrite (&info.size, sizeof (info.size), 1, file); + fwrite (info.hash.c_str(), 1, info.hash.size(), file); +}