From 8dd9ea3086b4934f2719648ffa6333c0d106ff36 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 24 Apr 2013 01:02:25 +0100 Subject: Some const correctness. --- src/lib/encoder.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib/encoder.cc') diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index 7b338407e..7a1eea069 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -231,7 +231,7 @@ Encoder::frame_done () } void -Encoder::process_video (shared_ptr image, bool same, boost::shared_ptr sub) +Encoder::process_video (shared_ptr image, bool same, boost::shared_ptr sub) { FrameRateConversion frc (_film->source_frame_rate(), _film->dcp_frame_rate()); @@ -294,7 +294,7 @@ Encoder::process_video (shared_ptr image, bool same, boost::shared_ptr data) +Encoder::process_audio (shared_ptr data) { #if HAVE_SWRESAMPLE /* Maybe sample-rate convert */ -- cgit v1.2.3 From 7b2ec1dd69951649f2c912fcf90b22913b1f6c3a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 25 Apr 2013 13:44:02 +0100 Subject: Remove Image::clone in favour of a copy constructor for SimpleImage; clean up A/B transcoder slightly; fix combiner if image strides differ; try to fix problems when destroying Encoders; fix SimpleImage copy constructor to cope with aligned images; don't call encoder::process_end if the encode throws an exception. --- src/lib/ab_transcoder.cc | 14 +++++--------- src/lib/combiner.cc | 7 +++---- src/lib/encoder.cc | 4 +++- src/lib/image.cc | 34 +++++++++++++++++++++++++++------- src/lib/image.h | 7 +------ src/lib/transcoder.cc | 37 ++++++++++++++++--------------------- 6 files changed, 55 insertions(+), 48 deletions(-) (limited to 'src/lib/encoder.cc') diff --git a/src/lib/ab_transcoder.cc b/src/lib/ab_transcoder.cc index 26643b50e..d8f13dae4 100644 --- a/src/lib/ab_transcoder.cc +++ b/src/lib/ab_transcoder.cc @@ -122,25 +122,21 @@ ABTranscoder::go () } else { done[2] = true; } - + if (_job) { _da.video->set_progress (_job); } - + if (done[0] && done[1] && done[2]) { break; } } - - if (_delay_line) { - _delay_line->process_end (); - } + + _delay_line->process_end (); if (_matcher) { _matcher->process_end (); } - if (_gain) { - _gain->process_end (); - } + _gain->process_end (); _encoder->process_end (); } diff --git a/src/lib/combiner.cc b/src/lib/combiner.cc index 250528aeb..367cefa7f 100644 --- a/src/lib/combiner.cc +++ b/src/lib/combiner.cc @@ -35,7 +35,7 @@ Combiner::Combiner (shared_ptr log) void Combiner::process_video (shared_ptr image, bool, shared_ptr, double) { - _image = image->clone (); + _image.reset (new SimpleImage (image)); } /** Process video for the right half of the frame. @@ -50,15 +50,14 @@ Combiner::process_video_b (shared_ptr image, bool, shared_ptrcomponents(); ++i) { int const line_size = image->line_size()[i]; int const half_line_size = line_size / 2; - int const stride = image->stride()[i]; uint8_t* p = _image->data()[i]; uint8_t* q = image->data()[i]; for (int j = 0; j < image->lines (i); ++j) { memcpy (p + half_line_size, q + half_line_size, half_line_size); - p += stride; - q += stride; + p += _image->stride()[i]; + q += image->stride()[i]; } } diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index 7a1eea069..cff9899ac 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -333,7 +333,9 @@ Encoder::terminate_threads () lock.unlock (); for (list::iterator i = _threads.begin(); i != _threads.end(); ++i) { - (*i)->join (); + if ((*i)->joinable ()) { + (*i)->join (); + } delete *i; } } diff --git a/src/lib/image.cc b/src/lib/image.cc index 9bcbb87ab..1be41fecf 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -509,7 +509,33 @@ SimpleImage::SimpleImage (SimpleImage const & other) allocate (); for (int i = 0; i < components(); ++i) { - memcpy (_data[i], other._data[i], _line_size[i] * lines(i)); + uint8_t* p = _data[i]; + uint8_t* q = other._data[i]; + for (int j = 0; j < lines(i); ++j) { + memcpy (p, q, _line_size[i]); + p += stride()[i]; + q += other.stride()[i]; + } + } +} + +SimpleImage::SimpleImage (shared_ptr other) + : Image (*other.get()) +{ + _size = other->size (); + _aligned = true; + + allocate (); + + for (int i = 0; i < components(); ++i) { + assert(line_size()[i] == other->line_size()[i]); + uint8_t* p = _data[i]; + uint8_t* q = other->data()[i]; + for (int j = 0; j < lines(i); ++j) { + memcpy (p, q, line_size()[i]); + p += stride()[i]; + q += other->stride()[i]; + } } } @@ -583,12 +609,6 @@ SimpleImage::aligned () const return _aligned; } -shared_ptr -SimpleImage::clone () const -{ - return shared_ptr (new SimpleImage (*this)); -} - FilterBufferImage::FilterBufferImage (AVPixelFormat p, AVFilterBufferRef* b) : Image (p) , _buffer (b) diff --git a/src/lib/image.h b/src/lib/image.h index 31035d272..62961a92e 100644 --- a/src/lib/image.h +++ b/src/lib/image.h @@ -70,8 +70,6 @@ public: virtual bool aligned () const = 0; - virtual boost::shared_ptr clone () const = 0; - int components () const; int lines (int) const; @@ -120,9 +118,6 @@ private: /* Not allowed */ FilterBufferImage (FilterBufferImage const &); FilterBufferImage& operator= (FilterBufferImage const &); - boost::shared_ptr clone () const { - assert (false); - } AVFilterBufferRef* _buffer; int* _line_size; @@ -136,6 +131,7 @@ class SimpleImage : public Image public: SimpleImage (AVPixelFormat, libdcp::Size, bool); SimpleImage (SimpleImage const &); + SimpleImage (boost::shared_ptr); SimpleImage& operator= (SimpleImage const &); ~SimpleImage (); @@ -144,7 +140,6 @@ public: int * stride () const; libdcp::Size size () const; bool aligned () const; - boost::shared_ptr clone () const; protected: void allocate (); diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc index 4d3f29e83..faafcaf8b 100644 --- a/src/lib/transcoder.cc +++ b/src/lib/transcoder.cc @@ -103,31 +103,26 @@ void Transcoder::go () { _encoder->process_begin (); - try { - bool done[2] = { false, false }; - - while (1) { - if (!done[0]) { - done[0] = _decoders.video->pass (); - if (_job) { - _decoders.video->set_progress (_job); - } - } - - if (!done[1] && _decoders.audio && dynamic_pointer_cast (_decoders.audio) != dynamic_pointer_cast (_decoders.video)) { - done[1] = _decoders.audio->pass (); - } else { - done[1] = true; - } - if (done[0] && done[1]) { - break; + bool done[2] = { false, false }; + + while (1) { + if (!done[0]) { + done[0] = _decoders.video->pass (); + if (_job) { + _decoders.video->set_progress (_job); } } - } catch (...) { - _encoder->process_end (); - throw; + if (!done[1] && _decoders.audio && dynamic_pointer_cast (_decoders.audio) != dynamic_pointer_cast (_decoders.video)) { + done[1] = _decoders.audio->pass (); + } else { + done[1] = true; + } + + if (done[0] && done[1]) { + break; + } } _delay_line->process_end (); -- cgit v1.2.3