diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/interop_subtitle_asset.cc | 7 | ||||
| -rw-r--r-- | src/object.h | 2 | ||||
| -rw-r--r-- | src/smpte_subtitle_asset.cc | 30 | ||||
| -rw-r--r-- | src/subtitle_asset.cc | 10 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 5 | ||||
| -rw-r--r-- | src/subtitle_asset_internal.cc | 12 | ||||
| -rw-r--r-- | src/subtitle_asset_internal.h | 7 |
7 files changed, 56 insertions, 17 deletions
diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index 02e2d75b..2ef82c90 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -39,9 +39,11 @@ #include "util.h" #include "font_asset.h" #include "dcp_assert.h" +#include "compose.hpp" #include "subtitle_image.h" #include <libxml++/libxml++.h> #include <boost/foreach.hpp> +#include <boost/weak_ptr.hpp> #include <cmath> #include <cstdio> @@ -177,11 +179,12 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const _file = p; /* Image subtitles */ - int n = 0; BOOST_FOREACH (shared_ptr<dcp::Subtitle> i, _subtitles) { shared_ptr<dcp::SubtitleImage> im = dynamic_pointer_cast<dcp::SubtitleImage> (i); if (im) { - im->png_image().write (p.parent_path() / image_subtitle_file (n++)); + ImageUUIDMap::const_iterator uuid = _image_subtitle_uuid.find(im); + DCP_ASSERT (uuid != _image_subtitle_uuid.end()); + im->png_image().write (p.parent_path() / String::compose("%1.png", uuid->second)); } } diff --git a/src/object.h b/src/object.h index b2d0ad35..d44f1be2 100644 --- a/src/object.h +++ b/src/object.h @@ -46,6 +46,7 @@ class write_interop_subtitle_test2; class write_interop_subtitle_test3; class write_smpte_subtitle_test; class write_smpte_subtitle_test2; +class write_smpte_subtitle_test3; namespace dcp { @@ -70,6 +71,7 @@ protected: friend struct ::write_interop_subtitle_test3; friend struct ::write_smpte_subtitle_test; friend struct ::write_smpte_subtitle_test2; + friend struct ::write_smpte_subtitle_test3; /** ID */ std::string _id; diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 07d8f7eb..267ff27e 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -44,7 +44,7 @@ #include "util.h" #include "compose.hpp" #include "crypto_context.h" -#include "crypto_context.h" +#include "subtitle_image.h" #include <asdcp/AS_DCP.h> #include <asdcp/KM_util.h> #include <libxml++/libxml++.h> @@ -304,6 +304,8 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const descriptor.EditRate = ASDCP::Rational (_edit_rate.numerator, _edit_rate.denominator); descriptor.EncodingName = "UTF-8"; + /* Font references */ + BOOST_FOREACH (shared_ptr<dcp::SMPTELoadFontNode> i, _load_font_nodes) { list<Font>::const_iterator j = _fonts.begin (); while (j != _fonts.end() && j->load_id != i->id) { @@ -319,6 +321,17 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const } } + /* Image subtitle references */ + + for (ImageUUIDMap::const_iterator i = _image_subtitle_uuid.begin(); i != _image_subtitle_uuid.end(); ++i) { + ASDCP::TimedText::TimedTextResourceDescriptor res; + unsigned int c; + Kumu::hex2bin (i->second.c_str(), res.ResourceID, Kumu::UUID_Length, &c); + DCP_ASSERT (c == Kumu::UUID_Length); + res.Type = ASDCP::TimedText::MT_PNG; + descriptor.ResourceList.push_back (res); + } + descriptor.NamespaceName = "dcst"; memcpy (descriptor.AssetID, writer_info.AssetUUID, ASDCP::UUIDlen); descriptor.ContainerDuration = _intrinsic_duration; @@ -329,12 +342,13 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const boost::throw_exception (FileError ("could not open subtitle MXF for writing", p.string(), r)); } - /* XXX: no encryption */ r = writer.WriteTimedTextResource (xml_as_string (), enc.context(), enc.hmac()); if (ASDCP_FAILURE (r)) { boost::throw_exception (MXFFileError ("could not write XML to timed text resource", p.string(), r)); } + /* Font payload */ + BOOST_FOREACH (shared_ptr<dcp::SMPTELoadFontNode> i, _load_font_nodes) { list<Font>::const_iterator j = _fonts.begin (); while (j != _fonts.end() && j->load_id != i->id) { @@ -351,6 +365,18 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const } } + /* Image subtitle payload */ + + for (ImageUUIDMap::const_iterator i = _image_subtitle_uuid.begin(); i != _image_subtitle_uuid.end(); ++i) { + ASDCP::TimedText::FrameBuffer buffer; + buffer.SetData (i->first->png_image().data().get(), i->first->png_image().size()); + buffer.Size (i->first->png_image().size()); + r = writer.WriteAncillaryResource (buffer, enc.context(), enc.hmac()); + if (ASDCP_FAILURE(r)) { + boost::throw_exception (MXFFileError ("could not write PNG data to timed text resource", p.string(), r)); + } + } + writer.Finalize (); _file = p; diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index f93ffa85..5a096f20 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -373,6 +373,11 @@ void SubtitleAsset::add (shared_ptr<Subtitle> s) { _subtitles.push_back (s); + + shared_ptr<SubtitleImage> si = dynamic_pointer_cast<SubtitleImage> (s); + if (si) { + _image_subtitle_uuid[si] = make_uuid (); + } } Time @@ -573,8 +578,10 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, S shared_ptr<SubtitleImage> ii = dynamic_pointer_cast<SubtitleImage>(i); if (ii) { text.reset (); + ImageUUIDMap::const_iterator uuid = _image_subtitle_uuid.find(ii); + DCP_ASSERT (uuid != _image_subtitle_uuid.end()); subtitle->children.push_back ( - shared_ptr<order::Image> (new order::Image (subtitle, ii->png_image(), ii->h_align(), ii->h_position(), ii->v_align(), ii->v_position())) + shared_ptr<order::Image> (new order::Image (subtitle, uuid->second, ii->png_image(), ii->h_align(), ii->h_position(), ii->v_align(), ii->v_position())) ); } } @@ -589,7 +596,6 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, S context.time_code_rate = time_code_rate; context.standard = standard; context.spot_number = 1; - context.image_number = 0; root->write_xml (xml_root, context); } diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 1108514a..31cca185 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -56,6 +56,7 @@ namespace dcp { class SubtitleString; +class SubtitleImage; class FontNode; class TextNode; class SubtitleNode; @@ -164,6 +165,10 @@ protected: /** TTF font data that we need */ std::list<Font> _fonts; + /** Map of image subtitles to UUIDs */ + typedef std::map<boost::shared_ptr<dcp::SubtitleImage>, std::string> ImageUUIDMap; + ImageUUIDMap _image_subtitle_uuid; + private: friend struct ::pull_fonts_test1; friend struct ::pull_fonts_test2; diff --git a/src/subtitle_asset_internal.cc b/src/subtitle_asset_internal.cc index 13bdf6ab..7b9e18e9 100644 --- a/src/subtitle_asset_internal.cc +++ b/src/subtitle_asset_internal.cc @@ -238,13 +238,11 @@ order::Image::as_xml (xmlpp::Element* parent, Context& context) const xmlpp::Element* e = parent->add_child ("Image", context.xmlns()); position_align (e, context, _h_align, _h_position, _v_align, _v_position); - e->add_child_text (image_subtitle_file (context.image_number++)); + if (context.standard == SMPTE) { + e->add_child_text (_id); + } else { + e->add_child_text (_id + ".png"); + } return e; } - -string -dcp::image_subtitle_file (int n) -{ - return String::compose ("sub_%1.png", n); -} diff --git a/src/subtitle_asset_internal.h b/src/subtitle_asset_internal.h index e2b1602e..b0034743 100644 --- a/src/subtitle_asset_internal.h +++ b/src/subtitle_asset_internal.h @@ -60,7 +60,6 @@ struct Context int time_code_rate; Standard standard; int spot_number; - int image_number; }; class Font @@ -168,9 +167,10 @@ private: class Image : public Part { public: - Image (boost::shared_ptr<Part> parent, Data png_data, HAlign h_align, float h_position, VAlign v_align, float v_position) + Image (boost::shared_ptr<Part> parent, std::string id, Data png_data, HAlign h_align, float h_position, VAlign v_align, float v_position) : Part (parent) , _png_data (png_data) + , _id (id) , _h_align (h_align) , _h_position (h_position) , _v_align (v_align) @@ -181,6 +181,7 @@ public: private: Data _png_data; + std::string _id; ///< the ID of this image (index for Interop, UUID for SMPTE) HAlign _h_align; float _h_position; VAlign _v_align; @@ -189,8 +190,6 @@ private: } -std::string image_subtitle_file (int n); - } #endif |
