summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-01-13 00:19:41 +0100
committerCarl Hetherington <cth@carlh.net>2020-01-13 00:19:41 +0100
commit9979e28b2511c15982ca8d083947eedf513b14f3 (patch)
tree1775e3c6fabe4b089d864b1389b6e2b38164c51b /src
parentbbee721034df747169f7d75ef142e57a8a8ed646 (diff)
WIP: partially restore PlayerVideo transfer over network.faster-subtitle-moving
Diffstat (limited to 'src')
-rw-r--r--src/lib/bitmap_text.cc21
-rw-r--r--src/lib/bitmap_text.h5
-rw-r--r--src/lib/font.cc28
-rw-r--r--src/lib/font.h7
-rw-r--r--src/lib/player_text.cc36
-rw-r--r--src/lib/player_text.h5
-rw-r--r--src/lib/player_video.cc15
-rw-r--r--src/lib/string_text.cc28
-rw-r--r--src/lib/string_text.h2
9 files changed, 133 insertions, 14 deletions
diff --git a/src/lib/bitmap_text.cc b/src/lib/bitmap_text.cc
index 6e690b313..21f733983 100644
--- a/src/lib/bitmap_text.cc
+++ b/src/lib/bitmap_text.cc
@@ -20,6 +20,11 @@
#include "bitmap_text.h"
#include "image.h"
+#include "dcpomatic_socket.h"
+#include <dcp/raw_convert.h>
+
+using boost::shared_ptr;
+using dcp::raw_convert;
bool
operator== (BitmapText const & a, BitmapText const & b)
@@ -37,4 +42,20 @@ operator!= (BitmapText const & a, BitmapText const & b)
return !(a == b);
}
+void
+BitmapText::transfer_xml (xmlpp::Node* node) const
+{
+ node->add_child("Width")->add_child_text(raw_convert<std::string>(image->size().width));
+ node->add_child("Height")->add_child_text(raw_convert<std::string>(image->size().height));
+ node->add_child("RectX")->add_child_text(raw_convert<std::string>(rectangle.x));
+ node->add_child("RectY")->add_child_text(raw_convert<std::string>(rectangle.y));
+ node->add_child("RectWidth")->add_child_text(raw_convert<std::string>(rectangle.width));
+ node->add_child("RectHeight")->add_child_text(raw_convert<std::string>(rectangle.height));
+}
+
+void
+BitmapText::transfer_binary (shared_ptr<Socket> socket) const
+{
+ image->write_to_socket (socket);
+}
diff --git a/src/lib/bitmap_text.h b/src/lib/bitmap_text.h
index e9d7c3b79..6fa8ecd60 100644
--- a/src/lib/bitmap_text.h
+++ b/src/lib/bitmap_text.h
@@ -22,9 +22,11 @@
#define DCPOMATIC_BITMAP_CAPTION_H
#include "rect.h"
+#include <libxml++/libxml++.h>
#include <boost/shared_ptr.hpp>
class Image;
+class Socket;
class BitmapText
{
@@ -34,6 +36,9 @@ public:
, rectangle (r)
{}
+ void transfer_xml (xmlpp::Node* node) const;
+ void transfer_binary (boost::shared_ptr<Socket> socket) const;
+
boost::shared_ptr<Image> image;
/** Area that the subtitle covers on its corresponding video, expressed in
* proportions of the image size; e.g. rectangle.x = 0.5 would mean that
diff --git a/src/lib/font.cc b/src/lib/font.cc
index 019c9ab07..c817d3610 100644
--- a/src/lib/font.cc
+++ b/src/lib/font.cc
@@ -20,10 +20,15 @@
#include "font.h"
#include "dcpomatic_assert.h"
+#include "dcpomatic_socket.h"
+#include <dcp/data.h>
+#include <dcp/raw_convert.h>
#include <libxml++/libxml++.h>
#include <boost/foreach.hpp>
using std::string;
+using boost::shared_ptr;
+using dcp::raw_convert;
using namespace dcpomatic;
Font::Font (cxml::NodePtr node)
@@ -38,7 +43,7 @@ Font::Font (cxml::NodePtr node)
}
void
-Font::as_xml (xmlpp::Node* node)
+Font::as_xml (xmlpp::Node* node) const
{
node->add_child("Id")->add_child_text (_id);
if (_file) {
@@ -46,6 +51,27 @@ Font::as_xml (xmlpp::Node* node)
}
}
+/** Add things to an XML node to describe this font for transfer across
+ * a network to another machine. The companion method send_binary() will be called
+ * to send binary parts.
+ */
+void
+Font::transfer_xml (xmlpp::Node* node) const
+{
+ node->add_child("Id")->add_child_text (_id);
+ if (_file) {
+ node->add_child("FileLength")->add_child_text(raw_convert<string>(boost::filesystem::file_size(*_file)));
+ }
+}
+
+void
+Font::transfer_binary (shared_ptr<Socket> socket) const
+{
+ if (_file) {
+ dcp::Data data (*_file);
+ socket->write (data.data().get(), data.size());
+ }
+}
bool
dcpomatic::operator== (Font const & a, Font const & b)
diff --git a/src/lib/font.h b/src/lib/font.h
index 5876bf8a4..f6949e419 100644
--- a/src/lib/font.h
+++ b/src/lib/font.h
@@ -27,6 +27,8 @@
#include <boost/filesystem.hpp>
#include <string>
+class Socket;
+
namespace dcpomatic {
class Font
@@ -37,7 +39,10 @@ public:
explicit Font (cxml::NodePtr node);
- void as_xml (xmlpp::Node* node);
+ void as_xml (xmlpp::Node* node) const;
+
+ void transfer_xml (xmlpp::Node* node) const;
+ void transfer_binary (boost::shared_ptr<Socket> socket) const;
std::string id () const {
return _id;
diff --git a/src/lib/player_text.cc b/src/lib/player_text.cc
index d9c153416..736421705 100644
--- a/src/lib/player_text.cc
+++ b/src/lib/player_text.cc
@@ -21,13 +21,49 @@
#include "player_text.h"
#include "font.h"
#include "util.h"
+#include "dcpomatic_socket.h"
+#include "image.h"
+#include <dcp/raw_convert.h>
+#include <libxml++/libxml++.h>
#include <boost/foreach.hpp>
using std::list;
using boost::shared_ptr;
+using dcp::raw_convert;
using namespace dcpomatic;
void
+PlayerText::add_metadata (xmlpp::Node* node) const
+{
+ BOOST_FOREACH (shared_ptr<Font> i, fonts) {
+ /* XXX: transferring a font file for every frame that needs it seems a bit wasteful,
+ but probably not so bad in the great scheme of things.
+ */
+ i->transfer_xml (node->add_child("Font"));
+ }
+
+ BOOST_FOREACH (BitmapText i, bitmap) {
+ i.transfer_xml (node->add_child("Bitmap"));
+ }
+
+ BOOST_FOREACH (StringText i, string) {
+ i.transfer_xml (node->add_child("String"));
+ }
+}
+
+void
+PlayerText::send_binary (shared_ptr<Socket> socket) const
+{
+ BOOST_FOREACH (shared_ptr<Font> i, fonts) {
+ i->transfer_binary (socket);
+ }
+
+ BOOST_FOREACH (BitmapText i, bitmap) {
+ i.transfer_binary (socket);
+ }
+}
+
+void
PlayerText::add_fonts (list<shared_ptr<Font> > fonts_)
{
BOOST_FOREACH (shared_ptr<Font> i, fonts_) {
diff --git a/src/lib/player_text.h b/src/lib/player_text.h
index 3c571b324..51b49095d 100644
--- a/src/lib/player_text.h
+++ b/src/lib/player_text.h
@@ -29,10 +29,15 @@ namespace dcpomatic {
class Font;
}
+class Socket;
+
/** A set of text (subtitle/CCAP) which span the same time period */
class PlayerText
{
public:
+ void add_metadata (xmlpp::Node* node) const;
+ void send_binary (boost::shared_ptr<Socket> socket) const;
+
void add_fonts (std::list<boost::shared_ptr<dcpomatic::Font> > fonts_);
std::list<boost::shared_ptr<dcpomatic::Font> > fonts;
diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc
index 31038db03..431bc783b 100644
--- a/src/lib/player_video.cc
+++ b/src/lib/player_video.cc
@@ -234,25 +234,18 @@ PlayerVideo::add_metadata (xmlpp::Node* node) const
if (_colour_conversion) {
_colour_conversion.get().as_xml (node);
}
- /* XXX_c
- if (_text) {
- node->add_child ("SubtitleWidth")->add_child_text (raw_convert<string> (_text->image->size().width));
- node->add_child ("SubtitleHeight")->add_child_text (raw_convert<string> (_text->image->size().height));
- node->add_child ("SubtitleX")->add_child_text (raw_convert<string> (_text->position.x));
- node->add_child ("SubtitleY")->add_child_text (raw_convert<string> (_text->position.y));
+ BOOST_FOREACH (PlayerText i, _text) {
+ i.add_metadata(node->add_child("Text"));
}
- */
}
void
PlayerVideo::send_binary (shared_ptr<Socket> socket) const
{
_in->send_binary (socket);
- /* XXX_c
- if (_text) {
- _text->image->write_to_socket (socket);
+ BOOST_FOREACH (PlayerText i, _text) {
+ i.send_binary (socket);
}
- */
}
bool
diff --git a/src/lib/string_text.cc b/src/lib/string_text.cc
index 54ff32578..bf017caf8 100644
--- a/src/lib/string_text.cc
+++ b/src/lib/string_text.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2016-2019 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2016-2020 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -19,6 +19,11 @@
*/
#include "string_text.h"
+#include <dcp/raw_convert.h>
+#include <libxml++/libxml++.h>
+
+using std::string;
+using dcp::raw_convert;
bool
operator== (StringText const & a, StringText const & b)
@@ -26,3 +31,24 @@ operator== (StringText const & a, StringText const & b)
return static_cast<dcp::SubtitleString const &>(a) == static_cast<dcp::SubtitleString const &>(b) && a.outline_width == b.outline_width;
}
+void
+StringText::transfer_xml (xmlpp::Node* node) const
+{
+ if (font()) {
+ node->add_child("Font")->add_child_text(*font());
+ }
+ node->add_child("Italic")->add_child_text(italic() ? "1" : "0");
+ node->add_child("Bold")->add_child_text(bold() ? "1" : "0");
+ node->add_child("Underline")->add_child_text(underline() ? "1" : "0");
+ node->add_child("Colour")->add_child_text(colour().to_argb_string());
+ node->add_child("Size")->add_child_text(raw_convert<string>(size()));
+ node->add_child("AspectAdjust")->add_child_text(raw_convert<string>(aspect_adjust()));
+ node->add_child("Direction")->add_child_text(dcp::direction_to_string(direction()));
+ node->add_child("Text")->add_child_text(text());
+ node->add_child("Effect")->add_child_text(dcp::effect_to_string(effect()));
+ node->add_child("EffectColour")->add_child_text(effect_colour().to_argb_string());
+
+ node->add_child("OutlineWidth")->add_child_text(raw_convert<string>(outline_width));
+}
+
+
diff --git a/src/lib/string_text.h b/src/lib/string_text.h
index 4063a688d..ef965d129 100644
--- a/src/lib/string_text.h
+++ b/src/lib/string_text.h
@@ -35,6 +35,8 @@ public:
, outline_width (outline_width_)
{}
+ void transfer_xml (xmlpp::Node* node) const;
+
int outline_width;
};