diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-12-04 20:55:04 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-12-04 21:26:27 +0100 |
| commit | df66616a4d9af7b97480215f51266ab9f6a912e9 (patch) | |
| tree | fead77633bcc036bdfebc703dccdba0f2ffc96d3 /src | |
| parent | e42602d3f8ca95c26c87425a42ebcb17db88cd72 (diff) | |
Pass optimisation setting through to subtitle XML writers.
Diffstat (limited to 'src')
| -rw-r--r-- | src/interop_subtitle_asset.cc | 8 | ||||
| -rw-r--r-- | src/interop_subtitle_asset.h | 4 | ||||
| -rw-r--r-- | src/smpte_subtitle_asset.cc | 8 | ||||
| -rw-r--r-- | src/smpte_subtitle_asset.h | 4 | ||||
| -rw-r--r-- | src/subtitle_asset.cc | 4 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 12 | ||||
| -rw-r--r-- | src/subtitle_asset_internal.h | 5 |
7 files changed, 27 insertions, 18 deletions
diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index eaf2ceaf..0c35abbf 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -109,7 +109,7 @@ InteropSubtitleAsset::InteropSubtitleAsset () string -InteropSubtitleAsset::xml_as_string () const +InteropSubtitleAsset::xml_as_string(SubtitleOptimisation optimisation) const { xmlpp::Document doc; auto root = doc.create_root_node ("DCSubtitle"); @@ -126,7 +126,7 @@ InteropSubtitleAsset::xml_as_string () const load_font->set_attribute ("URI", i->uri); } - subtitles_as_xml (root, 250, Standard::INTEROP); + subtitles_as_xml(root, 250, Standard::INTEROP, optimisation); return format_xml(doc, {}); } @@ -192,14 +192,14 @@ InteropSubtitleAsset::load_font_nodes () const void -InteropSubtitleAsset::write(boost::filesystem::path path) const +InteropSubtitleAsset::write(boost::filesystem::path path, SubtitleOptimisation optimisation) const { File file(path, "wb"); if (!file) { throw FileError("Could not open file for writing", path, -1); } - _raw_xml = xml_as_string (); + _raw_xml = xml_as_string(optimisation); /* length() here gives bytes not characters */ file.write(_raw_xml->c_str(), 1, _raw_xml->length()); diff --git a/src/interop_subtitle_asset.h b/src/interop_subtitle_asset.h index f63740d5..64653973 100644 --- a/src/interop_subtitle_asset.h +++ b/src/interop_subtitle_asset.h @@ -76,10 +76,10 @@ public: void add_font (std::string load_id, dcp::ArrayData data) override; - std::string xml_as_string () const override; + std::string xml_as_string(SubtitleOptimisation optimisation = SubtitleOptimisation::FOR_SUBTITLE) const override; /** Write this content to an XML file with its fonts alongside */ - void write (boost::filesystem::path path) const override; + void write(boost::filesystem::path path, SubtitleOptimisation optimisation = SubtitleOptimisation::FOR_SUBTITLE) const override; void resolve_fonts (std::vector<std::shared_ptr<Asset>> assets); void set_font_file (std::string load_id, boost::filesystem::path file); diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index f907e189..651aa49d 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -363,7 +363,7 @@ SMPTESubtitleAsset::valid_mxf (boost::filesystem::path file) string -SMPTESubtitleAsset::xml_as_string () const +SMPTESubtitleAsset::xml_as_string(SubtitleOptimisation optimisation) const { xmlpp::Document doc; auto root = doc.create_root_node ("SubtitleReel"); @@ -393,14 +393,14 @@ SMPTESubtitleAsset::xml_as_string () const load_font->set_attribute ("ID", i->id); } - subtitles_as_xml (root->add_child("SubtitleList"), _time_code_rate, Standard::SMPTE); + subtitles_as_xml(root->add_child("SubtitleList"), _time_code_rate, Standard::SMPTE, optimisation); return format_xml(doc, std::make_pair(string{}, schema_namespace())); } void -SMPTESubtitleAsset::write(boost::filesystem::path path) const +SMPTESubtitleAsset::write(boost::filesystem::path path, SubtitleOptimisation optimisation) const { EncryptionContext enc (key(), Standard::SMPTE); @@ -458,7 +458,7 @@ SMPTESubtitleAsset::write(boost::filesystem::path path) const boost::throw_exception(FileError("could not open subtitle MXF for writing", path.string(), r)); } - _raw_xml = xml_as_string (); + _raw_xml = xml_as_string(optimisation); r = writer.WriteTimedTextResource (*_raw_xml, enc.context(), enc.hmac()); if (ASDCP_FAILURE (r)) { diff --git a/src/smpte_subtitle_asset.h b/src/smpte_subtitle_asset.h index 26144fe1..3e6e8837 100644 --- a/src/smpte_subtitle_asset.h +++ b/src/smpte_subtitle_asset.h @@ -90,10 +90,10 @@ public: std::vector<std::shared_ptr<LoadFontNode>> load_font_nodes () const override; - std::string xml_as_string () const override; + std::string xml_as_string(SubtitleOptimisation optimisation = SubtitleOptimisation::FOR_SUBTITLE) const override; /** Write this content to a MXF file */ - void write (boost::filesystem::path path) const override; + void write(boost::filesystem::path path, SubtitleOptimisation optimisation = SubtitleOptimisation::FOR_SUBTITLE) const override; void add (std::shared_ptr<Subtitle>) override; void add_font (std::string id, dcp::ArrayData data) override; diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 869bac0f..b3336d13 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -724,7 +724,7 @@ SubtitleAsset::pull_fonts (shared_ptr<order::Part> part) * class because the differences between the two are fairly subtle. */ void -SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, Standard standard) const +SubtitleAsset::subtitles_as_xml(xmlpp::Element* xml_root, int time_code_rate, Standard standard, SubtitleOptimisation optimisation) const { auto sorted = _subtitles; std::stable_sort(sorted.begin(), sorted.end(), SubtitleSorter()); @@ -814,7 +814,7 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, S /* Write XML */ - order::Context context(time_code_rate, standard, 1); + order::Context context(time_code_rate, standard, 1, optimisation); root->write_xml (xml_root, context); } diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 25758c2e..3296dc1b 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -85,6 +85,12 @@ namespace order { } +enum class SubtitleOptimisation { + FOR_SUBTITLE, + FOR_CCAP, +}; + + /** @class SubtitleAsset * @brief A parent for classes representing a file containing subtitles * @@ -114,8 +120,8 @@ public: std::map<std::string, ArrayData> font_data () const; std::map<std::string, boost::filesystem::path> font_filenames () const; - virtual void write (boost::filesystem::path) const = 0; - virtual std::string xml_as_string () const = 0; + virtual void write(boost::filesystem::path, SubtitleOptimisation optimisation = SubtitleOptimisation::FOR_SUBTITLE) const = 0; + virtual std::string xml_as_string(SubtitleOptimisation optimisation = SubtitleOptimisation::FOR_SUBTITLE) const = 0; Time latest_subtitle_out () const; @@ -177,7 +183,7 @@ protected: Time fade_time (xmlpp::Element const * node, std::string name, boost::optional<int> tcr) const; void position_align (ParseState& ps, xmlpp::Element const * node) const; - void subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Standard standard) const; + void subtitles_as_xml(xmlpp::Element* root, int time_code_rate, Standard standard, SubtitleOptimisation optimisation = SubtitleOptimisation::FOR_SUBTITLE) const; /** All our subtitles, in no particular order */ std::vector<std::shared_ptr<Subtitle>> _subtitles; diff --git a/src/subtitle_asset_internal.h b/src/subtitle_asset_internal.h index 2d6b6950..620d6274 100644 --- a/src/subtitle_asset_internal.h +++ b/src/subtitle_asset_internal.h @@ -45,6 +45,7 @@ #include "dcp_time.h" #include "h_align.h" #include "raw_convert.h" +#include "subtitle_asset.h" #include "v_align.h" #include "warnings.h" LIBDCP_DISABLE_WARNINGS @@ -71,15 +72,17 @@ namespace order { struct Context { - Context(int time_code_rate_, Standard standard_, int spot_number_) + Context(int time_code_rate_, Standard standard_, int spot_number_, SubtitleOptimisation optimisation_) : time_code_rate(time_code_rate_) , standard(standard_) , spot_number(spot_number_) + , optimisation(optimisation_) {} int time_code_rate; Standard standard; int spot_number; + SubtitleOptimisation optimisation; }; |
