Playlist::Playlist ()
: _loop (1)
+ , _sequence_video (true)
+ , _sequencing_video (false)
{
}
Playlist::Playlist (shared_ptr<const Playlist> 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<Content> c, int p)
+Playlist::~Playlist ()
{
- ContentChanged (c, p);
+ _content.clear ();
+ reconnect ();
}
-string
-Playlist::audio_digest () const
+void
+Playlist::content_changed (weak_ptr<Content> c, int p)
{
- string t;
-
- for (RegionList::const_iterator i = _regions.begin(); i != _regions.end(); ++i) {
- if (!dynamic_pointer_cast<const AudioContent> (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<VideoContent> (*i)) {
+ continue;
+ }
- shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (i->content);
- 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;
+ }
+
+ ContentChanged (c, p);
}
string
{
string t;
- for (RegionList::const_iterator i = _regions.begin(); i != _regions.end(); ++i) {
- if (!dynamic_pointer_cast<const VideoContent> (i->content)) {
+ for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+ if (!dynamic_pointer_cast<const VideoContent> (*i)) {
continue;
}
- t += i->content->digest ();
- shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (i->content);
+ t += (*i)->digest ();
+ shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
if (fc && fc->subtitle_stream()) {
t += fc->subtitle_stream()->id;
}
return md5_digest (t.c_str(), t.length());
}
+/** @param node <Playlist> node */
void
-Playlist::set_from_xml (shared_ptr<const cxml::Node> node)
+Playlist::set_from_xml (shared_ptr<const Film> film, shared_ptr<const cxml::Node> node)
{
- list<shared_ptr<cxml::Node> > c = node->node_children ("Region");
+ list<shared_ptr<cxml::Node> > c = node->node_children ("Content");
for (list<shared_ptr<cxml::Node> >::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> 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<int> ("Loop");
+ _sequence_video = node->bool_child ("SequenceVideo");
}
+/** @param node <Playlist> 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<string> (_loop));
+ node->add_child("SequenceVideo")->add_child_text(_sequence_video ? "1" : "0");
}
void
Playlist::add (shared_ptr<Content> c)
{
- _regions.push_back (Region (c, 0, this));
+ _content.push_back (c);
+ reconnect ();
Changed ();
}
void
Playlist::remove (shared_ptr<Content> 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 ();
}
}
bool
Playlist::has_subtitles () const
{
- for (RegionList::const_iterator i = _regions.begin(); i != _regions.end(); ++i) {
- shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (i->content);
+ for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+ shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (*i);
if (fc && !fc->subtitle_streams().empty()) {
return true;
}
return false;
}
-Playlist::Region::Region (shared_ptr<Content> 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<const cxml::Node> node, Playlist* p)
-{
- shared_ptr<const cxml::Node> 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<Time> ("Time");
- connection = content->Changed.connect (bind (&Playlist::content_changed, p, _1, _2));
-}
-
-void
-Playlist::Region::as_xml (xmlpp::Node* node) const
-{
- xmlpp::Node* sub = node->add_child ("Content");
- content->as_xml (sub);
- sub->add_child ("Time")->add_child_text (lexical_cast<string> (time));
-}
-
class FrameRateCandidate
{
public:
while (i != candidates.end()) {
float this_error = std::numeric_limits<float>::max ();
- for (RegionList::const_iterator j = _regions.begin(); j != _regions.end(); ++j) {
- shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (j->content);
+ for (ContentList::const_iterator j = _content.begin(); j != _content.end(); ++j) {
+ shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (*j);
if (!vc) {
continue;
}
}
Time
-Playlist::length (shared_ptr<const Film> film) const
+Playlist::length () const
{
Time len = 0;
- for (RegionList::const_iterator i = _regions.begin(); i != _regions.end(); ++i) {
- Time const t = i->time + i->content->length (film);
- len = max (len, t);
+ for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+ len = max (len, (*i)->end ());
}
return len;
}
+
+void
+Playlist::reconnect ()
+{
+ for (list<boost::signals2::connection>::iterator i = _content_connections.begin(); i != _content_connections.end(); ++i) {
+ i->disconnect ();
+ }
+
+ _content_connections.clear ();
+
+ for (ContentList::iterator i = _content.begin(); i != _content.end(); ++i) {
+ _content_connections.push_back ((*i)->Changed.connect (bind (&Playlist::content_changed, this, _1, _2)));
+ }
+}
+
+Time
+Playlist::video_end () const
+{
+ Time end = 0;
+ for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+ if (dynamic_pointer_cast<const VideoContent> (*i)) {
+ end = max (end, (*i)->end ());
+ }
+ }
+
+ return end;
+}
+
+void
+Playlist::set_sequence_video (bool s)
+{
+ _sequence_video = s;
+}
+
+bool
+ContentSorter::operator() (shared_ptr<Content> a, shared_ptr<Content> b)
+{
+ return a->start() < b->start();
+}