From: Carl Hetherington Date: Sun, 5 Jul 2015 19:38:32 +0000 (+0100) Subject: Restore ability to read SMPTE subs from XML files. X-Git-Tag: v1.2.0~13 X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;h=c5dfc40e4a75ebdecc486938b5f7bf4950aa119f;p=libdcp.git Restore ability to read SMPTE subs from XML files. --- diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 5e39f851..1ef9e7ca 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -31,6 +31,7 @@ #include "util.h" #include "AS_DCP.h" #include "KM_util.h" +#include "compose.hpp" #include #include #include @@ -55,30 +56,39 @@ SMPTESubtitleAsset::SMPTESubtitleAsset () } -/** Construct a SMPTESubtitleAsset by reading an MXF file. +/** Construct a SMPTESubtitleAsset by reading an MXF or XML file. * @param file Filename. */ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file) : SubtitleAsset (file) { - ASDCP::TimedText::MXFReader reader; - Kumu::Result_t r = reader.OpenRead (file.string().c_str ()); - if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for reading", file, r)); - } - - /* Read the subtitle XML */ - - string s; - reader.ReadTimedTextResource (s, 0, 0); - stringstream t; - t << s; shared_ptr xml (new cxml::Document ("SubtitleReel")); - xml->read_stream (t); - ASDCP::WriterInfo info; - reader.FillWriterInfo (info); - _id = read_writer_info (info); + shared_ptr reader (new ASDCP::TimedText::MXFReader ()); + Kumu::Result_t r = reader->OpenRead (file.string().c_str ()); + + if (!ASDCP_FAILURE (r)) { + string s; + reader->ReadTimedTextResource (s, 0, 0); + stringstream t; + t << s; + xml->read_stream (t); + ASDCP::WriterInfo info; + reader->FillWriterInfo (info); + _id = read_writer_info (info); + } else { + reader.reset (); + try { + xml->read_file (file); + _id = xml->string_child ("Id").substr (9); + } catch (cxml::Error& e) { + boost::throw_exception ( + DCPReadError ( + String::compose ("could not read subtitles from %1; MXF failed with %2, XML failed with %3", file, static_cast (r), e.what ()) + ) + ); + } + } _load_font_nodes = type_children (xml, "LoadFont"); @@ -115,10 +125,16 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file) parse_subtitles (xml, font_nodes); - /* Read fonts */ + if (reader) { + read_fonts (reader); + } +} +void +SMPTESubtitleAsset::read_fonts (shared_ptr reader) +{ ASDCP::TimedText::TimedTextDescriptor text_descriptor; - reader.FillTimedTextDescriptor (text_descriptor); + reader->FillTimedTextDescriptor (text_descriptor); for ( ASDCP::TimedText::ResourceList_t::const_iterator i = text_descriptor.ResourceList.begin(); i != text_descriptor.ResourceList.end(); @@ -127,7 +143,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file) if (i->Type == ASDCP::TimedText::MT_OPENTYPE) { ASDCP::TimedText::FrameBuffer buffer; buffer.Capacity (10 * 1024 * 1024); - reader.ReadAncillaryResource (i->ResourceID, buffer); + reader->ReadAncillaryResource (i->ResourceID, buffer); char id[64]; Kumu::bin2UUIDhex (i->ResourceID, ASDCP::UUIDlen, id, sizeof (id)); diff --git a/src/smpte_subtitle_asset.h b/src/smpte_subtitle_asset.h index 444c53e6..1b67dd15 100644 --- a/src/smpte_subtitle_asset.h +++ b/src/smpte_subtitle_asset.h @@ -26,6 +26,12 @@ #include "mxf.h" #include +namespace ASDCP { + namespace TimedText { + class MXFReader; + } +} + namespace dcp { class SMPTELoadFontNode; @@ -121,6 +127,8 @@ protected: } private: + void read_fonts (boost::shared_ptr); + std::string _content_title_text; boost::optional _language; boost::optional _annotation_text;