Try to fix build on OS X.
[libdcp.git] / src / mono_picture_asset.cc
index 91ab0d8a21ac10f095447ee89a168e27b0f7476a..27d879498c055c5b820a4e80c8ee299b65a393a5 100644 (file)
@@ -28,6 +28,8 @@
 
 using std::string;
 using std::vector;
+using std::list;
+using std::pair;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using namespace dcp;
@@ -68,6 +70,12 @@ MonoPictureAsset::get_frame (int n) const
        return shared_ptr<const MonoPictureFrame> (new MonoPictureFrame (_file, n, _decryption_context));
 }
 
+static void
+storing_note_handler (list<pair<NoteType, string> >& notes, NoteType t, string s)
+{
+       notes.push_back (make_pair (t, s));
+}
+
 bool
 MonoPictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler note) const
 {
@@ -103,25 +111,40 @@ MonoPictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, No
        shared_ptr<const MonoPictureAsset> other_picture = dynamic_pointer_cast<const MonoPictureAsset> (other);
        DCP_ASSERT (other_picture);
 
+       bool result = true;
+
+#pragma omp parallel for
        for (int i = 0; i < _intrinsic_duration; ++i) {
                if (i >= other_picture->intrinsic_duration()) {
-                       return false;
+                       result = false;
                }
 
-               note (DCP_PROGRESS, String::compose ("Comparing video frame %1 of %2", i, _intrinsic_duration));
-               shared_ptr<const MonoPictureFrame> frame_A = get_frame (i);
-               shared_ptr<const MonoPictureFrame> frame_B = other_picture->get_frame (i);
+               if (result || opt.keep_going) {
+
+#pragma omp critical
+                       note (DCP_PROGRESS, String::compose ("Comparing video frame %1 of %2", i, _intrinsic_duration));
+
+                       shared_ptr<const MonoPictureFrame> frame_A = get_frame (i);
+                       shared_ptr<const MonoPictureFrame> frame_B = other_picture->get_frame (i);
+
+                       list<pair<NoteType, string> > notes;
+
+                       if (!frame_buffer_equals (
+                                   i, opt, bind (&storing_note_handler, notes, _1, _2),
+                                   frame_A->j2k_data(), frame_A->j2k_size(),
+                                   frame_B->j2k_data(), frame_B->j2k_size()
+                                   )) {
+                               result = false;
+                       }
 
-               if (!frame_buffer_equals (
-                           i, opt, note,
-                           frame_A->j2k_data(), frame_A->j2k_size(),
-                           frame_B->j2k_data(), frame_B->j2k_size()
-                           )) {
-                       return false;
+#pragma omp critical
+                       for (list<pair<NoteType, string> >::const_iterator i = notes.begin(); i != notes.end(); ++i) {
+                               note (i->first, i->second);
+                       }
                }
        }
 
-       return true;
+       return result;
 }
 
 shared_ptr<PictureAssetWriter>