From 9cb73fbc0fa4643612f01665bc6d9fc430656f32 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 19 Jul 2018 21:48:27 +0100 Subject: Reword again: Text -> Caption and Plain -> Text. sed -i "s/ActiveText/ActiveCaptions/g" src/lib/*.{cc,h} sed -i "s/active_text.h/active_captions.h/g" src/lib/*.{cc,h} sed -i "s/active_text.cc/active_captions.cc/g" src/lib/wscript mv src/lib/active_text.cc src/lib/active_captions.cc mv src/lib/active_text.h src/lib/active_captions.h sed -i "s/PlainTextFileContent/TextCaptionFileContent/g" src/lib/*.{cc,h} src/wx/*.cc sed -i "s/PlainTextFile/TextCaptionFile/g" src/lib/*.{cc,h} src/wx/*.cc sed -i "s/plain_text_file_content/text_caption_file_content/g" src/lib/*.{cc,h} src/lib/wscript src/wx/*.{cc,h} test/*.cc mv src/lib/plain_text_file_content.cc src/lib/text_caption_file_content.cc mv src/lib/plain_text_file_content.h src/lib/text_caption_file_content.h sed -i "s/PlainTextFileDecoder/TextCaptionFileDecoder/g" src/lib/*.{cc,h} sed -i "s/plain_text_file_decoder/text_caption_file_decoder/g" src/lib/*.{cc,h} src/lib/wscript src/wx/*.{cc,h} mv src/lib/plain_text_file_decoder.cc src/lib/text_caption_file_decoder.cc mv src/lib/plain_text_file_decoder.h src/lib/text_caption_file_decoder.h sed -i "s/PlayerText/PlayerCaption/g" src/lib/*.{cc,h} sed -i "s/player_text.cc/player_caption.cc/g" src/lib/wscript sed -i "s/player_text.h/player_caption.h/g" src/lib/*.{cc,h} mv src/lib/player_text.cc src/lib/player_caption.cc mv src/lib/player_text.h src/lib/player_caption.h sed -i "s/ContentPlainText/ContentTextCaption/g" src/lib/*.{cc,h} src/wx/*.{cc,h} sed -i "s/ContentBitmapText/ContentBitmapCaption/g" src/lib/*.{cc,h} src/wx/*.{cc,h} sed -i "s/PlainText/TextCaption/g" src/lib/*.{cc,h} test/*.cc sed -i "s/plain_text.h/text_caption.h/g" src/lib/*.{cc,h} mv src/lib/plain_text.h src/lib/text_caption.h --- src/lib/active_captions.cc | 139 +++++++++++++++++++++++++++++++++++ src/lib/active_captions.h | 65 ++++++++++++++++ src/lib/active_text.cc | 139 ----------------------------------- src/lib/active_text.h | 65 ---------------- src/lib/content_factory.cc | 6 +- src/lib/content_text.h | 8 +- src/lib/dcp_encoder.cc | 2 +- src/lib/dcp_encoder.h | 4 +- src/lib/decoder_factory.cc | 8 +- src/lib/encoder.h | 2 +- src/lib/ffmpeg_encoder.cc | 2 +- src/lib/ffmpeg_encoder.h | 2 +- src/lib/plain_text.h | 46 ------------ src/lib/plain_text_file.cc | 8 +- src/lib/plain_text_file.h | 12 +-- src/lib/plain_text_file_content.cc | 95 ------------------------ src/lib/plain_text_file_content.h | 46 ------------ src/lib/plain_text_file_decoder.cc | 89 ---------------------- src/lib/plain_text_file_decoder.h | 44 ----------- src/lib/player.cc | 14 ++-- src/lib/player.h | 12 +-- src/lib/player_caption.cc | 42 +++++++++++ src/lib/player_caption.h | 42 +++++++++++ src/lib/player_text.cc | 42 ----------- src/lib/player_text.h | 42 ----------- src/lib/reel_writer.cc | 4 +- src/lib/reel_writer.h | 4 +- src/lib/render_text.cc | 12 +-- src/lib/render_text.h | 6 +- src/lib/text_caption.h | 46 ++++++++++++ src/lib/text_caption_file_content.cc | 95 ++++++++++++++++++++++++ src/lib/text_caption_file_content.h | 46 ++++++++++++ src/lib/text_caption_file_decoder.cc | 89 ++++++++++++++++++++++ src/lib/text_caption_file_decoder.h | 44 +++++++++++ src/lib/text_decoder.cc | 4 +- src/lib/text_decoder.h | 4 +- src/lib/writer.cc | 2 +- src/lib/writer.h | 4 +- src/lib/wscript | 8 +- 39 files changed, 672 insertions(+), 672 deletions(-) create mode 100644 src/lib/active_captions.cc create mode 100644 src/lib/active_captions.h delete mode 100644 src/lib/active_text.cc delete mode 100644 src/lib/active_text.h delete mode 100644 src/lib/plain_text.h delete mode 100644 src/lib/plain_text_file_content.cc delete mode 100644 src/lib/plain_text_file_content.h delete mode 100644 src/lib/plain_text_file_decoder.cc delete mode 100644 src/lib/plain_text_file_decoder.h create mode 100644 src/lib/player_caption.cc create mode 100644 src/lib/player_caption.h delete mode 100644 src/lib/player_text.cc delete mode 100644 src/lib/player_text.h create mode 100644 src/lib/text_caption.h create mode 100644 src/lib/text_caption_file_content.cc create mode 100644 src/lib/text_caption_file_content.h create mode 100644 src/lib/text_caption_file_decoder.cc create mode 100644 src/lib/text_caption_file_decoder.h (limited to 'src/lib') diff --git a/src/lib/active_captions.cc b/src/lib/active_captions.cc new file mode 100644 index 000000000..972095e37 --- /dev/null +++ b/src/lib/active_captions.cc @@ -0,0 +1,139 @@ +/* + Copyright (C) 2017-2018 Carl Hetherington + + 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. + + 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 DCP-o-matic. If not, see . + +*/ + +#include "active_captions.h" +#include "piece.h" +#include "text_content.h" +#include +#include + +using std::list; +using std::pair; +using std::make_pair; +using boost::weak_ptr; +using boost::shared_ptr; +using boost::optional; + +/** Get the subtitles that should be burnt into a given period. + * @param period Period of interest. + * @param always_burn_subtitles Always burn subtitles even if their content is not set to burn. + */ +list +ActiveCaptions::get_burnt (DCPTimePeriod period, bool always_burn_subtitles) const +{ + list ps; + + for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) { + + shared_ptr piece = i->first.lock (); + if (!piece) { + continue; + } + + if (!piece->content->subtitle->use() || (!always_burn_subtitles && !piece->content->subtitle->burn())) { + /* Not burning this piece */ + continue; + } + + BOOST_FOREACH (Period j, i->second) { + DCPTimePeriod test (j.from, j.to.get_value_or(DCPTime::max())); + optional overlap = period.overlap (test); + if (overlap && overlap->duration() > DCPTime(period.duration().get() / 2)) { + ps.push_back (j.subs); + } + } + } + + return ps; +} + +/** Remove subtitles that finish before a given time from our list. + * @param time Time to remove before. + */ +void +ActiveCaptions::clear_before (DCPTime time) +{ + Map updated; + for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) { + list as; + BOOST_FOREACH (Period j, i->second) { + if (!j.to || j.to.get() >= time) { + as.push_back (j); + } + } + if (!as.empty ()) { + updated[i->first] = as; + } + } + _data = updated; +} + +/** Add a new subtitle with a from time. + * @param piece Piece that the subtitle is from. + * @param ps Subtitles. + * @param from From time for these subtitles. + */ +void +ActiveCaptions::add_from (weak_ptr piece, PlayerCaption ps, DCPTime from) +{ + if (_data.find(piece) == _data.end()) { + _data[piece] = list(); + } + _data[piece].push_back (Period (ps, from)); +} + +/** Add the to time for the last subtitle added from a piece. + * @param piece Piece that the subtitle is from. + * @param to To time for the last subtitle submitted to add_from for this piece. + * @return Return the corresponding subtitles and their from time. + */ +pair +ActiveCaptions::add_to (weak_ptr piece, DCPTime to) +{ + DCPOMATIC_ASSERT (_data.find(piece) != _data.end()); + + _data[piece].back().to = to; + + BOOST_FOREACH (TextCaption& i, _data[piece].back().subs.text) { + i.set_out (dcp::Time(to.seconds(), 1000)); + } + + return make_pair (_data[piece].back().subs, _data[piece].back().from); +} + +/** @param piece A piece. + * @return true if we have any active subtitles from this piece. + */ +bool +ActiveCaptions::have (weak_ptr piece) const +{ + Map::const_iterator i = _data.find(piece); + if (i == _data.end()) { + return false; + } + + return !i->second.empty(); +} + +void +ActiveCaptions::clear () +{ + _data.clear (); +} diff --git a/src/lib/active_captions.h b/src/lib/active_captions.h new file mode 100644 index 000000000..718ba393e --- /dev/null +++ b/src/lib/active_captions.h @@ -0,0 +1,65 @@ +/* + Copyright (C) 2017-2018 Carl Hetherington + + 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. + + 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 DCP-o-matic. If not, see . + +*/ + +/** @file src/lib/active_captions.h + * @brief ActiveCaptions class. + */ + +#include "dcpomatic_time.h" +#include "player_caption.h" +#include +#include +#include + +class Piece; + +/** @class ActiveCaptions + * @brief A class to maintain information on active subtitles for Player. + */ +class ActiveCaptions : public boost::noncopyable +{ +public: + std::list get_burnt (DCPTimePeriod period, bool always_burn_subtitles) const; + void clear_before (DCPTime time); + void clear (); + void add_from (boost::weak_ptr piece, PlayerCaption ps, DCPTime from); + std::pair add_to (boost::weak_ptr piece, DCPTime to); + bool have (boost::weak_ptr piece) const; + +private: + class Period + { + public: + Period () {} + + Period (PlayerCaption s, DCPTime f) + : subs (s) + , from (f) + {} + + PlayerCaption subs; + DCPTime from; + boost::optional to; + }; + + typedef std::map, std::list > Map; + + Map _data; +}; diff --git a/src/lib/active_text.cc b/src/lib/active_text.cc deleted file mode 100644 index 885aa034c..000000000 --- a/src/lib/active_text.cc +++ /dev/null @@ -1,139 +0,0 @@ -/* - Copyright (C) 2017-2018 Carl Hetherington - - 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. - - 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 DCP-o-matic. If not, see . - -*/ - -#include "active_text.h" -#include "piece.h" -#include "text_content.h" -#include -#include - -using std::list; -using std::pair; -using std::make_pair; -using boost::weak_ptr; -using boost::shared_ptr; -using boost::optional; - -/** Get the subtitles that should be burnt into a given period. - * @param period Period of interest. - * @param always_burn_subtitles Always burn subtitles even if their content is not set to burn. - */ -list -ActiveText::get_burnt (DCPTimePeriod period, bool always_burn_subtitles) const -{ - list ps; - - for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) { - - shared_ptr piece = i->first.lock (); - if (!piece) { - continue; - } - - if (!piece->content->subtitle->use() || (!always_burn_subtitles && !piece->content->subtitle->burn())) { - /* Not burning this piece */ - continue; - } - - BOOST_FOREACH (Period j, i->second) { - DCPTimePeriod test (j.from, j.to.get_value_or(DCPTime::max())); - optional overlap = period.overlap (test); - if (overlap && overlap->duration() > DCPTime(period.duration().get() / 2)) { - ps.push_back (j.subs); - } - } - } - - return ps; -} - -/** Remove subtitles that finish before a given time from our list. - * @param time Time to remove before. - */ -void -ActiveText::clear_before (DCPTime time) -{ - Map updated; - for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) { - list as; - BOOST_FOREACH (Period j, i->second) { - if (!j.to || j.to.get() >= time) { - as.push_back (j); - } - } - if (!as.empty ()) { - updated[i->first] = as; - } - } - _data = updated; -} - -/** Add a new subtitle with a from time. - * @param piece Piece that the subtitle is from. - * @param ps Subtitles. - * @param from From time for these subtitles. - */ -void -ActiveText::add_from (weak_ptr piece, PlayerText ps, DCPTime from) -{ - if (_data.find(piece) == _data.end()) { - _data[piece] = list(); - } - _data[piece].push_back (Period (ps, from)); -} - -/** Add the to time for the last subtitle added from a piece. - * @param piece Piece that the subtitle is from. - * @param to To time for the last subtitle submitted to add_from for this piece. - * @return Return the corresponding subtitles and their from time. - */ -pair -ActiveText::add_to (weak_ptr piece, DCPTime to) -{ - DCPOMATIC_ASSERT (_data.find(piece) != _data.end()); - - _data[piece].back().to = to; - - BOOST_FOREACH (PlainText& i, _data[piece].back().subs.text) { - i.set_out (dcp::Time(to.seconds(), 1000)); - } - - return make_pair (_data[piece].back().subs, _data[piece].back().from); -} - -/** @param piece A piece. - * @return true if we have any active subtitles from this piece. - */ -bool -ActiveText::have (weak_ptr piece) const -{ - Map::const_iterator i = _data.find(piece); - if (i == _data.end()) { - return false; - } - - return !i->second.empty(); -} - -void -ActiveText::clear () -{ - _data.clear (); -} diff --git a/src/lib/active_text.h b/src/lib/active_text.h deleted file mode 100644 index 09ef1cdaf..000000000 --- a/src/lib/active_text.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - Copyright (C) 2017-2018 Carl Hetherington - - 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. - - 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 DCP-o-matic. If not, see . - -*/ - -/** @file src/lib/active_text.h - * @brief ActiveText class. - */ - -#include "dcpomatic_time.h" -#include "player_text.h" -#include -#include -#include - -class Piece; - -/** @class ActiveText - * @brief A class to maintain information on active subtitles for Player. - */ -class ActiveText : public boost::noncopyable -{ -public: - std::list get_burnt (DCPTimePeriod period, bool always_burn_subtitles) const; - void clear_before (DCPTime time); - void clear (); - void add_from (boost::weak_ptr piece, PlayerText ps, DCPTime from); - std::pair add_to (boost::weak_ptr piece, DCPTime to); - bool have (boost::weak_ptr piece) const; - -private: - class Period - { - public: - Period () {} - - Period (PlayerText s, DCPTime f) - : subs (s) - , from (f) - {} - - PlayerText subs; - DCPTime from; - boost::optional to; - }; - - typedef std::map, std::list > Map; - - Map _data; -}; diff --git a/src/lib/content_factory.cc b/src/lib/content_factory.cc index 167b3f4e9..9429f1c46 100644 --- a/src/lib/content_factory.cc +++ b/src/lib/content_factory.cc @@ -26,7 +26,7 @@ #include "audio_content.h" #include "image_content.h" #include "atmos_mxf_content.h" -#include "plain_text_file_content.h" +#include "text_caption_file_content.h" #include "dcp_content.h" #include "dcp_text_content.h" #include "util.h" @@ -88,7 +88,7 @@ content_factory (shared_ptr film, cxml::NodePtr node, int version, l ); } else if (type == "SubRip" || type == "TextSubtitle") { - content.reset (new PlainTextFileContent (film, node, version)); + content.reset (new TextCaptionFileContent (film, node, version)); } else if (type == "DCP") { content.reset (new DCPContent (film, node, version)); } else if (type == "DCPSubtitle") { @@ -210,7 +210,7 @@ content_factory (shared_ptr film, boost::filesystem::path path) if (valid_image_file (path)) { single.reset (new ImageContent (film, path)); } else if (ext == ".srt" || ext == ".ssa" || ext == ".ass") { - single.reset (new PlainTextFileContent (film, path)); + single.reset (new TextCaptionFileContent (film, path)); } else if (ext == ".xml") { cxml::Document doc; doc.read_file (path); diff --git a/src/lib/content_text.h b/src/lib/content_text.h index eaba64ecf..1b550c96d 100644 --- a/src/lib/content_text.h +++ b/src/lib/content_text.h @@ -51,10 +51,10 @@ private: TextType _type; }; -class ContentBitmapText : public ContentText +class ContentBitmapCaption : public ContentText { public: - ContentBitmapText (ContentTime f, TextType type, boost::shared_ptr im, dcpomatic::Rect r) + ContentBitmapCaption (ContentTime f, TextType type, boost::shared_ptr im, dcpomatic::Rect r) : ContentText (f, type) , sub (im, r) {} @@ -67,10 +67,10 @@ public: * as the dcp::SubtitleString timings are sometimes quite heavily quantised and this causes problems * when we want to compare the quantised periods to the unquantised ones. */ -class ContentPlainText : public ContentText +class ContentTextCaption : public ContentText { public: - ContentPlainText (ContentTime f, TextType type, std::list s) + ContentTextCaption (ContentTime f, TextType type, std::list s) : ContentText (f, type) , subs (s) {} diff --git a/src/lib/dcp_encoder.cc b/src/lib/dcp_encoder.cc index cfc7da903..9766aad33 100644 --- a/src/lib/dcp_encoder.cc +++ b/src/lib/dcp_encoder.cc @@ -141,7 +141,7 @@ DCPEncoder::audio (shared_ptr data, DCPTime time) } void -DCPEncoder::text (PlayerText data, TextType type, DCPTimePeriod period) +DCPEncoder::text (PlayerCaption data, TextType type, DCPTimePeriod period) { if (type == TEXT_CLOSED_CAPTION || _non_burnt_subtitles) { _writer->write (data, type, period); diff --git a/src/lib/dcp_encoder.h b/src/lib/dcp_encoder.h index 8a2ad947d..850ead656 100644 --- a/src/lib/dcp_encoder.h +++ b/src/lib/dcp_encoder.h @@ -19,7 +19,7 @@ */ #include "types.h" -#include "player_text.h" +#include "player_caption.h" #include "encoder.h" #include @@ -52,7 +52,7 @@ private: void video (boost::shared_ptr, DCPTime); void audio (boost::shared_ptr, DCPTime); - void text (PlayerText, TextType, DCPTimePeriod); + void text (PlayerCaption, TextType, DCPTimePeriod); boost::shared_ptr _writer; boost::shared_ptr _j2k_encoder; diff --git a/src/lib/decoder_factory.cc b/src/lib/decoder_factory.cc index a7367dd24..3d4ce8a7b 100644 --- a/src/lib/decoder_factory.cc +++ b/src/lib/decoder_factory.cc @@ -24,8 +24,8 @@ #include "dcp_decoder.h" #include "image_content.h" #include "image_decoder.h" -#include "plain_text_file_content.h" -#include "plain_text_file_decoder.h" +#include "text_caption_file_content.h" +#include "text_caption_file_decoder.h" #include "dcp_text_content.h" #include "dcp_text_decoder.h" #include "video_mxf_content.h" @@ -54,9 +54,9 @@ decoder_factory (shared_ptr content, shared_ptr log, bool fa return shared_ptr (new ImageDecoder (ic, log)); } - shared_ptr rc = dynamic_pointer_cast (content); + shared_ptr rc = dynamic_pointer_cast (content); if (rc) { - return shared_ptr (new PlainTextFileDecoder (rc, log)); + return shared_ptr (new TextCaptionFileDecoder (rc, log)); } shared_ptr dsc = dynamic_pointer_cast (content); diff --git a/src/lib/encoder.h b/src/lib/encoder.h index f4116c50c..27fa0745f 100644 --- a/src/lib/encoder.h +++ b/src/lib/encoder.h @@ -22,7 +22,7 @@ #define DCPOMATIC_ENCODER_H #include "types.h" -#include "player_text.h" +#include "player_caption.h" #include #include diff --git a/src/lib/ffmpeg_encoder.cc b/src/lib/ffmpeg_encoder.cc index e9d872c8f..cc2591498 100644 --- a/src/lib/ffmpeg_encoder.cc +++ b/src/lib/ffmpeg_encoder.cc @@ -411,7 +411,7 @@ FFmpegEncoder::audio_frame (int size) } void -FFmpegEncoder::subtitle (PlayerText, DCPTimePeriod) +FFmpegEncoder::subtitle (PlayerCaption, DCPTimePeriod) { } diff --git a/src/lib/ffmpeg_encoder.h b/src/lib/ffmpeg_encoder.h index b1d07eb7f..35fd85064 100644 --- a/src/lib/ffmpeg_encoder.h +++ b/src/lib/ffmpeg_encoder.h @@ -54,7 +54,7 @@ public: private: void video (boost::shared_ptr, DCPTime); void audio (boost::shared_ptr); - void subtitle (PlayerText, DCPTimePeriod); + void subtitle (PlayerCaption, DCPTimePeriod); void setup_video (); void setup_audio (); diff --git a/src/lib/plain_text.h b/src/lib/plain_text.h deleted file mode 100644 index 05a95aef2..000000000 --- a/src/lib/plain_text.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright (C) 2016-2018 Carl Hetherington - - 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. - - 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 DCP-o-matic. If not, see . - -*/ - -#ifndef DCPOMATIC_PLAIN_TEXT_H -#define DCPOMATIC_PLAIN_TEXT_H - -#include - -/** A wrapper for SubtitleString which allows us to include settings that are not - * applicable to true DCP subtitles. For example, we can set outline width for burn-in - * but this cannot be specified in DCP XML. - */ -class PlainText : public dcp::SubtitleString -{ -public: - explicit PlainText (dcp::SubtitleString dcp_) - : dcp::SubtitleString (dcp_) - , outline_width (2) - {} - - PlainText (dcp::SubtitleString dcp_, int outline_width_) - : dcp::SubtitleString (dcp_) - , outline_width (outline_width_) - {} - - int outline_width; -}; - -#endif diff --git a/src/lib/plain_text_file.cc b/src/lib/plain_text_file.cc index 4ed13491c..666953c40 100644 --- a/src/lib/plain_text_file.cc +++ b/src/lib/plain_text_file.cc @@ -21,7 +21,7 @@ #include "plain_text_file.h" #include "cross.h" #include "exceptions.h" -#include "plain_text_file_content.h" +#include "text_caption_file_content.h" #include #include #include @@ -39,7 +39,7 @@ using boost::scoped_array; using boost::optional; using dcp::Data; -PlainTextFile::PlainTextFile (shared_ptr content) +TextCaptionFile::TextCaptionFile (shared_ptr content) { Data in (content->path (0)); @@ -96,7 +96,7 @@ PlainTextFile::PlainTextFile (shared_ptr content) /** @return time of first subtitle, if there is one */ optional -PlainTextFile::first () const +TextCaptionFile::first () const { if (_subtitles.empty()) { return optional(); @@ -106,7 +106,7 @@ PlainTextFile::first () const } ContentTime -PlainTextFile::length () const +TextCaptionFile::length () const { if (_subtitles.empty ()) { return ContentTime (); diff --git a/src/lib/plain_text_file.h b/src/lib/plain_text_file.h index 34dc08465..8c74d9e59 100644 --- a/src/lib/plain_text_file.h +++ b/src/lib/plain_text_file.h @@ -26,22 +26,22 @@ #include #include -class PlainTextFileContent; +class TextCaptionFileContent; class plain_text_time_test; class plain_text_coordinate_test; class plain_text_content_test; class plain_text_parse_test; -/** @class PlainTextFile - * @brief Base for PlainTextFile decoder and examiner. +/** @class TextCaptionFile + * @brief Base for TextCaptionFile decoder and examiner. * * In fact this is sufficient for the examiner, so it's used as-is rather than deriving - * a pointless PlainTextFileExaminer. + * a pointless TextCaptionFileExaminer. */ -class PlainTextFile +class TextCaptionFile { public: - explicit PlainTextFile (boost::shared_ptr); + explicit TextCaptionFile (boost::shared_ptr); boost::optional first () const; ContentTime length () const; diff --git a/src/lib/plain_text_file_content.cc b/src/lib/plain_text_file_content.cc deleted file mode 100644 index 2b52cee96..000000000 --- a/src/lib/plain_text_file_content.cc +++ /dev/null @@ -1,95 +0,0 @@ -/* - Copyright (C) 2014-2018 Carl Hetherington - - 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. - - 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 DCP-o-matic. If not, see . - -*/ - -#include "plain_text_file_content.h" -#include "util.h" -#include "plain_text_file.h" -#include "film.h" -#include "font.h" -#include "text_content.h" -#include -#include -#include - -#include "i18n.h" - -using std::string; -using std::cout; -using boost::shared_ptr; -using dcp::raw_convert; - -PlainTextFileContent::PlainTextFileContent (shared_ptr film, boost::filesystem::path path) - : Content (film, path) -{ - subtitle.reset (new TextContent (this)); -} - -PlainTextFileContent::PlainTextFileContent (shared_ptr film, cxml::ConstNodePtr node, int version) - : Content (film, node) - , _length (node->number_child ("Length")) -{ - subtitle = TextContent::from_xml (this, node, version); -} - -void -PlainTextFileContent::examine (boost::shared_ptr job) -{ - Content::examine (job); - PlainTextFile s (shared_from_this ()); - - /* Default to turning these subtitles on */ - subtitle->set_use (true); - - boost::mutex::scoped_lock lm (_mutex); - _length = s.length (); - subtitle->add_font (shared_ptr (new Font (TEXT_FONT_ID))); -} - -string -PlainTextFileContent::summary () const -{ - return path_summary() + " " + _("[subtitles]"); -} - -string -PlainTextFileContent::technical_summary () const -{ - return Content::technical_summary() + " - " + _("Text subtitles"); -} - -void -PlainTextFileContent::as_xml (xmlpp::Node* node, bool with_paths) const -{ - node->add_child("Type")->add_child_text ("TextSubtitle"); - Content::as_xml (node, with_paths); - - if (subtitle) { - subtitle->as_xml (node); - } - - node->add_child("Length")->add_child_text (raw_convert (_length.get ())); -} - -DCPTime -PlainTextFileContent::full_length () const -{ - FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate ()); - return DCPTime (_length, frc); -} diff --git a/src/lib/plain_text_file_content.h b/src/lib/plain_text_file_content.h deleted file mode 100644 index 603931e4c..000000000 --- a/src/lib/plain_text_file_content.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright (C) 2014-2018 Carl Hetherington - - 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. - - 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 DCP-o-matic. If not, see . - -*/ - -#include "content.h" - -class Job; - -/** @class PlainTextFileContent - * @brief A SubRip, SSA or ASS file. - */ -class PlainTextFileContent : public Content -{ -public: - PlainTextFileContent (boost::shared_ptr, boost::filesystem::path); - PlainTextFileContent (boost::shared_ptr, cxml::ConstNodePtr, int); - - boost::shared_ptr shared_from_this () { - return boost::dynamic_pointer_cast (Content::shared_from_this ()); - } - - void examine (boost::shared_ptr); - std::string summary () const; - std::string technical_summary () const; - void as_xml (xmlpp::Node *, bool with_paths) const; - DCPTime full_length () const; - -private: - ContentTime _length; -}; diff --git a/src/lib/plain_text_file_decoder.cc b/src/lib/plain_text_file_decoder.cc deleted file mode 100644 index 40a605963..000000000 --- a/src/lib/plain_text_file_decoder.cc +++ /dev/null @@ -1,89 +0,0 @@ -/* - Copyright (C) 2014-2018 Carl Hetherington - - 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. - - 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 DCP-o-matic. If not, see . - -*/ - -#include "plain_text_file_decoder.h" -#include "plain_text_file_content.h" -#include "text_content.h" -#include "text_decoder.h" -#include -#include -#include - -using std::list; -using std::vector; -using std::string; -using std::cout; -using std::max; -using boost::shared_ptr; -using boost::optional; -using boost::dynamic_pointer_cast; - -PlainTextFileDecoder::PlainTextFileDecoder (shared_ptr content, shared_ptr log) - : PlainTextFile (content) - , _next (0) -{ - ContentTime first; - if (!_subtitles.empty()) { - first = content_time_period(_subtitles[0]).from; - } - subtitle.reset (new TextDecoder (this, content->subtitle, log, first)); -} - -void -PlainTextFileDecoder::seek (ContentTime time, bool accurate) -{ - /* It's worth back-tracking a little here as decoding is cheap and it's nice if we don't miss - too many subtitles when seeking. - */ - time -= ContentTime::from_seconds (5); - if (time < ContentTime()) { - time = ContentTime(); - } - - Decoder::seek (time, accurate); - - _next = 0; - while (_next < _subtitles.size() && ContentTime::from_seconds (_subtitles[_next].from.all_as_seconds ()) < time) { - ++_next; - } -} - -bool -PlainTextFileDecoder::pass () -{ - if (_next >= _subtitles.size ()) { - return true; - } - - ContentTimePeriod const p = content_time_period (_subtitles[_next]); - subtitle->emit_plain (p, _subtitles[_next]); - - ++_next; - return false; -} - -ContentTimePeriod -PlainTextFileDecoder::content_time_period (sub::Subtitle s) const -{ - return ContentTimePeriod ( - ContentTime::from_seconds (s.from.all_as_seconds()), - ContentTime::from_seconds (s.to.all_as_seconds()) - ); -} diff --git a/src/lib/plain_text_file_decoder.h b/src/lib/plain_text_file_decoder.h deleted file mode 100644 index ea64a294b..000000000 --- a/src/lib/plain_text_file_decoder.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright (C) 2014-2018 Carl Hetherington - - 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. - - 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 DCP-o-matic. If not, see . - -*/ - -#ifndef DCPOMATIC_PLAIN_TEXT_FILE_DECODER_H -#define DCPOMATIC_PLAIN_TEXT_FILE_DECODER_H - -#include "plain_text_file.h" -#include "decoder.h" - -class PlainTextFileContent; -class Log; - -class PlainTextFileDecoder : public Decoder, public PlainTextFile -{ -public: - PlainTextFileDecoder (boost::shared_ptr, boost::shared_ptr log); - - void seek (ContentTime time, bool accurate); - bool pass (); - -private: - ContentTimePeriod content_time_period (sub::Subtitle s) const; - - size_t _next; -}; - -#endif diff --git a/src/lib/player.cc b/src/lib/player.cc index e300b5448..a7cd0fd94 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -663,7 +663,7 @@ Player::subtitles_for_frame (DCPTime time) const int const vfr = _film->video_frame_rate(); - BOOST_FOREACH (PlayerText i, _active_text[TEXT_SUBTITLE].get_burnt (DCPTimePeriod(time, time + DCPTime::from_frames(1, vfr)), _always_burn_subtitles)) { + BOOST_FOREACH (PlayerCaption i, _active_text[TEXT_SUBTITLE].get_burnt (DCPTimePeriod(time, time + DCPTime::from_frames(1, vfr)), _always_burn_subtitles)) { /* Image subtitles */ list c = transform_bitmap_texts (i.image); @@ -839,7 +839,7 @@ Player::audio (weak_ptr wp, AudioStreamPtr stream, ContentAudio content_a } void -Player::bitmap_text_start (weak_ptr wp, ContentBitmapText subtitle) +Player::bitmap_text_start (weak_ptr wp, ContentBitmapCaption subtitle) { shared_ptr piece = wp.lock (); if (!piece) { @@ -858,7 +858,7 @@ Player::bitmap_text_start (weak_ptr wp, ContentBitmapText subtitle) subtitle.sub.rectangle.width *= piece->content->subtitle->x_scale (); subtitle.sub.rectangle.height *= piece->content->subtitle->y_scale (); - PlayerText ps; + PlayerCaption ps; ps.image.push_back (subtitle.sub); DCPTime from (content_time_to_dcp (piece, subtitle.from())); @@ -866,14 +866,14 @@ Player::bitmap_text_start (weak_ptr wp, ContentBitmapText subtitle) } void -Player::plain_text_start (weak_ptr wp, ContentPlainText subtitle) +Player::plain_text_start (weak_ptr wp, ContentTextCaption subtitle) { shared_ptr piece = wp.lock (); if (!piece) { return; } - PlayerText ps; + PlayerCaption ps; DCPTime const from (content_time_to_dcp (piece, subtitle.from())); if (from > piece->content->end()) { @@ -901,7 +901,7 @@ Player::plain_text_start (weak_ptr wp, ContentPlainText subtitle) } s.set_in (dcp::Time(from.seconds(), 1000)); - ps.text.push_back (PlainText (s, piece->content->subtitle->outline_width())); + ps.text.push_back (TextCaption (s, piece->content->subtitle->outline_width())); ps.add_fonts (piece->content->subtitle->fonts ()); } @@ -926,7 +926,7 @@ Player::subtitle_stop (weak_ptr wp, ContentTime to, TextType type) return; } - pair from = _active_text[type].add_to (wp, dcp_to); + pair from = _active_text[type].add_to (wp, dcp_to); if (piece->content->subtitle->use() && !_always_burn_subtitles && !piece->content->subtitle->burn()) { Text (from.first, type, DCPTimePeriod (from.second, dcp_to)); diff --git a/src/lib/player.h b/src/lib/player.h index c936524a2..16e9d57a5 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -21,8 +21,8 @@ #ifndef DCPOMATIC_PLAYER_H #define DCPOMATIC_PLAYER_H -#include "player_text.h" -#include "active_text.h" +#include "player_caption.h" +#include "active_captions.h" #include "content_text.h" #include "film.h" #include "content.h" @@ -101,7 +101,7 @@ public: /** Emitted when a caption is ready. This signal may be emitted considerably * after the corresponding Video. */ - boost::signals2::signal Text; + boost::signals2::signal Text; private: friend class PlayerWrapper; @@ -126,8 +126,8 @@ private: boost::shared_ptr black_player_video_frame (Eyes eyes) const; void video (boost::weak_ptr, ContentVideo); void audio (boost::weak_ptr, AudioStreamPtr, ContentAudio); - void bitmap_text_start (boost::weak_ptr, ContentBitmapText); - void plain_text_start (boost::weak_ptr, ContentPlainText); + void bitmap_text_start (boost::weak_ptr, ContentBitmapCaption); + void plain_text_start (boost::weak_ptr, ContentTextCaption); void subtitle_stop (boost::weak_ptr, ContentTime, TextType); DCPTime one_video_frame () const; void fill_audio (DCPTimePeriod period); @@ -196,7 +196,7 @@ private: Empty _black; Empty _silent; - ActiveText _active_text[TEXT_COUNT]; + ActiveCaptions _active_text[TEXT_COUNT]; boost::shared_ptr _audio_processor; boost::signals2::scoped_connection _film_changed_connection; diff --git a/src/lib/player_caption.cc b/src/lib/player_caption.cc new file mode 100644 index 000000000..74c847aae --- /dev/null +++ b/src/lib/player_caption.cc @@ -0,0 +1,42 @@ +/* + Copyright (C) 2014-2018 Carl Hetherington + + 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. + + 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 DCP-o-matic. If not, see . + +*/ + +#include "player_caption.h" +#include "font.h" +#include + +using std::list; +using boost::shared_ptr; + +void +PlayerCaption::add_fonts (list > fonts_) +{ + BOOST_FOREACH (shared_ptr i, fonts_) { + bool got = false; + BOOST_FOREACH (shared_ptr j, fonts) { + if (*i == *j) { + got = true; + } + } + if (!got) { + fonts.push_back (i); + } + } +} diff --git a/src/lib/player_caption.h b/src/lib/player_caption.h new file mode 100644 index 000000000..2875790df --- /dev/null +++ b/src/lib/player_caption.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2014-2018 Carl Hetherington + + 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. + + 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 DCP-o-matic. If not, see . + +*/ + +#ifndef DCPOMATIC_PLAYER_TEXT_H +#define DCPOMATIC_PLAYER_TEXT_H + +#include "bitmap_text.h" +#include "dcpomatic_time.h" +#include "text_caption.h" + +class Font; + +/** A set of text (subtitle/CCAP) which span the same time period */ +class PlayerCaption +{ +public: + void add_fonts (std::list > fonts_); + std::list > fonts; + + /** BitmapTexts, with their rectangles transformed as specified by their content */ + std::list image; + std::list text; +}; + +#endif diff --git a/src/lib/player_text.cc b/src/lib/player_text.cc deleted file mode 100644 index 16e89b0f1..000000000 --- a/src/lib/player_text.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright (C) 2014-2018 Carl Hetherington - - 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. - - 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 DCP-o-matic. If not, see . - -*/ - -#include "player_text.h" -#include "font.h" -#include - -using std::list; -using boost::shared_ptr; - -void -PlayerText::add_fonts (list > fonts_) -{ - BOOST_FOREACH (shared_ptr i, fonts_) { - bool got = false; - BOOST_FOREACH (shared_ptr j, fonts) { - if (*i == *j) { - got = true; - } - } - if (!got) { - fonts.push_back (i); - } - } -} diff --git a/src/lib/player_text.h b/src/lib/player_text.h deleted file mode 100644 index 93b6cd970..000000000 --- a/src/lib/player_text.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright (C) 2014-2018 Carl Hetherington - - 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. - - 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 DCP-o-matic. If not, see . - -*/ - -#ifndef DCPOMATIC_PLAYER_TEXT_H -#define DCPOMATIC_PLAYER_TEXT_H - -#include "bitmap_text.h" -#include "dcpomatic_time.h" -#include "plain_text.h" - -class Font; - -/** A set of text (subtitle/CCAP) which span the same time period */ -class PlayerText -{ -public: - void add_fonts (std::list > fonts_); - std::list > fonts; - - /** BitmapTexts, with their rectangles transformed as specified by their content */ - std::list image; - std::list text; -}; - -#endif diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index 8eb0461bc..77d583353 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -528,7 +528,7 @@ ReelWriter::write (shared_ptr<const AudioBuffers> audio) } void -ReelWriter::write (PlayerText subs, TextType type, DCPTimePeriod period) +ReelWriter::write (PlayerCaption subs, TextType type, DCPTimePeriod period) { /* XXX: we need separate libdcp asset types here and to know how different they are */ @@ -558,7 +558,7 @@ ReelWriter::write (PlayerText subs, TextType type, DCPTimePeriod period) } } - BOOST_FOREACH (PlainText i, subs.text) { + BOOST_FOREACH (TextCaption i, subs.text) { /* XXX: couldn't / shouldn't we use period here rather than getting time from the subtitle? */ i.set_in (i.in() - dcp::Time (_period.from.seconds(), i.in().tcr)); i.set_out (i.out() - dcp::Time (_period.from.seconds(), i.out().tcr)); diff --git a/src/lib/reel_writer.h b/src/lib/reel_writer.h index 6de1de68d..cd22fa775 100644 --- a/src/lib/reel_writer.h +++ b/src/lib/reel_writer.h @@ -21,7 +21,7 @@ #include "types.h" #include "dcpomatic_time.h" #include "referenced_reel_asset.h" -#include "player_text.h" +#include "player_caption.h" #include <dcp/picture_asset_writer.h> #include <boost/shared_ptr.hpp> @@ -60,7 +60,7 @@ public: void fake_write (Frame frame, Eyes eyes, int size); void repeat_write (Frame frame, Eyes eyes); void write (boost::shared_ptr<const AudioBuffers> audio); - void write (PlayerText text, TextType type, DCPTimePeriod period); + void write (PlayerCaption text, TextType type, DCPTimePeriod period); void finish (); boost::shared_ptr<dcp::Reel> create_reel (std::list<ReferencedReelAsset> const & refs, std::list<boost::shared_ptr<Font> > const & fonts); diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc index 77a8036e8..63ff2b74c 100644 --- a/src/lib/render_text.cc +++ b/src/lib/render_text.cc @@ -51,11 +51,11 @@ static FcConfig* fc_config = 0; static list<pair<FontFiles, string> > fc_config_fonts; string -marked_up (list<PlainText> subtitles, int target_height, float fade_factor) +marked_up (list<TextCaption> subtitles, int target_height, float fade_factor) { string out; - BOOST_FOREACH (PlainText const & i, subtitles) { + BOOST_FOREACH (TextCaption const & i, subtitles) { out += "<span "; if (i.italic()) { out += "style=\"italic\" "; @@ -91,7 +91,7 @@ set_source_rgba (Cairo::RefPtr<Cairo::Context> context, dcp::Colour colour, floa * at the same time and with the same fade in/out. */ static PositionImage -render_line (list<PlainText> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate) +render_line (list<TextCaption> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate) { /* XXX: this method can only handle italic / bold changes mid-line, nothing else yet. @@ -365,12 +365,12 @@ render_line (list<PlainText> subtitles, list<shared_ptr<Font> > fonts, dcp::Size * @param frame_rate DCP frame rate. */ list<PositionImage> -render_text (list<PlainText> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate) +render_text (list<TextCaption> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate) { - list<PlainText> pending; + list<TextCaption> pending; list<PositionImage> images; - BOOST_FOREACH (PlainText const & i, subtitles) { + BOOST_FOREACH (TextCaption const & i, subtitles) { if (!pending.empty() && fabs (i.v_position() - pending.back().v_position()) > 1e-4) { images.push_back (render_line (pending, fonts, target, time, frame_rate)); pending.clear (); diff --git a/src/lib/render_text.h b/src/lib/render_text.h index f9c35005e..0a8e97bc9 100644 --- a/src/lib/render_text.h +++ b/src/lib/render_text.h @@ -20,12 +20,12 @@ #include "position_image.h" #include "dcpomatic_time.h" -#include "plain_text.h" +#include "text_caption.h" #include <dcp/util.h> class Font; -std::string marked_up (std::list<PlainText> subtitles, int target_height, float fade_factor); +std::string marked_up (std::list<TextCaption> subtitles, int target_height, float fade_factor); std::list<PositionImage> render_text ( - std::list<PlainText>, std::list<boost::shared_ptr<Font> > fonts, dcp::Size, DCPTime, int + std::list<TextCaption>, std::list<boost::shared_ptr<Font> > fonts, dcp::Size, DCPTime, int ); diff --git a/src/lib/text_caption.h b/src/lib/text_caption.h new file mode 100644 index 000000000..b4400f5bb --- /dev/null +++ b/src/lib/text_caption.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2016-2018 Carl Hetherington <cth@carlh.net> + + 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. + + 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#ifndef DCPOMATIC_PLAIN_TEXT_H +#define DCPOMATIC_PLAIN_TEXT_H + +#include <dcp/subtitle_string.h> + +/** A wrapper for SubtitleString which allows us to include settings that are not + * applicable to true DCP subtitles. For example, we can set outline width for burn-in + * but this cannot be specified in DCP XML. + */ +class TextCaption : public dcp::SubtitleString +{ +public: + explicit TextCaption (dcp::SubtitleString dcp_) + : dcp::SubtitleString (dcp_) + , outline_width (2) + {} + + TextCaption (dcp::SubtitleString dcp_, int outline_width_) + : dcp::SubtitleString (dcp_) + , outline_width (outline_width_) + {} + + int outline_width; +}; + +#endif diff --git a/src/lib/text_caption_file_content.cc b/src/lib/text_caption_file_content.cc new file mode 100644 index 000000000..df5de93ef --- /dev/null +++ b/src/lib/text_caption_file_content.cc @@ -0,0 +1,95 @@ +/* + Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net> + + 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. + + 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "text_caption_file_content.h" +#include "util.h" +#include "plain_text_file.h" +#include "film.h" +#include "font.h" +#include "text_content.h" +#include <dcp/raw_convert.h> +#include <libxml++/libxml++.h> +#include <iostream> + +#include "i18n.h" + +using std::string; +using std::cout; +using boost::shared_ptr; +using dcp::raw_convert; + +TextCaptionFileContent::TextCaptionFileContent (shared_ptr<const Film> film, boost::filesystem::path path) + : Content (film, path) +{ + subtitle.reset (new TextContent (this)); +} + +TextCaptionFileContent::TextCaptionFileContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version) + : Content (film, node) + , _length (node->number_child<ContentTime::Type> ("Length")) +{ + subtitle = TextContent::from_xml (this, node, version); +} + +void +TextCaptionFileContent::examine (boost::shared_ptr<Job> job) +{ + Content::examine (job); + TextCaptionFile s (shared_from_this ()); + + /* Default to turning these subtitles on */ + subtitle->set_use (true); + + boost::mutex::scoped_lock lm (_mutex); + _length = s.length (); + subtitle->add_font (shared_ptr<Font> (new Font (TEXT_FONT_ID))); +} + +string +TextCaptionFileContent::summary () const +{ + return path_summary() + " " + _("[subtitles]"); +} + +string +TextCaptionFileContent::technical_summary () const +{ + return Content::technical_summary() + " - " + _("Text subtitles"); +} + +void +TextCaptionFileContent::as_xml (xmlpp::Node* node, bool with_paths) const +{ + node->add_child("Type")->add_child_text ("TextSubtitle"); + Content::as_xml (node, with_paths); + + if (subtitle) { + subtitle->as_xml (node); + } + + node->add_child("Length")->add_child_text (raw_convert<string> (_length.get ())); +} + +DCPTime +TextCaptionFileContent::full_length () const +{ + FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate ()); + return DCPTime (_length, frc); +} diff --git a/src/lib/text_caption_file_content.h b/src/lib/text_caption_file_content.h new file mode 100644 index 000000000..f8f4a9851 --- /dev/null +++ b/src/lib/text_caption_file_content.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net> + + 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. + + 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "content.h" + +class Job; + +/** @class TextCaptionFileContent + * @brief A SubRip, SSA or ASS file. + */ +class TextCaptionFileContent : public Content +{ +public: + TextCaptionFileContent (boost::shared_ptr<const Film>, boost::filesystem::path); + TextCaptionFileContent (boost::shared_ptr<const Film>, cxml::ConstNodePtr, int); + + boost::shared_ptr<TextCaptionFileContent> shared_from_this () { + return boost::dynamic_pointer_cast<TextCaptionFileContent> (Content::shared_from_this ()); + } + + void examine (boost::shared_ptr<Job>); + std::string summary () const; + std::string technical_summary () const; + void as_xml (xmlpp::Node *, bool with_paths) const; + DCPTime full_length () const; + +private: + ContentTime _length; +}; diff --git a/src/lib/text_caption_file_decoder.cc b/src/lib/text_caption_file_decoder.cc new file mode 100644 index 000000000..d1a72faeb --- /dev/null +++ b/src/lib/text_caption_file_decoder.cc @@ -0,0 +1,89 @@ +/* + Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net> + + 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. + + 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "text_caption_file_decoder.h" +#include "text_caption_file_content.h" +#include "text_content.h" +#include "text_decoder.h" +#include <dcp/subtitle_string.h> +#include <boost/foreach.hpp> +#include <iostream> + +using std::list; +using std::vector; +using std::string; +using std::cout; +using std::max; +using boost::shared_ptr; +using boost::optional; +using boost::dynamic_pointer_cast; + +TextCaptionFileDecoder::TextCaptionFileDecoder (shared_ptr<const TextCaptionFileContent> content, shared_ptr<Log> log) + : TextCaptionFile (content) + , _next (0) +{ + ContentTime first; + if (!_subtitles.empty()) { + first = content_time_period(_subtitles[0]).from; + } + subtitle.reset (new TextDecoder (this, content->subtitle, log, first)); +} + +void +TextCaptionFileDecoder::seek (ContentTime time, bool accurate) +{ + /* It's worth back-tracking a little here as decoding is cheap and it's nice if we don't miss + too many subtitles when seeking. + */ + time -= ContentTime::from_seconds (5); + if (time < ContentTime()) { + time = ContentTime(); + } + + Decoder::seek (time, accurate); + + _next = 0; + while (_next < _subtitles.size() && ContentTime::from_seconds (_subtitles[_next].from.all_as_seconds ()) < time) { + ++_next; + } +} + +bool +TextCaptionFileDecoder::pass () +{ + if (_next >= _subtitles.size ()) { + return true; + } + + ContentTimePeriod const p = content_time_period (_subtitles[_next]); + subtitle->emit_plain (p, _subtitles[_next]); + + ++_next; + return false; +} + +ContentTimePeriod +TextCaptionFileDecoder::content_time_period (sub::Subtitle s) const +{ + return ContentTimePeriod ( + ContentTime::from_seconds (s.from.all_as_seconds()), + ContentTime::from_seconds (s.to.all_as_seconds()) + ); +} diff --git a/src/lib/text_caption_file_decoder.h b/src/lib/text_caption_file_decoder.h new file mode 100644 index 000000000..7f889e72d --- /dev/null +++ b/src/lib/text_caption_file_decoder.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net> + + 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. + + 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#ifndef DCPOMATIC_PLAIN_TEXT_FILE_DECODER_H +#define DCPOMATIC_PLAIN_TEXT_FILE_DECODER_H + +#include "plain_text_file.h" +#include "decoder.h" + +class TextCaptionFileContent; +class Log; + +class TextCaptionFileDecoder : public Decoder, public TextCaptionFile +{ +public: + TextCaptionFileDecoder (boost::shared_ptr<const TextCaptionFileContent>, boost::shared_ptr<Log> log); + + void seek (ContentTime time, bool accurate); + bool pass (); + +private: + ContentTimePeriod content_time_period (sub::Subtitle s) const; + + size_t _next; +}; + +#endif diff --git a/src/lib/text_decoder.cc b/src/lib/text_decoder.cc index 2423fc738..932a57564 100644 --- a/src/lib/text_decoder.cc +++ b/src/lib/text_decoder.cc @@ -60,7 +60,7 @@ TextDecoder::TextDecoder ( void TextDecoder::emit_bitmap_start (ContentTime from, shared_ptr<Image> image, dcpomatic::Rect<double> rect) { - BitmapStart (ContentBitmapText (from, _content->type(), image, rect)); + BitmapStart (ContentBitmapCaption (from, _content->type(), image, rect)); _position = from; } @@ -94,7 +94,7 @@ TextDecoder::emit_plain_start (ContentTime from, list<dcp::SubtitleString> s) } } - PlainStart (ContentPlainText (from, _content->type(), s)); + PlainStart (ContentTextCaption (from, _content->type(), s)); _position = from; } diff --git a/src/lib/text_decoder.h b/src/lib/text_decoder.h index 96eba80e2..ed2763916 100644 --- a/src/lib/text_decoder.h +++ b/src/lib/text_decoder.h @@ -62,8 +62,8 @@ public: return _content; } - boost::signals2::signal<void (ContentBitmapText)> BitmapStart; - boost::signals2::signal<void (ContentPlainText)> PlainStart; + boost::signals2::signal<void (ContentBitmapCaption)> BitmapStart; + boost::signals2::signal<void (ContentTextCaption)> PlainStart; boost::signals2::signal<void (ContentTime, TextType)> Stop; private: diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 7b2944d32..ea4a6d29b 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -665,7 +665,7 @@ Writer::can_fake_write (Frame frame) const } void -Writer::write (PlayerText text, TextType type, DCPTimePeriod period) +Writer::write (PlayerCaption text, TextType type, DCPTimePeriod period) { while (_text_reel[type]->period().to <= period.from) { ++_text_reel[type]; diff --git a/src/lib/writer.h b/src/lib/writer.h index 484ca1285..a776e54c3 100644 --- a/src/lib/writer.h +++ b/src/lib/writer.h @@ -23,7 +23,7 @@ */ #include "types.h" -#include "player_text.h" +#include "player_caption.h" #include "exception_store.h" #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> @@ -104,7 +104,7 @@ public: bool can_repeat (Frame) const; void repeat (Frame, Eyes); void write (boost::shared_ptr<const AudioBuffers>, DCPTime time); - void write (PlayerText text, TextType type, DCPTimePeriod period); + void write (PlayerCaption text, TextType type, DCPTimePeriod period); void write (std::list<boost::shared_ptr<Font> > fonts); void write (ReferencedReelAsset asset); void finish (); diff --git a/src/lib/wscript b/src/lib/wscript index ddbc1d4ff..71c94c28b 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -21,7 +21,7 @@ import os import i18n sources = """ - active_text.cc + active_captions.cc analyse_audio_job.cc atmos_mxf_content.cc audio_analysis.cc @@ -112,7 +112,7 @@ sources = """ mid_side_decoder.cc overlaps.cc player.cc - player_text.cc + player_caption.cc player_video.cc playlist.cc position_image.cc @@ -135,8 +135,8 @@ sources = """ text_content.cc text_decoder.cc plain_text_file.cc - plain_text_file_content.cc - plain_text_file_decoder.cc + text_caption_file_content.cc + text_caption_file_decoder.cc timer.cc transcode_job.cc types.cc -- cgit v1.2.3