Assorted image subtitle fixes.
[dcpomatic.git] / src / lib / ffmpeg_subtitle_stream.cc
1 /*
2     Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "ffmpeg_subtitle_stream.h"
21 #include "raw_convert.h"
22 #include <libxml++/libxml++.h>
23 #include <boost/foreach.hpp>
24
25 using std::string;
26
27 /** Construct a SubtitleStream from a value returned from to_string().
28  *  @param t String returned from to_string().
29  *  @param v State file version.
30  */
31 FFmpegSubtitleStream::FFmpegSubtitleStream (cxml::ConstNodePtr node)
32         : FFmpegStream (node)
33 {
34         BOOST_FOREACH (cxml::NodePtr i, node->node_children ("Period")) {
35                 periods.push_back (
36                         ContentTimePeriod (
37                                 ContentTime (node->number_child<ContentTime::Type> ("From")),
38                                 ContentTime (node->number_child<ContentTime::Type> ("To"))
39                                 )
40                         );
41         }
42 }
43
44 void
45 FFmpegSubtitleStream::as_xml (xmlpp::Node* root) const
46 {
47         FFmpegStream::as_xml (root);
48
49         BOOST_FOREACH (ContentTimePeriod const & i, periods) {
50                 xmlpp::Node* node = root->add_child ("Period");
51                 node->add_child("From")->add_child_text (raw_convert<string> (i.from.get ()));
52                 node->add_child("To")->add_child_text (raw_convert<string> (i.to.get ()));
53         }
54 }