X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fplaylist.cc;h=4175de4c9ce89d4f4baf8b403e92dac1ffcb05d0;hb=e2be8234013335379bd49a53854218039348c7a4;hp=8db5c5fc2bced2a8745a28effd3d0a33b7824ff1;hpb=2de990b0155fcb5c3dac821ef8c2659e903d2f6e;p=dcpomatic.git diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index 8db5c5fc2..4175de4c9 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 @@ -28,8 +26,8 @@ #include "video_content.h" #include "ffmpeg_decoder.h" #include "ffmpeg_content.h" -#include "imagemagick_decoder.h" -#include "imagemagick_content.h" +#include "image_decoder.h" +#include "content_factory.h" #include "job.h" #include "config.h" #include "util.h" @@ -43,6 +41,7 @@ using std::min; using std::max; using std::string; using std::stringstream; +using std::pair; using boost::optional; using boost::shared_ptr; using boost::weak_ptr; @@ -50,124 +49,140 @@ using boost::dynamic_pointer_cast; using boost::lexical_cast; Playlist::Playlist () - : _loop (1) + : _sequence_video (true) + , _sequencing_video (false) { } -Playlist::Playlist (shared_ptr other) - : _loop (other->_loop) +Playlist::~Playlist () { - for (RegionList::const_iterator i = other->_regions.begin(); i != other->_regions.end(); ++i) { - _regions.push_back (shared_ptr (new Region ((*i)->content->clone(), (*i)->time, this))); - } + _content.clear (); + reconnect (); } void -Playlist::content_changed (weak_ptr c, int p) +Playlist::content_changed (weak_ptr content, int property, bool frequent) { - ContentChanged (c, p); + if (property == ContentProperty::LENGTH) { + maybe_sequence_video (); + } + + ContentChanged (content, property, frequent); } -string -Playlist::audio_digest () const +void +Playlist::maybe_sequence_video () { - string t; + if (!_sequence_video || _sequencing_video) { + return; + } + + _sequencing_video = true; - for (RegionList::const_iterator i = _regions.begin(); i != _regions.end(); ++i) { - if (!dynamic_pointer_cast ((*i)->content)) { + ContentList cl = _content; + DCPTime next = 0; + for (ContentList::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); - if (fc) { - t += lexical_cast (fc->audio_stream()->id); - } + (*i)->set_position (next); + next = (*i)->end() + 1; } - t += lexical_cast (_loop); - - return md5_digest (t.c_str(), t.length()); + /* This won't change order, so it does not need a sort */ + + _sequencing_video = false; } string -Playlist::video_digest () const +Playlist::video_identifier () const { string t; - for (RegionList::const_iterator i = _regions.begin(); i != _regions.end(); ++i) { - if (!dynamic_pointer_cast ((*i)->content)) { - continue; - } - - t += (*i)->content->digest (); - shared_ptr fc = dynamic_pointer_cast ((*i)->content); - if (fc && fc->subtitle_stream()) { - t += fc->subtitle_stream()->id; + for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) { + shared_ptr vc = dynamic_pointer_cast (*i); + if (vc) { + t += vc->identifier (); } } - t += lexical_cast (_loop); - 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, int version) { - list > c = node->node_children ("Region"); - for (list >::iterator i = c.begin(); i != c.end(); ++i) { - _regions.push_back (shared_ptr (new Region (*i, this))); + list c = node->node_children ("Content"); + for (list::iterator i = c.begin(); i != c.end(); ++i) { + _content.push_back (content_factory (film, *i, version)); } - _loop = node->number_child ("Loop"); + sort (_content.begin(), _content.end(), ContentSorter ()); + + reconnect (); } +/** @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)); } void Playlist::add (shared_ptr c) { - _regions.push_back (shared_ptr (new Region (c, 0, this))); + _content.push_back (c); + sort (_content.begin(), _content.end(), ContentSorter ()); + 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 (); } + + /* This won't change order, so it does not need a sort */ } void -Playlist::set_loop (int l) +Playlist::remove (ContentList c) { - _loop = l; + for (ContentList::iterator i = c.begin(); i != c.end(); ++i) { + ContentList::iterator j = _content.begin (); + while (j != _content.end() && *j != *i) { + ++j; + } + + if (j != _content.end ()) { + _content.erase (j); + } + } + + /* This won't change order, so it does not need a sort */ + Changed (); } 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,40 +191,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