Optimise decoder_factory for DCPDecoder by offering the old decoder
[dcpomatic.git] / src / lib / dcp_decoder.cc
index 5a72fb2281b30fda0d06d1cefc6b33b779b9792c..b6947211c1d8ddf05461a62e5b78605088c39121 100644 (file)
@@ -56,7 +56,7 @@ using boost::dynamic_pointer_cast;
 using boost::optional;
 using namespace dcpomatic;
 
-DCPDecoder::DCPDecoder (shared_ptr<const Film> film, shared_ptr<const DCPContent> c, bool fast)
+DCPDecoder::DCPDecoder (shared_ptr<const Film> film, shared_ptr<const DCPContent> c, bool fast, shared_ptr<DCPDecoder> old)
        : DCP (c)
        , Decoder (film)
        , _decode_referenced (false)
@@ -74,30 +74,35 @@ DCPDecoder::DCPDecoder (shared_ptr<const Film> film, shared_ptr<const DCPContent
                }
        }
 
-       list<shared_ptr<dcp::CPL> > cpl_list = cpls ();
+       if (old) {
+               _reels = old->_reels;
+       } else {
 
-       if (cpl_list.empty()) {
-               throw DCPError (_("No CPLs found in DCP."));
-       }
+               list<shared_ptr<dcp::CPL> > cpl_list = cpls ();
 
-       shared_ptr<dcp::CPL> cpl;
-       BOOST_FOREACH (shared_ptr<dcp::CPL> 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<dcp::CPL> cpl;
+               BOOST_FOREACH (shared_ptr<dcp::CPL> 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 ();