From 57f112a2bd073123a686141be6c16ba997349056 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 25 Jul 2019 11:37:52 +0100 Subject: [PATCH] Optimise decoder_factory for DCPDecoder by offering the old decoder (if available) to recover the list of reels from, rather than having to scan the filesystem again. --- src/lib/dcp_decoder.cc | 39 +++++++++++++++++++++----------------- src/lib/dcp_decoder.h | 7 ++++++- src/lib/decoder_factory.cc | 18 +++++++++++++++--- src/lib/decoder_factory.h | 5 +++-- src/lib/player.cc | 11 ++++++++++- src/wx/text_panel.cc | 2 +- 6 files changed, 57 insertions(+), 25 deletions(-) diff --git a/src/lib/dcp_decoder.cc b/src/lib/dcp_decoder.cc index 5a72fb228..b6947211c 100644 --- a/src/lib/dcp_decoder.cc +++ b/src/lib/dcp_decoder.cc @@ -56,7 +56,7 @@ using boost::dynamic_pointer_cast; using boost::optional; using namespace dcpomatic; -DCPDecoder::DCPDecoder (shared_ptr film, shared_ptr c, bool fast) +DCPDecoder::DCPDecoder (shared_ptr film, shared_ptr c, bool fast, shared_ptr old) : DCP (c) , Decoder (film) , _decode_referenced (false) @@ -74,30 +74,35 @@ DCPDecoder::DCPDecoder (shared_ptr film, shared_ptr > cpl_list = cpls (); + if (old) { + _reels = old->_reels; + } else { - if (cpl_list.empty()) { - throw DCPError (_("No CPLs found in DCP.")); - } + list > cpl_list = cpls (); - shared_ptr cpl; - BOOST_FOREACH (shared_ptr i, cpl_list) { - if (_dcp_content->cpl() && i->id() == _dcp_content->cpl().get()) { - cpl = i; + if (cpl_list.empty()) { + throw DCPError (_("No CPLs found in DCP.")); + } + + shared_ptr cpl; + BOOST_FOREACH (shared_ptr i, cpl_list) { + if (_dcp_content->cpl() && i->id() == _dcp_content->cpl().get()) { + cpl = i; + } } - } - if (!cpl) { - /* No CPL found; probably an old file that doesn't specify it; - just use the first one. - */ - cpl = cpls().front (); + if (!cpl) { + /* No CPL found; probably an old file that doesn't specify it; + just use the first one. + */ + cpl = cpls().front (); + } + + _reels = cpl->reels (); } set_decode_referenced (false); - _reels = cpl->reels (); - _reel = _reels.begin (); _offset = 0; get_readers (); diff --git a/src/lib/dcp_decoder.h b/src/lib/dcp_decoder.h index 0fc598bd7..f31d28053 100644 --- a/src/lib/dcp_decoder.h +++ b/src/lib/dcp_decoder.h @@ -40,7 +40,12 @@ struct dcp_subtitle_within_dcp_test; class DCPDecoder : public DCP, public Decoder { public: - DCPDecoder (boost::shared_ptr film, boost::shared_ptr, bool fast); + DCPDecoder ( + boost::shared_ptr film, + boost::shared_ptr, + bool fast, + boost::shared_ptr old = boost::shared_ptr() + ); std::list > reels () const { return _reels; diff --git a/src/lib/decoder_factory.cc b/src/lib/decoder_factory.cc index 4b2a594e1..5d758956d 100644 --- a/src/lib/decoder_factory.cc +++ b/src/lib/decoder_factory.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Carl Hetherington + Copyright (C) 2016-2019 Carl Hetherington This file is part of DCP-o-matic. @@ -30,14 +30,26 @@ #include "dcp_subtitle_decoder.h" #include "video_mxf_content.h" #include "video_mxf_decoder.h" +#include "timer.h" #include using std::list; using boost::shared_ptr; using boost::dynamic_pointer_cast; +template +shared_ptr +maybe_cast (shared_ptr d) +{ + if (!d) { + return shared_ptr (); + } + return dynamic_pointer_cast (d); +} + +/** @param old_decoder A `used' decoder that has been previously made for this piece of content, or 0 */ shared_ptr -decoder_factory (shared_ptr film, shared_ptr content, bool fast) +decoder_factory (shared_ptr film, shared_ptr content, bool fast, shared_ptr old_decoder) { shared_ptr fc = dynamic_pointer_cast (content); if (fc) { @@ -47,7 +59,7 @@ decoder_factory (shared_ptr film, shared_ptr content, shared_ptr dc = dynamic_pointer_cast (content); if (dc) { try { - return shared_ptr (new DCPDecoder(film, dc, fast)); + return shared_ptr (new DCPDecoder(film, dc, fast, maybe_cast(old_decoder))); } catch (KDMError& e) { /* This will be found and reported to the user when the content is examined */ return shared_ptr(); diff --git a/src/lib/decoder_factory.h b/src/lib/decoder_factory.h index d4e39da17..cb145c8a9 100644 --- a/src/lib/decoder_factory.h +++ b/src/lib/decoder_factory.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Carl Hetherington + Copyright (C) 2016-2019 Carl Hetherington This file is part of DCP-o-matic. @@ -23,5 +23,6 @@ class ImageDecoder; extern boost::shared_ptr decoder_factory ( boost::shared_ptr film, boost::shared_ptr content, - bool fast + bool fast, + boost::shared_ptr old_decoder ); diff --git a/src/lib/player.cc b/src/lib/player.cc index 08e138fe6..acde910be 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -138,6 +138,7 @@ have_audio (shared_ptr piece) void Player::setup_pieces_unlocked () { + list > old_pieces = _pieces; _pieces.clear (); delete _shuffler; @@ -155,7 +156,15 @@ Player::setup_pieces_unlocked () continue; } - shared_ptr decoder = decoder_factory (_film, i, _fast); + shared_ptr old_decoder; + BOOST_FOREACH (shared_ptr j, old_pieces) { + if (j->content == i) { + old_decoder = j->decoder; + break; + } + } + + shared_ptr decoder = decoder_factory (_film, i, _fast, old_decoder); FrameRateChange frc (_film, i); if (!decoder) { diff --git a/src/wx/text_panel.cc b/src/wx/text_panel.cc index 7c48831fc..98398aaa6 100644 --- a/src/wx/text_panel.cc +++ b/src/wx/text_panel.cc @@ -667,7 +667,7 @@ TextPanel::text_view_clicked () ContentList c = _parent->selected_text (); DCPOMATIC_ASSERT (c.size() == 1); - shared_ptr decoder = decoder_factory (_parent->film(), c.front(), false); + shared_ptr decoder = decoder_factory (_parent->film(), c.front(), false, shared_ptr()); if (decoder) { _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer()); -- 2.30.2