+void
+DCPDecoder::pass_texts (ContentTime next, dcp::Size size)
+{
+ auto decoder = text.begin ();
+ if (decoder == text.end()) {
+ /* It's possible that there is now a main subtitle but no TextDecoders, for example if
+ the CPL has just changed but the TextContent's texts have not been recreated yet.
+ */
+ return;
+ }
+
+ if ((*_reel)->main_subtitle()) {
+ pass_texts (
+ next,
+ (*_reel)->main_subtitle()->asset(),
+ _dcp_content->reference_text(TextType::OPEN_SUBTITLE),
+ (*_reel)->main_subtitle()->entry_point().get_value_or(0),
+ *decoder,
+ size
+ );
+ ++decoder;
+ }
+
+ for (auto i: (*_reel)->closed_captions()) {
+ pass_texts (
+ next, i->asset(), _dcp_content->reference_text(TextType::CLOSED_CAPTION), i->entry_point().get_value_or(0), *decoder, size
+ );
+ ++decoder;
+ }
+}
+
+void
+DCPDecoder::pass_texts (
+ ContentTime next, shared_ptr<dcp::SubtitleAsset> asset, bool reference, int64_t entry_point, shared_ptr<TextDecoder> decoder, dcp::Size size
+ )
+{
+ double const vfr = _dcp_content->active_video_frame_rate (film());
+ /* Frame within the (played part of the) reel that is coming up next */
+ int64_t const frame = next.frames_round (vfr);
+
+ if (_decode_referenced || !reference) {
+ auto subs = asset->subtitles_during (
+ dcp::Time (entry_point + frame, vfr, vfr),
+ dcp::Time (entry_point + frame + 1, vfr, vfr),
+ true
+ );
+
+ list<dcp::SubtitleString> strings;
+
+ for (auto i: subs) {
+ auto is = dynamic_pointer_cast<const dcp::SubtitleString>(i);
+ if (is) {
+ if (!strings.empty() && (strings.back().in() != is->in() || strings.back().out() != is->out())) {
+ auto b = strings.back();
+ decoder->emit_plain (
+ ContentTimePeriod (
+ ContentTime::from_frames(_offset - entry_point, vfr) + ContentTime::from_seconds(b.in().as_seconds()),
+ ContentTime::from_frames(_offset - entry_point, vfr) + ContentTime::from_seconds(b.out().as_seconds())
+ ),
+ strings
+ );
+ strings.clear ();
+ }
+
+ strings.push_back (*is);
+ }
+
+ /* XXX: perhaps these image subs should also be collected together like the string ones are;
+ this would need to be done both here and in DCPSubtitleDecoder.
+ */
+
+ auto ii = dynamic_pointer_cast<const dcp::SubtitleImage>(i);
+ if (ii) {
+ emit_subtitle_image (
+ ContentTimePeriod (
+ ContentTime::from_frames (_offset - entry_point, vfr) + ContentTime::from_seconds (i->in().as_seconds ()),
+ ContentTime::from_frames (_offset - entry_point, vfr) + ContentTime::from_seconds (i->out().as_seconds ())
+ ),
+ *ii,
+ size,
+ decoder
+ );
+ }
+ }
+
+ if (!strings.empty()) {
+ auto b = strings.back();
+ decoder->emit_plain (
+ ContentTimePeriod (
+ ContentTime::from_frames(_offset - entry_point, vfr) + ContentTime::from_seconds(b.in().as_seconds()),
+ ContentTime::from_frames(_offset - entry_point, vfr) + ContentTime::from_seconds(b.out().as_seconds())
+ ),
+ strings
+ );
+ strings.clear ();
+ }
+ }
+}
+