Fix failure to display when loading old films with imported DCPs.
[dcpomatic.git] / src / lib / dcp_decoder.cc
index a4207f14441c513f3700bcc0b8f5a77df8140de8..156fba1017760629a2308db044d7f2f401b304b8 100644 (file)
@@ -51,7 +51,7 @@ using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 
 DCPDecoder::DCPDecoder (shared_ptr<const DCPContent> c, shared_ptr<Log> log)
-       : _dcp_content (c)
+       : DCP (c)
        , _decode_referenced (false)
 {
        video.reset (new VideoDecoder (this, c, log));
@@ -66,13 +66,21 @@ DCPDecoder::DCPDecoder (shared_ptr<const DCPContent> c, shared_ptr<Log> log)
                        )
                );
 
-       dcp::DCP dcp (c->directory ());
-       dcp.read (false, 0, true);
-       if (c->kdm ()) {
-               dcp.add (dcp::DecryptedKDM (c->kdm().get (), Config::instance()->decryption_chain()->key().get ()));
+       shared_ptr<dcp::CPL> cpl;
+       BOOST_FOREACH (shared_ptr<dcp::CPL> i, cpls ()) {
+               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 ();
        }
-       DCPOMATIC_ASSERT (dcp.cpls().size() == 1);
-       _reels = dcp.cpls().front()->reels ();
+
+       _reels = cpl->reels ();
 
        _reel = _reels.begin ();
        _offset = 0;
@@ -178,7 +186,7 @@ DCPDecoder::next_reel ()
 void
 DCPDecoder::get_readers ()
 {
-       if (_reel == _reels.end()) {
+       if (_reel == _reels.end() || !_dcp_content->can_be_played ()) {
                _mono_reader.reset ();
                _stereo_reader.reset ();
                _sound_reader.reset ();