X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdecoder.cc;h=f912c473cd5d7e37513cb7fa4a93df133d2c93d6;hb=006e38346a8bcdcc889979b7c00802d9bb8fc6f8;hp=637e0ddb291101af81f28115327f195a3e128116;hpb=a0856e3fbef17f24073b01cb96be6bbcb229ecbc;p=dcpomatic.git diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index 637e0ddb2..f912c473c 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -1,38 +1,94 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2018 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ -/** @file src/decoder.cc - * @brief Parent class for decoders of content. - */ - -#include "film.h" #include "decoder.h" +#include "video_decoder.h" +#include "audio_decoder.h" +#include "text_decoder.h" +#include +#include -#include "i18n.h" - +using std::cout; +using boost::optional; using boost::shared_ptr; +using boost::weak_ptr; +using namespace dcpomatic; + +Decoder::Decoder (weak_ptr film) + : _film (film) +{ + +} + +/** @return Earliest time of content that the next pass() will emit */ +ContentTime +Decoder::position () const +{ + optional pos; + shared_ptr f = film(); + + if (video && !video->ignore() && (!pos || video->position(f) < *pos)) { + pos = video->position(f); + } + + if (audio && !audio->ignore() && (!pos || audio->position(f) < *pos)) { + pos = audio->position(f); + } + + BOOST_FOREACH (shared_ptr i, text) { + if (!i->ignore() && (!pos || i->position(f) < *pos)) { + pos = i->position(f); + } + } + + 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 (); + } +} + +shared_ptr +Decoder::only_text () const +{ + DCPOMATIC_ASSERT (text.size() < 2); + if (text.empty ()) { + return shared_ptr (); + } + return text.front (); +} -/** @param f Film. - * @param o Decode options. - */ -Decoder::Decoder (shared_ptr f) - : _film (f) +shared_ptr +Decoder::film () const { - _film_connection = f->Changed.connect (bind (&Decoder::film_changed, this, _1)); + shared_ptr f = _film.lock (); + DCPOMATIC_ASSERT (f); + return f; }