X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fdecoder.cc;h=6078141dcfab4d0f84fff1026154106ff389595d;hb=422eb00b446d90e3588ae6793f676917ee195cca;hp=cba674d0415ed9df573c5fb955cd3ea72104392b;hpb=97d39f46795af78b84d5f7bc9118a188f2864781;p=dcpomatic.git diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index cba674d04..6078141dc 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2018 Carl Hetherington This file is part of DCP-o-matic. @@ -19,20 +19,59 @@ */ #include "decoder.h" +#include "video_decoder.h" +#include "audio_decoder.h" +#include "text_decoder.h" +#include +#include -void -Decoder::maybe_seek (ContentTime time, bool accurate) +using std::cout; +using boost::optional; +using boost::shared_ptr; + +/** @return Earliest time of content that the next pass() will emit */ +ContentTime +Decoder::position () const { - if (!_position) { - /* A seek has just happened */ - return; + optional pos; + + if (video && !video->ignore() && (!pos || video->position() < *pos)) { + pos = video->position(); + } + + if (audio && !audio->ignore() && (!pos || audio->position() < *pos)) { + pos = audio->position(); + } + + BOOST_FOREACH (shared_ptr i, text) { + if (!i->ignore() && (!pos || i->position() < *pos)) { + pos = i->position(); + } } - if (time >= *_position && time < (*_position + ContentTime::from_seconds(1))) { - /* No need to seek: caller should just pass() */ - return; + return pos.get_value_or(ContentTime()); +} + +void +Decoder::seek (ContentTime, bool) +{ + if (video) { + video->seek (); + } + if (audio) { + audio->seek (); } + BOOST_FOREACH (shared_ptr i, text) { + i->seek (); + } +} - _position.reset (); - seek (time, accurate); +shared_ptr +Decoder::only_text () const +{ + DCPOMATIC_ASSERT (text.size() < 2); + if (text.empty ()) { + return shared_ptr (); + } + return text.front (); }