X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplaylist.cc;h=703a14663448c5468dc10910a3ca5c978d3a96df;hb=c1bae7f0dac684147e00f5f51dcd5544ba13ee53;hp=d2df75a09a4a9e045c73c7f4d7f14803518630a0;hpb=a4642b6463430175d0f4e1ca284a4bf08bcf4de9;p=dcpomatic.git diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index d2df75a09..703a14663 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -1,5 +1,3 @@ -/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ - /* Copyright (C) 2013 Carl Hetherington @@ -51,6 +49,8 @@ using boost::lexical_cast; Playlist::Playlist () : _loop (1) + , _sequence_video (true) + , _sequencing_video (false) { } @@ -72,46 +72,36 @@ Playlist::~Playlist () void Playlist::content_changed (weak_ptr c, int p) { - ContentChanged (c, 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 (*i)) { + continue; + } -string -Playlist::audio_digest () const -{ - string t; - - for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) { - if (!dynamic_pointer_cast (*i)) { - continue; + (*i)->set_start (last); + last = (*i)->end (); } - - t += (*i)->digest (); - shared_ptr fc = dynamic_pointer_cast (*i); - if (fc) { - t += lexical_cast (fc->audio_stream()->id); - } + _sequencing_video = false; } - - t += lexical_cast (_loop); - - return md5_digest (t.c_str(), t.length()); + + ContentChanged (c, p); } 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 (*i)) { - continue; - } - - t += (*i)->digest (); - shared_ptr fc = dynamic_pointer_cast (*i); - if (fc && fc->subtitle_stream()) { - t += fc->subtitle_stream()->id; + shared_ptr vc = dynamic_pointer_cast (*i); + if (vc) { + t += vc->identifier (); } } @@ -143,6 +133,7 @@ Playlist::set_from_xml (shared_ptr film, shared_ptrnumber_child ("Loop"); + _sequence_video = node->bool_child ("SequenceVideo"); } /** @param node node */ @@ -154,6 +145,7 @@ Playlist::as_xml (xmlpp::Node* node) } node->add_child("Loop")->add_child_text(lexical_cast (_loop)); + node->add_child("SequenceVideo")->add_child_text(_sequence_video ? "1" : "0"); } void @@ -229,20 +221,21 @@ Playlist::best_dcp_frame_rate () const candidates.push_back (FrameRateCandidate (float (*i) * 2, *i)); } - /* Pick the best one, bailing early if we hit an exact match */ + /* Pick the best one */ float error = std::numeric_limits::max (); optional best; list::iterator i = candidates.begin(); while (i != candidates.end()) { - float this_error = std::numeric_limits::max (); + float this_error = 0; for (ContentList::const_iterator j = _content.begin(); j != _content.end(); ++j) { shared_ptr vc = dynamic_pointer_cast (*j); if (!vc) { continue; } - this_error += fabs (i->source - vc->video_frame_rate ()); + /* Use the largest difference between DCP and source as the "error" */ + this_error = max (this_error, float (fabs (i->source - vc->video_frame_rate ()))); } if (this_error < error) { @@ -297,3 +290,15 @@ Playlist::video_end () const return end; } + +void +Playlist::set_sequence_video (bool s) +{ + _sequence_video = s; +} + +bool +ContentSorter::operator() (shared_ptr a, shared_ptr b) +{ + return a->start() < b->start(); +}