diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-07-29 15:53:26 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-07-29 15:53:26 +0100 |
| commit | 8ef91325f4e565d04493bc05202f8e066b5e3e0c (patch) | |
| tree | 162fbc2bef7243ff1f650cd7e91c851e783ba8c6 /src | |
| parent | e02bf26f284c6efc72593e6b4a251301144e5d0b (diff) | |
Basics of allowing custom filenames for DCP components.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dcp.cc | 18 | ||||
| -rw-r--r-- | src/dcp.h | 5 | ||||
| -rw-r--r-- | src/filename_format.cc | 44 | ||||
| -rw-r--r-- | src/filename_format.h | 50 | ||||
| -rw-r--r-- | src/name_format.cc | 112 | ||||
| -rw-r--r-- | src/name_format.h | 95 | ||||
| -rw-r--r-- | src/wscript | 4 |
7 files changed, 321 insertions, 7 deletions
@@ -303,10 +303,10 @@ DCP::add (DecryptedKDM const & kdm) } boost::filesystem::path -DCP::write_pkl (Standard standard, string pkl_uuid, XMLMetadata metadata, shared_ptr<const CertificateChain> signer) const +DCP::write_pkl (string file, Standard standard, string pkl_uuid, XMLMetadata metadata, shared_ptr<const CertificateChain> signer) const { boost::filesystem::path p = _directory; - p /= String::compose ("pkl_%1.xml", pkl_uuid); + p /= file; xmlpp::Document doc; xmlpp::Element* pkl; @@ -458,16 +458,22 @@ void DCP::write_xml ( Standard standard, XMLMetadata metadata, - shared_ptr<const CertificateChain> signer + shared_ptr<const CertificateChain> signer, + FilenameFormat filename_format ) { BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) { - string const filename = "cpl_" + i->id() + ".xml"; - i->write_xml (_directory / filename, standard, signer); + NameFormat::Map values; + values["type"] = "cpl"; + values["id"] = i->id(); + i->write_xml (_directory / (filename_format.get(values) + ".xml"), standard, signer); } string const pkl_uuid = make_uuid (); - boost::filesystem::path const pkl_path = write_pkl (standard, pkl_uuid, metadata, signer); + NameFormat::Map values; + values["type"] = "pkl"; + values["id"] = pkl_uuid; + boost::filesystem::path const pkl_path = write_pkl (filename_format.get(values) + ".xml", standard, pkl_uuid, metadata, signer); write_volindex (standard); write_assetmap (standard, pkl_uuid, boost::filesystem::file_size (pkl_path), metadata); @@ -41,6 +41,7 @@ #include "types.h" #include "certificate.h" #include "metadata.h" +#include "filename_format.h" #include <boost/shared_ptr.hpp> #include <boost/signals2.hpp> #include <string> @@ -111,7 +112,8 @@ public: void write_xml ( Standard standard, XMLMetadata metadata = XMLMetadata (), - boost::shared_ptr<const CertificateChain> signer = boost::shared_ptr<const CertificateChain> () + boost::shared_ptr<const CertificateChain> signer = boost::shared_ptr<const CertificateChain> (), + FilenameFormat filename_format = FilenameFormat("%t_%i") ); void resolve_refs (std::list<boost::shared_ptr<Asset> > assets); @@ -127,6 +129,7 @@ private: * @param pkl_uuid UUID to use. */ boost::filesystem::path write_pkl ( + std::string file, Standard standard, std::string pkl_uuid, XMLMetadata metadata, diff --git a/src/filename_format.cc b/src/filename_format.cc new file mode 100644 index 00000000..37fc12a0 --- /dev/null +++ b/src/filename_format.cc @@ -0,0 +1,44 @@ +/* + Copyright (C) 2016 Carl Hetherington <cth@carlh.net> + + This file is part of libdcp. + + libdcp 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. + + libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>. + + In addition, as a special exception, the copyright holders give + permission to link the code of portions of this program with the + OpenSSL library under certain conditions as described in each + individual source file, and distribute linked combinations + including the two. + + You must obey the GNU General Public License in all respects + for all of the code used other than OpenSSL. If you modify + file(s) with this exception, you may extend this exception to your + version of the file(s), but you are not obligated to do so. If you + do not wish to do so, delete this exception statement from your + version. If you delete this exception statement from all source + files in the program, then also delete it here. +*/ + +#include "filename_format.h" + +using std::string; +using namespace dcp; + +FilenameFormat::FilenameFormat (string specification) + : NameFormat (specification) +{ + add ("type", 't', "asset type (j2c/pcm/sub/pkl/cpl)"); + add ("id", 'i', "unique ID"); +} diff --git a/src/filename_format.h b/src/filename_format.h new file mode 100644 index 00000000..836c643a --- /dev/null +++ b/src/filename_format.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2016 Carl Hetherington <cth@carlh.net> + + This file is part of libdcp. + + libdcp 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. + + libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>. + + In addition, as a special exception, the copyright holders give + permission to link the code of portions of this program with the + OpenSSL library under certain conditions as described in each + individual source file, and distribute linked combinations + including the two. + + You must obey the GNU General Public License in all respects + for all of the code used other than OpenSSL. If you modify + file(s) with this exception, you may extend this exception to your + version of the file(s), but you are not obligated to do so. If you + do not wish to do so, delete this exception statement from your + version. If you delete this exception statement from all source + files in the program, then also delete it here. +*/ + +#ifndef LIBDCP_FILENAME_FORMAT +#define LIBDCP_FILENAME_FORMAT + +#include "name_format.h" + +namespace dcp { + +class FilenameFormat : public NameFormat +{ +public: + FilenameFormat () {} + FilenameFormat (std::string specification); +}; + +} + +#endif diff --git a/src/name_format.cc b/src/name_format.cc new file mode 100644 index 00000000..1dc1135d --- /dev/null +++ b/src/name_format.cc @@ -0,0 +1,112 @@ +/* + Copyright (C) 2016 Carl Hetherington <cth@carlh.net> + + This file is part of libdcp. + + libdcp 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. + + libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>. + + In addition, as a special exception, the copyright holders give + permission to link the code of portions of this program with the + OpenSSL library under certain conditions as described in each + individual source file, and distribute linked combinations + including the two. + + You must obey the GNU General Public License in all respects + for all of the code used other than OpenSSL. If you modify + file(s) with this exception, you may extend this exception to your + version of the file(s), but you are not obligated to do so. If you + do not wish to do so, delete this exception statement from your + version. If you delete this exception statement from all source + files in the program, then also delete it here. +*/ + +#include "name_format.h" +#include <boost/optional.hpp> +#include <boost/foreach.hpp> + +using std::string; +using std::map; +using boost::optional; +using namespace dcp; + +static char +filter (char c) +{ + if (c == '/' || c == ':') { + c = '-'; + } else if (c == ' ') { + c = '_'; + } + + return c; +} + +static string +filter (string c) +{ + string o; + + for (size_t i = 0; i < c.length(); ++i) { + o += filter (c[i]); + } + + return o; +} + +void +NameFormat::add (string name, char placeholder, string title) +{ + _components.push_back (Component (name, placeholder, title)); +} + +optional<NameFormat::Component> +NameFormat::component_by_placeholder (char p) const +{ + BOOST_FOREACH (Component const & i, _components) { + if (i.placeholder == p) { + return i; + } + } + + return optional<Component> (); +} + +string +NameFormat::get (Map values) const +{ + string result; + for (size_t i = 0; i < _specification.length(); ++i) { + bool done = false; + if (_specification[i] == '%' && (i < _specification.length() - 1)) { + optional<Component> c = component_by_placeholder (_specification[i + 1]); + if (c) { + result += filter (values[c->name]); + ++i; + done = true; + } + } + + if (!done) { + result += filter (_specification[i]); + } + } + + return result; +} + +bool +dcp::operator== (NameFormat const & a, NameFormat const & b) +{ + return a.specification() == b.specification(); +} diff --git a/src/name_format.h b/src/name_format.h new file mode 100644 index 00000000..c2a71280 --- /dev/null +++ b/src/name_format.h @@ -0,0 +1,95 @@ +/* + Copyright (C) 2016 Carl Hetherington <cth@carlh.net> + + This file is part of libdcp. + + libdcp 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. + + libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>. + + In addition, as a special exception, the copyright holders give + permission to link the code of portions of this program with the + OpenSSL library under certain conditions as described in each + individual source file, and distribute linked combinations + including the two. + + You must obey the GNU General Public License in all respects + for all of the code used other than OpenSSL. If you modify + file(s) with this exception, you may extend this exception to your + version of the file(s), but you are not obligated to do so. If you + do not wish to do so, delete this exception statement from your + version. If you delete this exception statement from all source + files in the program, then also delete it here. +*/ + +#ifndef LIBDCP_NAME_FORMAT +#define LIBDCP_NAME_FORMAT + +#include <boost/optional.hpp> +#include <map> +#include <list> + +namespace dcp { + +class NameFormat +{ +public: + struct Component + { + Component (std::string name_, char placeholder_, std::string title_) + : name (name_) + , placeholder (placeholder_) + , title (title_) + {} + + std::string name; + char placeholder; + std::string title; + }; + + std::list<Component> components () const { + return _components; + } + + std::string specification () const { + return _specification; + } + + void set_specification (std::string specification) { + _specification = specification; + } + + typedef std::map<std::string, std::string> Map; + + std::string get (Map) const; + +protected: + NameFormat () {} + + NameFormat (std::string specification) + : _specification (specification) + {} + + void add (std::string name, char placeholder, std::string title); + +private: + boost::optional<NameFormat::Component> component_by_placeholder (char p) const; + + std::list<Component> _components; + std::string _specification; +}; + +extern bool operator== (NameFormat const & a, NameFormat const & b); + +} + +#endif diff --git a/src/wscript b/src/wscript index f9f769db..43fc0e69 100644 --- a/src/wscript +++ b/src/wscript @@ -51,6 +51,7 @@ def build(bld): encrypted_kdm.cc exceptions.cc file.cc + filename_format.cc font_asset.cc font_node.cc gamma_transfer_function.cc @@ -66,6 +67,7 @@ def build(bld): mono_picture_asset_writer.cc mono_picture_frame.cc mxf.cc + name_format.cc object.cc openjpeg_image.cc picture_asset.cc @@ -119,6 +121,7 @@ def build(bld): decrypted_kdm_key.h encrypted_kdm.h exceptions.h + filename_format.h font_asset.h gamma_transfer_function.h interop_load_font_node.h @@ -133,6 +136,7 @@ def build(bld): mono_picture_frame.h modified_gamma_transfer_function.h mxf.h + name_format.h object.h openjpeg_image.h picture_asset.h |
