Replace a shared_ptr with a weak_ptr.
authorCarl Hetherington <cth@carlh.net>
Tue, 7 Jun 2016 15:03:38 +0000 (16:03 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 7 Jun 2016 15:03:38 +0000 (16:03 +0100)
src/lib/transcoder.cc
src/lib/transcoder.h

index 8afd647092512c2d802d9541e1ef5680cac86752..fd44e4df75ceb1e2f4f093e6b6dfd6aa6d8d036d 100644 (file)
@@ -53,7 +53,7 @@ using boost::dynamic_pointer_cast;
  *  @param f Film that we are transcoding.
  *  @param j Job that this transcoder is being used in.
  */
-Transcoder::Transcoder (shared_ptr<const Film> film, shared_ptr<Job> j)
+Transcoder::Transcoder (shared_ptr<const Film> film, weak_ptr<Job> j)
        : _film (film)
        , _job (j)
        , _player (new Player (film, film->playlist ()))
@@ -70,7 +70,11 @@ Transcoder::go ()
        _writer->start ();
        _encoder->begin ();
 
-       _job->sub (_("Encoding picture and sound"));
+       {
+               shared_ptr<Job> job = _job.lock ();
+               DCPOMATIC_ASSERT (job);
+               job->sub (_("Encoding picture and sound"));
+       }
 
        DCPTime const frame = DCPTime::from_frames (1, _film->video_frame_rate ());
        DCPTime const length = _film->length ();
@@ -99,7 +103,11 @@ Transcoder::go ()
                        _writer->write (_player->get_subtitles (t, frame, true, false, true));
                }
 
-               _job->set_progress (float(t.get()) / length.get());
+               {
+                       shared_ptr<Job> job = _job.lock ();
+                       DCPOMATIC_ASSERT (job);
+                       job->set_progress (float(t.get()) / length.get());
+               }
        }
 
        BOOST_FOREACH (ReferencedReelAsset i, _player->get_reel_assets ()) {
index a01b6a64ad4048d336e6c9b871a80e6517644755..4256a5c91dfa4aa44caa2d6ebb60bc0dc13552d9 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "types.h"
+#include <boost/weak_ptr.hpp>
 
 class Film;
 class Encoder;
@@ -30,7 +31,7 @@ class Job;
 class Transcoder : public boost::noncopyable
 {
 public:
-       Transcoder (boost::shared_ptr<const Film>, boost::shared_ptr<Job>);
+       Transcoder (boost::shared_ptr<const Film>, boost::weak_ptr<Job>);
 
        void go ();
 
@@ -44,7 +45,7 @@ public:
 
 private:
        boost::shared_ptr<const Film> _film;
-       boost::shared_ptr<Job> _job;
+       boost::weak_ptr<Job> _job;
        boost::shared_ptr<Player> _player;
        boost::shared_ptr<Writer> _writer;
        boost::shared_ptr<Encoder> _encoder;