X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplaylist.cc;h=995067b66ee7bf7133f6d0b025c70f381869dd1e;hb=09a9ac376db005a40a351736bcff4077f098825d;hp=912d90f0e5f482d19404101e282e713a1268b48e;hpb=f2caad0df1a451e2aff68dfd37277faa72116e12;p=dcpomatic.git diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index 912d90f0e..995067b66 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) { } @@ -58,38 +58,39 @@ Playlist::Playlist () Playlist::Playlist (shared_ptr other) : _loop (other->_loop) { - for (RegionList::const_iterator i = other->_regions.begin(); i != other->_regions.end(); ++i) { - _regions.push_back (Region (i->content->clone(), i->time, this)); + for (ContentList::const_iterator i = other->_content.begin(); i != other->_content.end(); ++i) { + _content.push_back ((*i)->clone ()); } } -void -Playlist::content_changed (weak_ptr c, int p) +Playlist::~Playlist () { - ContentChanged (c, p); + _content.clear (); + reconnect (); } -string -Playlist::audio_digest () const +void +Playlist::content_changed (weak_ptr c, int p) { - string t; - - for (RegionList::const_iterator i = _regions.begin(); i != _regions.end(); ++i) { - if (!dynamic_pointer_cast (i->content)) { - continue; - } - - t += i->content->digest (); + 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; + } - shared_ptr fc = dynamic_pointer_cast (i->content); - if (fc) { - t += lexical_cast (fc->audio_stream()->id); + (*i)->set_start (last); + last = (*i)->end (); } - } - t += lexical_cast (_loop); - - return md5_digest (t.c_str(), t.length()); + _sequencing_video = false; + } + + ContentChanged (c, p); } string @@ -97,13 +98,13 @@ Playlist::video_digest () const { string t; - for (RegionList::const_iterator i = _regions.begin(); i != _regions.end(); ++i) { - if (!dynamic_pointer_cast (i->content)) { + for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) { + if (!dynamic_pointer_cast (*i)) { continue; } - t += i->content->digest (); - shared_ptr fc = dynamic_pointer_cast (i->content); + t += (*i)->digest (); + shared_ptr fc = dynamic_pointer_cast (*i); if (fc && fc->subtitle_stream()) { t += fc->subtitle_stream()->id; } @@ -114,44 +115,62 @@ Playlist::video_digest () const return md5_digest (t.c_str(), t.length()); } +/** @param node node */ void -Playlist::set_from_xml (shared_ptr node) +Playlist::set_from_xml (shared_ptr film, shared_ptr node) { - list > c = node->node_children ("Region"); + list > c = node->node_children ("Content"); for (list >::iterator i = c.begin(); i != c.end(); ++i) { - _regions.push_back (Region (*i, this)); + string const type = (*i)->string_child ("Type"); + + boost::shared_ptr content; + + if (type == "FFmpeg") { + content.reset (new FFmpegContent (film, *i)); + } else if (type == "ImageMagick") { + content.reset (new ImageMagickContent (film, *i)); + } else if (type == "Sndfile") { + content.reset (new SndfileContent (film, *i)); + } + + _content.push_back (content); } + reconnect (); _loop = node->number_child ("Loop"); + _sequence_video = node->bool_child ("SequenceVideo"); } +/** @param node node */ void Playlist::as_xml (xmlpp::Node* node) { - for (RegionList::iterator i = _regions.begin(); i != _regions.end(); ++i) { - i->as_xml (node->add_child ("Region")); + for (ContentList::iterator i = _content.begin(); i != _content.end(); ++i) { + (*i)->as_xml (node->add_child ("Content")); } node->add_child("Loop")->add_child_text(lexical_cast (_loop)); + node->add_child("SequenceVideo")->add_child_text(_sequence_video ? "1" : "0"); } void Playlist::add (shared_ptr c) { - _regions.push_back (Region (c, 0, this)); + _content.push_back (c); + reconnect (); Changed (); } void Playlist::remove (shared_ptr c) { - RegionList::iterator i = _regions.begin (); - while (i != _regions.end() && i->content != c) { + ContentList::iterator i = _content.begin (); + while (i != _content.end() && *i != c) { ++i; } - if (i != _regions.end ()) { - _regions.erase (i); + if (i != _content.end ()) { + _content.erase (i); Changed (); } } @@ -166,8 +185,8 @@ Playlist::set_loop (int l) bool Playlist::has_subtitles () const { - for (RegionList::const_iterator i = _regions.begin(); i != _regions.end(); ++i) { - shared_ptr fc = dynamic_pointer_cast (i->content); + for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) { + shared_ptr fc = dynamic_pointer_cast (*i); if (fc && !fc->subtitle_streams().empty()) { return true; } @@ -176,38 +195,6 @@ Playlist::has_subtitles () const return false; } -Playlist::Region::Region (shared_ptr c, Time t, Playlist* p) - : content (c) - , time (t) -{ - connection = c->Changed.connect (bind (&Playlist::content_changed, p, _1, _2)); -} - -Playlist::Region::Region (shared_ptr node, Playlist* p) -{ - shared_ptr content_node = node->node_child ("Content"); - string const type = content_node->string_child ("Type"); - - if (type == "FFmpeg") { - content.reset (new FFmpegContent (content_node)); - } else if (type == "ImageMagick") { - content.reset (new ImageMagickContent (content_node)); - } else if (type == "Sndfile") { - content.reset (new SndfileContent (content_node)); - } - - time = node->number_child