Resequence video (perhaps) on DCP video frame rate change.
[dcpomatic.git] / src / lib / playlist.cc
index 5ee764a8e73d4e14491e3bac9d6333b19fb87392..aea6c5f413deaae0f6c95e2a702a596f6e7010ae 100644 (file)
@@ -72,64 +72,46 @@ Playlist::~Playlist ()
 void
 Playlist::content_changed (weak_ptr<Content> c, int p)
 {
-       if (p == ContentProperty::LENGTH && _sequence_video && !_sequencing_video) {
-               _sequencing_video = true;
-
-               ContentList cl = _content;
-               sort (cl.begin(), cl.end(), ContentSorter ());
-               Time last = 0;
-               for (ContentList::iterator i = cl.begin(); i != cl.end(); ++i) {
-                       if (!dynamic_pointer_cast<VideoContent> (*i)) {
-                               continue;
-                       }
-
-                       (*i)->set_start (last);
-                       last = (*i)->end ();
-               }
-
-               _sequencing_video = false;
+       if (p == ContentProperty::LENGTH) {
+               maybe_sequence_video ();
        }
        
        ContentChanged (c, p);
 }
 
-string
-Playlist::audio_digest () const
+void
+Playlist::maybe_sequence_video ()
 {
-       string t;
+       if (!_sequence_video || _sequencing_video) {
+               return;
+       }
        
-       for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
-               if (!dynamic_pointer_cast<const AudioContent> (*i)) {
+       _sequencing_video = true;
+       
+       ContentList cl = _content;
+       sort (cl.begin(), cl.end(), ContentSorter ());
+       Time last = 0;
+       for (ContentList::iterator i = cl.begin(); i != cl.end(); ++i) {
+               if (!dynamic_pointer_cast<VideoContent> (*i)) {
                        continue;
                }
                
-               t += (*i)->digest ();
-
-               shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
-               if (fc) {
-                       t += lexical_cast<string> (fc->audio_stream()->id);
-               }
+               (*i)->set_start (last);
+               last = (*i)->end ();
        }
-
-       t += lexical_cast<string> (_loop);
-
-       return md5_digest (t.c_str(), t.length());
+       
+       _sequencing_video = false;
 }
 
 string
-Playlist::video_digest () const
+Playlist::video_identifier () const
 {
        string t;
        
        for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
-               if (!dynamic_pointer_cast<const VideoContent> (*i)) {
-                       continue;
-               }
-               
-               t += (*i)->digest ();
-               shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
-               if (fc && fc->subtitle_stream()) {
-                       t += fc->subtitle_stream()->id;
+               shared_ptr<const VideoContent> vc = dynamic_pointer_cast<const VideoContent> (*i);
+               if (vc) {
+                       t += vc->identifier ();
                }
        }
 
@@ -255,7 +237,7 @@ Playlist::best_dcp_frame_rate () const
        list<FrameRateCandidate>::iterator i = candidates.begin();
        while (i != candidates.end()) {
 
-               float this_error = std::numeric_limits<float>::max ();
+               float this_error = 0;
                for (ContentList::const_iterator j = _content.begin(); j != _content.end(); ++j) {
                        shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (*j);
                        if (!vc) {