+
+ if (_atmos_asset) {
+ _atmos_asset_writer->finalize ();
+ boost::filesystem::path atmos_to;
+ atmos_to /= _film->dir (_film->dcp_name());
+ string const aaf = atmos_asset_filename (_atmos_asset, _reel_index, _reel_count, _content_summary);
+ atmos_to /= aaf;
+
+ boost::system::error_code ec;
+ boost::filesystem::rename (_film->file(aaf), atmos_to, ec);
+ if (ec) {
+ throw FileError (
+ String::compose (_("could not move atmos asset into the DCP (%1)"), ec.value ()), aaf
+ );
+ }
+
+ _atmos_asset->set_file (atmos_to);
+ }
+}
+
+template <class T>
+shared_ptr<T>
+maybe_add_text (
+ shared_ptr<dcp::SubtitleAsset> asset,
+ int64_t picture_duration,
+ shared_ptr<dcp::Reel> reel,
+ list<ReferencedReelAsset> const & refs,
+ list<shared_ptr<Font> > const & fonts,
+ shared_ptr<const Film> film,
+ DCPTimePeriod period
+ )
+{
+ Frame const period_duration = period.duration().frames_round(film->video_frame_rate());
+
+ shared_ptr<T> reel_asset;
+
+ if (asset) {
+ /* Add the font to the subtitle content */
+ BOOST_FOREACH (shared_ptr<Font> j, fonts) {
+ asset->add_font (j->id(), j->file().get_value_or(default_font_file()));
+ }
+
+ if (dynamic_pointer_cast<dcp::InteropSubtitleAsset> (asset)) {
+ boost::filesystem::path directory = film->dir (film->dcp_name ()) / asset->id ();
+ boost::filesystem::create_directories (directory);
+ asset->write (directory / ("sub_" + asset->id() + ".xml"));
+ } else {
+ /* All our assets should be the same length; use the picture asset length here
+ as a reference to set the subtitle one. We'll use the duration rather than
+ the intrinsic duration; we don't care if the picture asset has been trimmed, we're
+ just interested in its presentation length.
+ */
+ dynamic_pointer_cast<dcp::SMPTESubtitleAsset>(asset)->set_intrinsic_duration (picture_duration);
+
+ asset->write (
+ film->dir(film->dcp_name()) / ("sub_" + asset->id() + ".mxf")
+ );
+ }
+
+ reel_asset.reset (
+ new T (
+ asset,
+ dcp::Fraction (film->video_frame_rate(), 1),
+ picture_duration,
+ 0
+ )
+ );
+ } else {
+ /* We don't have a subtitle asset of our own; hopefully we have one to reference */
+ BOOST_FOREACH (ReferencedReelAsset j, refs) {
+ shared_ptr<T> k = dynamic_pointer_cast<T> (j.asset);
+ if (k && j.period == period) {
+ reel_asset = k;
+ /* If we have a hash for this asset in the CPL, assume that it is correct */
+ if (k->hash()) {
+ k->asset_ref()->set_hash (k->hash().get());
+ }
+ }
+ }
+ }
+
+ if (reel_asset) {
+ if (reel_asset->actual_duration() != period_duration) {
+ throw ProgrammingError (
+ __FILE__, __LINE__,
+ String::compose ("%1 vs %2", reel_asset->actual_duration(), period_duration)
+ );
+ }
+ reel->add (reel_asset);
+ }
+
+ return reel_asset;