Remove ReelEncryptableAsset and tidy up a bit.
[libdcp.git] / src / cpl.cc
index c528af31ebb763796db993bac48efd62839cad7b..145ce1cdcc53b273ce48b32a156701bce62dc71d 100644 (file)
 #include <boost/algorithm/string.hpp>
 
 
-using std::string;
+using std::cout;
+using std::dynamic_pointer_cast;
 using std::list;
-using std::pair;
 using std::make_pair;
-using std::cout;
+using std::make_shared;
+using std::pair;
 using std::set;
-using std::vector;
 using std::shared_ptr;
+using std::string;
+using std::vector;
 using boost::optional;
-using std::dynamic_pointer_cast;
 using namespace dcp;
 
 
@@ -79,7 +80,7 @@ static string const smpte_395_ns = "http://www.smpte-ra.org/reg/395/2014/13/1/aa
 static string const smpte_335_ns = "http://www.smpte-ra.org/reg/335/2012";
 
 
-CPL::CPL (string annotation_text, ContentKind content_kind)
+CPL::CPL (string annotation_text, ContentKind content_kind, Standard standard)
        /* default _content_title_text to annotation_text */
        : _issuer ("libdcp" LIBDCP_VERSION)
        , _creator ("libdcp" LIBDCP_VERSION)
@@ -87,6 +88,7 @@ CPL::CPL (string annotation_text, ContentKind content_kind)
        , _annotation_text (annotation_text)
        , _content_title_text (annotation_text)
        , _content_kind (content_kind)
+       , _standard (standard)
 {
        ContentVersion cv;
        cv.label_text = cv.id + LocalTime().as_string();
@@ -136,7 +138,10 @@ CPL::CPL (boost::filesystem::path file)
                        _ratings.push_back (Rating(i));
                }
        }
-       _reels = type_grand_children<Reel> (f, "ReelList", "Reel");
+
+       for (auto i: f.node_child("ReelList")->node_children("Reel")) {
+               _reels.push_back (make_shared<Reel>(i, _standard));
+       }
 
        auto reel_list = f.node_child ("ReelList");
        if (reel_list) {
@@ -166,11 +171,11 @@ CPL::add (std::shared_ptr<Reel> reel)
 
 
 void
-CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptr<const CertificateChain> signer) const
+CPL::write_xml (boost::filesystem::path file, shared_ptr<const CertificateChain> signer) const
 {
        xmlpp::Document doc;
        xmlpp::Element* root;
-       if (standard == Standard::INTEROP) {
+       if (_standard == Standard::INTEROP) {
                root = doc.create_root_node ("CompositionPlaylist", cpl_interop_ns);
        } else {
                root = doc.create_root_node ("CompositionPlaylist", cpl_smpte_ns);
@@ -205,8 +210,8 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptr<cons
 
        bool first = true;
        for (auto i: _reels) {
-               auto asset_list = i->write_to_cpl (reel_list, standard);
-               if (first && standard == Standard::SMPTE) {
+               auto asset_list = i->write_to_cpl (reel_list, _standard);
+               if (first && _standard == Standard::SMPTE) {
                        maybe_write_composition_metadata_asset (asset_list);
                        first = false;
                }
@@ -215,7 +220,7 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptr<cons
        indent (root, 0);
 
        if (signer) {
-               signer->sign (root, standard);
+               signer->sign (root, _standard);
        }
 
        doc.write_to_file_formatted (file.string(), "UTF-8");
@@ -291,9 +296,9 @@ CPL::read_composition_metadata_asset (cxml::ConstNodePtr node)
                /* If the first language on SubtitleLanguageList is the same as the language of the first subtitle we'll ignore it */
                size_t first = 0;
                if (!_reels.empty()) {
-                       shared_ptr<dcp::ReelSubtitleAsset> sub = _reels.front()->main_subtitle();
+                       auto sub = _reels.front()->main_subtitle();
                        if (sub) {
-                               optional<string> lang = sub->language();
+                               auto lang = sub->language();
                                if (lang && lang == sll_split[0]) {
                                        first = 1;
                                }
@@ -523,6 +528,7 @@ CPL::reel_file_assets ()
        return c;
 }
 
+
 vector<shared_ptr<const ReelFileAsset>>
 CPL::reel_file_assets () const
 {