Try to fix crash on drop()ping JobManager. More debugging when resampler fails.
authorCarl Hetherington <cth@carlh.net>
Sat, 9 Nov 2013 20:29:19 +0000 (20:29 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 9 Nov 2013 20:29:19 +0000 (20:29 +0000)
src/lib/job_manager.cc
src/lib/job_manager.h
src/lib/player.cc
src/lib/resampler.cc

index 2695d3d10b992dfcec35cc86914ff62e6db76090..056b9f925e1b237946122d804241614bb87f416c 100644 (file)
@@ -37,9 +37,23 @@ using boost::weak_ptr;
 JobManager* JobManager::_instance = 0;
 
 JobManager::JobManager ()
-       : _last_active_jobs (false)
+       : _terminate (false)
+       , _last_active_jobs (false)
+       , _scheduler (new boost::thread (boost::bind (&JobManager::scheduler, this)))
 {
-       boost::thread (boost::bind (&JobManager::scheduler, this));
+       
+}
+
+JobManager::~JobManager ()
+{
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _terminate = true;
+       }
+
+       if (_scheduler->joinable ()) {
+               _scheduler->join ();
+       }
 }
 
 shared_ptr<Job>
@@ -98,6 +112,10 @@ JobManager::scheduler ()
 
                {
                        boost::mutex::scoped_lock lm (_mutex);
+                       if (_terminate) {
+                               return;
+                       }
+                       
                        for (list<shared_ptr<Job> >::iterator i = _jobs.begin(); i != _jobs.end(); ++i) {
 
                                if (!(*i)->finished ()) {
index d0dac7d19369073eda9761b2290b4e272056c786..0c92efd2831f5d1b213d1a9e19ae2a0e4fdb9f1b 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <list>
 #include <boost/thread/mutex.hpp>
+#include <boost/thread.hpp>
 #include <boost/signals2.hpp>
 
 class Job;
@@ -50,12 +51,15 @@ private:
        friend void ::wait_for_jobs ();
        
        JobManager ();
+       ~JobManager ();
        void scheduler ();
        
        mutable boost::mutex _mutex;
        std::list<boost::shared_ptr<Job> > _jobs;
+       bool _terminate;
 
        bool _last_active_jobs;
+       boost::thread* _scheduler;
 
        static JobManager* _instance;
 };
index 4fbd906c64ec9591538d05d9399bea9f2df2a572..220cf83c0ad6c58814fd96eef768aa32404f182f 100644 (file)
@@ -564,6 +564,12 @@ Player::resampler (shared_ptr<AudioContent> c, bool create)
        if (!create) {
                return shared_ptr<Resampler> ();
        }
+
+       _film->log()->log (
+               String::compose (
+                       "Creating new resampler for %1 to %2 with %3 channels", c->content_audio_frame_rate(), c->output_audio_frame_rate(), c->audio_channels()
+                       )
+               );
        
        shared_ptr<Resampler> r (new Resampler (c->content_audio_frame_rate(), c->output_audio_frame_rate(), c->audio_channels()));
        _resamplers[c] = r;
index 7bc933fd01b2536da1b8d7f0e70c6a9264d6a6f0..d897bf562dc4a97dcf5c314a8e7242e050f93e2f 100644 (file)
@@ -23,6 +23,7 @@ extern "C" {
 #include "resampler.h"
 #include "audio_buffers.h"
 #include "exceptions.h"
+#include "compose.hpp"
 
 #include "i18n.h"
 
@@ -77,7 +78,9 @@ Resampler::run (shared_ptr<const AudioBuffers> in, AudioContent::Frame frame)
                );
        
        if (resampled_frames < 0) {
-               throw EncodeError (_("could not run sample-rate converter"));
+               char buf[256];
+               av_strerror (resampled_frames, buf, sizeof(buf));
+               throw EncodeError (String::compose (_("could not run sample-rate converter for %1 samples (%2) (%3)"), in->frames(), resampled_frames, buf));
        }
        
        resampled->set_frames (resampled_frames);