Comment.
[dcpomatic.git] / src / lib / playlist.cc
index a0afae0adf70888315aadda255695d209dd50e6a..89421097cd26829647ebf079e3805dcd4916a08d 100644 (file)
@@ -17,8 +17,6 @@
 
 */
 
-#include <libcxml/cxml.h>
-#include <boost/shared_ptr.hpp>
 #include "playlist.h"
 #include "sndfile_content.h"
 #include "sndfile_decoder.h"
@@ -31,6 +29,9 @@
 #include "config.h"
 #include "util.h"
 #include "md5_digester.h"
+#include <libcxml/cxml.h>
+#include <libxml++/libxml++.h>
+#include <boost/shared_ptr.hpp>
 
 #include "i18n.h"
 
@@ -237,8 +238,14 @@ Playlist::best_dcp_frame_rate () const
                                continue;
                        }
 
+                       /* Best error for this content; we could use the content as-is or double its rate */
+                       float best_error = min (
+                               float (fabs (i->source - vc->video_frame_rate ())),
+                               float (fabs (i->source - vc->video_frame_rate () * 2))
+                               );
+
                        /* Use the largest difference between DCP and source as the "error" */
-                       this_error = max (this_error, float (fabs (i->source - vc->video_frame_rate ())));
+                       this_error = max (this_error, best_error);
                }
 
                if (this_error < error) {
@@ -297,13 +304,16 @@ Playlist::video_end () const
 FrameRateChange
 Playlist::active_frame_rate_change (DCPTime t, int dcp_video_frame_rate) const
 {
-       for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+       for (ContentList::const_reverse_iterator i = _content.rbegin(); i != _content.rend(); ++i) {
                shared_ptr<const VideoContent> vc = dynamic_pointer_cast<const VideoContent> (*i);
                if (!vc) {
                        continue;
                }
 
-               if (vc->position() >= t && t < vc->end()) {
+               if (vc->position() <= t) {
+                       /* This is the first piece of content (going backwards...) that starts before t,
+                          so it's the active one.
+                       */
                        return FrameRateChange (vc->video_frame_rate(), dcp_video_frame_rate);
                }
        }