Merge master; MXF subtitle stuff not included.
[libdcp.git] / src / cpl.cc
index 99c14d40048a8b138856e259a3fd41dc5e0ff601..9eae09ad51d456168af3d37f18f2a8f3b9b4a4ae 100644 (file)
@@ -47,9 +47,18 @@ using namespace dcp;
 
 CPL::CPL (string annotation_text, ContentKind content_kind)
        : _annotation_text (annotation_text)
+       /* default _content_title_text to _annotation_text */
+       , _content_title_text (annotation_text)
        , _content_kind (content_kind)
+       , _content_version_id ("urn:uuid:" + make_uuid ())
 {
-
+       /* default _content_version_id to and _content_version_label to
+          a random ID and the current time.
+       */
+       time_t now = time (0);
+       struct tm* tm = localtime (&now);
+       _content_version_id = "urn:uuid:" + make_uuid() + tm_to_string (tm);
+       _content_version_label_text = _content_version_id;
 }
 
 /** Construct a CPL object from a XML file */
@@ -65,8 +74,9 @@ CPL::CPL (boost::filesystem::path file)
                _id = _id.substr (9);
        }
        _annotation_text = f.optional_string_child ("AnnotationText").get_value_or ("");
-       _issue_date = f.string_child ("IssueDate");
-       _creator = f.optional_string_child ("Creator").get_value_or ("");
+       _metadata.issuer = f.optional_string_child ("Issuer").get_value_or ("");
+       _metadata.creator = f.optional_string_child ("Creator").get_value_or ("");
+       _metadata.issue_date = f.string_child ("IssueDate");
        _content_title_text = f.string_child ("ContentTitleText");
        _content_kind = content_kind_from_string (f.string_child ("ContentKind"));
        shared_ptr<cxml::Node> content_version = f.optional_node_child ("ContentVersion");
@@ -94,8 +104,13 @@ CPL::add (boost::shared_ptr<Reel> reel)
        _reels.push_back (reel);
 }
 
+/** Write an CompositonPlaylist XML file.
+ *  @param file Filename to write.
+ *  @param standard INTEROP or SMPTE.
+ *  @param signer Signer to sign the CPL, or 0 to add no signature.
+ */
 void
-CPL::write_xml (boost::filesystem::path file, Standard standard, XMLMetadata metadata, shared_ptr<const Signer> signer) const
+CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptr<const Signer> signer) const
 {
        xmlpp::Document doc;
        xmlpp::Element* root;
@@ -111,10 +126,10 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, XMLMetadata met
        
        root->add_child("Id")->add_child_text ("urn:uuid:" + _id);
        root->add_child("AnnotationText")->add_child_text (_annotation_text);
-       root->add_child("IssueDate")->add_child_text (metadata.issue_date);
-       root->add_child("Issuer")->add_child_text (metadata.issuer);
-       root->add_child("Creator")->add_child_text (metadata.creator);
-       root->add_child("ContentTitleText")->add_child_text (_content_version_label_text);
+       root->add_child("IssueDate")->add_child_text (_metadata.issue_date);
+       root->add_child("Issuer")->add_child_text (_metadata.issuer);
+       root->add_child("Creator")->add_child_text (_metadata.creator);
+       root->add_child("ContentTitleText")->add_child_text (_content_title_text);
        root->add_child("ContentKind")->add_child_text (content_kind_to_string (_content_kind));
        {
                xmlpp::Node* cv = root->add_child ("ContentVersion");
@@ -143,6 +158,7 @@ list<shared_ptr<const Content> >
 CPL::content () const
 {
        list<shared_ptr<const Content> > c;
+
        for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
                if ((*i)->main_picture ()) {
                        c.push_back ((*i)->main_picture()->mxf ());
@@ -205,6 +221,10 @@ CPL::encrypted () const
        return false;
 }
 
+/** Add a KDM to this CPL.  If the KDM is for any of this CPLs assets it will be used
+ *  to decrypt those assets.
+ *  @param kdm KDM.
+ */
 void
 CPL::add (KDM const & kdm)
 {
@@ -232,3 +252,17 @@ CPL::resolve_refs (list<shared_ptr<Object> > objects)
                (*i)->resolve_refs (objects);
        }
 }
+
+string
+CPL::pkl_type (Standard standard) const
+{
+       switch (standard) {
+       case INTEROP:
+               return "text/xml;asdcpKind=CPL";
+       case SMPTE:
+               return "text/xml";
+       default:
+               assert (false);
+       }
+}
+