diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-06-24 22:23:41 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-06-24 22:23:41 +0100 |
| commit | 93d06f01683ec7ad351db329627b02d4fb23f4fa (patch) | |
| tree | dd6f1a265b2965e8c177a7e14afa639bd699ae91 /src | |
| parent | 9e523d8a4062ad52330dff6c2ba50e54184c9bb2 (diff) | |
| parent | 69f188e13db64d8a3b17e49351d0be0ac3676b99 (diff) | |
Merge.
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset.cc | 7 | ||||
| -rw-r--r-- | src/asset.h | 1 | ||||
| -rw-r--r-- | src/data.cc | 42 | ||||
| -rw-r--r-- | src/data.h | 4 | ||||
| -rw-r--r-- | src/dcp.cc | 2 | ||||
| -rw-r--r-- | src/font_asset.cc | 4 | ||||
| -rw-r--r-- | src/font_asset.h | 2 | ||||
| -rw-r--r-- | src/interop_subtitle_asset.cc | 23 | ||||
| -rw-r--r-- | src/interop_subtitle_asset.h | 2 | ||||
| -rw-r--r-- | src/smpte_subtitle_asset.cc | 23 | ||||
| -rw-r--r-- | src/subtitle_asset.cc | 27 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 30 | ||||
| -rw-r--r-- | src/wscript | 3 |
13 files changed, 111 insertions, 59 deletions
diff --git a/src/asset.cc b/src/asset.cc index 3d397831..6a15f216 100644 --- a/src/asset.cc +++ b/src/asset.cc @@ -49,6 +49,13 @@ Asset::Asset (boost::filesystem::path file) } +Asset::Asset (string id, boost::filesystem::path file) + : Object (id) + , _file (file) +{ + +} + void Asset::write_to_pkl (xmlpp::Node* node, Standard standard) const { diff --git a/src/asset.h b/src/asset.h index 12fe2657..f5b60bf7 100644 --- a/src/asset.h +++ b/src/asset.h @@ -47,6 +47,7 @@ class Asset : public Object public: Asset (); Asset (boost::filesystem::path file); + Asset (std::string id, boost::filesystem::path file); virtual bool equals ( boost::shared_ptr<const Asset> other, diff --git a/src/data.cc b/src/data.cc new file mode 100644 index 00000000..7f390ead --- /dev/null +++ b/src/data.cc @@ -0,0 +1,42 @@ +/* + Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + + This program 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. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "data.h" +#include "util.h" +#include "exceptions.h" +#include <cstdio> + +using namespace dcp; + +Data::Data (boost::filesystem::path file) +{ + FILE* f = fopen_boost (file, "rb"); + if (!f) { + throw FileError ("could not open file for reading", file, errno); + } + + size = boost::filesystem::file_size (file); + data.reset (new uint8_t[size]); + size_t const read = fread (data.get(), 1, size, f); + fclose (f); + + if (read != size) { + throw FileError ("could not read file", file, -1); + } +} @@ -18,6 +18,8 @@ */ #include <boost/shared_array.hpp> +#include <boost/filesystem.hpp> +#include <stdint.h> namespace dcp { @@ -31,6 +33,8 @@ public: , size (size_) {} + Data (boost::filesystem::path file); + boost::shared_array<uint8_t> data; boost::uintmax_t size; }; @@ -176,7 +176,7 @@ DCP::read (bool keep_going, ReadErrors* errors) throw DCPReadError ("Unknown MXF essence type"); } } else if (boost::filesystem::extension (path) == ".ttf") { - other_assets.push_back (shared_ptr<FontAsset> (new FontAsset (path))); + other_assets.push_back (shared_ptr<FontAsset> (new FontAsset (i->first, path))); } } diff --git a/src/font_asset.cc b/src/font_asset.cc index 8f8e4ff3..2cd03f27 100644 --- a/src/font_asset.cc +++ b/src/font_asset.cc @@ -27,8 +27,8 @@ using std::string; using namespace dcp; -FontAsset::FontAsset (boost::filesystem::path file) - : Asset (file) +FontAsset::FontAsset (string id, boost::filesystem::path file) + : Asset (id, file) { } diff --git a/src/font_asset.h b/src/font_asset.h index d0999322..8abd6047 100644 --- a/src/font_asset.h +++ b/src/font_asset.h @@ -31,7 +31,7 @@ namespace dcp { class FontAsset : public Asset { public: - FontAsset (boost::filesystem::path file); + FontAsset (std::string id, boost::filesystem::path file); private: std::string pkl_type (Standard standard) const; diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index ffa7d50b..620fed73 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -90,10 +90,10 @@ InteropSubtitleAsset::xml_as_string () const } void -InteropSubtitleAsset::add_font (string id, boost::filesystem::path file) +InteropSubtitleAsset::add_font (string load_id, boost::filesystem::path file) { - add_font_data (id, file); - _load_font_nodes.push_back (shared_ptr<InteropLoadFontNode> (new InteropLoadFontNode (id, file.leaf().string ()))); + _fonts.push_back (Font (load_id, make_uuid(), file)); + _load_font_nodes.push_back (shared_ptr<InteropLoadFontNode> (new InteropLoadFontNode (load_id, file.leaf().string ()))); } bool @@ -163,10 +163,13 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const if (!f) { throw FileError ("could not open font file for writing", file, errno); } - map<string, FileData>::const_iterator j = _fonts.find (i->id); + list<Font>::const_iterator j = _fonts.begin (); + while (j != _fonts.end() && j->load_id != i->id) { + ++j; + } if (j != _fonts.end ()) { - fwrite (j->second.data.get(), 1, j->second.size, f); - j->second.file = file; + fwrite (j->data.data.get(), 1, j->data.size, f); + j->file = file; } fclose (f); } @@ -183,7 +186,7 @@ InteropSubtitleAsset::resolve_fonts (list<shared_ptr<Object> > objects) BOOST_FOREACH (shared_ptr<InteropLoadFontNode> j, _load_font_nodes) { if (j->uri == font->file().leaf().string ()) { - add_font_data (j->id, font->file ()); + _fonts.push_back (Font (j->id, i->id(), font->file ())); } } } @@ -192,8 +195,8 @@ InteropSubtitleAsset::resolve_fonts (list<shared_ptr<Object> > objects) void InteropSubtitleAsset::add_font_assets (list<shared_ptr<Asset> >& assets) { - for (map<string, FileData>::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { - DCP_ASSERT (i->second.file); - assets.push_back (shared_ptr<FontAsset> (new FontAsset (i->second.file.get ()))); + BOOST_FOREACH (Font const & i, _fonts) { + DCP_ASSERT (i.file); + assets.push_back (shared_ptr<FontAsset> (new FontAsset (i.uuid, i.file.get ()))); } } diff --git a/src/interop_subtitle_asset.h b/src/interop_subtitle_asset.h index 41ed83b3..8690d11c 100644 --- a/src/interop_subtitle_asset.h +++ b/src/interop_subtitle_asset.h @@ -47,7 +47,7 @@ public: std::list<boost::shared_ptr<LoadFontNode> > load_font_nodes () const; - void add_font (std::string id, boost::filesystem::path file); + void add_font (std::string load_id, boost::filesystem::path file); Glib::ustring xml_as_string () const; void write (boost::filesystem::path path) const; diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 8ea68362..8c0ce111 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -144,7 +144,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file) } if (j != _load_font_nodes.end ()) { - _fonts[(*j)->id] = FileData (data, buffer.Size ()); + _fonts.push_back (Font ((*j)->id, (*j)->urn, Data (data, buffer.Size ()))); } } } @@ -217,7 +217,10 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const descriptor.EncodingName = "UTF-8"; BOOST_FOREACH (shared_ptr<dcp::SMPTELoadFontNode> i, _load_font_nodes) { - map<string, FileData>::const_iterator j = _fonts.find (i->id); + list<Font>::const_iterator j = _fonts.begin (); + while (j != _fonts.end() && j->load_id != i->id) { + ++j; + } if (j != _fonts.end ()) { ASDCP::TimedText::TimedTextResourceDescriptor res; unsigned int c; @@ -245,11 +248,14 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const } BOOST_FOREACH (shared_ptr<dcp::SMPTELoadFontNode> i, _load_font_nodes) { - map<string, FileData>::const_iterator j = _fonts.find (i->id); + list<Font>::const_iterator j = _fonts.begin (); + while (j != _fonts.end() && j->load_id != i->id) { + ++j; + } if (j != _fonts.end ()) { ASDCP::TimedText::FrameBuffer buffer; - buffer.SetData (j->second.data.get(), j->second.size); - buffer.Size (j->second.size); + buffer.SetData (j->data.data.get(), j->data.size); + buffer.Size (j->data.size); r = writer.WriteAncillaryResource (buffer); if (ASDCP_FAILURE (r)) { boost::throw_exception (MXFFileError ("could not write font to timed text resource", p.string(), r)); @@ -341,8 +347,9 @@ SMPTESubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions } void -SMPTESubtitleAsset::add_font (string id, boost::filesystem::path file) +SMPTESubtitleAsset::add_font (string load_id, boost::filesystem::path file) { - add_font_data (id, file); - _load_font_nodes.push_back (shared_ptr<SMPTELoadFontNode> (new SMPTELoadFontNode (id, make_uuid ()))); + string const uuid = make_uuid (); + _fonts.push_back (Font (load_id, uuid, file)); + _load_font_nodes.push_back (shared_ptr<SMPTELoadFontNode> (new SMPTELoadFontNode (load_id, uuid))); } diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 8d492727..c0ffb75a 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -30,6 +30,7 @@ #include <libxml++/nodes/element.h> #include <boost/algorithm/string.hpp> #include <boost/shared_array.hpp> +#include <boost/foreach.hpp> #include <fstream> using std::string; @@ -308,32 +309,12 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, strin } } -void -SubtitleAsset::add_font_data (string id, boost::filesystem::path file) -{ - boost::uintmax_t size = boost::filesystem::file_size (file); - FILE* f = fopen_boost (file, "rb"); - if (!f) { - throw FileError ("could not open font file for reading", file, errno); - } - - shared_array<uint8_t> data (new uint8_t[size]); - size_t const read = fread (data.get(), 1, size, f); - fclose (f); - - if (read != size) { - throw FileError ("could not read font file", file, -1); - } - - _fonts[id] = FileData (data, size); -} - map<string, Data> -SubtitleAsset::fonts () const +SubtitleAsset::fonts_with_load_ids () const { map<string, Data> out; - for (map<string, FileData>::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { - out[i->first] = i->second; + BOOST_FOREACH (Font const & i, _fonts) { + out[i.load_id] = i.data; } return out; } diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index cc27f958..44ac455f 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -70,7 +70,7 @@ public: void add (SubtitleString); virtual void add_font (std::string id, boost::filesystem::path file) = 0; - std::map<std::string, Data> fonts () const; + std::map<std::string, Data> fonts_with_load_ids () const; virtual void write (boost::filesystem::path) const = 0; virtual Glib::ustring xml_as_string () const = 0; @@ -85,28 +85,34 @@ protected: void parse_subtitles (boost::shared_ptr<cxml::Document> xml, std::list<boost::shared_ptr<FontNode> > font_nodes); void subtitles_as_xml (xmlpp::Element* root, int time_code_rate, std::string xmlns) const; - void add_font_data (std::string id, boost::filesystem::path file); /** All our subtitles, in no particular order */ std::list<SubtitleString> _subtitles; - class FileData : public Data { + class Font + { public: - FileData () {} + Font (std::string load_id_, std::string uuid_, boost::filesystem::path file_) + : load_id (load_id_) + , uuid (uuid_) + , data (file_) + , file (file_) + {} - FileData (boost::shared_array<uint8_t> data_, boost::uintmax_t size_) - : Data (data_, size_) + Font (std::string load_id_, std::string uuid_, Data data_) + : load_id (load_id_) + , uuid (uuid_) + , data (data_) {} - /** .ttf file that this data was last written to */ + std::string load_id; + std::string uuid; + Data data; + /** .ttf file that this data was last written to, if applicable */ mutable boost::optional<boost::filesystem::path> file; }; - /** Font data, keyed by a subclass-dependent identifier. - * For Interop, the string is the font ID from the subtitle file. - * For SMPTE, the string is the font's URN from the subtitle file. - */ - std::map<std::string, FileData> _fonts; + std::list<Font> _fonts; private: /** @struct ParseState diff --git a/src/wscript b/src/wscript index bf28183e..a3f56b82 100644 --- a/src/wscript +++ b/src/wscript @@ -8,7 +8,8 @@ def build(bld): colour_conversion.cc colour_matrix.cc cpl.cc - dcp.cc + data.cc + dcp.cc dcp_time.cc decrypted_kdm.cc decrypted_kdm_key.cc |
