diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-06-01 22:06:16 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-06-01 22:06:16 +0100 |
| commit | 7a0c2256cbf94d2434ba6e7485517df0a7f894af (patch) | |
| tree | 1f00da832f30fa325429a4a5cbb4594a7f706999 /src/lib/dcp_decoder.cc | |
| parent | 97d25da42455d0ed93c2eebe023883767bb12d53 (diff) | |
Compute offset as we go rather than once every pass().
Diffstat (limited to 'src/lib/dcp_decoder.cc')
| -rw-r--r-- | src/lib/dcp_decoder.cc | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/lib/dcp_decoder.cc b/src/lib/dcp_decoder.cc index 420c6a7be..18cbda84c 100644 --- a/src/lib/dcp_decoder.cc +++ b/src/lib/dcp_decoder.cc @@ -69,7 +69,9 @@ DCPDecoder::DCPDecoder (shared_ptr<const DCPContent> c, shared_ptr<Log> log, boo } DCPOMATIC_ASSERT (dcp.cpls().size() == 1); _reels = dcp.cpls().front()->reels (); + _reel = _reels.begin (); + _offset = 0; } bool @@ -79,14 +81,6 @@ DCPDecoder::pass (PassReason reason, bool) return true; } - /* Offset of the start of the current reel from the start of the content in frames */ - int offset = 0; - list<shared_ptr<dcp::Reel> >::const_iterator i = _reels.begin(); - while (i != _reel) { - offset += (*i)->main_picture()->duration (); - ++i; - } - double const vfr = _dcp_content->active_video_frame_rate (); /* Frame within the (played part of the) reel that is coming up next */ @@ -98,16 +92,16 @@ DCPDecoder::pass (PassReason reason, bool) shared_ptr<dcp::StereoPictureAsset> stereo = dynamic_pointer_cast<dcp::StereoPictureAsset> (asset); int64_t const entry_point = (*_reel)->main_picture()->entry_point (); if (mono) { - video->give (shared_ptr<ImageProxy> (new J2KImageProxy (mono->get_frame (entry_point + frame), asset->size())), offset + frame); + video->give (shared_ptr<ImageProxy> (new J2KImageProxy (mono->get_frame (entry_point + frame), asset->size())), _offset + frame); } else { video->give ( shared_ptr<ImageProxy> (new J2KImageProxy (stereo->get_frame (entry_point + frame), asset->size(), dcp::EYE_LEFT)), - offset + frame + _offset + frame ); video->give ( shared_ptr<ImageProxy> (new J2KImageProxy (stereo->get_frame (entry_point + frame), asset->size(), dcp::EYE_RIGHT)), - offset + frame + _offset + frame ); } } @@ -127,7 +121,7 @@ DCPDecoder::pass (PassReason reason, bool) } } - audio->give (_dcp_content->audio->stream(), data, ContentTime::from_frames (offset, vfr) + _next); + audio->give (_dcp_content->audio->stream(), data, ContentTime::from_frames (_offset, vfr) + _next); } if ((*_reel)->main_subtitle ()) { @@ -142,8 +136,8 @@ DCPDecoder::pass (PassReason reason, bool) /* XXX: assuming that all `subs' are at the same time; maybe this is ok */ subtitle->give_text ( ContentTimePeriod ( - ContentTime::from_frames (offset - entry_point, vfr) + ContentTime::from_seconds (subs.front().in().as_seconds ()), - ContentTime::from_frames (offset - entry_point, vfr) + ContentTime::from_seconds (subs.front().out().as_seconds ()) + ContentTime::from_frames (_offset - entry_point, vfr) + ContentTime::from_seconds (subs.front().in().as_seconds ()), + ContentTime::from_frames (_offset - entry_point, vfr) + ContentTime::from_seconds (subs.front().out().as_seconds ()) ), subs ); @@ -154,7 +148,7 @@ DCPDecoder::pass (PassReason reason, bool) if ((*_reel)->main_picture ()) { if (_next.frames_round (vfr) >= (*_reel)->main_picture()->duration()) { - ++_reel; + next_reel (); _next = ContentTime (); } } @@ -163,16 +157,24 @@ DCPDecoder::pass (PassReason reason, bool) } void +DCPDecoder::next_reel () +{ + _offset += (*_reel)->main_picture()->duration(); + ++_reel; +} + +void DCPDecoder::seek (ContentTime t, bool accurate) { video->seek (t, accurate); audio->seek (t, accurate); subtitle->seek (t, accurate); + _offset = 0; _reel = _reels.begin (); while (_reel != _reels.end() && t >= ContentTime::from_frames ((*_reel)->main_picture()->duration(), _dcp_content->active_video_frame_rate ())) { t -= ContentTime::from_frames ((*_reel)->main_picture()->duration(), _dcp_content->active_video_frame_rate ()); - ++_reel; + next_reel (); } _next = t; |
