diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-01-09 16:29:21 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-01-09 16:29:21 +0100 |
| commit | 92b7d1cffbd0d457f8b4b23cc72937bcf8e5ed5e (patch) | |
| tree | b175db682422765468991702e8563bcd89713b70 /src/lib/util.cc | |
| parent | 7392cb8383c9b857edad5f99eaf917ed70da237d (diff) | |
Tidying.
Diffstat (limited to 'src/lib/util.cc')
| -rw-r--r-- | src/lib/util.cc | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc index 64fdd6a37..106a56541 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -112,14 +112,14 @@ using std::shared_ptr; using std::string; using std::vector; using std::wstring; -using boost::thread; -using boost::optional; -using boost::lexical_cast; using boost::bad_lexical_cast; +using boost::lexical_cast; +using boost::optional; using boost::scoped_array; +using boost::thread; using dcp::Size; -using dcp::raw_convert; using dcp::locale_convert; +using dcp::raw_convert; using namespace dcpomatic; @@ -131,6 +131,7 @@ bool is_batch_converter = false; static boost::thread::id ui_thread; static boost::filesystem::path backtrace_file; + /** Convert some number of seconds to a string representation * in hours, minutes and seconds. * @@ -151,6 +152,7 @@ seconds_to_hms (int s) return buffer; } + string time_to_hmsf (DCPTime time, Frame rate) { @@ -167,6 +169,7 @@ time_to_hmsf (DCPTime time, Frame rate) return buffer; } + /** @param s Number of seconds. * @return String containing an approximate description of s (e.g. "about 2 hours") */ @@ -225,12 +228,14 @@ seconds_to_approximate_hms (int s) return ap; } + double seconds (struct timeval t) { return t.tv_sec + (double (t.tv_usec) / 1e6); } + #ifdef DCPOMATIC_WINDOWS /** Resolve symbol name and source location given the path to the executable */ @@ -242,6 +247,7 @@ addr2line (void const * const addr) return system(addr2line_cmd); } + DCPOMATIC_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. @@ -302,12 +308,14 @@ exception_handler(struct _EXCEPTION_POINTERS * info) DCPOMATIC_ENABLE_WARNINGS #endif + void set_backtrace_file (boost::filesystem::path p) { backtrace_file = p; } + /** This is called when there is an unhandled exception. Any * backtrace in this function is useless on Windows as the stack has * already been unwound from the throw; we have the gdb wrap hack to @@ -336,6 +344,7 @@ terminate () abort(); } + void dcpomatic_setup_path_encoding () { @@ -357,6 +366,7 @@ dcpomatic_setup_path_encoding () #endif } + /** Call the required functions to set up DCP-o-matic's static arrays, etc. * Must be called from the UI thread, if there is one. */ @@ -424,6 +434,7 @@ DCPOMATIC_ENABLE_WARNINGS ui_thread = boost::this_thread::get_id (); } + #ifdef DCPOMATIC_WINDOWS boost::filesystem::path mo_path () @@ -438,6 +449,7 @@ mo_path () } #endif + #ifdef DCPOMATIC_OSX boost::filesystem::path mo_path () @@ -446,6 +458,7 @@ mo_path () } #endif + void dcpomatic_setup_gettext_i18n (string lang) { @@ -478,6 +491,7 @@ dcpomatic_setup_gettext_i18n (string lang) #endif } + /** Compute a digest of the first and last `size' bytes of a set of files. */ string digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size) @@ -550,6 +564,7 @@ stride_round_up (int c, int const * stride, int t) return a - (a % t); } + /** Trip an assert if the caller is not in the UI thread */ void ensure_ui_thread () @@ -557,6 +572,7 @@ ensure_ui_thread () DCPOMATIC_ASSERT (boost::this_thread::get_id() == ui_thread); } + string audio_channel_name (int c) { @@ -586,6 +602,7 @@ audio_channel_name (int c) return channels[c]; } + string short_audio_channel_name (int c) { @@ -635,6 +652,7 @@ valid_image_file (boost::filesystem::path f) ); } + bool valid_sound_file (boost::filesystem::path f) { @@ -647,6 +665,7 @@ valid_sound_file (boost::filesystem::path f) return (ext == ".wav" || ext == ".mp3" || ext == ".aif" || ext == ".aiff"); } + bool valid_j2k_file (boost::filesystem::path f) { @@ -655,6 +674,7 @@ valid_j2k_file (boost::filesystem::path f) return (ext == ".j2k" || ext == ".j2c" || ext == ".jp2"); } + string tidy_for_filename (string f) { @@ -662,6 +682,7 @@ tidy_for_filename (string f) return f; } + dcp::Size fit_ratio_within (float ratio, dcp::Size full_frame) { @@ -672,6 +693,7 @@ 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) { @@ -682,6 +704,7 @@ wrapped_av_malloc (size_t s) return p; } + map<string, string> split_get_request (string url) { @@ -728,6 +751,7 @@ split_get_request (string url) return r; } + string video_asset_filename (shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count, optional<string> summary) { @@ -741,6 +765,7 @@ video_asset_filename (shared_ptr<dcp::PictureAsset> asset, int reel_index, int r return Config::instance()->dcp_asset_filename_format().get(values, "_" + asset->id() + ".mxf"); } + string audio_asset_filename (shared_ptr<dcp::SoundAsset> asset, int reel_index, int reel_count, optional<string> summary) { @@ -811,6 +836,7 @@ careful_string_filter (string s) return boost::locale::conv::utf_to_utf<char>(out); } + /** @param mapped List of mapped audio channels from a Film. * @param channels Total number of channels in the Film. * @return First: number of non-LFE soundtrack channels (L/R/C/Ls/Rs/Lc/Rc/Bsl/Bsr), second: number of LFE channels. @@ -853,6 +879,7 @@ audio_channel_types (list<int> mapped, int channels) return make_pair (non_lfe, lfe); } + shared_ptr<AudioBuffers> remap (shared_ptr<const AudioBuffers> input, int output_channels, AudioMapping map) { @@ -877,6 +904,7 @@ remap (shared_ptr<const AudioBuffers> input, int output_channels, AudioMapping m return mapped; } + Eyes increment_eyes (Eyes e) { @@ -887,6 +915,7 @@ increment_eyes (Eyes e) return Eyes::LEFT; } + void checked_fwrite (void const * ptr, size_t size, FILE* stream, boost::filesystem::path path) { @@ -902,6 +931,7 @@ checked_fwrite (void const * ptr, size_t size, FILE* stream, boost::filesystem:: } } + void checked_fread (void* ptr, size_t size, FILE* stream, boost::filesystem::path path) { @@ -917,6 +947,7 @@ checked_fread (void* ptr, size_t size, FILE* stream, boost::filesystem::path pat } } + size_t utf8_strlen (string s) { @@ -936,6 +967,7 @@ utf8_strlen (string s) return N; } + string day_of_week_to_string (boost::gregorian::greg_weekday d) { @@ -959,6 +991,7 @@ day_of_week_to_string (boost::gregorian::greg_weekday d) return d.as_long_string (); } + /** @param size Size of picture that the subtitle will be overlaid onto */ void emit_subtitle_image (ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size size, shared_ptr<TextDecoder> decoder) @@ -998,6 +1031,7 @@ emit_subtitle_image (ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size decoder->emit_bitmap (period, image, rect); } + bool show_jobs_on_console (bool progress) { @@ -1053,6 +1087,7 @@ show_jobs_on_console (bool progress) return error; } + /** XXX: could use mmap? */ void copy_in_bits (boost::filesystem::path from, boost::filesystem::path to, std::function<void (float)> progress) @@ -1105,12 +1140,14 @@ 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) { |
