Somewhat hacky rearrangement to support multiple CPLs per DCP.
authorCarl Hetherington <cth@carlh.net>
Sun, 9 Sep 2012 11:48:47 +0000 (12:48 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 9 Sep 2012 11:48:47 +0000 (12:48 +0100)
16 files changed:
examples/make_dcp.cc
src/asset.h
src/dcp.cc
src/dcp.h
src/reel.cc
src/reel.h
src/util.cc
test/ref/DCP/81fb54df-e1bf-4647-8788-ea7ba154375b_cpl.xml [new file with mode: 0644]
test/ref/DCP/9892e944-5046-4dbb-af7c-f50742f62fc2_cpl.xml [deleted file]
test/ref/DCP/ASSETMAP.xml
test/ref/DCP/audio.mxf
test/ref/DCP/df0e4141-13c3-4a7a-bef8-b5a04fcbc4bb_pkl.xml
test/ref/DCP/video.mxf
test/ref/info.log
test/tests.cc
tools/dcpinfo.cc

index 5b764393fbc64d813176b668bd76e0f5749ddb82..a84a19c1594dedfd066e1a5413c12e6df8c3b2fd 100644 (file)
@@ -49,14 +49,19 @@ video_frame (int /* frame */)
 int
 main ()
 {
-       /* Make a DCP object.  "My Film DCP" is the directory name for the DCP, "My Film" is the title
-          that will be shown on the projector / TMS when the DCP is ingested.
+       /* Make a DCP object.  "My Film DCP" is the directory name for the DCP */
+       libdcp::DCP dcp ("My Film DCP");
+       
+       /* Now make a CPL object.
 
+          "My Film" is the title that will be shown on the projector / TMS when the DCP is ingested.
           FEATURE is the type that the projector will list the DCP as.
-
           24 is the frame rate, and the DCP will be 48 frames long (ie 2 seconds at 24 fps).
-       */
-       libdcp::DCP dcp ("My Film DCP", "My Film", libdcp::FEATURE, 24, 48);
+       */      
+       boost::shared_ptr<libdcp::CPL> cpl (new libdcp::CPL ("My Film DCP", "My Film", libdcp::FEATURE, 24, 48));
+
+       /* And add the CPL to the DCP */
+       dcp.add_cpl (cpl);
 
        /* Now make a `picture asset'.  This is a collection of the JPEG2000 files that make up the picture, one per frame.
           Here we're using a function (video_frame) to obtain the name of the JPEG2000 file for each frame.
@@ -92,8 +97,8 @@ main ()
                new libdcp::SoundAsset (sound_files, "My Film DCP", "audio.mxf", 0, 24, 48)
                );
 
-       /* Now that we have the assets, we can create a Reel to put them in and add it to the DCP */
-       dcp.add_reel (
+       /* Now that we have the assets, we can create a Reel to put them in and add it to the CPL */
+       cpl->add_reel (
                boost::shared_ptr<libdcp::Reel> (
                        new libdcp::Reel (picture_asset, sound_asset, boost::shared_ptr<libdcp::SubtitleAsset> ())
                        )
index 0c8df0c85b6621022b627394e3678125639fd69d..eab24d28339e5b4ac15361679fe30e49dad7753a 100644 (file)
@@ -64,6 +64,10 @@ public:
         */
        void write_to_assetmap (std::ostream& s) const;
 
+       std::string uuid () const {
+               return _uuid;
+       }
+
        virtual std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityOptions opt) const = 0;
 
 protected:
index 907f7dd5105fcb34d31278bf9000d8345dd687a3..8de1ddd9dbbeaf2fbe3278a74779a44c702be8f4 100644 (file)
@@ -45,77 +45,31 @@ using namespace std;
 using namespace boost;
 using namespace libdcp;
 
-DCP::DCP (string directory, string name, ContentKind content_kind, int fps, int length)
+DCP::DCP (string directory)
        : _directory (directory)
-       , _name (name)
-       , _content_kind (content_kind)
-       , _fps (fps)
-       , _length (length)
 {
        filesystem::create_directories (directory);
 }
 
-void
-DCP::add_reel (shared_ptr<const Reel> reel)
-{
-       _reels.push_back (reel);
-}
-
 void
 DCP::write_xml () const
 {
-       string cpl_uuid = make_uuid ();
-       string cpl_path = write_cpl (cpl_uuid);
-       int cpl_length = filesystem::file_size (cpl_path);
-       string cpl_digest = make_digest (cpl_path, 0);
+       for (list<shared_ptr<const CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
+               (*i)->write_xml ();
+       }
 
        string pkl_uuid = make_uuid ();
-       string pkl_path = write_pkl (pkl_uuid, cpl_uuid, cpl_digest, cpl_length);
+       string pkl_path = write_pkl (pkl_uuid);
        
        write_volindex ();
-       write_assetmap (cpl_uuid, cpl_length, pkl_uuid, filesystem::file_size (pkl_path));
-}
-
-string
-DCP::write_cpl (string cpl_uuid) const
-{
-       filesystem::path p;
-       p /= _directory;
-       stringstream s;
-       s << cpl_uuid << "_cpl.xml";
-       p /= s.str();
-       ofstream cpl (p.string().c_str());
-       
-       cpl << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-           << "<CompositionPlaylist xmlns=\"http://www.smpte-ra.org/schemas/429-7/2006/CPL\">\n"
-           << "  <Id>urn:uuid:" << cpl_uuid << "</Id>\n"
-           << "  <AnnotationText>" << _name << "</AnnotationText>\n"
-           << "  <IssueDate>" << Metadata::instance()->issue_date << "</IssueDate>\n"
-           << "  <Creator>" << Metadata::instance()->creator << "</Creator>\n"
-           << "  <ContentTitleText>" << _name << "</ContentTitleText>\n"
-           << "  <ContentKind>" << content_kind_to_string (_content_kind) << "</ContentKind>\n"
-           << "  <ContentVersion>\n"
-           << "    <Id>urn:uri:" << cpl_uuid << "_" << Metadata::instance()->issue_date << "</Id>\n"
-           << "    <LabelText>" << cpl_uuid << "_" << Metadata::instance()->issue_date << "</LabelText>\n"
-           << "  </ContentVersion>\n"
-           << "  <RatingList/>\n"
-           << "  <ReelList>\n";
-
-       for (list<shared_ptr<const Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
-               (*i)->write_to_cpl (cpl);
-       }
-
-       cpl << "      </AssetList>\n"
-           << "    </Reel>\n"
-           << "  </ReelList>\n"
-           << "</CompositionPlaylist>\n";
-
-       return p.string ();
+       write_assetmap (pkl_uuid, filesystem::file_size (pkl_path));
 }
 
 std::string
-DCP::write_pkl (string pkl_uuid, string cpl_uuid, string cpl_digest, int cpl_length) const
+DCP::write_pkl (string pkl_uuid) const
 {
+       assert (!_cpls.empty ());
+       
        filesystem::path p;
        p /= _directory;
        stringstream s;
@@ -126,22 +80,21 @@ DCP::write_pkl (string pkl_uuid, string cpl_uuid, string cpl_digest, int cpl_len
        pkl << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            << "<PackingList xmlns=\"http://www.smpte-ra.org/schemas/429-8/2007/PKL\">\n"
            << "  <Id>urn:uuid:" << pkl_uuid << "</Id>\n"
-           << "  <AnnotationText>" << _name << "</AnnotationText>\n"
+               /* XXX: this is a bit of a hack */
+           << "  <AnnotationText>" << _cpls.front()->name() << "</AnnotationText>\n"
            << "  <IssueDate>" << Metadata::instance()->issue_date << "</IssueDate>\n"
            << "  <Issuer>" << Metadata::instance()->issuer << "</Issuer>\n"
            << "  <Creator>" << Metadata::instance()->creator << "</Creator>\n"
            << "  <AssetList>\n";
 
-       for (list<shared_ptr<const Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
+       list<shared_ptr<const Asset> > a = assets ();
+       for (list<shared_ptr<const Asset> >::const_iterator i = a.begin(); i != a.end(); ++i) {
                (*i)->write_to_pkl (pkl);
        }
 
-       pkl << "    <Asset>\n"
-           << "      <Id>urn:uuid:" << cpl_uuid << "</Id>\n"
-           << "      <Hash>" << cpl_digest << "</Hash>\n"
-           << "      <Size>" << cpl_length << "</Size>\n"
-           << "      <Type>text/xml</Type>\n"
-           << "    </Asset>\n";
+       for (list<shared_ptr<const CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
+               (*i)->write_to_pkl (pkl);
+       }
 
        pkl << "  </AssetList>\n"
            << "</PackingList>\n";
@@ -164,7 +117,7 @@ DCP::write_volindex () const
 }
 
 void
-DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_length) const
+DCP::write_assetmap (string pkl_uuid, int pkl_length) const
 {
        filesystem::path p;
        p /= _directory;
@@ -192,20 +145,13 @@ DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_l
           << "        </Chunk>\n"
           << "      </ChunkList>\n"
           << "    </Asset>\n";
-
-       am << "    <Asset>\n"
-          << "      <Id>urn:uuid:" << cpl_uuid << "</Id>\n"
-          << "      <ChunkList>\n"
-          << "        <Chunk>\n"
-          << "          <Path>" << cpl_uuid << "_cpl.xml</Path>\n"
-          << "          <VolumeIndex>1</VolumeIndex>\n"
-          << "          <Offset>0</Offset>\n"
-          << "          <Length>" << cpl_length << "</Length>\n"
-          << "        </Chunk>\n"
-          << "      </ChunkList>\n"
-          << "    </Asset>\n";
        
-       for (list<shared_ptr<const Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
+       for (list<shared_ptr<const CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
+               (*i)->write_to_assetmap (am);
+       }
+
+       list<shared_ptr<const Asset> > a = assets ();
+       for (list<shared_ptr<const Asset> >::const_iterator i = a.begin(); i != a.end(); ++i) {
                (*i)->write_to_assetmap (am);
        }
 
@@ -214,8 +160,8 @@ DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_l
 }
 
 
-DCP::DCP (string directory, bool require_mxfs)
-       : _directory (directory)
+void
+DCP::read (bool require_mxfs)
 {
        Files files;
 
@@ -263,11 +209,7 @@ DCP::DCP (string directory, bool require_mxfs)
                delete p;
 
                if (root == "CompositionPlaylist") {
-                       if (files.cpl.empty ()) {
-                               files.cpl = t.string();
-                       } else {
-                               throw DCPReadError ("duplicate CPLs found");
-                       }
+                       files.cpls.push_back (t.string());
                } else if (root == "PackingList") {
                        if (files.pkl.empty ()) {
                                files.pkl = t.string();
@@ -279,22 +221,14 @@ DCP::DCP (string directory, bool require_mxfs)
                }
        }
        
-       if (files.cpl.empty ()) {
-               throw FileError ("no CPL file found", "");
+       if (files.cpls.empty ()) {
+               throw FileError ("no CPL files found", "");
        }
 
        if (files.pkl.empty ()) {
                throw FileError ("no PKL file found", "");
        }
 
-       /* Read the XML */
-       shared_ptr<CPLFile> cpl;
-       try {
-               cpl.reset (new CPLFile (files.cpl));
-       } catch (FileError& e) {
-               throw FileError ("could not load CPL file", files.cpl);
-       }
-
        shared_ptr<PKLFile> pkl;
        try {
                pkl.reset (new PKLFile (files.pkl));
@@ -305,12 +239,91 @@ DCP::DCP (string directory, bool require_mxfs)
        /* Cross-check */
        /* XXX */
 
+       for (list<string>::iterator i = files.cpls.begin(); i != files.cpls.end(); ++i) {
+               _cpls.push_back (shared_ptr<CPL> (new CPL (_directory, *i, asset_map, require_mxfs)));
+       }
+
+}
+
+list<string>
+DCP::equals (DCP const & other, EqualityOptions opt) const
+{
+       list<string> notes;
+
+       if (_cpls.size() != other._cpls.size()) {
+               notes.push_back ("CPL counts differ");
+       }
+
+       list<shared_ptr<const CPL> >::const_iterator a = _cpls.begin ();
+       list<shared_ptr<const CPL> >::const_iterator b = other._cpls.begin ();
+
+       while (a != _cpls.end ()) {
+               list<string> n = (*a)->equals (*b->get(), opt);
+               notes.merge (n);
+               ++a;
+               ++b;
+       }
+
+       return notes;
+}
+
+
+void
+DCP::add_cpl (shared_ptr<CPL> cpl)
+{
+       _cpls.push_back (cpl);
+}
+
+class AssetComparator
+{
+public:
+       bool operator() (shared_ptr<const Asset> a, shared_ptr<const Asset> b) {
+               return a->uuid() < b->uuid();
+       }
+};
+
+list<shared_ptr<const Asset> >
+DCP::assets () const
+{
+       list<shared_ptr<const Asset> > a;
+       for (list<shared_ptr<const CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
+               list<shared_ptr<const Asset> > t = (*i)->assets ();
+               a.merge (t);
+       }
+
+       a.sort ();
+       a.unique ();
+       return a;
+}
+
+CPL::CPL (string directory, string name, ContentKind content_kind, int length, int frames_per_second)
+       : _directory (directory)
+       , _name (name)
+       , _content_kind (content_kind)
+       , _length (length)
+       , _fps (frames_per_second)
+{
+       _uuid = make_uuid ();
+}
+
+CPL::CPL (string directory, string file, shared_ptr<const AssetMap> asset_map, bool require_mxfs)
+       : _directory (directory)
+       , _content_kind (FEATURE)
+       , _length (0)
+       , _fps (0)
+{
+       /* Read the XML */
+       shared_ptr<CPLFile> cpl;
+       try {
+               cpl.reset (new CPLFile (file));
+       } catch (FileError& e) {
+               throw FileError ("could not load CPL file", file);
+       }
+       
        /* Now cherry-pick the required bits into our own data structure */
        
        _name = cpl->annotation_text;
        _content_kind = cpl->content_kind;
-       _length = 0;
-       _fps = 0;
 
        for (list<shared_ptr<CPLReel> >::iterator i = cpl->reels.begin(); i != cpl->reels.end(); ++i) {
 
@@ -322,7 +335,6 @@ DCP::DCP (string directory, bool require_mxfs)
                        p = (*i)->asset_list->main_stereoscopic_picture;
                }
                
-               assert (_fps == 0 || _fps == p->edit_rate.numerator);
                _fps = p->edit_rate.numerator;
                _length += p->duration;
 
@@ -397,8 +409,102 @@ DCP::DCP (string directory, bool require_mxfs)
        }
 }
 
+void
+CPL::add_reel (shared_ptr<const Reel> reel)
+{
+       _reels.push_back (reel);
+}
+
+void
+CPL::write_xml () const
+{
+       filesystem::path p;
+       p /= _directory;
+       stringstream s;
+       s << _uuid << "_cpl.xml";
+       p /= s.str();
+       ofstream os (p.string().c_str());
+       
+       os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+          << "<CompositionPlaylist xmlns=\"http://www.smpte-ra.org/schemas/429-7/2006/CPL\">\n"
+          << "  <Id>urn:uuid:" << _uuid << "</Id>\n"
+          << "  <AnnotationText>" << _name << "</AnnotationText>\n"
+          << "  <IssueDate>" << Metadata::instance()->issue_date << "</IssueDate>\n"
+          << "  <Creator>" << Metadata::instance()->creator << "</Creator>\n"
+          << "  <ContentTitleText>" << _name << "</ContentTitleText>\n"
+          << "  <ContentKind>" << content_kind_to_string (_content_kind) << "</ContentKind>\n"
+          << "  <ContentVersion>\n"
+          << "    <Id>urn:uri:" << _uuid << "_" << Metadata::instance()->issue_date << "</Id>\n"
+          << "    <LabelText>" << _uuid << "_" << Metadata::instance()->issue_date << "</LabelText>\n"
+          << "  </ContentVersion>\n"
+          << "  <RatingList/>\n"
+          << "  <ReelList>\n";
+       
+       for (list<shared_ptr<const Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
+               (*i)->write_to_cpl (os);
+       }
+
+       os << "      </AssetList>\n"
+          << "    </Reel>\n"
+          << "  </ReelList>\n"
+          << "</CompositionPlaylist>\n";
+
+       os.close ();
+
+       _digest = make_digest (p.string (), 0);
+       _length = filesystem::file_size (p.string ());
+}
+
+void
+CPL::write_to_pkl (ostream& s) const
+{
+       s << "    <Asset>\n"
+         << "      <Id>urn:uuid:" << _uuid << "</Id>\n"
+         << "      <Hash>" << _digest << "</Hash>\n"
+         << "      <Size>" << _length << "</Size>\n"
+         << "      <Type>text/xml</Type>\n"
+         << "    </Asset>\n";
+}
+
+list<shared_ptr<const Asset> >
+CPL::assets () const
+{
+       list<shared_ptr<const Asset> > a;
+       for (list<shared_ptr<const Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
+               if ((*i)->main_picture ()) {
+                       a.push_back ((*i)->main_picture ());
+               }
+               if ((*i)->main_sound ()) {
+                       a.push_back ((*i)->main_sound ());
+               }
+               if ((*i)->main_subtitle ()) {
+                       a.push_back ((*i)->main_subtitle ());
+               }
+       }
+
+       return a;
+}
+
+void
+CPL::write_to_assetmap (ostream& s) const
+{
+       s << "    <Asset>\n"
+         << "      <Id>urn:uuid:" << _uuid << "</Id>\n"
+         << "      <ChunkList>\n"
+         << "        <Chunk>\n"
+         << "          <Path>" << _uuid << "_cpl.xml</Path>\n"
+         << "          <VolumeIndex>1</VolumeIndex>\n"
+         << "          <Offset>0</Offset>\n"
+         << "          <Length>" << _length << "</Length>\n"
+         << "        </Chunk>\n"
+         << "      </ChunkList>\n"
+         << "    </Asset>\n";
+}
+       
+       
+       
 list<string>
-DCP::equals (DCP const & other, EqualityOptions opt) const
+CPL::equals (CPL const & other, EqualityOptions opt) const
 {
        list<string> notes;
        
@@ -433,4 +539,3 @@ DCP::equals (DCP const & other, EqualityOptions opt) const
 
        return notes;
 }
-
index 8dd7a412a2287f87319112ab6e29c75c557553d2..79be5ca59fda265a2a4d1d5d37058e9e193a4c3a 100644 (file)
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -43,6 +43,68 @@ class PictureAsset;
 class SoundAsset;
 class SubtitleAsset;
 class Reel;
+class AssetMap;
+
+class CPL
+{
+public:
+       CPL (std::string directory, std::string name, ContentKind content_kind, int length, int frames_per_second);
+       CPL (std::string directory, std::string file, boost::shared_ptr<const AssetMap> asset_map, bool require_mxfs = true);
+
+       void add_reel (boost::shared_ptr<const Reel> reel);
+       
+       /** @return the length in frames */
+       int length () const {
+               return _length;
+       }
+
+       /** @return the type of the content, used by media servers
+        *  to categorise things (e.g. feature, trailer, etc.)
+        */
+       ContentKind content_kind () const {
+               return _content_kind;
+       }
+
+       std::list<boost::shared_ptr<const Reel> > reels () const {
+               return _reels;
+       }
+
+       /** @return the CPL's name, as will be presented on projector
+        *  media servers and theatre management systems.
+        */
+       std::string name () const {
+               return _name;
+       }
+
+       /** @return the number of frames per second */
+       int frames_per_second () const {
+               return _fps;
+       }
+
+       std::list<boost::shared_ptr<const Asset> > assets () const;
+       
+       std::list<std::string> equals (CPL const & other, EqualityOptions options) const;
+       
+       void write_xml () const;
+       void write_to_assetmap (std::ostream& s) const;
+       void write_to_pkl (std::ostream& s) const;
+       
+private:
+       std::string _directory;
+       /** the name of the DCP */
+       std::string _name;
+       /** the content kind of the CPL */
+       ContentKind _content_kind;
+       /** length in frames */
+       mutable int _length;
+       /** frames per second */
+       int _fps;
+       /** reels */
+       std::list<boost::shared_ptr<const Reel> > _reels;
+
+       std::string _uuid;
+       mutable std::string _digest;
+};
 
 /** @class DCP dcp.h libdcp/dcp.h
  *  @brief A class to create or read a DCP.
@@ -51,64 +113,29 @@ class Reel;
 class DCP
 {
 public:
-       /** Construct a DCP.
-        *
-        *  This is for making a new DCP that you are going to add assets to.
+       /** Construct a DCP.  You can pass an existing DCP's directory
+        *  as the parameter, or a non-existant folder to create a new
+        *  DCP in.
         *
-        *  @param directory Directory to write files to.
-        *  @param name Name.
-        *  @param content_kind Content kind.
-        *  @param fps Frames per second.
-        *  @param length Length in frames.
+        *  @param directory Directory containing the DCP's files.
         */
-       DCP (std::string directory, std::string name, ContentKind content_kind, int fps, int length);
+       DCP (std::string directory);
 
-       /** Construct a DCP object for an existing DCP.
+       /** Read an existing DCP's data.
         *
         *  The DCP's XML metadata will be examined, and you can then look at the contents
         *  of the DCP.
         *
-        *  @param directory Existing DCP's directory.
-        *  @param read_mxfs true to read MXF files; setting to false can be useful for testing, but
-        *  normally it should be set to true.
+        *  @param require_mxfs true to throw an exception if MXF files are missing; setting to false
+        *  can be useful for testing, but normally it should be set to true.
         */
-       DCP (std::string directory, bool read_mxfs = true);
-
-       void add_reel (boost::shared_ptr<const Reel> reel);
+       void read (bool require_mxfs = true);
 
        /** Write the required XML files to the directory that was
         *  passed into the constructor.
         */
        void write_xml () const;
 
-       /** @return the DCP's name, as will be presented on projector
-        *  media servers and theatre management systems.
-        */
-       std::string name () const {
-               return _name;
-       }
-
-       /** @return the type of the content, used by media servers
-        *  to categorise things (e.g. feature, trailer, etc.)
-        */
-       ContentKind content_kind () const {
-               return _content_kind;
-       }
-
-       /** @return the number of frames per second */
-       int frames_per_second () const {
-               return _fps;
-       }
-
-       /** @return the length in frames */
-       int length () const {
-               return _length;
-       }
-
-       std::list<boost::shared_ptr<const Reel> > reels () const {
-               return _reels;
-       }
-
        /** Compare this DCP with another, according to various options.
         *  @param other DCP to compare this one to.
         *  @param options Options to define just what "equality" means.
@@ -117,6 +144,12 @@ public:
         */
        std::list<std::string> equals (DCP const & other, EqualityOptions options) const;
 
+       void add_cpl (boost::shared_ptr<CPL> cpl);
+
+       std::list<boost::shared_ptr<const CPL> > cpls () const {
+               return _cpls;
+       }
+
        /** Emitted with a parameter between 0 and 1 to indicate progress
         *  for long jobs.
         */
@@ -124,33 +157,24 @@ public:
 
 private:
 
-       /** Write the CPL file.
-        *  @param cpl_uuid UUID to use.
-        *  @return CPL pathname.
-        */
-       std::string write_cpl (std::string cpl_uuid) const;
-
        /** Write the PKL file.
         *  @param pkl_uuid UUID to use.
-        *  @param cpl_uuid UUID of the CPL file.
-        *  @param cpl_digest SHA digest of the CPL file.
-        *  @param cpl_length Length of the CPL file in bytes.
         */
-       std::string write_pkl (std::string pkl_uuid, std::string cpl_uuid, std::string cpl_digest, int cpl_length) const;
+       std::string write_pkl (std::string pkl_uuid) const;
        
        /** Write the VOLINDEX file */
        void write_volindex () const;
 
        /** Write the ASSETMAP file.
-        *  @param cpl_uuid UUID of our CPL.
-        *  @param cpl_length Length of our CPL in bytes.
         *  @param pkl_uuid UUID of our PKL.
         *  @param pkl_length Length of our PKL in bytes.
         */
-       void write_assetmap (std::string cpl_uuid, int cpl_length, std::string pkl_uuid, int pkl_length) const;
+       void write_assetmap (std::string pkl_uuid, int pkl_length) const;
+
+       std::list<boost::shared_ptr<const Asset> > assets () const;
 
        struct Files {
-               std::string cpl;
+               std::list<std::string> cpls;
                std::string pkl;
                std::string asset_map;
                std::list<std::string> subtitles;
@@ -158,16 +182,7 @@ private:
 
        /** the directory that we are writing to */
        std::string _directory;
-       /** the name of the DCP */
-       std::string _name;
-       /** the content kind of the DCP */
-       ContentKind _content_kind;
-       /** frames per second */
-       int _fps;
-       /** length in frames */
-       int _length;
-       /** reels */
-       std::list<boost::shared_ptr<const Reel> > _reels;
+       std::list<boost::shared_ptr<const CPL> > _cpls;
 };
 
 }
index 431af69a2eb3c48367e5a9dbd7c742ff29537100..50426cc1b617b918470cb6ddcbad48e0cfe8c72d 100644 (file)
@@ -46,38 +46,6 @@ Reel::write_to_cpl (ostream& s) const
        }
 }
        
-void
-Reel::write_to_pkl (ostream& s) const
-{
-       if (_main_picture) {
-               _main_picture->write_to_pkl (s);
-       }
-
-       if (_main_sound) {
-               _main_sound->write_to_pkl (s);
-       }
-
-       if (_main_subtitle) {
-               _main_subtitle->write_to_pkl (s);
-       }
-}
-
-void
-Reel::write_to_assetmap (ostream& s) const
-{
-       if (_main_picture) {
-               _main_picture->write_to_assetmap (s);
-       }
-
-       if (_main_sound) {
-               _main_sound->write_to_assetmap (s);
-       }
-
-       if (_main_subtitle) {
-               _main_subtitle->write_to_assetmap (s);
-       }
-}
-
 list<string>
 Reel::equals (boost::shared_ptr<const Reel> other, EqualityOptions opt) const
 {
index 2148e122c6b05bc19b943c9645698b94389bab19..58caed31c2b17972ad28224777fb6bf01720ab5c 100644 (file)
@@ -53,8 +53,6 @@ public:
        }
 
        void write_to_cpl (std::ostream & s) const;
-       void write_to_pkl (std::ostream & s) const;
-       void write_to_assetmap (std::ostream & s) const;
 
        std::list<std::string> equals (boost::shared_ptr<const Reel> other, EqualityOptions opt) const;
 
index c171b2c7f8a6048b45f18fe10b45d5fdf601aa0a..4434b98ce11cfca884296436e48c54ff15c2a564 100644 (file)
@@ -127,7 +127,7 @@ libdcp::content_kind_from_string (string type)
                return FEATURE;
        } else if (type == "short") {
                return SHORT;
-       } else if (type == "trailer") {
+       } else if (type == "trailer" || type == "Trailer") {
                return TRAILER;
        } else if (type == "test") {
                return TEST;
diff --git a/test/ref/DCP/81fb54df-e1bf-4647-8788-ea7ba154375b_cpl.xml b/test/ref/DCP/81fb54df-e1bf-4647-8788-ea7ba154375b_cpl.xml
new file mode 100644 (file)
index 0000000..59d5007
--- /dev/null
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CompositionPlaylist xmlns="http://www.smpte-ra.org/schemas/429-7/2006/CPL">
+  <Id>urn:uuid:81fb54df-e1bf-4647-8788-ea7ba154375b</Id>
+  <AnnotationText>A Test DCP</AnnotationText>
+  <IssueDate>2012-07-17T04:45:18+00:00</IssueDate>
+  <Creator>OpenDCP 0.0.25</Creator>
+  <ContentTitleText>A Test DCP</ContentTitleText>
+  <ContentKind>feature</ContentKind>
+  <ContentVersion>
+    <Id>urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00</Id>
+    <LabelText>81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00</LabelText>
+  </ContentVersion>
+  <RatingList/>
+  <ReelList>
+    <Reel>
+      <Id>urn:uuid:379fa64c-ad71-46cf-bef7-b45624006610</Id>
+      <AssetList>
+        <MainPicture>
+          <Id>urn:uuid:d36f4bb3-c4fa-4a95-9915-6fec3110cd71</Id>
+          <AnnotationText>video.mxf</AnnotationText>
+          <EditRate>24 1</EditRate>
+          <IntrinsicDuration>24</IntrinsicDuration>
+          <EntryPoint>0</EntryPoint>
+          <Duration>24</Duration>
+          <FrameRate>24 1</FrameRate>
+          <ScreenAspectRatio>32 32</ScreenAspectRatio>
+        </MainPicture>
+        <MainSound>
+          <Id>urn:uuid:c38bdd62-ce03-4988-8603-195f134207c7</Id>
+          <AnnotationText>audio.mxf</AnnotationText>
+          <EditRate>24 1</EditRate>
+          <IntrinsicDuration>24</IntrinsicDuration>
+          <EntryPoint>0</EntryPoint>
+          <Duration>24</Duration>
+        </MainSound>
+      </AssetList>
+    </Reel>
+  </ReelList>
+</CompositionPlaylist>
diff --git a/test/ref/DCP/9892e944-5046-4dbb-af7c-f50742f62fc2_cpl.xml b/test/ref/DCP/9892e944-5046-4dbb-af7c-f50742f62fc2_cpl.xml
deleted file mode 100644 (file)
index 1cd273f..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<CompositionPlaylist xmlns="http://www.smpte-ra.org/schemas/429-7/2006/CPL">
-  <Id>urn:uuid:9892e944-5046-4dbb-af7c-f50742f62fc2</Id>
-  <AnnotationText>A Test DCP</AnnotationText>
-  <IssueDate>2012-07-17T04:45:18+00:00</IssueDate>
-  <Creator>OpenDCP 0.0.25</Creator>
-  <ContentTitleText>A Test DCP</ContentTitleText>
-  <ContentKind>feature</ContentKind>
-  <ContentVersion>
-    <Id>urn:uri:9892e944-5046-4dbb-af7c-f50742f62fc2_2012-07-17T04:45:18+00:00</Id>
-    <LabelText>9892e944-5046-4dbb-af7c-f50742f62fc2_2012-07-17T04:45:18+00:00</LabelText>
-  </ContentVersion>
-  <RatingList/>
-  <ReelList>
-    <Reel>
-      <Id>urn:uuid:379fa64c-ad71-46cf-bef7-b45624006610</Id>
-      <AssetList>
-        <MainPicture>
-          <Id>urn:uuid:81fb54df-e1bf-4647-8788-ea7ba154375b</Id>
-          <AnnotationText>video.mxf</AnnotationText>
-          <EditRate>24 1</EditRate>
-          <IntrinsicDuration>24</IntrinsicDuration>
-          <EntryPoint>0</EntryPoint>
-          <Duration>24</Duration>
-          <FrameRate>24 1</FrameRate>
-          <ScreenAspectRatio>32 32</ScreenAspectRatio>
-        </MainPicture>
-        <MainSound>
-          <Id>urn:uuid:67b9341e-cadd-4dac-9d5c-f5a1d59f2d06</Id>
-          <AnnotationText>audio.mxf</AnnotationText>
-          <EditRate>24 1</EditRate>
-          <IntrinsicDuration>24</IntrinsicDuration>
-          <EntryPoint>0</EntryPoint>
-          <Duration>24</Duration>
-        </MainSound>
-      </AssetList>
-    </Reel>
-  </ReelList>
-</CompositionPlaylist>
index b0168478e93266a40522e1926a66941567a487f6..defe18da3ec38863eeac33464d018403d7089c92 100644 (file)
       </ChunkList>
     </Asset>
     <Asset>
-      <Id>urn:uuid:9892e944-5046-4dbb-af7c-f50742f62fc2</Id>
+      <Id>urn:uuid:81fb54df-e1bf-4647-8788-ea7ba154375b</Id>
       <ChunkList>
         <Chunk>
-          <Path>9892e944-5046-4dbb-af7c-f50742f62fc2_cpl.xml</Path>
+          <Path>81fb54df-e1bf-4647-8788-ea7ba154375b_cpl.xml</Path>
           <VolumeIndex>1</VolumeIndex>
           <Offset>0</Offset>
           <Length>1526</Length>
       </ChunkList>
     </Asset>
     <Asset>
-      <Id>urn:uuid:81fb54df-e1bf-4647-8788-ea7ba154375b</Id>
+      <Id>urn:uuid:c38bdd62-ce03-4988-8603-195f134207c7</Id>
       <ChunkList>
         <Chunk>
-          <Path>video.mxf</Path>
+          <Path>audio.mxf</Path>
           <VolumeIndex>1</VolumeIndex>
           <Offset>0</Offset>
-          <Length>26080</Length>
+          <Length>305326</Length>
         </Chunk>
       </ChunkList>
     </Asset>
     <Asset>
-      <Id>urn:uuid:67b9341e-cadd-4dac-9d5c-f5a1d59f2d06</Id>
+      <Id>urn:uuid:d36f4bb3-c4fa-4a95-9915-6fec3110cd71</Id>
       <ChunkList>
         <Chunk>
-          <Path>audio.mxf</Path>
+          <Path>video.mxf</Path>
           <VolumeIndex>1</VolumeIndex>
           <Offset>0</Offset>
-          <Length>305326</Length>
+          <Length>26080</Length>
         </Chunk>
       </ChunkList>
     </Asset>
index 52f92d21813a354a8797a771c23a08c6c619eba9..9bc735afc03e7d041ef4982312865b584dbd0d96 100644 (file)
Binary files a/test/ref/DCP/audio.mxf and b/test/ref/DCP/audio.mxf differ
index 98e3db8100c16f14e2913df6854b9c5b5d0f8c18..7a8ec6970f2298be32b4daee90cc78f3f6fbd425 100644 (file)
@@ -7,22 +7,22 @@
   <Creator>OpenDCP 0.0.25</Creator>
   <AssetList>
     <Asset>
-      <Id>urn:uuid:81fb54df-e1bf-4647-8788-ea7ba154375b</Id>
-      <AnnotationText>video.mxf</AnnotationText>
-      <Hash>VB9LCTmiD9OLlw4SvrEWUm5d67Q=</Hash>
-      <Size>26080</Size>
+      <Id>urn:uuid:c38bdd62-ce03-4988-8603-195f134207c7</Id>
+      <AnnotationText>audio.mxf</AnnotationText>
+      <Hash>+qImGHkt/XouNaJ1V/+7BtcB4VU=</Hash>
+      <Size>305326</Size>
       <Type>application/mxf</Type>
     </Asset>
     <Asset>
-      <Id>urn:uuid:67b9341e-cadd-4dac-9d5c-f5a1d59f2d06</Id>
-      <AnnotationText>audio.mxf</AnnotationText>
-      <Hash>HapNpn7MjiJLa1OHRI61Rx8N/is=</Hash>
-      <Size>305326</Size>
+      <Id>urn:uuid:d36f4bb3-c4fa-4a95-9915-6fec3110cd71</Id>
+      <AnnotationText>video.mxf</AnnotationText>
+      <Hash>E2vhyxdJQhEzSQZdp31w84ZZpfk=</Hash>
+      <Size>26080</Size>
       <Type>application/mxf</Type>
     </Asset>
     <Asset>
-      <Id>urn:uuid:9892e944-5046-4dbb-af7c-f50742f62fc2</Id>
-      <Hash>PbXuvpUOKccTLMxg/lEbaXvNCT4=</Hash>
+      <Id>urn:uuid:81fb54df-e1bf-4647-8788-ea7ba154375b</Id>
+      <Hash>TTn7vvdUQi/G+KaW1Pym/DjxULM=</Hash>
       <Size>1526</Size>
       <Type>text/xml</Type>
     </Asset>
index 70040fc3c3563b9cb645a0a76ced9e604e962102..645fb85affaaca1d273f5fff2b5f7abf10a850c5 100644 (file)
Binary files a/test/ref/DCP/video.mxf and b/test/ref/DCP/video.mxf differ
index ba0c9991d4882755b0e82cc93a54fbdbcbac9022..fe961a32ad3a05d328ab68cac4f872c2c7c0000e 100644 (file)
@@ -1,49 +1,71 @@
 DCP: ../libdcp-test/ASTERIX_TSR_F_FR-DE_51_2K_20120411_SE_2D
-       Length: 1439
-       Frames per second: 24
-Reel 1
-Reel 2
-       Subtitle: 30 subtitles in Custom
+  CPL: ASTERIX_TSR_F_FR-DE_51_2K_20120411_SE_2D
+    Length: 1439
+    Frames per second: 24
+    Reel 1
+    Reel 2
+      Subtitle: 30 subtitles in Custom
 DCP: ../libdcp-test/WRECK-IT-RALPH_TLR-A-3D_S_EN-DEFR_INT_51_2K_DI_20120620_TEU_i3D
-       Length: 3385
-       Frames per second: 24
-Reel 1
+  CPL: WRECK-IT-RALPH_TLR-A-3D_S_EN-DEFR_INT_51_2K_DI_20120620_TEU_i3D
+    Length: 3385
+    Frames per second: 24
+    Reel 1
 DCP: ../libdcp-test/AVATAR-3D_TLR-H_F_EN-XX_INTL-TXTD_2K_51_TCF_20091022_DUK-i3D-ngb
-       Length: 4960
-       Frames per second: 24
-Reel 1
+  CPL: AVATAR-3D_TLR-H_F_EN-XX_INTL-TXTD_2K_51_TCF_20091022_DUK-i3D-ngb
+    Length: 4960
+    Frames per second: 24
+    Reel 1
 DCP: ../libdcp-test/END-OF-TIME_TLR_F_XX-XX_CH_51_2K_LOK_20120726_DGL_OV
-       Length: 2865
-       Frames per second: 24
-Reel 1
-Reel 2
+  CPL: 
+    Length: 2865
+    Frames per second: 24
+    Reel 1
+    Reel 2
 DCP: ../libdcp-test/THE-GUARD_TRL_F_EN-DE-FR_CH_51_2K_20110718_TIT
-       Length: 3201
-       Frames per second: 24
-Reel 1
+  CPL: THE-GUARD_TRL_F_EN-DE-FR_CH_51_2K_20110718_TIT
+    Length: 3201
+    Frames per second: 24
+    Reel 1
+DCP: ../libdcp-test/SANS-ISSUE_TLR_F_EN-FR_FR_51_2K_SND_20120316_ECL_OV
+  CPL: SANS-ISSUE_TLR_F_FR-XX_FR_51_2K_SND_20120316_ECL_OV
+    Length: 2972
+    Frames per second: 24
+    Reel 1
+    Reel 2
+  CPL: SANS-ISSUE_TLR_F_EN-FR_FR_51_2K_SND_20120316_ECL_OV
+    Length: 2972
+    Frames per second: 24
+    Reel 1
+    Reel 2
+      Subtitle: 49 subtitles in French
 DCP: ../libdcp-test/BARBARA_TLR_F_DE-FR_CH_51_2K_LOK_20120410_OV
-       Length: 2917
-       Frames per second: 24
-Reel 1
-       Subtitle: 31 subtitles in French
+  CPL: BARBARA_TLR_F_DE-FR_CH_51_2K_LOK_20120410_OV
+    Length: 2917
+    Frames per second: 24
+    Reel 1
+      Subtitle: 31 subtitles in French
 DCP: ../libdcp-test/MACHINE-GUN-PREACH_TLR-1_F_EN-de-fr_CH_51_2K_TIT_20111107
-       Length: 3513
-       Frames per second: 24
-Reel 1
-       Subtitle: 94 subtitles in English
+  CPL: MACHINE-GUN-PREACH_TLR-1_F_EN-de-fr_CH_51_2K_TIT_20111107
+    Length: 3513
+    Frames per second: 24
+    Reel 1
+      Subtitle: 94 subtitles in English
 DCP: ../libdcp-test/ASTERIX_TLR-01_F_FR-DE_CH_51_2K_FRE_20120730_DGL_OV
-       Length: 3080
-       Frames per second: 24
-Reel 1
-       Subtitle: 49 subtitles in French
+  CPL: 
+    Length: 3080
+    Frames per second: 24
+    Reel 1
+      Subtitle: 49 subtitles in French
 DCP: ../libdcp-test/EPIC-3D_TLR-D_S_EN-DE-FR_CH_51_48_ST_20120718_TIT_i3D-ngb_OV
-       Length: 3166
-       Frames per second: 24
-Reel 1
-       Subtitle: 32 subtitles in English
+  CPL: 
+    Length: 3166
+    Frames per second: 24
+    Reel 1
+      Subtitle: 32 subtitles in English
 DCP: ../libdcp-test/ELLES_TLR_C_FR-DE_20_2K_20120412_SE
-       Length: 2794
-       Frames per second: 24
-Reel 1
-Reel 2
-       Subtitle: 52 subtitles in Custom
+  CPL: ELLES_TLR_C_FR-DE_20_2K_20120412_SE
+    Length: 2794
+    Frames per second: 24
+    Reel 1
+    Reel 2
+      Subtitle: 52 subtitles in Custom
index 43c959057ea02eb7cff2c4762aa9bd91b32e0327..ce9dae7547f0ba48e5062f168bcc8c45d319cafc 100644 (file)
@@ -63,7 +63,8 @@ BOOST_AUTO_TEST_CASE (dcp_test)
        t->issue_date = "2012-07-17T04:45:18+00:00";
        filesystem::remove_all ("build/test/foo");
        filesystem::create_directories ("build/test/foo");
-       libdcp::DCP d ("build/test/foo", "A Test DCP", libdcp::FEATURE, 24, 24);
+       libdcp::DCP d ("build/test/foo");
+       shared_ptr<libdcp::CPL> cpl (new libdcp::CPL ("build/test/foo", "A Test DCP", libdcp::FEATURE, 24, 24));
 
        shared_ptr<libdcp::MonoPictureAsset> mp (new libdcp::MonoPictureAsset (
                                                         sigc::ptr_fun (&j2c),
@@ -86,14 +87,15 @@ BOOST_AUTO_TEST_CASE (dcp_test)
                                                  2
                                                  ));
 
-       d.add_reel (shared_ptr<libdcp::Reel> (new libdcp::Reel (mp, ms, shared_ptr<libdcp::SubtitleAsset> ())));
+       cpl->add_reel (shared_ptr<libdcp::Reel> (new libdcp::Reel (mp, ms, shared_ptr<libdcp::SubtitleAsset> ())));
+       d.add_cpl (cpl);
 
        d.write_xml ();
 }
 
 BOOST_AUTO_TEST_CASE (error_test)
 {
-       libdcp::DCP d ("build/test/bar", "A Test DCP", libdcp::TEST, 24, 24);
+       libdcp::DCP d ("build/test/bar");
        vector<string> p;
        p.push_back ("frobozz");
 
@@ -104,11 +106,15 @@ BOOST_AUTO_TEST_CASE (error_test)
 BOOST_AUTO_TEST_CASE (read_dcp)
 {
        libdcp::DCP d ("test/ref/DCP");
+       d.read ();
 
-       BOOST_CHECK_EQUAL (d.name(), "A Test DCP");
-       BOOST_CHECK_EQUAL (d.content_kind(), libdcp::FEATURE);
-       BOOST_CHECK_EQUAL (d.frames_per_second(), 24);
-       BOOST_CHECK_EQUAL (d.length(), 24);
+       list<shared_ptr<const libdcp::CPL> > cpls = d.cpls ();
+       BOOST_CHECK_EQUAL (cpls.size(), 1);
+
+       BOOST_CHECK_EQUAL (cpls.front()->name(), "A Test DCP");
+       BOOST_CHECK_EQUAL (cpls.front()->content_kind(), libdcp::FEATURE);
+       BOOST_CHECK_EQUAL (cpls.front()->frames_per_second(), 24);
+       BOOST_CHECK_EQUAL (cpls.front()->length(), 24);
 }
        
 BOOST_AUTO_TEST_CASE (subtitles1)
index ba1fed0a66980f9bef0e47008c6747c4ff19b532..7d49d699bf567a266c05b270d1cecab59ce96566 100644 (file)
@@ -58,31 +58,39 @@ main (int argc, char* argv[])
 
        DCP* dcp = 0;
        try {
-               dcp = new DCP (argv[optind], false);
+               dcp = new DCP (argv[optind]);
+               dcp->read (false);
        } catch (FileError& e) {
                cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
                exit (EXIT_FAILURE);
        }
 
-       cout << "DCP: " << argv[optind] << "\n"
-            << "\tLength: " << dcp->length() << "\n"
-            << "\tFrames per second: " << dcp->frames_per_second() << "\n";
+       cout << "DCP: " << argv[optind] << "\n";
 
-       list<shared_ptr<const Reel> > reels = dcp->reels ();
+       list<shared_ptr<const CPL> > cpls = dcp->cpls ();
 
-       int R = 1;
-       for (list<shared_ptr<const Reel> >::const_iterator i = reels.begin(); i != reels.end(); ++i) {
-               cout << "Reel " << R << "\n";
-               if ((*i)->main_picture()) {
-                       cout << "\tPicture:  " << (*i)->main_picture()->width() << "x" << (*i)->main_picture()->height() << "\n";
-               }
-               if ((*i)->main_sound()) {
-                       cout << "\tSound:    " << (*i)->main_sound()->channels() << " channels at " << (*i)->main_sound()->sampling_rate() << "Hz\n";
-               }
-               if ((*i)->main_subtitle()) {
-                       cout << "\tSubtitle: " << (*i)->main_subtitle()->subtitles().size() << " subtitles in " << (*i)->main_subtitle()->language() << "\n";
+       for (list<shared_ptr<const CPL> >::iterator i = cpls.begin(); i != cpls.end(); ++i) {
+               cout << "  CPL: " << (*i)->name() << "\n"
+                    << "    Length: " << (*i)->length() << "\n"
+                    << "    Frames per second: " << (*i)->frames_per_second() << "\n";
+               
+               list<shared_ptr<const Reel> > reels = (*i)->reels ();
+
+               int R = 1;
+               for (list<shared_ptr<const Reel> >::const_iterator j = reels.begin(); j != reels.end(); ++j) {
+                       cout << "    Reel " << R << "\n";
+                       
+                       if ((*j)->main_picture()) {
+                               cout << "      Picture:  " << (*j)->main_picture()->width() << "x" << (*j)->main_picture()->height() << "\n";
+                       }
+                       if ((*j)->main_sound()) {
+                               cout << "      Sound:    " << (*j)->main_sound()->channels() << " channels at " << (*j)->main_sound()->sampling_rate() << "Hz\n";
+                       }
+                       if ((*j)->main_subtitle()) {
+                               cout << "      Subtitle: " << (*j)->main_subtitle()->subtitles().size() << " subtitles in " << (*j)->main_subtitle()->language() << "\n";
+                       }
+                       ++R;
                }
-               ++R;
        }
 
        return 0;