- video.reset (new VideoDecoder (this, c, log));
- audio.reset (new AudioDecoder (this, c->audio, fast, log));
-
- subtitle.reset (
- new SubtitleDecoder (
- this,
- c->subtitle,
- bind (&DCPDecoder::image_subtitles_during, this, _1, _2),
- bind (&DCPDecoder::text_subtitles_during, this, _1, _2)
- )
- );
-
- 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 ()));
- }
- DCPOMATIC_ASSERT (dcp.cpls().size() == 1);
- _reels = dcp.cpls().front()->reels ();
+ if (content->can_be_played()) {
+ if (content->video) {
+ video = make_shared<VideoDecoder>(this, content);
+ }
+ if (content->audio) {
+ audio = make_shared<AudioDecoder>(this, content->audio, fast);
+ }
+ for (auto i: content->text) {
+ text.push_back (make_shared<TextDecoder>(this, i));
+ /* We should really call maybe_set_position() on this TextDecoder to set the time
+ * of the first subtitle, but it probably doesn't matter since we'll always
+ * have regularly occurring video (and maybe audio) content.
+ */
+ }
+ if (content->atmos) {
+ atmos = make_shared<AtmosDecoder>(this, content);
+ }
+ }
+
+ /* We try to avoid re-scanning the DCP's files every time we make a new DCPDecoder; we do this
+ by re-using the _reels list. Before we do this we need to check that nothing too serious
+ has changed in the DCPContent.
+
+ We do this by storing a digest of the important bits of the DCPContent and then checking that's
+ the same before we re-use _reels.
+ */
+
+ _lazy_digest = calculate_lazy_digest (content);
+
+ if (old && old->lazy_digest() == _lazy_digest) {
+ _reels = old->_reels;
+ } else {
+
+ auto cpl_list = dcp::find_and_resolve_cpls(content->directories(), tolerant);
+
+ if (cpl_list.empty()) {
+ throw DCPError (_("No CPLs found in DCP."));
+ }
+
+ shared_ptr<dcp::CPL> cpl;
+ for (auto 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 = cpl_list.front();
+ }
+
+ if (content->kdm()) {
+ cpl->add (decrypt_kdm_with_helpful_error(content->kdm().get()));
+ }
+
+ _reels = cpl->reels ();
+ }
+
+ set_decode_referenced (false);
+