summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-06-04 12:25:48 +0100
committerCarl Hetherington <cth@carlh.net>2015-06-04 15:09:28 +0100
commitd76ee110c29b631a71d965b71bcdb8663232b17f (patch)
tree4234c10900671eb80a1961e126d8398ad714f017
parent951572c6eb7e31834d2d7f1fbc67a9cdb1336696 (diff)
Start of work.1.0-smpte-subs
-rw-r--r--src/dcp_time.cc1
-rw-r--r--src/smpte_subtitle_content.cc62
-rw-r--r--src/smpte_subtitle_content.h12
-rw-r--r--src/subtitle_content.h5
-rw-r--r--src/types.cc7
-rw-r--r--src/types.h2
6 files changed, 82 insertions, 7 deletions
diff --git a/src/dcp_time.cc b/src/dcp_time.cc
index d34804e9..5d9bed81 100644
--- a/src/dcp_time.cc
+++ b/src/dcp_time.cc
@@ -66,6 +66,7 @@ Time::set (double seconds, int tcr_)
}
}
+/** @param time String of the form HH:MM:SS:EE */
Time::Time (string time, int tcr_)
: tcr (tcr_)
{
diff --git a/src/smpte_subtitle_content.cc b/src/smpte_subtitle_content.cc
index e95a64fc..31c9b059 100644
--- a/src/smpte_subtitle_content.cc
+++ b/src/smpte_subtitle_content.cc
@@ -24,13 +24,18 @@
#include "xml.h"
#include "AS_DCP.h"
#include "KM_util.h"
+#include "raw_convert.h"
#include <boost/foreach.hpp>
+#include <boost/algorithm/string.hpp>
using std::string;
using std::list;
using std::stringstream;
using std::cout;
+using std::vector;
using boost::shared_ptr;
+using boost::split;
+using boost::is_any_of;
using namespace dcp;
SMPTESubtitleContent::SMPTESubtitleContent (boost::filesystem::path file, bool mxf)
@@ -64,16 +69,37 @@ SMPTESubtitleContent::SMPTESubtitleContent (boost::filesystem::path file, bool m
_load_font_nodes = type_children<dcp::SMPTELoadFontNode> (xml, "LoadFont");
- int tcr = xml->number_child<int> ("TimeCodeRate");
+ _content_title_text = xml->string_child ("ContentTitleText");
+ _annotation_text = xml->optional_string_child ("AnnotationText");
+ _issue_date = LocalTime (xml->string_child ("IssueDate"));
+ _reel_number = xml->optional_number_child<int> ("ReelNumber");
+ _language = xml->optional_string_child ("Language");
+
+ /* This is supposed to be two numbers, but a single number has been seen in the wild */
+ string const er = xml->string_child ("EditRate");
+ vector<string> er_parts;
+ split (er_parts, er, is_any_of (" "));
+ if (er_parts.size() == 1) {
+ _edit_rate = Fraction (raw_convert<int> (er_parts[0]), 1);
+ } else if (er_parts.size() == 2) {
+ _edit_rate = Fraction (raw_convert<int> (er_parts[0]), raw_convert<int> (er_parts[1]));
+ } else {
+ throw XMLError ("malformed EditRate " + er);
+ }
+
+ _time_code_rate = xml->number_child<int> ("TimeCodeRate");
+ if (xml->optional_string_child ("StartTime")) {
+ _start_time = Time (xml->string_child ("StartTime"), _time_code_rate);
+ }
shared_ptr<cxml::Node> subtitle_list = xml->optional_node_child ("SubtitleList");
list<cxml::NodePtr> f = subtitle_list->node_children ("Font");
list<shared_ptr<dcp::FontNode> > font_nodes;
BOOST_FOREACH (cxml::NodePtr& i, f) {
- font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, tcr)));
+ font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, _time_code_rate)));
}
-
+
parse_common (xml, font_nodes);
}
@@ -92,3 +118,33 @@ SMPTESubtitleContent::valid_mxf (boost::filesystem::path file)
Kumu::Result_t r = reader.OpenRead (file.string().c_str ());
return !ASDCP_FAILURE (r);
}
+
+Glib::ustring
+SMPTESubtitleContent::xml_as_string () const
+{
+ xmlpp::Document doc;
+ xmlpp::Element* root = doc.create_root_node ("SubtitleReel", "dcst");
+ root->set_namespace_declaration ("http://www.smpte-ra.org/schemas/428-7/2010/DCST", "xmlns:dcst");
+ root->set_namespace_declaration ("http://www.w3.org/2001/XMLSchema", "xmlns:xs");
+
+ root->add_child("ID", "dcst")->add_child_text (_id);
+ root->add_child("ContentTitleText", "dcst")->add_child_text (_content_title_text);
+ if (_annotation_text) {
+ root->add_child("AnnotationText", "dcst")->add_child_text (_annotation_text.get ());
+ }
+ root->add_child("IssueDate", "dcst")->add_child_text (_issue_date.as_string (true));
+ if (_reel_number) {
+ root->add_child("ReelNumber", "dcst")->add_child_text (raw_convert<string> (_reel_number.get ()));
+ }
+ if (_language) {
+ root->add_child("Language", "dcst")->add_child_text (_language.get ());
+ }
+ root->add_child("EditRate", "dcst")->add_child_text (_edit_rate.as_string ());
+ root->add_child("TimeCodeRate", "dcst")->add_child_text (raw_convert<string> (_time_code_rate));
+ if (_start_time) {
+ root->add_child("StartTime", "dcst")->add_child_text (_start_time.get().to_string ());
+ }
+
+ return doc.write_to_string_formatted ("UTF-8");
+}
+
diff --git a/src/smpte_subtitle_content.h b/src/smpte_subtitle_content.h
index 8526e0ec..2e716b67 100644
--- a/src/smpte_subtitle_content.h
+++ b/src/smpte_subtitle_content.h
@@ -18,6 +18,7 @@
*/
#include "subtitle_content.h"
+#include "local_time.h"
#include <boost/filesystem.hpp>
namespace dcp {
@@ -34,9 +35,20 @@ public:
std::list<boost::shared_ptr<LoadFontNode> > load_font_nodes () const;
+ Glib::ustring xml_as_string () const;
+
static bool valid_mxf (boost::filesystem::path);
private:
+ std::string _content_title_text;
+ boost::optional<std::string> _annotation_text;
+ LocalTime _issue_date;
+ boost::optional<int> _reel_number;
+ boost::optional<std::string> _language;
+ Fraction _edit_rate;
+ int _time_code_rate;
+ boost::optional<Time> _start_time;
+
std::list<boost::shared_ptr<SMPTELoadFontNode> > _load_font_nodes;
};
diff --git a/src/subtitle_content.h b/src/subtitle_content.h
index ee424916..b97346fa 100644
--- a/src/subtitle_content.h
+++ b/src/subtitle_content.h
@@ -61,10 +61,7 @@ public:
void add (SubtitleString);
void write_xml (boost::filesystem::path) const;
- virtual Glib::ustring xml_as_string () const {
- /* XXX: this should be pure virtual when SMPTE writing is implemented */
- return "";
- }
+ virtual Glib::ustring xml_as_string () const = 0;
Time latest_subtitle_out () const;
diff --git a/src/types.cc b/src/types.cc
index e86e999c..37666701 100644
--- a/src/types.cc
+++ b/src/types.cc
@@ -20,6 +20,7 @@
#include "raw_convert.h"
#include "types.h"
#include "exceptions.h"
+#include "compose.hpp"
#include <boost/algorithm/string.hpp>
#include <vector>
#include <cstdio>
@@ -43,6 +44,12 @@ Fraction::Fraction (string s)
denominator = raw_convert<int> (b[1]);
}
+string
+Fraction::as_string () const
+{
+ return String::compose ("%1 %2", numerator, denominator);
+}
+
bool
dcp::operator== (Fraction const & a, Fraction const & b)
{
diff --git a/src/types.h b/src/types.h
index a8e63faf..75303f9c 100644
--- a/src/types.h
+++ b/src/types.h
@@ -139,6 +139,8 @@ public:
return float (numerator) / denominator;
}
+ std::string as_string () const;
+
int numerator;
int denominator;
};