summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-12-20 22:29:21 +0000
committerCarl Hetherington <cth@carlh.net>2014-12-20 22:29:21 +0000
commit5f2a57d1c21c3e8067dfd1f68505b1bf96e1d7c7 (patch)
tree01e112c11223eb94772e86ca40fbefdb7ec05b8e /src/lib
parentb607482671ee26a3462d9fcefdd7d7ddcd25184c (diff)
Basic pass-through of font information when using DCP subtitles.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/film.cc27
-rw-r--r--src/lib/film.h2
-rw-r--r--src/lib/font.cc7
-rw-r--r--src/lib/font.h6
-rw-r--r--src/lib/player.cc28
-rw-r--r--src/lib/player.h1
-rw-r--r--src/lib/player_subtitles.h2
-rw-r--r--src/lib/subrip_content.cc4
-rw-r--r--src/lib/subrip_content.h2
-rw-r--r--src/lib/subrip_decoder.cc2
-rw-r--r--src/lib/transcoder.cc5
-rw-r--r--src/lib/writer.cc16
-rw-r--r--src/lib/writer.h6
13 files changed, 86 insertions, 22 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 46c27d195..d7620be8d 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -48,6 +48,7 @@
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
+#include <boost/foreach.hpp>
#include <unistd.h>
#include <stdexcept>
#include <iostream>
@@ -69,6 +70,7 @@ using std::make_pair;
using std::endl;
using std::cout;
using std::list;
+using std::set;
using boost::shared_ptr;
using boost::weak_ptr;
using boost::dynamic_pointer_cast;
@@ -1142,3 +1144,28 @@ Film::should_be_enough_disk_space (double& required, double& available) const
available = double (s.available) / 1073741824.0f;
return (available - required) > 1;
}
+
+string
+Film::subtitle_language () const
+{
+ set<string> languages;
+
+ ContentList cl = content ();
+ BOOST_FOREACH (shared_ptr<Content>& c, cl) {
+ shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (c);
+ if (sc) {
+ languages.insert (sc->subtitle_language ());
+ }
+ }
+
+ string all;
+ BOOST_FOREACH (string s, languages) {
+ if (!all.empty ()) {
+ all += "/" + s;
+ } else {
+ all += s;
+ }
+ }
+
+ return all;
+}
diff --git a/src/lib/film.h b/src/lib/film.h
index 8628d8b38..0227f26c9 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -143,6 +143,8 @@ public:
return _state_version;
}
+ std::string subtitle_language () const;
+
/** Identifiers for the parts of our state;
used for signalling changes.
*/
diff --git a/src/lib/font.cc b/src/lib/font.cc
index bf7a79a3d..ecf7aabf0 100644
--- a/src/lib/font.cc
+++ b/src/lib/font.cc
@@ -22,17 +22,14 @@
Font::Font (cxml::NodePtr node)
{
- id = node->optional_string_child ("Id");
+ id = node->string_child ("Id");
file = node->optional_string_child ("File");
}
void
Font::as_xml (xmlpp::Node* node)
{
- if (id) {
- node->add_child("Id")->add_child_text (id.get ());
- }
-
+ node->add_child("Id")->add_child_text (id);
if (file) {
node->add_child("File")->add_child_text (file.get().string ());
}
diff --git a/src/lib/font.h b/src/lib/font.h
index 7a26eefc9..6161c20a9 100644
--- a/src/lib/font.h
+++ b/src/lib/font.h
@@ -25,8 +25,6 @@
class Font
{
public:
- Font () {}
-
Font (std::string id_)
: id (id_) {}
@@ -34,8 +32,8 @@ public:
void as_xml (xmlpp::Node* node);
- /** Font ID, or empty for the default font */
- boost::optional<std::string> id;
+ /** Font ID */
+ std::string id;
boost::optional<boost::filesystem::path> file;
};
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 396dc9906..695ce00ce 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -551,12 +551,6 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting)
continue;
}
- /* XXX: this will break down if we have multiple subtitle content */
- ps.language = subtitle_content->subtitle_language();
- if (ps.language.empty ()) {
- ps.language = _("Unknown");
- }
-
shared_ptr<SubtitleDecoder> subtitle_decoder = dynamic_pointer_cast<SubtitleDecoder> ((*j)->decoder);
ContentTime const from = dcp_to_content_subtitle (*j, time);
/* XXX: this video_frame_rate() should be the rate that the subtitle content has been prepared for */
@@ -592,3 +586,25 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting)
return ps;
}
+
+list<shared_ptr<Font> >
+Player::get_subtitle_fonts ()
+{
+ if (!_have_valid_pieces) {
+ setup_pieces ();
+ }
+
+ list<shared_ptr<Font> > fonts;
+ BOOST_FOREACH (shared_ptr<Piece>& p, _pieces) {
+ shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (p->content);
+ if (sc) {
+ /* XXX: things may go wrong if there are duplicate font IDs
+ with different font files.
+ */
+ list<shared_ptr<Font> > f = sc->fonts ();
+ copy (f.begin(), f.end(), back_inserter (fonts));
+ }
+ }
+
+ return fonts;
+}
diff --git a/src/lib/player.h b/src/lib/player.h
index 5d2273a44..9a1e8cc23 100644
--- a/src/lib/player.h
+++ b/src/lib/player.h
@@ -89,6 +89,7 @@ public:
std::list<boost::shared_ptr<PlayerVideo> > get_video (DCPTime time, bool accurate);
boost::shared_ptr<AudioBuffers> get_audio (DCPTime time, DCPTime length, bool accurate);
PlayerSubtitles get_subtitles (DCPTime time, DCPTime length, bool starting);
+ std::list<boost::shared_ptr<Font> > get_subtitle_fonts ();
void set_video_container_size (dcp::Size);
void set_approximate_size ();
diff --git a/src/lib/player_subtitles.h b/src/lib/player_subtitles.h
index 804c87cb9..65de500f6 100644
--- a/src/lib/player_subtitles.h
+++ b/src/lib/player_subtitles.h
@@ -37,8 +37,6 @@ public:
/** ImageSubtitles, with their rectangles transformed as specified by their content */
std::list<ImageSubtitle> image;
std::list<dcp::SubtitleString> text;
-
- std::string language;
};
#endif
diff --git a/src/lib/subrip_content.cc b/src/lib/subrip_content.cc
index 969829b31..992947a2d 100644
--- a/src/lib/subrip_content.cc
+++ b/src/lib/subrip_content.cc
@@ -32,6 +32,8 @@ using dcp::raw_convert;
using boost::shared_ptr;
using boost::lexical_cast;
+std::string const SubRipContent::font_id = "font";
+
SubRipContent::SubRipContent (shared_ptr<const Film> film, boost::filesystem::path path)
: Content (film, path)
, SubtitleContent (film, path)
@@ -60,7 +62,7 @@ SubRipContent::examine (boost::shared_ptr<Job> job, bool calculate_digest)
boost::mutex::scoped_lock lm (_mutex);
_length = len;
- _fonts.push_back (shared_ptr<Font> (new Font ()));
+ _fonts.push_back (shared_ptr<Font> (new Font (font_id)));
}
string
diff --git a/src/lib/subrip_content.h b/src/lib/subrip_content.h
index 243032691..0202e21d7 100644
--- a/src/lib/subrip_content.h
+++ b/src/lib/subrip_content.h
@@ -42,6 +42,8 @@ public:
return true;
}
+ static std::string const font_id;
+
private:
DCPTime _length;
};
diff --git a/src/lib/subrip_decoder.cc b/src/lib/subrip_decoder.cc
index e13b11063..ea8997e31 100644
--- a/src/lib/subrip_decoder.cc
+++ b/src/lib/subrip_decoder.cc
@@ -60,7 +60,7 @@ SubRipDecoder::pass ()
for (list<sub::Block>::const_iterator j = i->blocks.begin(); j != i->blocks.end(); ++j) {
out.push_back (
dcp::SubtitleString (
- optional<string> (),
+ SubRipContent::font_id,
j->italic,
dcp::Color (255, 255, 255),
/* .srt files don't specify size, so this is an arbitrary value */
diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc
index 9d8eebe25..5718a05b4 100644
--- a/src/lib/transcoder.cc
+++ b/src/lib/transcoder.cc
@@ -63,6 +63,11 @@ Transcoder::go ()
DCPTime const frame = DCPTime::from_frames (1, _film->video_frame_rate ());
DCPTime const length = _film->length ();
+
+ if (!_film->burn_subtitles ()) {
+ _writer->write (_player->get_subtitle_fonts ());
+ }
+
for (DCPTime t; t < length; t += frame) {
list<shared_ptr<PlayerVideo> > v = _player->get_video (t, true);
for (list<shared_ptr<PlayerVideo> >::const_iterator i = v.begin(); i != v.end(); ++i) {
diff --git a/src/lib/writer.cc b/src/lib/writer.cc
index 5a6998c8a..07b637d46 100644
--- a/src/lib/writer.cc
+++ b/src/lib/writer.cc
@@ -32,6 +32,7 @@
#include "md5_digester.h"
#include "encoded_data.h"
#include "version.h"
+#include "font.h"
#include <dcp/mono_picture_mxf.h>
#include <dcp/stereo_picture_mxf.h>
#include <dcp/sound_mxf.h>
@@ -616,7 +617,7 @@ Writer::write (PlayerSubtitles subs)
}
if (!_subtitle_content) {
- _subtitle_content.reset (new dcp::InteropSubtitleContent (_film->name(), subs.language));
+ _subtitle_content.reset (new dcp::InteropSubtitleContent (_film->name(), _film->subtitle_language ()));
}
for (list<dcp::SubtitleString>::const_iterator i = subs.text.begin(); i != subs.text.end(); ++i) {
@@ -624,6 +625,19 @@ Writer::write (PlayerSubtitles subs)
}
}
+void
+Writer::write (list<shared_ptr<Font> > fonts)
+{
+ if (!_subtitle_content) {
+ _subtitle_content.reset (new dcp::InteropSubtitleContent (_film->name(), _film->subtitle_language ()));
+ }
+
+ for (list<shared_ptr<Font> >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
+ /* XXX: this LiberationSans-Regular needs to be a path to a DCP-o-matic-distributed copy */
+ _subtitle_content->add_font ((*i)->id, (*i)->file.get_value_or ("LiberationSans-Regular.ttf").leaf().string ());
+ }
+}
+
bool
operator< (QueueItem const & a, QueueItem const & b)
{
diff --git a/src/lib/writer.h b/src/lib/writer.h
index 5efb14e50..6aa0f4c1f 100644
--- a/src/lib/writer.h
+++ b/src/lib/writer.h
@@ -24,7 +24,6 @@
#include "exceptions.h"
#include "types.h"
#include "player_subtitles.h"
-#include <dcp/subtitle_content.h>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/thread.hpp>
@@ -35,6 +34,7 @@ class Film;
class EncodedData;
class AudioBuffers;
class Job;
+class Font;
namespace dcp {
class MonoPictureMXF;
@@ -45,6 +45,7 @@ namespace dcp {
class PictureMXFWriter;
class SoundMXF;
class SoundMXFWriter;
+ class InteropSubtitleContent;
}
struct QueueItem
@@ -95,6 +96,7 @@ public:
void fake_write (int, Eyes);
void write (boost::shared_ptr<const AudioBuffers>);
void write (PlayerSubtitles subs);
+ void write (std::list<boost::shared_ptr<Font> > fonts);
void repeat (int f, Eyes);
void finish ();
@@ -149,5 +151,5 @@ private:
boost::shared_ptr<dcp::PictureMXFWriter> _picture_mxf_writer;
boost::shared_ptr<dcp::SoundMXF> _sound_mxf;
boost::shared_ptr<dcp::SoundMXFWriter> _sound_mxf_writer;
- boost::shared_ptr<dcp::SubtitleContent> _subtitle_content;
+ boost::shared_ptr<dcp::InteropSubtitleContent> _subtitle_content;
};