+void
+ReelWriter::create_reel_text (
+ shared_ptr<dcp::Reel> reel,
+ list<ReferencedReelAsset> const & refs,
+ FontIdMap const& fonts,
+ shared_ptr<dcpomatic::Font> chosen_interop_font,
+ int64_t duration,
+ boost::filesystem::path output_dcp,
+ bool ensure_subtitles,
+ set<DCPTextTrack> ensure_closed_captions
+ ) const
+{
+ auto subtitle = maybe_add_text<dcp::ReelInteropSubtitleAsset, dcp::ReelSMPTESubtitleAsset, dcp::ReelSubtitleAsset> (
+ _subtitle_asset, duration, reel, _reel_index, _reel_count, _content_summary, refs, fonts, chosen_interop_font, _default_font, film(), _period, output_dcp, _text_only
+ );
+
+ if (subtitle) {
+ /* We have a subtitle asset that we either made or are referencing */
+ if (auto main_language = film()->subtitle_languages().first) {
+ subtitle->set_language (*main_language);
+ }
+ } else if (ensure_subtitles) {
+ /* We had no subtitle asset, but we've been asked to make sure there is one */
+ subtitle = maybe_add_text<dcp::ReelInteropSubtitleAsset, dcp::ReelSMPTESubtitleAsset, dcp::ReelSubtitleAsset> (
+ empty_text_asset(TextType::OPEN_SUBTITLE, optional<DCPTextTrack>(), true),
+ duration,
+ reel,
+ _reel_index,
+ _reel_count,
+ _content_summary,
+ refs,
+ fonts,
+ chosen_interop_font,
+ _default_font,
+ film(),
+ _period,
+ output_dcp,
+ _text_only
+ );
+ }
+
+ for (auto const& i: _closed_caption_assets) {
+ auto a = maybe_add_text<dcp::ReelInteropClosedCaptionAsset, dcp::ReelSMPTEClosedCaptionAsset, dcp::ReelClosedCaptionAsset> (
+ i.second, duration, reel, _reel_index, _reel_count, _content_summary, refs, fonts, chosen_interop_font, _default_font, film(), _period, output_dcp, _text_only
+ );
+ DCPOMATIC_ASSERT (a);
+ a->set_annotation_text (i.first.name);
+ if (i.first.language) {
+ a->set_language (i.first.language.get());
+ }
+
+ ensure_closed_captions.erase (i.first);
+ }
+
+ /* Make empty tracks for anything we've been asked to ensure but that we haven't added */
+ for (auto i: ensure_closed_captions) {
+ auto a = maybe_add_text<dcp::ReelInteropClosedCaptionAsset, dcp::ReelSMPTEClosedCaptionAsset, dcp::ReelClosedCaptionAsset> (
+ empty_text_asset(TextType::CLOSED_CAPTION, i, true),
+ duration,
+ reel,
+ _reel_index,
+ _reel_count,
+ _content_summary,
+ refs,
+ fonts,
+ chosen_interop_font,
+ _default_font,
+ film(),
+ _period,
+ output_dcp,
+ _text_only
+ );
+ DCPOMATIC_ASSERT (a);
+ a->set_annotation_text (i.name);
+ if (i.language) {
+ a->set_language (i.language.get());
+ }
+ }
+}
+
+
+void
+ReelWriter::create_reel_markers (shared_ptr<dcp::Reel> reel) const
+{
+ auto markers = film()->markers();
+ film()->add_ffoc_lfoc(markers);
+ Film::Markers reel_markers;
+ for (auto const& i: markers) {
+ if (_period.contains(i.second)) {
+ reel_markers[i.first] = i.second;
+ }
+ }
+
+ if (!reel_markers.empty ()) {
+ auto ma = make_shared<dcp::ReelMarkersAsset>(dcp::Fraction(film()->video_frame_rate(), 1), reel->duration());
+ for (auto const& i: reel_markers) {
+ DCPTime relative = i.second - _period.from;
+ auto hmsf = relative.split (film()->video_frame_rate());
+ ma->set (i.first, dcp::Time(hmsf.h, hmsf.m, hmsf.s, hmsf.f, film()->video_frame_rate()));
+ }
+ reel->add (ma);
+ }
+}
+
+
+/** @param ensure_subtitles true to make sure the reel has a subtitle asset.
+ * @param ensure_closed_captions make sure the reel has these closed caption tracks.
+ */
+shared_ptr<dcp::Reel>
+ReelWriter::create_reel (
+ list<ReferencedReelAsset> const & refs,
+ FontIdMap const & fonts,
+ shared_ptr<dcpomatic::Font> chosen_interop_font,
+ boost::filesystem::path output_dcp,
+ bool ensure_subtitles,
+ set<DCPTextTrack> ensure_closed_captions
+ )
+{
+ LOG_GENERAL ("create_reel for %1-%2; %3 of %4", _period.from.get(), _period.to.get(), _reel_index, _reel_count);
+
+ auto reel = make_shared<dcp::Reel>();
+
+ /* This is a bit of a hack; in the strange `_text_only' mode we have no picture, so we don't know
+ * how long the subtitle / CCAP assets should be. However, since we're only writing them to see
+ * how big they are, we don't care about that.
+ */
+ int64_t duration = 0;
+ if (!_text_only) {
+ auto reel_picture_asset = create_reel_picture (reel, refs);
+ duration = reel_picture_asset->actual_duration ();
+ create_reel_sound (reel, refs);
+ create_reel_markers (reel);
+ }
+
+ create_reel_text (reel, refs, fonts, chosen_interop_font, duration, output_dcp, ensure_subtitles, ensure_closed_captions);
+
+ if (_atmos_asset) {
+ reel->add (make_shared<dcp::ReelAtmosAsset>(_atmos_asset, 0));
+ }