Fix bug causing frames to be missed when encoding.
authorCarl Hetherington <cth@carlh.net>
Sat, 28 Jul 2012 14:37:50 +0000 (15:37 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 28 Jul 2012 14:37:50 +0000 (15:37 +0100)
ChangeLog
TODO
src/lib/j2k_wav_encoder.cc

index 10854d1a4f615a47f53e0b54b7c6874656bd88e2..12fb66c7dd4ecd0ae83aae70ae1fa6d258b4cd29 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2012-07-28  Carl Hetherington  <cth@carlh.net>
 
+       * 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  <cth@carlh.net>
diff --git a/TODO b/TODO
index 914ba8d697e59f0f93f423cc75606ea018ea564d..1ba9d56e462c35b5f7568142b40d5f2d78f22bd7 100644 (file)
--- 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
index 3bcb1e5fd0f6d93b65cc03ea7bd89210d915073b..2f29f9021d2ba7561e53bb8406df0f5c35f6ba1a 100644 (file)
@@ -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<shared_ptr<DCPVideoFrame> >::iterator i = _queue.begin(); i != _queue.end(); ++i) {
+               stringstream s;
+               s << "Encode left-over frame " << (*i)->frame();
+               _log->log (s.str ());
+               try {
+                       shared_ptr<EncodedData> 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 */