Purge assert() from src/, at least (not asdcplib).
[libdcp.git] / src / reel_picture_asset.cc
index d1910bb3d2028e8304fdd7d513b8472c1fa4e6e2..5cf2b858716a928129a248d2833899bb05235966 100644 (file)
 #include "content.h"
 #include "reel_picture_asset.h"
 #include "picture_mxf.h"
+#include "dcp_assert.h"
 #include "compose.hpp"
 #include <libcxml/cxml.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 ()
@@ -40,16 +43,16 @@ ReelPictureAsset::ReelPictureAsset ()
 
 }
 
-ReelPictureAsset::ReelPictureAsset (boost::shared_ptr<PictureMXF> content, int64_t entry_point)
-       : ReelAsset (content, entry_point)
+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 (boost::shared_ptr<const cxml::Node> node)
-       : ReelAsset (node)
+ReelPictureAsset::ReelPictureAsset (shared_ptr<const cxml::Node> node)
+       : ReelMXFAsset (node)
 {
        _frame_rate = Fraction (node->string_child ("FrameRate"));
        try {
@@ -68,7 +71,7 @@ ReelPictureAsset::ReelPictureAsset (boost::shared_ptr<const cxml::Node> node)
 void
 ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
 {
-       ReelAsset::write_to_cpl (node, standard);
+       ReelMXFAsset::write_to_cpl (node, standard);
 
        xmlpp::Node::NodeList c = node->get_children ();
        xmlpp::Node::NodeList::iterator i = c.begin();
@@ -76,7 +79,7 @@ ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
                ++i;
        }
 
-       assert (i != c.end ());
+       DCP_ASSERT (i != c.end ());
        
        (*i)->add_child ("FrameRate")->add_child_text (String::compose ("%1 %2", _frame_rate.numerator, _frame_rate.denominator));
        if (standard == INTEROP) {
@@ -89,3 +92,34 @@ ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
                        );
        }
 }
+
+string
+ReelPictureAsset::key_type () const
+{
+       return "MDIK";
+}
+
+bool
+ReelPictureAsset::equals (shared_ptr<const ReelAsset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> 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;
+}