diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-02-28 00:03:01 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-02-29 21:51:47 +0100 |
| commit | d3f97ca7ca2877689f4ed59482e935431d43f027 (patch) | |
| tree | d4d43304982d6122a009b747eb3eaedc28727517 /src/lib | |
| parent | adeab682b76138d7a05bab3943af23cd57e2bc57 (diff) | |
Copy swaroop_ playlist editor stuff back to main DoM.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/spl.cc | 71 | ||||
| -rw-r--r-- | src/lib/spl.h | 112 | ||||
| -rw-r--r-- | src/lib/spl_entry.cc | 72 | ||||
| -rw-r--r-- | src/lib/spl_entry.h | 63 | ||||
| -rw-r--r-- | src/lib/wscript | 2 |
5 files changed, 320 insertions, 0 deletions
diff --git a/src/lib/spl.cc b/src/lib/spl.cc new file mode 100644 index 000000000..02ed966a4 --- /dev/null +++ b/src/lib/spl.cc @@ -0,0 +1,71 @@ +/* + Copyright (C) 2018-2019 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "swaroop_spl.h" +#include "content_store.h" +#include <libcxml/cxml.h> +#include <dcp/raw_convert.h> +#include <libxml++/libxml++.h> +#include <boost/foreach.hpp> +#include <iostream> + +using std::cout; +using std::string; +using boost::shared_ptr; +using dcp::raw_convert; + +void +SPL::read (boost::filesystem::path path, ContentStore* store) +{ + _path = path; + + _spl.clear (); + _missing = false; + cxml::Document doc ("SPL"); + doc.read_file (path); + _id = doc.string_child("Id"); + BOOST_FOREACH (cxml::ConstNodePtr i, doc.node_children("Entry")) { + shared_ptr<Content> c = store->get(i->string_child("Digest")); + if (c) { + add (SPLEntry(c, i)); + } else { + _missing = true; + } + } + + _allowed_shows = doc.optional_number_child<int>("AllowedShows"); +} + +void +SPL::write (boost::filesystem::path path) const +{ + _path = path; + + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("SPL"); + root->add_child("Id")->add_child_text (_id); + BOOST_FOREACH (SPLEntry i, _spl) { + i.as_xml (root->add_child("Entry")); + } + if (_allowed_shows) { + root->add_child("AllowedShows")->add_child_text(raw_convert<string>(*_allowed_shows)); + } + doc.write_to_file_formatted (path.string()); +} diff --git a/src/lib/spl.h b/src/lib/spl.h new file mode 100644 index 000000000..308f5286d --- /dev/null +++ b/src/lib/spl.h @@ -0,0 +1,112 @@ +/* + Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#ifndef DCPOMATIC_SPL_H +#define DCPOMATIC_SPL_H + +#include "swaroop_spl_entry.h" +#include <dcp/util.h> + +class ContentStore; + +class SPL +{ +public: + SPL () + : _id (dcp::make_uuid()) + , _missing (false) + {} + + void add (SPLEntry e) { + _spl.push_back (e); + } + + void remove (std::size_t index) { + _spl.erase (_spl.begin() + index); + } + + std::vector<SPLEntry> const & get () const { + return _spl; + } + + SPLEntry & operator[] (std::size_t index) { + return _spl[index]; + } + + SPLEntry const & operator[] (std::size_t index) const { + return _spl[index]; + } + + void read (boost::filesystem::path path, ContentStore* store); + void write (boost::filesystem::path path) const; + + std::string id () const { + return _id; + } + + boost::optional<boost::filesystem::path> path () const { + return _path; + } + + std::string name () const { + if (!_path) { + return ""; + } + return _path->filename().string(); + } + + bool missing () const { + return _missing; + } + + boost::optional<int> allowed_shows () const { + return _allowed_shows; + } + + bool have_allowed_shows () const { + return !_allowed_shows || *_allowed_shows > 0; + } + + void set_allowed_shows (int s) { + _allowed_shows = s; + } + + void unset_allowed_shows () { + _allowed_shows = boost::optional<int>(); + } + + void decrement_allowed_shows () { + if (_allowed_shows) { + (*_allowed_shows)--; + } + + } + +private: + std::string _id; + mutable boost::optional<boost::filesystem::path> _path; + std::vector<SPLEntry> _spl; + /** true if any content was missing when read() was last called on this SPL */ + bool _missing; + /** number of times left that the player will allow this playlist to be played (unset means infinite shows) */ + boost::optional<int> _allowed_shows; +}; + +#endif diff --git a/src/lib/spl_entry.cc b/src/lib/spl_entry.cc new file mode 100644 index 000000000..ed5a469ac --- /dev/null +++ b/src/lib/spl_entry.cc @@ -0,0 +1,72 @@ +/* + Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "swaroop_spl_entry.h" +#include "dcp_content.h" +#include "dcpomatic_assert.h" +#include <libxml++/libxml++.h> + +using boost::shared_ptr; +using boost::dynamic_pointer_cast; + +SPLEntry::SPLEntry (shared_ptr<Content> content) + : skippable (false) + , disable_timeline (false) + , stop_after_play (false) +{ + construct (content); +} + +SPLEntry::SPLEntry (shared_ptr<Content> content, cxml::ConstNodePtr node) + : skippable (node->bool_child("Skippable")) + , disable_timeline (node->bool_child("DisableTimeline")) + , stop_after_play (node->bool_child("StopAfterPlay")) +{ + construct (content); +} + +void +SPLEntry::construct (shared_ptr<Content> c) +{ + content = c; + shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (content); + digest = content->digest (); + if (dcp) { + name = dcp->name (); + DCPOMATIC_ASSERT (dcp->cpl()); + id = *dcp->cpl(); + kind = dcp->content_kind().get_value_or(dcp::FEATURE); + type = DCP; + encrypted = dcp->encrypted (); + } else { + name = content->path(0).filename().string(); + type = ECINEMA; + kind = dcp::FEATURE; + } +} + +void +SPLEntry::as_xml (xmlpp::Element* e) +{ + e->add_child("Digest")->add_child_text(digest); + e->add_child("Skippable")->add_child_text(skippable ? "1" : "0"); + e->add_child("DisableTimeline")->add_child_text(disable_timeline ? "1" : "0"); + e->add_child("StopAfterPlay")->add_child_text(stop_after_play ? "1" : "0"); +} diff --git a/src/lib/spl_entry.h b/src/lib/spl_entry.h new file mode 100644 index 000000000..75e0b5223 --- /dev/null +++ b/src/lib/spl_entry.h @@ -0,0 +1,63 @@ +/* + Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#ifndef DCPOMATIC_SWAROOP_SPL_ENTRY_H +#define DCPOMATIC_SWAROOP_SPL_ENTRY_H + +#include <libcxml/cxml.h> +#include <dcp/types.h> +#include <boost/shared_ptr.hpp> + +namespace xmlpp { + class Element; +} + +class Content; + +class SPLEntry +{ +public: + SPLEntry (boost::shared_ptr<Content> content); + SPLEntry (boost::shared_ptr<Content> content, cxml::ConstNodePtr node); + + void as_xml (xmlpp::Element* e); + + boost::shared_ptr<Content> content; + std::string name; + /** Digest of this content */ + std::string digest; + /** CPL ID or something else for MP4 (?) */ + std::string id; + dcp::ContentKind kind; + enum Type { + DCP, + ECINEMA + }; + Type type; + bool encrypted; + bool skippable; + bool disable_timeline; + bool stop_after_play; + +private: + void construct (boost::shared_ptr<Content> content); +}; + +#endif diff --git a/src/lib/wscript b/src/lib/wscript index 6ef41e91e..a37d873a8 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -150,6 +150,8 @@ sources = """ server.cc shuffler.cc state.cc + spl.cc + spl_entry.cc string_log_entry.cc string_text_file.cc string_text_file_content.cc |
