Use an enum class for Marker.
[libdcp.git] / src / smpte_subtitle_asset.cc
index 81a0aa6f42093f26b7737a361b17a1ba53ce70d4..7604fd397ee50a8f553c5ba8d4d2bf5e2b0f6b12 100644 (file)
@@ -56,11 +56,11 @@ using std::string;
 using std::list;
 using std::vector;
 using std::map;
-using boost::shared_ptr;
+using std::shared_ptr;
 using boost::split;
 using boost::is_any_of;
 using boost::shared_array;
-using boost::dynamic_pointer_cast;
+using std::dynamic_pointer_cast;
 using boost::optional;
 using boost::starts_with;
 using namespace dcp;
@@ -86,7 +86,11 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file)
        shared_ptr<cxml::Document> xml (new cxml::Document ("SubtitleReel"));
 
        shared_ptr<ASDCP::TimedText::MXFReader> reader (new ASDCP::TimedText::MXFReader ());
-       Kumu::Result_t r = reader->OpenRead (_file->string().c_str ());
+       Kumu::Result_t r = Kumu::RESULT_OK;
+       {
+               ASDCPErrorSuspender sus;
+               r = reader->OpenRead (_file->string().c_str ());
+       }
        if (!ASDCP_FAILURE (r)) {
                /* MXF-wrapped */
                ASDCP::WriterInfo info;
@@ -136,6 +140,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file)
                                }
                        }
                }
+               _standard = dcp::SMPTE;
        }
 
        /* Check that all required image data have been found */
@@ -178,7 +183,7 @@ SMPTESubtitleAsset::parse_xml (shared_ptr<cxml::Document> xml)
 
        /* Now we need to drop down to xmlpp */
 
-       list<ParseState> ps;
+       vector<ParseState> ps;
        xmlpp::Node::NodeList c = xml->node()->get_children ();
        for (xmlpp::Node::NodeList::const_iterator i = c.begin(); i != c.end(); ++i) {
                xmlpp::Element const * e = dynamic_cast<xmlpp::Element const *> (*i);
@@ -217,25 +222,25 @@ SMPTESubtitleAsset::read_mxf_descriptor (shared_ptr<ASDCP::TimedText::MXFReader>
                switch (i->Type) {
                case ASDCP::TimedText::MT_OPENTYPE:
                {
-                       list<shared_ptr<SMPTELoadFontNode> >::const_iterator j = _load_font_nodes.begin ();
+                       auto j = _load_font_nodes.begin();
                        while (j != _load_font_nodes.end() && (*j)->urn != id) {
                                ++j;
                        }
 
                        if (j != _load_font_nodes.end ()) {
-                               _fonts.push_back (Font ((*j)->id, (*j)->urn, Data (data, buffer.Size ())));
+                               _fonts.push_back (Font ((*j)->id, (*j)->urn, ArrayData (data, buffer.Size ())));
                        }
                        break;
                }
                case ASDCP::TimedText::MT_PNG:
                {
-                       list<shared_ptr<Subtitle> >::const_iterator j = _subtitles.begin ();
+                       auto j = _subtitles.begin();
                        while (j != _subtitles.end() && ((!dynamic_pointer_cast<SubtitleImage>(*j)) || dynamic_pointer_cast<SubtitleImage>(*j)->id() != id)) {
                                ++j;
                        }
 
                        if (j != _subtitles.end()) {
-                               dynamic_pointer_cast<SubtitleImage>(*j)->set_png_image (Data(data, buffer.Size()));
+                               dynamic_pointer_cast<SubtitleImage>(*j)->set_png_image (ArrayData(data, buffer.Size()));
                        }
                        break;
                }
@@ -286,10 +291,10 @@ SMPTESubtitleAsset::set_key (Key key)
        read_mxf_descriptor (reader, dec);
 }
 
-list<shared_ptr<LoadFontNode> >
+vector<shared_ptr<LoadFontNode>>
 SMPTESubtitleAsset::load_font_nodes () const
 {
-       list<shared_ptr<LoadFontNode> > lf;
+       vector<shared_ptr<LoadFontNode>> lf;
        copy (_load_font_nodes.begin(), _load_font_nodes.end(), back_inserter (lf));
        return lf;
 }
@@ -357,7 +362,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const
        /* Font references */
 
        BOOST_FOREACH (shared_ptr<dcp::SMPTELoadFontNode> i, _load_font_nodes) {
-               list<Font>::const_iterator j = _fonts.begin ();
+               auto j = _fonts.begin();
                while (j != _fonts.end() && j->load_id != i->id) {
                        ++j;
                }
@@ -393,7 +398,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const
 
        ASDCP::TimedText::MXFWriter writer;
        /* This header size is a guess.  Empirically it seems that each subtitle reference is 90 bytes, and we need some extra.
-          The defualt size is not enough for some feature-length PNG sub projects (see DCP-o-matic #1561).
+          The default size is not enough for some feature-length PNG sub projects (see DCP-o-matic #1561).
        */
        ASDCP::Result_t r = writer.OpenWrite (p.string().c_str(), writer_info, descriptor, _subtitles.size() * 90 + 16384);
        if (ASDCP_FAILURE (r)) {
@@ -408,13 +413,14 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const
        /* Font payload */
 
        BOOST_FOREACH (shared_ptr<dcp::SMPTELoadFontNode> i, _load_font_nodes) {
-               list<Font>::const_iterator j = _fonts.begin ();
+               auto j = _fonts.begin();
                while (j != _fonts.end() && j->load_id != i->id) {
                        ++j;
                }
                if (j != _fonts.end ()) {
                        ASDCP::TimedText::FrameBuffer buffer;
-                       buffer.SetData (j->data.data().get(), j->data.size());
+                       ArrayData data_copy(j->data);
+                       buffer.SetData (data_copy.data(), data_copy.size());
                        buffer.Size (j->data.size());
                        r = writer.WriteAncillaryResource (buffer, enc.context(), enc.hmac());
                        if (ASDCP_FAILURE (r)) {
@@ -429,7 +435,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const
                shared_ptr<SubtitleImage> si = dynamic_pointer_cast<SubtitleImage>(i);
                if (si) {
                        ASDCP::TimedText::FrameBuffer buffer;
-                       buffer.SetData (si->png_image().data().get(), si->png_image().size());
+                       buffer.SetData (si->png_image().data(), si->png_image().size());
                        buffer.Size (si->png_image().size());
                        r = writer.WriteAncillaryResource (buffer, enc.context(), enc.hmac());
                        if (ASDCP_FAILURE(r)) {
@@ -456,8 +462,8 @@ SMPTESubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions
                return false;
        }
 
-       list<shared_ptr<SMPTELoadFontNode> >::const_iterator i = _load_font_nodes.begin ();
-       list<shared_ptr<SMPTELoadFontNode> >::const_iterator j = other->_load_font_nodes.begin ();
+       auto i = _load_font_nodes.begin();
+       auto j = other->_load_font_nodes.begin();
 
        while (i != _load_font_nodes.end ()) {
                if (j == other->_load_font_nodes.end ()) {
@@ -480,7 +486,7 @@ SMPTESubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions
        }
 
        if (_language != other->_language) {
-               note (DCP_ERROR, "Subtitle languages differ");
+               note (DCP_ERROR, String::compose("Subtitle languages differ (`%1' vs `%2')", _language.get_value_or("[none]"), other->_language.get_value_or("[none]")));
                return false;
        }
 
@@ -522,10 +528,10 @@ SMPTESubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions
 }
 
 void
-SMPTESubtitleAsset::add_font (string load_id, boost::filesystem::path file)
+SMPTESubtitleAsset::add_font (string load_id, dcp::ArrayData data)
 {
        string const uuid = make_uuid ();
-       _fonts.push_back (Font (load_id, uuid, file));
+       _fonts.push_back (Font(load_id, uuid, data));
        _load_font_nodes.push_back (shared_ptr<SMPTELoadFontNode> (new SMPTELoadFontNode (load_id, uuid)));
 }