Use an enum class for Marker.
[libdcp.git] / src / smpte_subtitle_asset.cc
index cf0ed6c0c38616f8f0ad16c733f6358b795d3dad..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;
@@ -140,6 +140,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file)
                                }
                        }
                }
+               _standard = dcp::SMPTE;
        }
 
        /* Check that all required image data have been found */
@@ -182,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);
@@ -221,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;
                }
@@ -290,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;
 }
@@ -361,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;
                }
@@ -412,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)) {
@@ -433,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)) {
@@ -460,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 ()) {
@@ -484,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;
        }
 
@@ -526,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)));
 }