diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-04-13 16:34:22 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-05-18 11:50:29 +0100 |
| commit | 775ae0e37bbec115d742feade0adc614a9a2301c (patch) | |
| tree | 3f9b7d86c547b2340b09ec4e3b157e88de44ff2e /src/lib | |
| parent | 334b94526f2c1271718a94fe97cfa843cf6ef7a1 (diff) | |
Subtitle rearrangements.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/content_part.h | 1 | ||||
| -rw-r--r-- | src/lib/player.cc | 6 | ||||
| -rw-r--r-- | src/lib/playlist.cc | 2 | ||||
| -rw-r--r-- | src/lib/subtitle_content.cc | 91 | ||||
| -rw-r--r-- | src/lib/subtitle_content.h | 33 | ||||
| -rw-r--r-- | src/lib/text_subtitle_content.cc | 80 | ||||
| -rw-r--r-- | src/lib/text_subtitle_content.h | 43 | ||||
| -rw-r--r-- | src/lib/text_subtitle_decoder.cc | 10 | ||||
| -rw-r--r-- | src/lib/types.h | 1 |
9 files changed, 121 insertions, 146 deletions
diff --git a/src/lib/content_part.h b/src/lib/content_part.h index b1282d98d..9ee26cbdb 100644 --- a/src/lib/content_part.h +++ b/src/lib/content_part.h @@ -21,6 +21,7 @@ #define DCPOMATIC_CONTENT_PART_H #include <boost/weak_ptr.hpp> +#include <boost/thread/mutex.hpp> class Content; class Film; diff --git a/src/lib/player.cc b/src/lib/player.cc index ca833208c..9c216c253 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -219,9 +219,9 @@ Player::playlist_content_changed (weak_ptr<Content> w, int property, bool freque property == ContentProperty::PATH || property == VideoContentProperty::VIDEO_FRAME_TYPE || property == DCPContentProperty::CAN_BE_PLAYED || - property == TextSubtitleContentProperty::TEXT_SUBTITLE_COLOUR || - property == TextSubtitleContentProperty::TEXT_SUBTITLE_OUTLINE || - property == TextSubtitleContentProperty::TEXT_SUBTITLE_OUTLINE_COLOUR || + property == SubtitleContentProperty::SUBTITLE_COLOUR || + property == SubtitleContentProperty::SUBTITLE_OUTLINE || + property == SubtitleContentProperty::SUBTITLE_OUTLINE_COLOUR || property == FFmpegContentProperty::SUBTITLE_STREAM ) { diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index 9df7857b5..645993050 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -130,7 +130,7 @@ Playlist::maybe_sequence () DCPTime next; BOOST_FOREACH (shared_ptr<Content> i, _content) { - if (!i->subtitle || !i->subtitle->has_subtitles() || find (placed.begin(), placed.end(), i) != placed.end()) { + if (!i->subtitle || find (placed.begin(), placed.end(), i) != placed.end()) { continue; } diff --git a/src/lib/subtitle_content.cc b/src/lib/subtitle_content.cc index bdc2b729c..a6dcbf9ae 100644 --- a/src/lib/subtitle_content.cc +++ b/src/lib/subtitle_content.cc @@ -23,6 +23,7 @@ #include "safe_stringstream.h" #include "font.h" #include "raw_convert.h" +#include "content.h" #include <libcxml/cxml.h> #include <libxml++/libxml++.h> #include <boost/foreach.hpp> @@ -46,6 +47,9 @@ int const SubtitleContentProperty::BURN_SUBTITLES = 505; int const SubtitleContentProperty::SUBTITLE_LANGUAGE = 506; int const SubtitleContentProperty::FONTS = 507; int const SubtitleContentProperty::SUBTITLE_VIDEO_FRAME_RATE = 508; +int const SubtitleContentProperty::SUBTITLE_COLOUR = 509; +int const SubtitleContentProperty::SUBTITLE_OUTLINE = 510; +int const SubtitleContentProperty::SUBTITLE_OUTLINE_COLOUR = 511; SubtitleContent::SubtitleContent (Content* parent, shared_ptr<const Film> film) : ContentPart (parent, film) @@ -55,18 +59,32 @@ SubtitleContent::SubtitleContent (Content* parent, shared_ptr<const Film> film) , _subtitle_y_offset (0) , _subtitle_x_scale (1) , _subtitle_y_scale (1) + , _colour (255, 255, 255) + , _outline (false) + , _outline_colour (0, 0, 0) { } SubtitleContent::SubtitleContent (Content* parent, shared_ptr<const Film> film, cxml::ConstNodePtr node, int version) - : ContentParet (parent, film) + : ContentPart (parent, film) , _use_subtitles (false) , _burn_subtitles (false) , _subtitle_x_offset (0) , _subtitle_y_offset (0) , _subtitle_x_scale (1) , _subtitle_y_scale (1) + , _colour ( + node->optional_number_child<int>("Red").get_value_or(255), + node->optional_number_child<int>("Green").get_value_or(255), + node->optional_number_child<int>("Blue").get_value_or(255) + ) + , _outline (node->optional_bool_child("Outline").get_value_or(false)) + , _outline_colour ( + node->optional_number_child<int>("OutlineRed").get_value_or(255), + node->optional_number_child<int>("OutlineGreen").get_value_or(255), + node->optional_number_child<int>("OutlineBlue").get_value_or(255) + ) { if (version >= 32) { _use_subtitles = node->bool_child ("UseSubtitles"); @@ -173,6 +191,13 @@ SubtitleContent::as_xml (xmlpp::Node* root) const root->add_child("SubtitleXScale")->add_child_text (raw_convert<string> (_subtitle_x_scale)); root->add_child("SubtitleYScale")->add_child_text (raw_convert<string> (_subtitle_y_scale)); root->add_child("SubtitleLanguage")->add_child_text (_subtitle_language); + root->add_child("Red")->add_child_text (raw_convert<string> (_colour.r)); + root->add_child("Green")->add_child_text (raw_convert<string> (_colour.g)); + root->add_child("Blue")->add_child_text (raw_convert<string> (_colour.b)); + root->add_child("Outline")->add_child_text (raw_convert<string> (_outline)); + root->add_child("OutlineRed")->add_child_text (raw_convert<string> (_outline_colour.r)); + root->add_child("OutlineGreen")->add_child_text (raw_convert<string> (_outline_colour.g)); + root->add_child("OutlineBlue")->add_child_text (raw_convert<string> (_outline_colour.b)); for (list<shared_ptr<Font> >::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { (*i)->as_xml (root->add_child("Font")); @@ -186,7 +211,7 @@ SubtitleContent::set_use_subtitles (bool u) boost::mutex::scoped_lock lm (_mutex); _use_subtitles = u; } - signal_changed (SubtitleContentProperty::USE_SUBTITLES); + _parent->signal_changed (SubtitleContentProperty::USE_SUBTITLES); } void @@ -196,7 +221,7 @@ SubtitleContent::set_burn_subtitles (bool b) boost::mutex::scoped_lock lm (_mutex); _burn_subtitles = b; } - signal_changed (SubtitleContentProperty::BURN_SUBTITLES); + _parent->signal_changed (SubtitleContentProperty::BURN_SUBTITLES); } void @@ -206,7 +231,7 @@ SubtitleContent::set_subtitle_x_offset (double o) boost::mutex::scoped_lock lm (_mutex); _subtitle_x_offset = o; } - signal_changed (SubtitleContentProperty::SUBTITLE_X_OFFSET); + _parent->signal_changed (SubtitleContentProperty::SUBTITLE_X_OFFSET); } void @@ -216,7 +241,7 @@ SubtitleContent::set_subtitle_y_offset (double o) boost::mutex::scoped_lock lm (_mutex); _subtitle_y_offset = o; } - signal_changed (SubtitleContentProperty::SUBTITLE_Y_OFFSET); + _parent->signal_changed (SubtitleContentProperty::SUBTITLE_Y_OFFSET); } void @@ -226,7 +251,7 @@ SubtitleContent::set_subtitle_x_scale (double s) boost::mutex::scoped_lock lm (_mutex); _subtitle_x_scale = s; } - signal_changed (SubtitleContentProperty::SUBTITLE_X_SCALE); + _parent->signal_changed (SubtitleContentProperty::SUBTITLE_X_SCALE); } void @@ -236,7 +261,7 @@ SubtitleContent::set_subtitle_y_scale (double s) boost::mutex::scoped_lock lm (_mutex); _subtitle_y_scale = s; } - signal_changed (SubtitleContentProperty::SUBTITLE_Y_SCALE); + _parent->signal_changed (SubtitleContentProperty::SUBTITLE_Y_SCALE); } void @@ -246,15 +271,14 @@ SubtitleContent::set_subtitle_language (string language) boost::mutex::scoped_lock lm (_mutex); _subtitle_language = language; } - signal_changed (SubtitleContentProperty::SUBTITLE_LANGUAGE); + _parent->signal_changed (SubtitleContentProperty::SUBTITLE_LANGUAGE); } string SubtitleContent::identifier () const { SafeStringStream s; - s << Content::identifier() - << "_" << raw_convert<string> (subtitle_x_scale()) + s << raw_convert<string> (subtitle_x_scale()) << "_" << raw_convert<string> (subtitle_y_scale()) << "_" << raw_convert<string> (subtitle_x_offset()) << "_" << raw_convert<string> (subtitle_y_offset()); @@ -299,11 +323,50 @@ SubtitleContent::connect_to_fonts () void SubtitleContent::font_changed () { - signal_changed (SubtitleContentProperty::FONTS); + _parent->signal_changed (SubtitleContentProperty::FONTS); +} + +void +SubtitleContent::set_colour (dcp::Colour colour) +{ + { + boost::mutex::scoped_lock lm (_mutex); + if (_colour == colour) { + return; + } + + _colour = colour; + } + + _parent->signal_changed (SubtitleContentProperty::SUBTITLE_COLOUR); +} + +void +SubtitleContent::set_outline (bool o) +{ + { + boost::mutex::scoped_lock lm (_mutex); + if (_outline == o) { + return; + } + + _outline = o; + } + + _parent->signal_changed (SubtitleContentProperty::SUBTITLE_OUTLINE); } -bool -SubtitleContent::has_subtitles () const +void +SubtitleContent::set_outline_colour (dcp::Colour colour) { - return has_text_subtitles() || has_image_subtitles(); + { + boost::mutex::scoped_lock lm (_mutex); + if (_outline_colour == colour) { + return; + } + + _outline_colour = colour; + } + + _parent->signal_changed (SubtitleContentProperty::SUBTITLE_OUTLINE_COLOUR); } diff --git a/src/lib/subtitle_content.h b/src/lib/subtitle_content.h index f9d5336f2..5982cc52c 100644 --- a/src/lib/subtitle_content.h +++ b/src/lib/subtitle_content.h @@ -22,6 +22,7 @@ #include "content_part.h" #include <libcxml/cxml.h> +#include <dcp/types.h> #include <boost/signals2.hpp> class Font; @@ -38,6 +39,9 @@ public: static int const SUBTITLE_LANGUAGE; static int const FONTS; static int const SUBTITLE_VIDEO_FRAME_RATE; + static int const SUBTITLE_COLOUR; + static int const SUBTITLE_OUTLINE; + static int const SUBTITLE_OUTLINE_COLOUR; }; class SubtitleContent : public ContentPart @@ -50,7 +54,10 @@ public: void as_xml (xmlpp::Node *) const; std::string identifier () const; - bool has_subtitles () const; + bool has_image_subtitles () const { + /* XXX */ + return true; + } void add_font (boost::shared_ptr<Font> font); @@ -102,6 +109,27 @@ public: return _subtitle_language; } + void set_colour (dcp::Colour); + + dcp::Colour colour () const { + boost::mutex::scoped_lock lm (_mutex); + return _colour; + } + + void set_outline (bool); + + bool outline () const { + boost::mutex::scoped_lock lm (_mutex); + return _outline; + } + + void set_outline_colour (dcp::Colour); + + dcp::Colour outline_colour () const { + boost::mutex::scoped_lock lm (_mutex); + return _outline_colour; + } + protected: /** subtitle language (e.g. "German") or empty if it is not known */ std::string _subtitle_language; @@ -126,6 +154,9 @@ private: /** y scale factor to apply to subtitles */ double _subtitle_y_scale; std::list<boost::shared_ptr<Font> > _fonts; + dcp::Colour _colour; + bool _outline; + dcp::Colour _outline_colour; std::list<boost::signals2::connection> _font_connections; }; diff --git a/src/lib/text_subtitle_content.cc b/src/lib/text_subtitle_content.cc index 88890ebdc..c7dd19d03 100644 --- a/src/lib/text_subtitle_content.cc +++ b/src/lib/text_subtitle_content.cc @@ -35,34 +35,15 @@ using boost::shared_ptr; std::string const TextSubtitleContent::font_id = "font"; -int const TextSubtitleContentProperty::TEXT_SUBTITLE_COLOUR = 300; -int const TextSubtitleContentProperty::TEXT_SUBTITLE_OUTLINE = 301; -int const TextSubtitleContentProperty::TEXT_SUBTITLE_OUTLINE_COLOUR = 302; - TextSubtitleContent::TextSubtitleContent (shared_ptr<const Film> film, boost::filesystem::path path) : Content (film, path) - , _colour (255, 255, 255) - , _outline (false) - , _outline_colour (0, 0, 0) { - subtitle.reset (new SubtitleContent (this, film, path)); + subtitle.reset (new SubtitleContent (this, film)); } TextSubtitleContent::TextSubtitleContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version) : Content (film, node) , _length (node->number_child<ContentTime::Type> ("Length")) - , _frame_rate (node->optional_number_child<double>("SubtitleVideoFrameRate")) - , _colour ( - node->optional_number_child<int>("Red").get_value_or(255), - node->optional_number_child<int>("Green").get_value_or(255), - node->optional_number_child<int>("Blue").get_value_or(255) - ) - , _outline (node->optional_bool_child("Outline").get_value_or(false)) - , _outline_colour ( - node->optional_number_child<int>("OutlineRed").get_value_or(255), - node->optional_number_child<int>("OutlineGreen").get_value_or(255), - node->optional_number_child<int>("OutlineBlue").get_value_or(255) - ) { subtitle.reset (new SubtitleContent (this, film, node, version)); } @@ -74,11 +55,11 @@ TextSubtitleContent::examine (boost::shared_ptr<Job> job) TextSubtitle s (shared_from_this ()); /* Default to turning these subtitles on */ - set_use_subtitles (true); + subtitle->set_use_subtitles (true); boost::mutex::scoped_lock lm (_mutex); _length = s.length (); - add_font (shared_ptr<Font> (new Font (font_id))); + subtitle->add_font (shared_ptr<Font> (new Font (font_id))); } string @@ -100,16 +81,6 @@ TextSubtitleContent::as_xml (xmlpp::Node* node) const Content::as_xml (node); subtitle->as_xml (node); node->add_child("Length")->add_child_text (raw_convert<string> (_length.get ())); - if (_frame_rate) { - node->add_child("SubtitleVideoFrameRate")->add_child_text (raw_convert<string> (_frame_rate.get())); - } - node->add_child("Red")->add_child_text (raw_convert<string> (_colour.r)); - node->add_child("Green")->add_child_text (raw_convert<string> (_colour.g)); - node->add_child("Blue")->add_child_text (raw_convert<string> (_colour.b)); - node->add_child("Outline")->add_child_text (raw_convert<string> (_outline)); - node->add_child("OutlineRed")->add_child_text (raw_convert<string> (_outline_colour.r)); - node->add_child("OutlineGreen")->add_child_text (raw_convert<string> (_outline_colour.g)); - node->add_child("OutlineBlue")->add_child_text (raw_convert<string> (_outline_colour.b)); } DCPTime @@ -145,48 +116,3 @@ TextSubtitleContent::subtitle_video_frame_rate () const */ return film()->active_frame_rate_change(position()).source; } - -void -TextSubtitleContent::set_colour (dcp::Colour colour) -{ - { - boost::mutex::scoped_lock lm (_mutex); - if (_colour == colour) { - return; - } - - _colour = colour; - } - - signal_changed (TextSubtitleContentProperty::TEXT_SUBTITLE_COLOUR); -} - -void -TextSubtitleContent::set_outline (bool o) -{ - { - boost::mutex::scoped_lock lm (_mutex); - if (_outline == o) { - return; - } - - _outline = o; - } - - signal_changed (TextSubtitleContentProperty::TEXT_SUBTITLE_OUTLINE); -} - -void -TextSubtitleContent::set_outline_colour (dcp::Colour colour) -{ - { - boost::mutex::scoped_lock lm (_mutex); - if (_outline_colour == colour) { - return; - } - - _outline_colour = colour; - } - - signal_changed (TextSubtitleContentProperty::TEXT_SUBTITLE_OUTLINE_COLOUR); -} diff --git a/src/lib/text_subtitle_content.h b/src/lib/text_subtitle_content.h index a2ef5d98a..76440ba9b 100644 --- a/src/lib/text_subtitle_content.h +++ b/src/lib/text_subtitle_content.h @@ -21,14 +21,6 @@ class Job; -class TextSubtitleContentProperty -{ -public: - static int const TEXT_SUBTITLE_COLOUR; - static int const TEXT_SUBTITLE_OUTLINE; - static int const TEXT_SUBTITLE_OUTLINE_COLOUR; -}; - /** @class TextSubtitleContent * @brief SubRip or SSA subtitles. */ @@ -42,54 +34,19 @@ public: return boost::dynamic_pointer_cast<TextSubtitleContent> (Content::shared_from_this ()); } - /* Content */ void examine (boost::shared_ptr<Job>); std::string summary () const; std::string technical_summary () const; void as_xml (xmlpp::Node *) const; DCPTime full_length () const; - /* SubtitleContent */ - - bool has_text_subtitles () const { - return true; - } - - bool has_image_subtitles () const { - return false; - } - double subtitle_video_frame_rate () const; void set_subtitle_video_frame_rate (double r); - void set_colour (dcp::Colour); - - dcp::Colour colour () const { - boost::mutex::scoped_lock lm (_mutex); - return _colour; - } - - void set_outline (bool); - - bool outline () const { - boost::mutex::scoped_lock lm (_mutex); - return _outline; - } - - void set_outline_colour (dcp::Colour); - - dcp::Colour outline_colour () const { - boost::mutex::scoped_lock lm (_mutex); - return _outline_colour; - } - static std::string const font_id; private: ContentTime _length; /** Video frame rate that this content has been prepared for, if known */ boost::optional<double> _frame_rate; - dcp::Colour _colour; - bool _outline; - dcp::Colour _outline_colour; }; diff --git a/src/lib/text_subtitle_decoder.cc b/src/lib/text_subtitle_decoder.cc index 36e44cc99..94604cd71 100644 --- a/src/lib/text_subtitle_decoder.cc +++ b/src/lib/text_subtitle_decoder.cc @@ -19,6 +19,7 @@ #include "text_subtitle_decoder.h" #include "text_subtitle_content.h" +#include "subtitle_content.h" #include <dcp/subtitle_string.h> #include <boost/foreach.hpp> #include <iostream> @@ -60,9 +61,6 @@ TextSubtitleDecoder::pass (PassReason, bool) /* XXX: we are ignoring positioning specified in the file */ - shared_ptr<const TextSubtitleContent> content = dynamic_pointer_cast<const TextSubtitleContent> (_subtitle_content); - DCPOMATIC_ASSERT (content); - list<dcp::SubtitleString> out; /* Highest line index in this subtitle */ @@ -81,7 +79,7 @@ TextSubtitleDecoder::pass (PassReason, bool) j.italic, j.bold, /* force the colour to whatever is configured */ - content->colour(), + _subtitle_content->colour(), j.font_size.points (72 * 11), 1.0, dcp::Time (_subtitles[_next].from.all_as_seconds(), 1000), @@ -95,8 +93,8 @@ TextSubtitleDecoder::pass (PassReason, bool) dcp::VALIGN_TOP, dcp::DIRECTION_LTR, j.text, - content->outline() ? dcp::BORDER : dcp::NONE, - content->outline_colour(), + _subtitle_content->outline() ? dcp::BORDER : dcp::NONE, + _subtitle_content->outline_colour(), dcp::Time (0, 1000), dcp::Time (0, 1000) ) diff --git a/src/lib/types.h b/src/lib/types.h index 33bad1d24..2bc6fa3a4 100644 --- a/src/lib/types.h +++ b/src/lib/types.h @@ -49,7 +49,6 @@ namespace xmlpp { typedef std::vector<boost::shared_ptr<Content> > ContentList; typedef std::vector<boost::shared_ptr<AudioContent> > AudioContentList; -typedef std::vector<boost::shared_ptr<SubtitleContent> > SubtitleContentList; typedef std::vector<boost::shared_ptr<FFmpegContent> > FFmpegContentList; typedef int64_t Frame; |
