X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Futil.cc;h=92b8847bd121685ba9729430c7e100e81336d5a8;hb=7cd7b360169493d864206e2cdfb4f688cf5a12cf;hp=c298a1946be278847e905693e4f9f663eeb13a86;hpb=bfe277e664a03ec47cd6bee7e1b1e4aca6eb38e6;p=dcpomatic.git diff --git a/src/lib/util.cc b/src/lib/util.cc index c298a1946..92b8847bd 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,13 @@ #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 #include -#include #include -#ifdef DCPOMATIC_IMAGE_MAGICK -#include -#else -#include -#include -#endif -#include -#include #include #include #include @@ -87,6 +71,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 +83,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 +171,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) { @@ -352,9 +325,9 @@ dcpomatic_setup () dcp::init (); Ratio::setup_ratios (); + PresetColourConversion::setup_colour_conversion_presets (); 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 +385,7 @@ dcpomatic_setup_gettext_i18n (string lang) #endif #ifdef DCPOMATIC_LINUX - bindtextdomain ("libdcpomatic", POSIX_LOCALE_PREFIX); + bindtextdomain ("libdcpomatic", LINUX_LOCALE_PREFIX); #endif } @@ -454,7 +427,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; @@ -540,12 +513,16 @@ audio_channel_name (int c) bool valid_image_file (boost::filesystem::path f) { + if (boost::starts_with (f.leaf().string(), "._")) { + return false; + } + string ext = f.extension().string(); transform (ext.begin(), ext.end(), ext.begin(), ::tolower); return ( ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp" || ext == ".tga" || ext == ".dpx" || - ext == ".j2c" || ext == ".j2k" + ext == ".j2c" || ext == ".j2k" || ext == ".jp2" ); } @@ -554,7 +531,7 @@ valid_j2k_file (boost::filesystem::path f) { string ext = f.extension().string(); transform (ext.begin(), ext.end(), ext.begin(), ::tolower); - return (ext == ".j2k" || ext == ".j2c"); + return (ext == ".j2k" || ext == ".j2c" || ext == ".jp2"); } string @@ -573,13 +550,13 @@ tidy_for_filename (string f) } dcp::Size -fit_ratio_within (float ratio, dcp::Size full_frame, int round) +fit_ratio_within (float ratio, dcp::Size full_frame) { if (ratio < full_frame.ratio ()) { - return dcp::Size (round_to (full_frame.height * ratio, round), full_frame.height); + return dcp::Size (rint (full_frame.height * ratio), full_frame.height); } - return dcp::Size (full_frame.width, round_to (full_frame.width / ratio, round)); + return dcp::Size (full_frame.width, rint (full_frame.width / ratio)); } void * @@ -591,34 +568,77 @@ 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 +FFmpegSubtitlePeriod subtitle_period (AVSubtitle const & sub) { ContentTime const packet_time = ContentTime::from_seconds (static_cast (sub.pts) / AV_TIME_BASE); - ContentTimePeriod period ( + if (sub.end_display_time == static_cast (-1)) { + /* End time is not known */ + return FFmpegSubtitlePeriod (packet_time + ContentTime::from_seconds (sub.start_display_time / 1e3)); + } + + return FFmpegSubtitlePeriod ( packet_time + ContentTime::from_seconds (sub.start_display_time / 1e3), packet_time + ContentTime::from_seconds (sub.end_display_time / 1e3) ); +} - 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; +} + +string +video_asset_filename (shared_ptr asset) +{ + return "j2c_" + asset->id() + ".mxf"; +} + +string +audio_asset_filename (shared_ptr asset) +{ + return "pcm_" + asset->id() + ".mxf"; }