X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdecoder.cc;h=2fddddc914dee09bee221af4c5b1fdc985d61c9b;hb=cbd4450197a083bf58bda510e626f73ba583cb66;hp=b7bd78c1404415e6b61c11940d4ccae67502b8d2;hpb=fa155dece604627b76c45e18501dfecba3e6ab88;p=dcpomatic.git diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index b7bd78c14..2fddddc91 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,19 +19,59 @@ */ #include "decoder.h" +#include "video_decoder.h" +#include "audio_decoder.h" +#include "caption_decoder.h" +#include #include 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 +{ + 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, caption) { + if (!i->ignore() && (!pos || i->position() < *pos)) { + pos = i->position(); + } + } + + return pos.get_value_or(ContentTime()); +} void -Decoder::maybe_seek (optional& position, ContentTime time, bool accurate) +Decoder::seek (ContentTime, bool) { - if (position && (time >= *position && time < (*position + ContentTime::from_seconds(1)))) { - /* No need to seek: caller should just pass() */ - return; + if (video) { + video->seek (); + } + if (audio) { + audio->seek (); + } + BOOST_FOREACH (shared_ptr i, caption) { + i->seek (); } +} - position.reset (); - seek (time, accurate); +shared_ptr +Decoder::only_caption () const +{ + DCPOMATIC_ASSERT (caption.size() < 2); + if (caption.empty ()) { + return shared_ptr (); + } + return caption.front (); }