Destroy Job threads at the start of the subclass destructors,
[dcpomatic.git] / src / lib / transcode_job.cc
index da7571b96db1219d63dbe7c6abfaf411535c528c..f2711bf1760e86e4fc837fff27d91ec2b2822290 100644 (file)
@@ -31,6 +31,7 @@
 #include "log.h"
 #include "dcpomatic_log.h"
 #include "compose.hpp"
+#include "analytics.h"
 #include <iostream>
 #include <iomanip>
 
@@ -41,6 +42,7 @@ using std::fixed;
 using std::setprecision;
 using std::cout;
 using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
 
 /** @param film Film to use */
 TranscodeJob::TranscodeJob (shared_ptr<const Film> film)
@@ -49,6 +51,11 @@ TranscodeJob::TranscodeJob (shared_ptr<const Film> film)
 
 }
 
+TranscodeJob::~TranscodeJob ()
+{
+       destroy_thread ();
+}
+
 string
 TranscodeJob::name () const
 {
@@ -89,14 +96,19 @@ TranscodeJob::run ()
                }
 
                LOG_GENERAL (N_("Transcode job completed successfully: %1 fps"), fps);
-               _encoder.reset ();
+
+               if (dynamic_pointer_cast<DCPEncoder>(_encoder)) {
+                       Analytics::instance()->successful_dcp_encode();
+               }
 
                /* XXX: this shouldn't be here */
-               if (_film->upload_after_make_dcp ()) {
+               if (_film->upload_after_make_dcp() && dynamic_pointer_cast<DCPEncoder>(_encoder)) {
                        shared_ptr<Job> job (new UploadJob (_film));
                        JobManager::instance()->add (job);
                }
 
+               _encoder.reset ();
+
        } catch (...) {
                _encoder.reset ();
                throw;