From: Carl Hetherington Date: Sat, 28 Jul 2012 14:37:50 +0000 (+0100) Subject: Fix bug causing frames to be missed when encoding. X-Git-Tag: v2.0.48~1788 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=333e8c59f591c14f7ba9a67ed890bd635fdfecb7 Fix bug causing frames to be missed when encoding. --- diff --git a/ChangeLog b/ChangeLog index 10854d1a4..12fb66c7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2012-07-28 Carl Hetherington + * Fix missed frames when encoding caused by server + threads that are attempting to access non-responding + servers. + * Fix makedcp parsing of -v option. 2012-07-28 Carl Hetherington diff --git a/TODO b/TODO index 914ba8d69..1ba9d56e4 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,6 @@ Port DVD rip Write still j2ks straight to a MXF. -Seem to be problems when waiting for (failing) server threads at the end of an encode; -their frames aren't reprocessed locally. md5_data to use openssl Standardise j2c/j2k diff --git a/src/lib/j2k_wav_encoder.cc b/src/lib/j2k_wav_encoder.cc index 3bcb1e5fd..2f29f9021 100644 --- a/src/lib/j2k_wav_encoder.cc +++ b/src/lib/j2k_wav_encoder.cc @@ -174,7 +174,7 @@ J2KWAVEncoder::encoder_thread (Server* server) remote_backoff += 10; } stringstream s; - s << "Remote encode on " << server->host_name() << " failed (" << e.what() << "); thread sleeping for " << remote_backoff << "s."; + s << "Remote encode of " << vf->frame() << " on " << server->host_name() << " failed (" << e.what() << "); thread sleeping for " << remote_backoff << "s."; _log->log (s.str ()); } @@ -236,6 +236,31 @@ J2KWAVEncoder::process_end () lock.unlock (); terminate_worker_threads (); + + /* The following sequence of events can occur in the above code: + 1. a remote worker takes the last image off the queue + 2. the loop above terminates + 3. the remote worker fails to encode the image and puts it back on the queue + 4. the remote worker is then terminated by terminate_worker_threads + + So just mop up anything left in the queue here. + */ + + for (list >::iterator i = _queue.begin(); i != _queue.end(); ++i) { + stringstream s; + s << "Encode left-over frame " << (*i)->frame(); + _log->log (s.str ()); + try { + shared_ptr e = (*i)->encode_locally (); + e->write (_opt, (*i)->frame ()); + frame_done (); + } catch (std::exception& e) { + stringstream s; + s << "Local encode failed " << e.what() << "."; + _log->log (s.str ()); + } + } + close_sound_files (); /* Rename .wav.tmp files to .wav */