Destroy Transcoder when cancelling transcode jobs; this closes the audio MXF so it...
authorCarl Hetherington <cth@carlh.net>
Sat, 11 Jan 2014 18:37:15 +0000 (18:37 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 11 Jan 2014 18:37:15 +0000 (18:37 +0000)
ChangeLog
src/lib/encoder.cc
src/lib/transcode_job.cc
src/lib/writer.cc
src/lib/writer.h

index 2972c6caa3a4c49affd4fa888e49ecedef90bc11..0a353e57ab930a14d22b8fab1b9276afbbf54804 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-01-11  Carl Hetherington  <cth@carlh.net>
+
+       * Hopefully fix error on restarting a cancelled transcode job
+       on Windows.
+
 2014-01-10  Carl Hetherington  <cth@carlh.net>
 
        * Version 1.62.2 released.
index b78bcaeea7081bd12317608ff7e45a09695a18b7..fbec3e4d0d0e65c2a4dfa51653e0461d18873777 100644 (file)
@@ -68,9 +68,6 @@ Encoder::Encoder (shared_ptr<const Film> f, weak_ptr<Job> j)
 Encoder::~Encoder ()
 {
        terminate_threads ();
-       if (_writer) {
-               _writer->finish ();
-       }
 }
 
 /** Add a worker thread for a each thread on a remote server.  Caller must hold
index fd69b08e7c58b5a353570433d5f53c937585ed48..87fd5daefca06d06ed1e2fee5cf6eb89237d4104 100644 (file)
@@ -64,12 +64,11 @@ TranscodeJob::run ()
 
                _film->log()->log (N_("Transcode job completed successfully"));
 
-       } catch (std::exception& e) {
-
+       } catch (...) {
                set_progress (1);
                set_state (FINISHED_ERROR);
-               _film->log()->log (String::compose (N_("Transcode job failed (%1)"), e.what()));
-
+               _film->log()->log (N_("Transcode job failed or cancelled"));
+               _transcoder.reset ();
                throw;
        }
 }
@@ -78,7 +77,7 @@ string
 TranscodeJob::status () const
 {
        if (!_transcoder) {
-               return _("0%");
+               return Job::status ();
        }
 
        float const fps = _transcoder->current_encoding_rate ();
index cfc19a13dd041adb38307489eaf97ef1a1036e71..572a1c3a462d1ffa3f117b6b56378f82ae8435dc 100644 (file)
@@ -104,38 +104,8 @@ Writer::Writer (shared_ptr<const Film> f, weak_ptr<Job> j)
        }
        
        /* Write the sound asset into the film directory so that we leave the creation
-          of the DCP directory until the last minute.  Some versions of windows inexplicably
-          don't like overwriting existing files here, so try to remove it using boost.
+          of the DCP directory until the last minute.
        */
-       boost::system::error_code ec;
-       boost::filesystem::remove_all (_film->file (_film->audio_mxf_filename ()), ec);
-       if (ec) {
-
-               stringstream s;
-               boost::filesystem::path p = _film->file (_film->audio_mxf_filename ());
-               s << p << "\n"
-                 << "exists=" << boost::filesystem::exists (p) << "\n"
-                 << "file_size=" << boost::filesystem::file_size (p) << "\n"
-                 << "hard_link_count=" << boost::filesystem::hard_link_count (p) << "\n"
-                 << "is_directory=" << boost::filesystem::is_directory (p) << "\n"
-                 << "is_empty=" << boost::filesystem::is_empty (p) << "\n"
-                 << "is_other=" << boost::filesystem::is_other (p) << "\n"
-                 << "is_regular_file=" << boost::filesystem::is_regular_file (p) << "\n"
-                 << "last_write_time=" << boost::filesystem::last_write_time (p) << "\n"
-                 << "type=" << boost::filesystem::status (p).type () << "\n"
-                 << "permissions=" << boost::filesystem::status (p).permissions () << "\n";
-
-               _film->log()->log (s.str ());
-               
-               _film->log()->log (
-                       String::compose (
-                               "Could not remove existing audio MXF file %1 (%2)",
-                               _film->file (_film->audio_mxf_filename ()),
-                               ec.value ()
-                               )
-                       );
-       }
-
        _sound_asset_writer = _sound_asset->start_write ();
 
        _thread = new boost::thread (boost::bind (&Writer::thread, this));
@@ -143,6 +113,11 @@ Writer::Writer (shared_ptr<const Film> f, weak_ptr<Job> j)
        job->sub (_("Encoding image data"));
 }
 
+Writer::~Writer ()
+{
+       terminate_thread (false);
+}
+
 void
 Writer::write (shared_ptr<const EncodedData> encoded, int frame, Eyes eyes)
 {
@@ -366,23 +341,31 @@ catch (...)
 }
 
 void
-Writer::finish ()
+Writer::terminate_thread (bool can_throw)
 {
-       if (!_thread) {
-               return;
-       }
-       
        boost::mutex::scoped_lock lock (_mutex);
        _finish = true;
        _empty_condition.notify_all ();
        _full_condition.notify_all ();
        lock.unlock ();
 
-       _thread->join ();
-       rethrow ();
+       _thread->join ();
+       if (can_throw) {
+               rethrow ();
+       }
        
        delete _thread;
        _thread = 0;
+}      
+
+void
+Writer::finish ()
+{
+       if (!_thread) {
+               return;
+       }
+       
+       terminate_thread (true);
 
        _picture_asset_writer->finalize ();
        _sound_asset_writer->finalize ();
index e2807d71240612090aed3541d641fd9b9619c0ca..7af79a417ed193780931e805eda92d5ca1d58515 100644 (file)
@@ -71,6 +71,7 @@ class Writer : public ExceptionStore, public boost::noncopyable
 {
 public:
        Writer (boost::shared_ptr<const Film>, boost::weak_ptr<Job>);
+       ~Writer ();
 
        bool can_fake_write (int) const;
        
@@ -83,6 +84,7 @@ public:
 private:
 
        void thread ();
+       void terminate_thread (bool);
        void check_existing_picture_mxf ();
        bool check_existing_picture_mxf_frame (FILE *, int, Eyes);
        bool have_sequenced_image_at_queue_head ();