summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-11-09 00:51:31 +0000
committerCarl Hetherington <cth@carlh.net>2013-11-09 00:51:31 +0000
commitd33a11798fc39336eb9442f11a06a9a1f2470d83 (patch)
treeac3c8b51b36eeb729eff19b2f9a017c50cd3beb9 /src/lib
parentc2679b662dfb8c3c654e85153ef6fb552e0a218c (diff)
Fix a few memory leaks.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/encoder.cc3
-rw-r--r--src/lib/encoder.h4
-rw-r--r--src/lib/ffmpeg_decoder.cc1
-rw-r--r--src/lib/player.cc12
-rw-r--r--src/lib/transcoder.cc4
-rw-r--r--src/lib/transcoder.h8
-rw-r--r--src/lib/writer.cc29
-rw-r--r--src/lib/writer.h4
8 files changed, 35 insertions, 30 deletions
diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc
index eb331551f..ecbf2e5bf 100644
--- a/src/lib/encoder.cc
+++ b/src/lib/encoder.cc
@@ -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)
diff --git a/src/lib/encoder.h b/src/lib/encoder.h
index 9875a179b..686aaa2f2 100644
--- a/src/lib/encoder.h
+++ b/src/lib/encoder.h
@@ -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;
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index 45c242237..19b99df90 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -339,6 +339,7 @@ FFmpegDecoder::seek (VideoContent::Frame frame, bool accurate)
}
if (_packet.stream_index != _video_stream) {
+ av_free_packet (&_packet);
continue;
}
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 53186af6e..4fbd906c6 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -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;
}
diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc
index 24f22a9cb..826cba4fc 100644
--- a/src/lib/transcoder.cc
+++ b/src/lib/transcoder.cc
@@ -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)
{
diff --git a/src/lib/transcoder.h b/src/lib/transcoder.h
index b1183b0bb..d7736d4e8 100644
--- a/src/lib/transcoder.h
+++ b/src/lib/transcoder.h
@@ -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;
diff --git a/src/lib/writer.cc b/src/lib/writer.cc
index 40f6ed971..5386efd9d 100644
--- a/src/lib/writer.cc
+++ b/src/lib/writer.cc
@@ -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)) {
diff --git a/src/lib/writer.h b/src/lib/writer.h
index d922cfce0..17ce42572 100644
--- a/src/lib/writer.h
+++ b/src/lib/writer.h
@@ -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;