Fix a few memory leaks.
authorCarl Hetherington <cth@carlh.net>
Sat, 9 Nov 2013 00:51:31 +0000 (00:51 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 9 Nov 2013 00:51:31 +0000 (00:51 +0000)
src/lib/encoder.cc
src/lib/encoder.h
src/lib/ffmpeg_decoder.cc
src/lib/player.cc
src/lib/transcoder.cc
src/lib/transcoder.h
src/lib/writer.cc
src/lib/writer.h

index eb331551fffb6d6c10dee1e3b96280a72e8f89e4..ecbf2e5bf87ca0bbc046ffa4f39fbac2ea874a3a 100644 (file)
@@ -46,13 +46,14 @@ using std::cout;
 using std::min;
 using std::make_pair;
 using boost::shared_ptr;
+using boost::weak_ptr;
 using boost::optional;
 using boost::scoped_array;
 
 int const Encoder::_history_size = 25;
 
 /** @param f Film that we are encoding */
-Encoder::Encoder (shared_ptr<const Film> f, shared_ptr<Job> j)
+Encoder::Encoder (shared_ptr<const Film> f, weak_ptr<Job> j)
        : _film (f)
        , _job (j)
        , _video_frames_out (0)
index 9875a179b45152407b73ffeead41317a670f4de1..686aaa2f25e4977d16644813016e0f0550e208c3 100644 (file)
@@ -58,7 +58,7 @@ class ServerFinder;
 class Encoder : public boost::noncopyable
 {
 public:
-       Encoder (boost::shared_ptr<const Film> f, boost::shared_ptr<Job>);
+       Encoder (boost::shared_ptr<const Film> f, boost::weak_ptr<Job>);
        virtual ~Encoder ();
 
        /** Called to indicate that a processing run is about to begin */
@@ -90,7 +90,7 @@ private:
 
        /** Film that we are encoding */
        boost::shared_ptr<const Film> _film;
-       boost::shared_ptr<Job> _job;
+       boost::weak_ptr<Job> _job;
 
        /** Mutex for _time_history and _last_frame */
        mutable boost::mutex _state_mutex;
index 45c242237e6b50f3c504389c3e8a765cec3d522f..19b99df90748c071bdc43db06ad4b19e23fb2e6d 100644 (file)
@@ -339,6 +339,7 @@ FFmpegDecoder::seek (VideoContent::Frame frame, bool accurate)
                }
 
                if (_packet.stream_index != _video_stream) {
+                       av_free_packet (&_packet);
                        continue;
                }
                
index 53186af6e176480067ef3134421af7d419b51b7d..4fbd906c64ec9591538d05d9399bea9f2df2a572 100644 (file)
@@ -452,9 +452,9 @@ Player::setup_pieces ()
                if (fc) {
                        shared_ptr<FFmpegDecoder> fd (new FFmpegDecoder (_film, fc, _video, _audio));
                        
-                       fd->Video.connect (bind (&Player::process_video, this, piece, _1, _2, _3, _4, 0));
-                       fd->Audio.connect (bind (&Player::process_audio, this, piece, _1, _2));
-                       fd->Subtitle.connect (bind (&Player::process_subtitle, this, piece, _1, _2, _3, _4));
+                       fd->Video.connect (bind (&Player::process_video, this, weak_ptr<Piece> (piece), _1, _2, _3, _4, 0));
+                       fd->Audio.connect (bind (&Player::process_audio, this, weak_ptr<Piece> (piece), _1, _2));
+                       fd->Subtitle.connect (bind (&Player::process_subtitle, this, weak_ptr<Piece> (piece), _1, _2, _3, _4));
 
                        fd->seek (fc->time_to_content_video_frames (fc->trim_start ()), true);
                        piece->decoder = fd;
@@ -474,7 +474,7 @@ Player::setup_pieces ()
 
                        if (!id) {
                                id.reset (new StillImageDecoder (_film, ic));
-                               id->Video.connect (bind (&Player::process_video, this, piece, _1, _2, _3, _4, 0));
+                               id->Video.connect (bind (&Player::process_video, this, weak_ptr<Piece> (piece), _1, _2, _3, _4, 0));
                        }
 
                        piece->decoder = id;
@@ -486,7 +486,7 @@ Player::setup_pieces ()
 
                        if (!md) {
                                md.reset (new MovingImageDecoder (_film, mc));
-                               md->Video.connect (bind (&Player::process_video, this, piece, _1, _2, _3, _4, 0));
+                               md->Video.connect (bind (&Player::process_video, this, weak_ptr<Piece> (piece), _1, _2, _3, _4, 0));
                        }
 
                        piece->decoder = md;
@@ -495,7 +495,7 @@ Player::setup_pieces ()
                shared_ptr<const SndfileContent> sc = dynamic_pointer_cast<const SndfileContent> (*i);
                if (sc) {
                        shared_ptr<AudioDecoder> sd (new SndfileDecoder (_film, sc));
-                       sd->Audio.connect (bind (&Player::process_audio, this, piece, _1, _2));
+                       sd->Audio.connect (bind (&Player::process_audio, this, weak_ptr<Piece> (piece), _1, _2));
 
                        piece->decoder = sd;
                }
index 24f22a9cb4cc35030d1d34ac27a9053b10eff9e5..826cba4fc61aa8755b7665dff5b97ee705166e04 100644 (file)
@@ -59,12 +59,10 @@ audio_proxy (weak_ptr<Encoder> encoder, shared_ptr<const AudioBuffers> audio)
 
 /** Construct a transcoder using a Decoder that we create and a supplied Encoder.
  *  @param f Film that we are transcoding.
- *  @param j Job that we are running under, or 0.
  *  @param e Encoder to use.
  */
 Transcoder::Transcoder (shared_ptr<const Film> f, shared_ptr<Job> j)
-       : _job (j)
-       , _player (f->make_player ())
+       : _player (f->make_player ())
        , _encoder (new Encoder (f, j))
        , _finishing (false)
 {
index b1183b0bb5448ebbcc41921dde4fcf0e0b90ed0e..d7736d4e8e56dd3a1cdf7440e6a5872bb7a59db1 100644 (file)
@@ -21,7 +21,6 @@
 #include "encoder.h"
 
 class Film;
-class Job;
 class Encoder;
 class VideoFilter;
 class Player;
@@ -30,10 +29,7 @@ class Player;
 class Transcoder : public boost::noncopyable
 {
 public:
-       Transcoder (
-               boost::shared_ptr<const Film> f,
-               boost::shared_ptr<Job> j
-               );
+       Transcoder (boost::shared_ptr<const Film>, boost::shared_ptr<Job>);
 
        void go ();
 
@@ -46,8 +42,6 @@ public:
        }
 
 private:
-       /** A Job that is running this Transcoder, or 0 */
-       boost::shared_ptr<Job> _job;
        boost::shared_ptr<Player> _player;
        boost::shared_ptr<Encoder> _encoder;
        bool _finishing;
index 40f6ed9714baacd1a2bc9bb93b813d651a48225e..5386efd9d200b0cadd734ba7d643c876fe4fbbbb 100644 (file)
@@ -46,10 +46,11 @@ using std::ifstream;
 using std::list;
 using std::cout;
 using boost::shared_ptr;
+using boost::weak_ptr;
 
 int const Writer::_maximum_frames_in_memory = 8;
 
-Writer::Writer (shared_ptr<const Film> f, shared_ptr<Job> j)
+Writer::Writer (shared_ptr<const Film> f, weak_ptr<Job> j)
        : _film (f)
        , _job (j)
        , _first_nonexistant_frame (0)
@@ -66,7 +67,9 @@ Writer::Writer (shared_ptr<const Film> f, shared_ptr<Job> j)
        /* Remove any old DCP */
        boost::filesystem::remove_all (_film->dir (_film->dcp_name ()));
 
-       _job->sub (_("Checking existing image data"));
+       shared_ptr<Job> job = _job.lock ();
+
+       job->sub (_("Checking existing image data"));
        check_existing_picture_mxf ();
 
        /* Create our picture asset in a subdirectory, named according to those
@@ -102,7 +105,7 @@ Writer::Writer (shared_ptr<const Film> f, shared_ptr<Job> j)
 
        _thread = new boost::thread (boost::bind (&Writer::thread, this));
 
-       _job->sub (_("Encoding image data"));
+       job->sub (_("Encoding image data"));
 }
 
 void
@@ -267,7 +270,9 @@ try
                        _last_written_eyes = qi.eyes;
                        
                        if (_film->length()) {
-                               _job->set_progress (
+                               shared_ptr<Job> job = _job.lock ();
+                               assert (job);
+                               job->set_progress (
                                        float (_full_written + _fake_written + _repeat_written) / _film->time_to_video_frames (_film->length())
                                        );
                        }
@@ -382,11 +387,14 @@ Writer::finish ()
                                                         )
                               ));
 
-       _job->sub (_("Computing image digest"));
-       _picture_asset->compute_digest (boost::bind (&Job::set_progress, _job.get(), _1, false));
+       shared_ptr<Job> job = _job.lock ();
+       assert (job);
+
+       job->sub (_("Computing image digest"));
+       _picture_asset->compute_digest (boost::bind (&Job::set_progress, job.get(), _1, false));
 
-       _job->sub (_("Computing audio digest"));
-       _sound_asset->compute_digest (boost::bind (&Job::set_progress, _job.get(), _1, false));
+       job->sub (_("Computing audio digest"));
+       _sound_asset->compute_digest (boost::bind (&Job::set_progress, job.get(), _1, false));
 
        libdcp::XMLMetadata meta = Config::instance()->dcp_metadata ();
        meta.set_issue_date_now ();
@@ -470,7 +478,10 @@ Writer::check_existing_picture_mxf ()
 
        while (1) {
 
-               _job->set_progress (float (_first_nonexistant_frame) / N);
+               shared_ptr<Job> job = _job.lock ();
+               assert (job);
+
+               job->set_progress (float (_first_nonexistant_frame) / N);
 
                if (_film->three_d ()) {
                        if (!check_existing_picture_mxf_frame (mxf, _first_nonexistant_frame, EYES_LEFT)) {
index d922cfce01a4685ed1b5941dc1bf0998f999c3ba..17ce42572c52da3df2d9e1a2eea96dd182da2847 100644 (file)
@@ -70,7 +70,7 @@ bool operator== (QueueItem const & a, QueueItem const & b);
 class Writer : public ExceptionStore, public boost::noncopyable
 {
 public:
-       Writer (boost::shared_ptr<const Film>, boost::shared_ptr<Job>);
+       Writer (boost::shared_ptr<const Film>, boost::weak_ptr<Job>);
 
        bool can_fake_write (int) const;
        
@@ -89,7 +89,7 @@ private:
 
        /** our Film */
        boost::shared_ptr<const Film> _film;
-       boost::shared_ptr<Job> _job;
+       boost::weak_ptr<Job> _job;
        /** the first frame index that does not already exist in our MXF */
        int _first_nonexistant_frame;