diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-01-11 21:20:47 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-01-17 20:13:23 +0100 |
| commit | e668388d1a552c845dbe9ae3cdcdfd979f2da582 (patch) | |
| tree | 4ab2077764723436dc4e3f1264963e107d55de83 /src | |
| parent | d95eacd3851a20e52202465ec22b4f72a4983dc8 (diff) | |
Change subtitle SubtitleAsset API to return const Subtitle pointers; add subtitles_in_reel().
Diffstat (limited to 'src')
| -rw-r--r-- | src/subtitle_asset.cc | 43 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 10 |
2 files changed, 45 insertions, 8 deletions
diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 59aff6be..fc9b972a 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of libdcp. @@ -41,6 +41,7 @@ #include "subtitle_image.h" #include "dcp_assert.h" #include "load_font_node.h" +#include "reel_asset.h" #include <asdcp/AS_DCP.h> #include <asdcp/KM_util.h> #include <libxml++/nodes/element.h> @@ -56,6 +57,7 @@ using std::cerr; using std::map; using std::shared_ptr; using std::vector; +using std::make_shared; using boost::shared_array; using boost::optional; using boost::lexical_cast; @@ -407,11 +409,23 @@ SubtitleAsset::maybe_add_subtitle (string text, vector<ParseState> const & parse } } -vector<shared_ptr<Subtitle>> + +vector<shared_ptr<const Subtitle>> +SubtitleAsset::subtitles () const +{ + vector<shared_ptr<const Subtitle>> s; + for (auto i: _subtitles) { + s.push_back (i); + } + return s; +} + + +vector<shared_ptr<const Subtitle>> SubtitleAsset::subtitles_during (Time from, Time to, bool starting) const { - vector<shared_ptr<Subtitle> > s; - BOOST_FOREACH (shared_ptr<Subtitle> i, _subtitles) { + vector<shared_ptr<const Subtitle>> s; + for (auto i: _subtitles) { if ((starting && from <= i->in() && i->in() < to) || (!starting && i->out() >= from && i->in() <= to)) { s.push_back (i); } @@ -420,6 +434,27 @@ SubtitleAsset::subtitles_during (Time from, Time to, bool starting) const return s; } + +/* XXX: this needs a test */ +vector<shared_ptr<const Subtitle>> +SubtitleAsset::subtitles_in_reel (shared_ptr<const dcp::ReelAsset> asset) const +{ + auto frame_rate = asset->edit_rate().as_float(); + auto start = dcp::Time(asset->entry_point().get_value_or(0), frame_rate, time_code_rate()); + auto during = subtitles_during (start, start + dcp::Time(asset->intrinsic_duration(), frame_rate, time_code_rate()), false); + + vector<shared_ptr<const dcp::Subtitle>> corrected; + for (auto i: during) { + auto c = make_shared<dcp::Subtitle>(*i); + c->set_in (c->in() - start); + c->set_out (c->out() - start); + corrected.push_back (c); + } + + return corrected; +} + + void SubtitleAsset::add (shared_ptr<Subtitle> s) { diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 60ddc357..02976f7d 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -62,6 +62,7 @@ class FontNode; class TextNode; class SubtitleNode; class LoadFontNode; +class ReelAsset; namespace order { class Part; @@ -88,10 +89,9 @@ public: NoteHandler note ) const; - std::vector<std::shared_ptr<Subtitle>> subtitles_during (Time from, Time to, bool starting) const; - std::vector<std::shared_ptr<Subtitle>> const & subtitles () const { - return _subtitles; - } + std::vector<std::shared_ptr<const Subtitle>> subtitles_during (Time from, Time to, bool starting) const; + std::vector<std::shared_ptr<const Subtitle>> subtitles_in_reel(std::shared_ptr<const dcp::ReelAsset> asset) const; + std::vector<std::shared_ptr<const Subtitle>> subtitles () const; virtual void add (std::shared_ptr<Subtitle>); virtual void add_font (std::string id, dcp::ArrayData data) = 0; @@ -107,6 +107,8 @@ public: virtual std::vector<std::shared_ptr<LoadFontNode>> load_font_nodes () const = 0; + virtual int time_code_rate () const = 0; + std::string raw_xml () const { return _raw_xml; } |
