X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Futil.cc;h=bbb44436713281d5a3a88ee0bec5a265bd2e6efa;hp=fee4a3c26aab11ac4bf094d5977d6d9c27e18e9a;hb=f515b8daea9d28200be803bb64ff17e9f30343c4;hpb=bf19399f8c009ff211d5c7b45b0941417d963c4e diff --git a/src/lib/util.cc b/src/lib/util.cc index fee4a3c26..bbb444367 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -473,7 +473,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 +493,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 +779,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 +793,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; } } @@ -953,7 +967,7 @@ show_jobs_on_console (bool progress) bool error = false; while (true) { - dcpomatic_sleep (5); + dcpomatic_sleep_seconds (5); list > jobs = JobManager::instance()->get(); @@ -1001,6 +1015,58 @@ show_jobs_on_console (bool progress) 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 */