X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Futil.cc;h=c1ef4245f16b18713dd008bbb9d212ab858b1674;hb=4edc14c8b1410e24f68b510cc14409b96c0338a3;hp=3b6be6dcc227625d28574da53b3af4419d893d28;hpb=4d11fe7cea71b0564df9a21a3cc706509d12b0d1;p=dcpomatic.git diff --git a/src/lib/util.cc b/src/lib/util.cc index 3b6be6dcc..c1ef4245f 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2019 Carl Hetherington + Copyright (C) 2012-2020 Carl Hetherington This file is part of DCP-o-matic. @@ -394,7 +394,6 @@ dcpomatic_setup () Ratio::setup_ratios (); PresetColourConversion::setup_colour_conversion_presets (); - VideoContentScale::setup_scales (); DCPContentType::setup_dcp_content_types (); Filter::setup_filters (); CinemaSoundProcessor::setup_cinema_sound_processors (); @@ -473,7 +472,7 @@ digest_head_tail (vector files, boost::uintmax_t size) while (i < int64_t (files.size()) && to_do > 0) { FILE* f = fopen_boost (files[i], "rb"); if (!f) { - throw OpenFileError (files[i].string(), errno, true); + throw OpenFileError (files[i].string(), errno, OpenFileError::READ); } boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i])); @@ -493,7 +492,7 @@ digest_head_tail (vector files, boost::uintmax_t size) while (i >= 0 && to_do > 0) { FILE* f = fopen_boost (files[i], "rb"); if (!f) { - throw OpenFileError (files[i].string(), errno, true); + throw OpenFileError (files[i].string(), errno, OpenFileError::READ); } boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i])); @@ -779,7 +778,7 @@ careful_string_filter (string s) /** @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 channels, second: number of LFE channels. + * @return First: number of non-LFE soundtrack channels (L/R/C/Ls/Rs/Lc/Rc/Bsl/Bsr), second: number of LFE channels. */ pair audio_channel_types (list mapped, int channels) @@ -793,10 +792,24 @@ audio_channel_types (list mapped, int channels) continue; } - if (static_cast (i) == dcp::LFE) { + switch (static_cast(i)) { + case dcp::LFE: ++lfe; - } else { + break; + case dcp::LEFT: + case dcp::RIGHT: + case dcp::CENTRE: + case dcp::LS: + case dcp::RS: + case dcp::LC: + case dcp::RC: + case dcp::BSL: + case dcp::BSR: ++non_lfe; + break; + case dcp::HI: + case dcp::VI: + break; } } @@ -913,7 +926,7 @@ emit_subtitle_image (ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size { /* XXX: this is rather inefficient; decoding the image just to get its size */ FFmpegImageProxy proxy (sub.png_image()); - shared_ptr image = proxy.image().first; + shared_ptr image = proxy.image().image; /* set up rect with height and width */ dcpomatic::Rect rect(0, 0, image->size().width / double(size.width), image->size().height / double(size.height)); @@ -949,12 +962,11 @@ emit_subtitle_image (ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size bool show_jobs_on_console (bool progress) { - bool should_stop = false; bool first = true; bool error = false; - while (!should_stop) { + while (true) { - dcpomatic_sleep (5); + dcpomatic_sleep_seconds (5); list > jobs = JobManager::instance()->get(); @@ -967,9 +979,6 @@ show_jobs_on_console (bool progress) first = false; - int unfinished = 0; - int finished_in_error = 0; - BOOST_FOREACH (shared_ptr i, jobs) { if (progress) { cout << i->name(); @@ -985,31 +994,78 @@ show_jobs_on_console (bool progress) } } - if (!i->finished ()) { - ++unfinished; - } - - if (i->finished_in_error ()) { - ++finished_in_error; - error = true; - } - - if (!progress && i->finished_in_error ()) { + if (!progress && i->finished_in_error()) { /* We won't see this error if we haven't been showing progress, so show it now. */ cout << i->status() << "\n"; } + + if (i->finished_in_error()) { + error = true; + } } - if (unfinished == 0 || finished_in_error != 0) { - should_stop = true; + if (!JobManager::instance()->work_to_do()) { + break; } } return error; } +/** XXX: could use mmap? */ +void +copy_in_bits (boost::filesystem::path from, boost::filesystem::path to, boost::function progress) +{ + FILE* f = fopen_boost (from, "rb"); + if (!f) { + throw OpenFileError (from, errno, OpenFileError::READ); + } + FILE* t = fopen_boost (to, "wb"); + if (!t) { + fclose (f); + throw OpenFileError (to, errno, OpenFileError::WRITE); + } + + /* on the order of a second's worth of copying */ + boost::uintmax_t const chunk = 20 * 1024 * 1024; + + uint8_t* buffer = static_cast (malloc(chunk)); + if (!buffer) { + throw std::bad_alloc (); + } + + boost::uintmax_t const total = boost::filesystem::file_size (from); + boost::uintmax_t remaining = total; + + while (remaining) { + boost::uintmax_t this_time = min (chunk, remaining); + size_t N = fread (buffer, 1, chunk, f); + if (N < this_time) { + fclose (f); + fclose (t); + free (buffer); + throw ReadFileError (from, errno); + } + + N = fwrite (buffer, 1, this_time, t); + if (N < this_time) { + fclose (f); + fclose (t); + free (buffer); + throw WriteFileError (to, errno); + } + + progress (1 - float(remaining) / total); + remaining -= this_time; + } + + fclose (f); + fclose (t); + free (buffer); +} + #ifdef DCPOMATIC_VARIANT_SWAROOP /* Make up a key from the machine UUID */ @@ -1114,3 +1170,34 @@ write_swaroop_chain (shared_ptr chain, boost::files } #endif + +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) +{ + /* Now scale it down if the display container is smaller than the film container */ + if (display_container != film_container) { + float const scale = min ( + float (display_container.width) / film_container.width, + float (display_container.height) / film_container.height + ); + + s.width = lrintf (s.width * scale); + s.height = lrintf (s.height * scale); + } + + return s; +} +