MXF -> Asset in lots of places.
[libdcp.git] / src / reel_picture_asset.cc
index c8556b4c35faf3b0e2d2616e5d90b7aa4cdfcccf..fd18dc3015d7bc1827ba1b9577c8f386804d3977 100644 (file)
  *  @brief ReelPictureAsset class.
  */
 
-#include "content.h"
 #include "reel_picture_asset.h"
-#include "picture_mxf.h"
+#include "picture_asset.h"
+#include "dcp_assert.h"
 #include "compose.hpp"
 #include <libcxml/cxml.h>
+#include <libxml++/libxml++.h>
 #include <iomanip>
 
 using std::bad_cast;
 using std::string;
 using std::stringstream;
 using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
 using namespace dcp;
 
 ReelPictureAsset::ReelPictureAsset ()
@@ -41,10 +43,10 @@ ReelPictureAsset::ReelPictureAsset ()
 
 }
 
-ReelPictureAsset::ReelPictureAsset (shared_ptr<PictureMXF> content, int64_t entry_point)
-       : ReelMXFAsset (content, content->edit_rate(), content->intrinsic_duration(), entry_point)
-       , _frame_rate (content->frame_rate ())
-       , _screen_aspect_ratio (content->screen_aspect_ratio ())
+ReelPictureAsset::ReelPictureAsset (shared_ptr<PictureAsset> asset, int64_t entry_point)
+       : ReelMXFAsset (asset, asset->key_id(), asset->edit_rate(), asset->intrinsic_duration(), entry_point)
+       , _frame_rate (asset->frame_rate ())
+       , _screen_aspect_ratio (asset->screen_aspect_ratio ())
 {
        
 }
@@ -69,24 +71,56 @@ ReelPictureAsset::ReelPictureAsset (shared_ptr<const cxml::Node> node)
 void
 ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
 {
-       ReelMXFAsset::write_to_cpl (node, standard);
+       ReelAsset::write_to_cpl (node, standard);
 
-       xmlpp::Node::NodeList c = node->get_children ();
-       xmlpp::Node::NodeList::iterator i = c.begin();
-       while (i != c.end() && (*i)->get_name() != cpl_node_name ()) {
-               ++i;
-       }
-
-       assert (i != c.end ());
+       /* Find <MainPicture> */
+       xmlpp::Node* mp = find_child (node, cpl_node_name ());
        
-       (*i)->add_child ("FrameRate")->add_child_text (String::compose ("%1 %2", _frame_rate.numerator, _frame_rate.denominator));
+       mp->add_child ("FrameRate")->add_child_text (String::compose ("%1 %2", _frame_rate.numerator, _frame_rate.denominator));
        if (standard == INTEROP) {
                stringstream s;
                s << std::fixed << std::setprecision (2) << (float (_screen_aspect_ratio.numerator) / _screen_aspect_ratio.denominator);
-               (*i)->add_child ("ScreenAspectRatio")->add_child_text (s.str ());
+               mp->add_child ("ScreenAspectRatio")->add_child_text (s.str ());
        } else {
-               (*i)->add_child ("ScreenAspectRatio")->add_child_text (
+               mp->add_child ("ScreenAspectRatio")->add_child_text (
                        String::compose ("%1 %2", _screen_aspect_ratio.numerator, _screen_aspect_ratio.denominator)
                        );
        }
+
+        if (!key_id ().empty ()) {
+               /* Find <Hash> */
+               xmlpp::Node* hash = find_child (mp, "Hash");
+               mp->add_child_before (hash, "KeyId")->add_child_text ("urn:uuid:" + key_id ());
+        }
+}
+
+string
+ReelPictureAsset::key_type () const
+{
+       return "MDIK";
+}
+
+bool
+ReelPictureAsset::equals (shared_ptr<const ReelAsset> other, EqualityOptions opt, NoteHandler note) const
+{
+       if (!ReelAsset::equals (other, opt, note)) {
+               return false;
+       }
+       
+       shared_ptr<const ReelPictureAsset> rpa = dynamic_pointer_cast<const ReelPictureAsset> (other);
+       if (!rpa) {
+               return false;
+       }
+
+       if (_frame_rate != rpa->_frame_rate) {
+               note (DCP_ERROR, "frame rates differ in reel");
+               return false;
+       }
+
+       if (_screen_aspect_ratio != rpa->_screen_aspect_ratio) {
+               note (DCP_ERROR, "screen aspect ratios differ in reel");
+               return false;
+       }
+
+       return true;
 }