*/
-#include "smpte_subtitle_asset.h"
-#include "smpte_load_font_node.h"
-#include "exceptions.h"
-#include "xml.h"
-#include "raw_convert.h"
-#include "dcp_assert.h"
-#include "util.h"
#include "compose.hpp"
#include "crypto_context.h"
+#include "dcp_assert.h"
+#include "equality_options.h"
+#include "exceptions.h"
+#include "raw_convert.h"
+#include "smpte_load_font_node.h"
+#include "smpte_subtitle_asset.h"
#include "subtitle_image.h"
+#include "util.h"
+#include "warnings.h"
+#include "xml.h"
+LIBDCP_DISABLE_WARNINGS
#include <asdcp/AS_DCP.h>
#include <asdcp/KM_util.h>
#include <asdcp/KM_log.h>
#include <libxml++/libxml++.h>
+LIBDCP_ENABLE_WARNINGS
#include <boost/algorithm/string.hpp>
using namespace dcp;
-static string const subtitle_smpte_ns = "http://www.smpte-ra.org/schemas/428-7/2010/DCST";
+static string const subtitle_smpte_ns_2007 = "http://www.smpte-ra.org/schemas/428-7/2007/DCST";
+static string const subtitle_smpte_ns_2010 = "http://www.smpte-ra.org/schemas/428-7/2010/DCST";
+static string const subtitle_smpte_ns_2014 = "http://www.smpte-ra.org/schemas/428-7/2014/DCST";
-SMPTESubtitleAsset::SMPTESubtitleAsset ()
- : MXF (Standard::SMPTE)
+SMPTESubtitleAsset::SMPTESubtitleAsset(SubtitleStandard standard)
+ : MXF(Standard::SMPTE)
, _edit_rate (24, 1)
, _time_code_rate (24)
+ , _subtitle_standard(standard)
, _xml_id (make_uuid())
{
_id = read_writer_info (info);
if (!_key_id) {
/* Not encrypted; read it in now */
- reader->ReadTimedTextResource (_raw_xml);
- xml->read_string (_raw_xml);
+ string xml_string;
+ reader->ReadTimedTextResource (xml_string);
+ _raw_xml = xml_string;
+ xml->read_string (xml_string);
parse_xml (xml);
- read_mxf_descriptor (reader, make_shared<DecryptionContext>(optional<Key>(), Standard::SMPTE));
+ read_mxf_descriptor (reader);
+ read_mxf_resources(reader, std::make_shared<DecryptionContext>(optional<Key>(), Standard::SMPTE));
+ } else {
+ read_mxf_descriptor (reader);
}
} else {
/* Plain XML */
xml = make_shared<cxml::Document>("SubtitleReel");
xml->read_file (file);
parse_xml (xml);
- _id = _xml_id = remove_urn_uuid (xml->string_child ("Id"));
} catch (cxml::Error& e) {
boost::throw_exception (
ReadError (
void
SMPTESubtitleAsset::parse_xml (shared_ptr<cxml::Document> xml)
{
+ if (xml->namespace_uri() == subtitle_smpte_ns_2007) {
+ _subtitle_standard = SubtitleStandard::SMPTE_2007;
+ } else if (xml->namespace_uri() == subtitle_smpte_ns_2010) {
+ _subtitle_standard = SubtitleStandard::SMPTE_2010;
+ } else if (xml->namespace_uri() == subtitle_smpte_ns_2014) {
+ _subtitle_standard = SubtitleStandard::SMPTE_2014;
+ } else {
+ throw XMLError("Unrecognised subtitle namespace " + xml->namespace_uri());
+ }
_xml_id = remove_urn_uuid(xml->string_child("Id"));
_load_font_nodes = type_children<dcp::SMPTELoadFontNode> (xml, "LoadFont");
}
/* Guess intrinsic duration */
- _intrinsic_duration = latest_subtitle_out().as_editable_units (_edit_rate.numerator / _edit_rate.denominator);
+ _intrinsic_duration = latest_subtitle_out().as_editable_units_ceil(_edit_rate.numerator / _edit_rate.denominator);
}
void
-SMPTESubtitleAsset::read_mxf_descriptor (shared_ptr<ASDCP::TimedText::MXFReader> reader, shared_ptr<DecryptionContext> dec)
+SMPTESubtitleAsset::read_mxf_resources (shared_ptr<ASDCP::TimedText::MXFReader> reader, shared_ptr<DecryptionContext> dec)
{
ASDCP::TimedText::TimedTextDescriptor descriptor;
reader->FillTimedTextDescriptor (descriptor);
++i) {
ASDCP::TimedText::FrameBuffer buffer;
- buffer.Capacity (10 * 1024 * 1024);
- reader->ReadAncillaryResource (i->ResourceID, buffer, dec->context(), dec->hmac());
+ buffer.Capacity(32 * 1024 * 1024);
+ auto const result = reader->ReadAncillaryResource(i->ResourceID, buffer, dec->context(), dec->hmac());
+ if (ASDCP_FAILURE(result)) {
+ switch (i->Type) {
+ case ASDCP::TimedText::MT_OPENTYPE:
+ throw ReadError(String::compose("Could not read font from MXF file (%1)", static_cast<int>(result)));
+ case ASDCP::TimedText::MT_PNG:
+ throw ReadError(String::compose("Could not read subtitle image from MXF file (%1)", static_cast<int>(result)));
+ default:
+ throw ReadError(String::compose("Could not read resource from MXF file (%1)", static_cast<int>(result)));
+ }
+ }
char id[64];
Kumu::bin2UUIDhex (i->ResourceID, ASDCP::UUIDlen, id, sizeof(id));
- shared_array<uint8_t> data (new uint8_t[buffer.Size()]);
- memcpy (data.get(), buffer.RoData(), buffer.Size());
-
switch (i->Type) {
case ASDCP::TimedText::MT_OPENTYPE:
{
}
if (j != _load_font_nodes.end ()) {
- _fonts.push_back (Font ((*j)->id, (*j)->urn, ArrayData (data, buffer.Size ())));
+ _fonts.push_back(Font((*j)->id, (*j)->urn, ArrayData(buffer.RoData(), buffer.Size())));
}
break;
}
}
if (j != _subtitles.end()) {
- dynamic_pointer_cast<SubtitleImage>(*j)->set_png_image (ArrayData(data, buffer.Size()));
+ dynamic_pointer_cast<SubtitleImage>(*j)->set_png_image(ArrayData(buffer.RoData(), buffer.Size()));
}
break;
}
break;
}
}
+}
+
+
+void
+SMPTESubtitleAsset::read_mxf_descriptor (shared_ptr<ASDCP::TimedText::MXFReader> reader)
+{
+ ASDCP::TimedText::TimedTextDescriptor descriptor;
+ reader->FillTimedTextDescriptor (descriptor);
_intrinsic_duration = descriptor.ContainerDuration;
+ /* The thing which is called AssetID in the descriptor is also known as the
+ * ResourceID of the MXF. We store that, at present just for verification
+ * purposes.
+ */
+ char id[64];
+ Kumu::bin2UUIDhex (descriptor.AssetID, ASDCP::UUIDlen, id, sizeof(id));
+ _resource_id = id;
}
}
auto dec = make_shared<DecryptionContext>(key, Standard::SMPTE);
- reader->ReadTimedTextResource (_raw_xml, dec->context(), dec->hmac());
+ string xml_string;
+ reader->ReadTimedTextResource (xml_string, dec->context(), dec->hmac());
+ _raw_xml = xml_string;
auto xml = make_shared<cxml::Document>("SubtitleReel");
- xml->read_string (_raw_xml);
+ xml->read_string (xml_string);
parse_xml (xml);
- read_mxf_descriptor (reader, dec);
+ read_mxf_resources (reader, dec);
}
SMPTESubtitleAsset::xml_as_string () const
{
xmlpp::Document doc;
- auto root = doc.create_root_node ("dcst:SubtitleReel");
- root->set_namespace_declaration (subtitle_smpte_ns, "dcst");
- root->set_namespace_declaration ("http://www.w3.org/2001/XMLSchema", "xs");
+ auto root = doc.create_root_node ("SubtitleReel");
- root->add_child("Id", "dcst")->add_child_text ("urn:uuid:" + _xml_id);
- root->add_child("ContentTitleText", "dcst")->add_child_text (_content_title_text);
+ DCP_ASSERT (_xml_id);
+ root->add_child("Id")->add_child_text("urn:uuid:" + *_xml_id);
+ root->add_child("ContentTitleText")->add_child_text(_content_title_text);
if (_annotation_text) {
- root->add_child("AnnotationText", "dcst")->add_child_text (_annotation_text.get ());
+ root->add_child("AnnotationText")->add_child_text(_annotation_text.get());
}
- root->add_child("IssueDate", "dcst")->add_child_text (_issue_date.as_string (true));
+ root->add_child("IssueDate")->add_child_text(_issue_date.as_string(false, false));
if (_reel_number) {
- root->add_child("ReelNumber", "dcst")->add_child_text (raw_convert<string> (_reel_number.get ()));
+ root->add_child("ReelNumber")->add_child_text(raw_convert<string>(_reel_number.get()));
}
if (_language) {
- root->add_child("Language", "dcst")->add_child_text (_language.get ());
+ root->add_child("Language")->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));
+ root->add_child("EditRate")->add_child_text(_edit_rate.as_string());
+ root->add_child("TimeCodeRate")->add_child_text(raw_convert<string>(_time_code_rate));
if (_start_time) {
- root->add_child("StartTime", "dcst")->add_child_text(_start_time.get().as_string(Standard::SMPTE));
+ root->add_child("StartTime")->add_child_text(_start_time.get().as_string(Standard::SMPTE));
}
for (auto i: _load_font_nodes) {
- auto load_font = root->add_child("LoadFont", "dcst");
+ auto load_font = root->add_child("LoadFont");
load_font->add_child_text ("urn:uuid:" + i->urn);
load_font->set_attribute ("ID", i->id);
}
- subtitles_as_xml (root->add_child("SubtitleList", "dcst"), _time_code_rate, Standard::SMPTE);
+ subtitles_as_xml (root->add_child("SubtitleList"), _time_code_rate, Standard::SMPTE);
- return doc.write_to_string ("UTF-8");
+ return format_xml(doc, std::make_pair(string{}, schema_namespace()));
}
}
}
- descriptor.NamespaceName = subtitle_smpte_ns;
+ descriptor.NamespaceName = schema_namespace();
unsigned int c;
- Kumu::hex2bin (_xml_id.c_str(), descriptor.AssetID, ASDCP::UUIDlen, &c);
+ DCP_ASSERT (_xml_id);
+ Kumu::hex2bin (_xml_id->c_str(), descriptor.AssetID, ASDCP::UUIDlen, &c);
DCP_ASSERT (c == Kumu::UUID_Length);
descriptor.ContainerDuration = _intrinsic_duration;
boost::throw_exception (FileError ("could not open subtitle MXF for writing", p.string(), r));
}
- r = writer.WriteTimedTextResource (xml_as_string (), enc.context(), enc.hmac());
+ _raw_xml = xml_as_string ();
+
+ r = writer.WriteTimedTextResource (*_raw_xml, enc.context(), enc.hmac());
if (ASDCP_FAILURE (r)) {
boost::throw_exception (MXFFileError ("could not write XML to timed text resource", p.string(), r));
}
}
bool
-SMPTESubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions options, NoteHandler note) const
+SMPTESubtitleAsset::equals(shared_ptr<const Asset> other_asset, EqualityOptions const& options, NoteHandler note) const
{
if (!SubtitleAsset::equals (other_asset, options, note)) {
return false;
SMPTESubtitleAsset::add (shared_ptr<Subtitle> s)
{
SubtitleAsset::add (s);
- _intrinsic_duration = latest_subtitle_out().as_editable_units (_edit_rate.numerator / _edit_rate.denominator);
+ _intrinsic_duration = latest_subtitle_out().as_editable_units_ceil(_edit_rate.numerator / _edit_rate.denominator);
+}
+
+
+string
+SMPTESubtitleAsset::schema_namespace() const
+{
+ switch (_subtitle_standard) {
+ case SubtitleStandard::SMPTE_2007:
+ return subtitle_smpte_ns_2007;
+ case SubtitleStandard::SMPTE_2010:
+ return subtitle_smpte_ns_2010;
+ case SubtitleStandard::SMPTE_2014:
+ return subtitle_smpte_ns_2014;
+ default:
+ DCP_ASSERT(false);
+ }
+
+ DCP_ASSERT(false);
}