A possibly-better approach to seeking.
[dcpomatic.git] / src / lib / dcp_decoder.cc
index 2e3ed374aaa8c07ef9dffe276ca40ab297aa78cd..38c2a7ccfa2bdcab2bb96ecf850eed4de53ba5e4 100644 (file)
@@ -73,7 +73,13 @@ DCPDecoder::DCPDecoder (shared_ptr<const DCPContent> c, shared_ptr<Log> log)
                }
        }
 
-       DCPOMATIC_ASSERT (cpl);
+       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 ();
 
        _reel = _reels.begin ();
@@ -157,6 +163,7 @@ DCPDecoder::pass (PassReason reason, bool)
                }
        }
 
+       _position = _next;
        _next += ContentTime::from_frames (1, vfr);
 
        if ((*_reel)->main_picture ()) {
@@ -245,27 +252,32 @@ DCPDecoder::text_subtitles_during (ContentTimePeriod period, bool starting) cons
        list<ContentTimePeriod> ctp;
        double const vfr = _dcp_content->active_video_frame_rate ();
 
+       int offset = 0;
+
        BOOST_FOREACH (shared_ptr<dcp::Reel> r, _reels) {
                if (!r->main_subtitle ()) {
+                       offset += r->main_picture()->duration();
                        continue;
                }
 
                int64_t const entry_point = r->main_subtitle()->entry_point ();
 
                list<dcp::SubtitleString> subs = r->main_subtitle()->asset()->subtitles_during (
-                       dcp::Time (period.from.seconds(), 1000) - dcp::Time (entry_point, vfr, vfr),
-                       dcp::Time (period.to.seconds(), 1000) - dcp::Time (entry_point, vfr, vfr),
+                       dcp::Time (period.from.seconds(), 1000) - dcp::Time (offset - entry_point, vfr, vfr),
+                       dcp::Time (period.to.seconds(), 1000) - dcp::Time (offset - entry_point, vfr, vfr),
                        starting
                        );
 
                BOOST_FOREACH (dcp::SubtitleString const & s, subs) {
                        ctp.push_back (
                                ContentTimePeriod (
-                                       ContentTime::from_seconds (s.in().as_seconds ()),
-                                       ContentTime::from_seconds (s.out().as_seconds ())
+                                       ContentTime::from_seconds (s.in().as_seconds ()) + ContentTime::from_frames (offset - entry_point, vfr),
+                                       ContentTime::from_seconds (s.out().as_seconds ()) + ContentTime::from_frames (offset - entry_point, vfr)
                                        )
                                );
                }
+
+               offset += r->main_subtitle()->duration();
        }
 
        return ctp;