WIP: partially restore PlayerVideo transfer over network.
[dcpomatic.git] / src / lib / player_text.cc
1 /*
2     Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "player_text.h"
22 #include "font.h"
23 #include "util.h"
24 #include "dcpomatic_socket.h"
25 #include "image.h"
26 #include <dcp/raw_convert.h>
27 #include <libxml++/libxml++.h>
28 #include <boost/foreach.hpp>
29
30 using std::list;
31 using boost::shared_ptr;
32 using dcp::raw_convert;
33 using namespace dcpomatic;
34
35 void
36 PlayerText::add_metadata (xmlpp::Node* node) const
37 {
38         BOOST_FOREACH (shared_ptr<Font> i, fonts) {
39                 /* XXX: transferring a font file for every frame that needs it seems a bit wasteful,
40                    but probably not so bad in the great scheme of things.
41                 */
42                 i->transfer_xml (node->add_child("Font"));
43         }
44
45         BOOST_FOREACH (BitmapText i, bitmap) {
46                 i.transfer_xml (node->add_child("Bitmap"));
47         }
48
49         BOOST_FOREACH (StringText i, string) {
50                 i.transfer_xml (node->add_child("String"));
51         }
52 }
53
54 void
55 PlayerText::send_binary (shared_ptr<Socket> socket) const
56 {
57         BOOST_FOREACH (shared_ptr<Font> i, fonts) {
58                 i->transfer_binary (socket);
59         }
60
61         BOOST_FOREACH (BitmapText i, bitmap) {
62                 i.transfer_binary (socket);
63         }
64 }
65
66 void
67 PlayerText::add_fonts (list<shared_ptr<Font> > fonts_)
68 {
69         BOOST_FOREACH (shared_ptr<Font> i, fonts_) {
70                 bool got = false;
71                 BOOST_FOREACH (shared_ptr<Font> j, fonts) {
72                         if (*i == *j) {
73                                 got = true;
74                         }
75                 }
76                 if (!got) {
77                         fonts.push_back (i);
78                 }
79         }
80 }
81
82 bool
83 operator== (PlayerText const & a, PlayerText const & b)
84 {
85         return deep_equals(a.fonts, b.fonts) && deep_equals(a.bitmap, b.bitmap) && deep_equals(a.string, b.string);
86 }
87
88 bool
89 operator!= (PlayerText const & a, PlayerText const & b)
90 {
91         return !(a == b);
92 }