Fix a couple of errors in Interop XML
[libdcp.git] / src / mono_picture_asset.cc
index 81508065eadaca5982c8d9e8e767b0b61a0b3176..0ac48d37b8077eb7b45b65c70743f7721131f639 100644 (file)
@@ -31,7 +31,7 @@ using boost::dynamic_pointer_cast;
 using boost::lexical_cast;
 using namespace libdcp;
 
-MonoPictureAsset::MonoPictureAsset (boost::filesystem::path directory, string mxf_name)
+MonoPictureAsset::MonoPictureAsset (boost::filesystem::path directory, boost::filesystem::path mxf_name)
        : PictureAsset (directory, mxf_name)
 {
 
@@ -48,8 +48,9 @@ MonoPictureAsset::create (boost::function<boost::filesystem::path (int)> get_pat
 {
        ASDCP::JP2K::CodestreamParser j2k_parser;
        ASDCP::JP2K::FrameBuffer frame_buffer (4 * Kumu::Megabyte);
-       if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (get_path(0).string().c_str(), frame_buffer))) {
-               boost::throw_exception (FileError ("could not open JPEG2000 file for reading", get_path (0)));
+       Kumu::Result_t r = j2k_parser.OpenReadFrame (get_path(0).string().c_str(), frame_buffer);
+       if (ASDCP_FAILURE (r)) {
+               boost::throw_exception (FileError ("could not open JPEG2000 file for reading", get_path(0), r));
        }
        
        ASDCP::JP2K::PictureDescriptor picture_desc;
@@ -57,23 +58,26 @@ MonoPictureAsset::create (boost::function<boost::filesystem::path (int)> get_pat
        picture_desc.EditRate = ASDCP::Rational (_edit_rate, 1);
        
        ASDCP::WriterInfo writer_info;
-       fill_writer_info (&writer_info, _uuid, _interop, _metadata);
+       fill_writer_info (&writer_info);
        
        ASDCP::JP2K::MXFWriter mxf_writer;
-       if (ASDCP_FAILURE (mxf_writer.OpenWrite (path().string().c_str(), writer_info, picture_desc, 16384, false))) {
-               boost::throw_exception (MXFFileError ("could not open MXF file for writing", path().string()));
+       r = mxf_writer.OpenWrite (path().string().c_str(), writer_info, picture_desc, 16384, false);
+       if (ASDCP_FAILURE (r)) {
+               boost::throw_exception (MXFFileError ("could not open MXF file for writing", path().string(), r));
        }
 
        for (int i = 0; i < _intrinsic_duration; ++i) {
 
                boost::filesystem::path const path = get_path (i);
 
-               if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (path.string().c_str(), frame_buffer))) {
-                       boost::throw_exception (FileError ("could not open JPEG2000 file for reading", path));
+               Kumu::Result_t r = j2k_parser.OpenReadFrame (path.string().c_str(), frame_buffer);
+               if (ASDCP_FAILURE (r)) {
+                       boost::throw_exception (FileError ("could not open JPEG2000 file for reading", path, r));
                }
 
-               if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, _encryption_context, 0))) {
-                       boost::throw_exception (MXFFileError ("error in writing video MXF", this->path().string()));
+               r = mxf_writer.WriteFrame (frame_buffer, _encryption_context, 0);
+               if (ASDCP_FAILURE (r)) {
+                       boost::throw_exception (MXFFileError ("error in writing video MXF", this->path().string(), r));
                }
 
                if (_progress) {
@@ -81,8 +85,9 @@ MonoPictureAsset::create (boost::function<boost::filesystem::path (int)> get_pat
                }
        }
        
-       if (ASDCP_FAILURE (mxf_writer.Finalize())) {
-               boost::throw_exception (MXFFileError ("error in finalising video MXF", path().string()));
+       r = mxf_writer.Finalize();
+       if (ASDCP_FAILURE (r)) {
+               boost::throw_exception (MXFFileError ("error in finalising video MXF", path().string(), r));
        }
 }
 
@@ -90,8 +95,9 @@ void
 MonoPictureAsset::read ()
 {
        ASDCP::JP2K::MXFReader reader;
-       if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
-               boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string()));
+       Kumu::Result_t r = reader.OpenRead (path().string().c_str());
+       if (ASDCP_FAILURE (r)) {
+               boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r));
        }
        
        ASDCP::JP2K::PictureDescriptor desc;
@@ -121,7 +127,32 @@ MonoPictureAsset::get_frame (int n) const
 bool
 MonoPictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const
 {
-       if (!PictureAsset::equals (other, opt, note)) {
+       if (!MXFAsset::equals (other, opt, note)) {
+               return false;
+       }
+
+       ASDCP::JP2K::MXFReader reader_A;
+       Kumu::Result_t r = reader_A.OpenRead (path().string().c_str());
+       if (ASDCP_FAILURE (r)) {
+               boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r));
+       }
+       
+       ASDCP::JP2K::MXFReader reader_B;
+       r = reader_B.OpenRead (other->path().string().c_str());
+       if (ASDCP_FAILURE (r)) {
+               boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r));
+       }
+       
+       ASDCP::JP2K::PictureDescriptor desc_A;
+       if (ASDCP_FAILURE (reader_A.FillPictureDescriptor (desc_A))) {
+               boost::throw_exception (DCPReadError ("could not read video MXF information"));
+       }
+       ASDCP::JP2K::PictureDescriptor desc_B;
+       if (ASDCP_FAILURE (reader_B.FillPictureDescriptor (desc_B))) {
+               boost::throw_exception (DCPReadError ("could not read video MXF information"));
+       }
+       
+       if (!descriptor_equals (desc_A, desc_B, note)) {
                return false;
        }