- 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 (c->video) {
+ video.reset (new VideoDecoder (this, c, log));
+ }
+ if (c->audio) {
+ audio.reset (new AudioDecoder (this, c->audio, log, fast));
+ }
+ if (c->caption) {
+ /* XXX: this time here should be the time of the first subtitle, not 0 */
+ caption.reset (new CaptionDecoder (this, c->caption, log, ContentTime()));
+ }
+
+ list<shared_ptr<dcp::CPL> > cpl_list = cpls ();
+
+ 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 ();
+ }
+
+ set_decode_referenced (false);
+
+ _reels = cpl->reels ();
+