path -> dir, name for MXFs.
[libdcp.git] / src / dcp.cc
index ca2a2d143e933fb188957f4e7b8f0a8967dfe5bb..8f7a73bcedaadc44a0cefe59e97c12c6371c9aa1 100644 (file)
 
 */
 
+/** @file  src/dcp.cc
+ *  @brief A class to create a DCP.
+ */
+
 #include <sstream>
 #include <fstream>
 #include <iomanip>
 #include "picture_asset.h"
 #include "util.h"
 #include "metadata.h"
+#include "exceptions.h"
+#include "cpl.h"
+#include "pkl.h"
+#include "asset_map.h"
 
 using namespace std;
 using namespace boost;
 using namespace libdcp;
 
-DCP::DCP (string directory, string name, ContentType content_type, int fps, int length)
+DCP::DCP (string directory, string name, ContentKind content_kind, int fps, int length)
        : _directory (directory)
        , _name (name)
-       , _content_type (content_type)
+       , _content_kind (content_kind)
        , _fps (fps)
        , _length (length)
 {
@@ -44,21 +52,27 @@ DCP::DCP (string directory, string name, ContentType content_type, int fps, int
 }
 
 void
-DCP::add_sound_asset (list<string> const & files)
+DCP::add_sound_asset (vector<string> const & files)
 {
-       filesystem::path p;
-       p /= _directory;
-       p /= "audio.mxf";
-       _assets.push_back (shared_ptr<SoundAsset> (new SoundAsset (files, p.string(), &Progress, _fps, _length)));
+       _assets.push_back (shared_ptr<SoundAsset> (new SoundAsset (files, _directory, "audio.mxf", &Progress, _fps, _length)));
 }
 
 void
-DCP::add_picture_asset (list<string> const & files, int w, int h)
+DCP::add_sound_asset (sigc::slot<string, Channel> get_path, int channels)
 {
-       filesystem::path p;
-       p /= _directory;
-       p /= "video.mxf";
-       _assets.push_back (shared_ptr<PictureAsset> (new PictureAsset (files, p.string(), &Progress, _fps, _length, w, h)));
+       _assets.push_back (shared_ptr<SoundAsset> (new SoundAsset (get_path, _directory, "audio.mxf", &Progress, _fps, _length, channels)));
+}
+
+void
+DCP::add_picture_asset (vector<string> const & files, int width, int height)
+{
+       _assets.push_back (shared_ptr<PictureAsset> (new PictureAsset (files, _directory, "video.mxf", &Progress, _fps, _length, width, height)));
+}
+
+void
+DCP::add_picture_asset (sigc::slot<string, int> get_path, int width, int height)
+{
+       _assets.push_back (shared_ptr<PictureAsset> (new PictureAsset (get_path, _directory, "video.mxf", &Progress, _fps, _length, width, height)));
 }
 
 void
@@ -93,7 +107,7 @@ DCP::write_cpl (string cpl_uuid) const
            << "  <IssueDate>" << Metadata::instance()->issue_date << "</IssueDate>\n"
            << "  <Creator>" << Metadata::instance()->creator << "</Creator>\n"
            << "  <ContentTitleText>" << _name << "</ContentTitleText>\n"
-           << "  <ContentKind>" << content_type_string (_content_type) << "</ContentKind>\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"
@@ -217,32 +231,76 @@ DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_l
           << "</AssetMap>\n";
 }
 
-string
-DCP::content_type_string (ContentType type)
+
+DCP::DCP (string directory)
+       : _directory (directory)
 {
-       switch (type) {
-       case FEATURE:
-               return "feature";
-       case SHORT:
-               return "short";
-       case TRAILER:
-               return "trailer";
-       case TEST:
-               return "test";
-       case TRANSITIONAL:
-               return "transitional";
-       case RATING:
-               return "rating";
-       case TEASER:
-               return "teaser";
-       case POLICY:
-               return "policy";
-       case PUBLIC_SERVICE_ANNOUNCEMENT:
-               return "psa";
-       case ADVERTISEMENT:
-               return "advertisement";
+       string cpl_file;
+       string pkl_file;
+       string asset_map_file;
+
+       for (filesystem::directory_iterator i = filesystem::directory_iterator(directory); i != filesystem::directory_iterator(); ++i) {
+               string const t = i->path().string ();
+               if (ends_with (t, "_cpl.xml")) {
+                       if (cpl_file.empty ()) {
+                               cpl_file = t;
+                       } else {
+                               throw DCPReadError ("duplicate CPLs found");
+                       }
+               } else if (ends_with (t, "_pkl.xml")) {
+                       if (pkl_file.empty ()) {
+                               pkl_file = t;
+                       } else {
+                               throw DCPReadError ("duplicate PKLs found");
+                       }
+               } else if (ends_with (t, "ASSETMAP.xml")) {
+                       if (asset_map_file.empty ()) {
+                               asset_map_file = t;
+                       } else {
+                               throw DCPReadError ("duplicate AssetMaps found");
+                       }
+               }
        }
 
-       assert (false);
+       /* Read the XML */
+       CPL cpl (cpl_file);
+       PKL pkl (pkl_file);
+       AssetMap asset_map (asset_map_file);
+
+       /* Cross-check */
+       /* XXX */
+
+       /* Now cherry-pick the required bits into our own data structure */
+       
+       _name = cpl.annotation_text;
+       _content_kind = cpl.content_kind;
+
+       shared_ptr<CPLAssetList> cpl_assets = cpl.reels.front()->asset_list;
+       
+       /* XXX */
+       _fps = cpl_assets->main_picture->frame_rate.numerator;
+       _length = cpl_assets->main_picture->duration;
+
+       _assets.push_back (shared_ptr<PictureAsset> (
+                                  new PictureAsset (
+                                          _directory,
+                                          cpl_assets->main_picture->annotation_text,
+                                          _fps,
+                                          _length,
+                                          cpl_assets->main_picture->screen_aspect_ratio.numerator,
+                                          cpl_assets->main_picture->screen_aspect_ratio.denominator
+                                          )
+                                  ));
+
+       if (cpl_assets->main_sound) {
+               _assets.push_back (shared_ptr<SoundAsset> (
+                                          new SoundAsset (
+                                                  _directory,
+                                                  cpl_assets->main_picture->annotation_text,
+                                                  _fps,
+                                                  _length
+                                                  )
+                                          ));
+       }
 }
-               
+