From 6a5c7209770aa2c20d702b6f31d877ad2864ece7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 8 Dec 2020 11:19:16 +0100 Subject: [PATCH] Split create_reel() up into some separate bits. --- src/lib/reel_writer.cc | 84 ++++++++++++++++++++++++++++-------------- src/lib/reel_writer.h | 10 +++++ 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index ab06819b1..bc1d65e49 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -507,25 +507,22 @@ maybe_add_text ( return reel_asset; } -shared_ptr -ReelWriter::create_reel (list const & refs, list > const & fonts) -{ - LOG_GENERAL ("create_reel for %1-%2; %3 of %4", _period.from.get(), _period.to.get(), _reel_index, _reel_count); - - shared_ptr reel (new dcp::Reel ()); - shared_ptr reel_picture_asset; +shared_ptr +ReelWriter::create_reel_picture (shared_ptr reel, list const & refs) const +{ + shared_ptr reel_asset; if (_picture_asset) { /* We have made a picture asset of our own. Put it into the reel */ shared_ptr mono = dynamic_pointer_cast (_picture_asset); if (mono) { - reel_picture_asset.reset (new dcp::ReelMonoPictureAsset (mono, 0)); + reel_asset.reset (new dcp::ReelMonoPictureAsset (mono, 0)); } shared_ptr stereo = dynamic_pointer_cast (_picture_asset); if (stereo) { - reel_picture_asset.reset (new dcp::ReelStereoPictureAsset (stereo, 0)); + reel_asset.reset (new dcp::ReelStereoPictureAsset (stereo, 0)); } } else { LOG_GENERAL ("no picture asset of our own; look through %1", refs.size()); @@ -536,32 +533,39 @@ ReelWriter::create_reel (list const & refs, listvideo_frame_rate()); - DCPOMATIC_ASSERT (reel_picture_asset); - if (reel_picture_asset->duration() != period_duration) { + DCPOMATIC_ASSERT (reel_asset); + if (reel_asset->duration() != period_duration) { throw ProgrammingError ( __FILE__, __LINE__, - String::compose ("%1 vs %2", reel_picture_asset->actual_duration(), period_duration) + String::compose ("%1 vs %2", reel_asset->actual_duration(), period_duration) ); } - reel->add (reel_picture_asset); + reel->add (reel_asset); /* If we have a hash for this asset in the CPL, assume that it is correct */ - if (reel_picture_asset->hash()) { - reel_picture_asset->asset_ref()->set_hash (reel_picture_asset->hash().get()); + if (reel_asset->hash()) { + reel_asset->asset_ref()->set_hash (reel_asset->hash().get()); } - shared_ptr reel_sound_asset; + return reel_asset; +} + + +void +ReelWriter::create_reel_sound (shared_ptr reel, list const & refs) const +{ + shared_ptr reel_asset; if (_sound_asset) { /* We have made a sound asset of our own. Put it into the reel */ - reel_sound_asset.reset (new dcp::ReelSoundAsset (_sound_asset, 0)); + reel_asset.reset (new dcp::ReelSoundAsset(_sound_asset, 0)); } else { LOG_GENERAL ("no sound asset of our own; look through %1", refs.size()); /* We don't have a sound asset of our own; hopefully we have one to reference */ @@ -571,7 +575,7 @@ ReelWriter::create_reel (list const & refs, listhash()) { k->asset_ref()->set_hash (k->hash().get()); @@ -580,31 +584,38 @@ ReelWriter::create_reel (list const & refs, listactual_duration() != period_duration) { + Frame const period_duration = _period.duration().frames_round(_film->video_frame_rate()); + + DCPOMATIC_ASSERT (reel_asset); + if (reel_asset->actual_duration() != period_duration) { LOG_ERROR ( "Reel sound asset has length %1 but reel period is %2", - reel_sound_asset->actual_duration(), + reel_asset->actual_duration(), period_duration ); - if (reel_sound_asset->actual_duration() != period_duration) { + if (reel_asset->actual_duration() != period_duration) { throw ProgrammingError ( __FILE__, __LINE__, - String::compose ("%1 vs %2", reel_sound_asset->actual_duration(), period_duration) + String::compose ("%1 vs %2", reel_asset->actual_duration(), period_duration) ); } } - reel->add (reel_sound_asset); + reel->add (reel_asset); +} + - shared_ptr subtitle = maybe_add_text (_subtitle_asset, reel_picture_asset->actual_duration(), reel, refs, fonts, _film, _period); +void +ReelWriter::create_reel_text (shared_ptr reel, list const & refs, list > const& fonts, int64_t duration) const +{ + shared_ptr subtitle = maybe_add_text (_subtitle_asset, duration, reel, refs, fonts, _film, _period); if (subtitle && !_film->subtitle_languages().empty()) { subtitle->set_language (_film->subtitle_languages().front()); } for (map >::const_iterator i = _closed_caption_assets.begin(); i != _closed_caption_assets.end(); ++i) { shared_ptr a = maybe_add_text ( - i->second, reel_picture_asset->actual_duration(), reel, refs, fonts, _film, _period + i->second, duration, reel, refs, fonts, _film, _period ); if (a) { a->set_annotation_text (i->first.name); @@ -613,7 +624,13 @@ ReelWriter::create_reel (list const & refs, list reel) const +{ Film::Markers markers = _film->markers (); _film->add_ffoc_lfoc (markers); Film::Markers reel_markers; @@ -633,6 +650,19 @@ ReelWriter::create_reel (list const & refs, listadd (ma); } +} + + +shared_ptr +ReelWriter::create_reel (list const & refs, list > const & fonts) +{ + LOG_GENERAL ("create_reel for %1-%2; %3 of %4", _period.from.get(), _period.to.get(), _reel_index, _reel_count); + + shared_ptr reel (new dcp::Reel()); + shared_ptr reel_picture_asset = create_reel_picture (reel, refs); + create_reel_sound (reel, refs); + create_reel_text (reel, refs, fonts, reel_picture_asset->actual_duration()); + create_reel_markers (reel); if (_atmos_asset) { reel->add (shared_ptr(new dcp::ReelAtmosAsset(_atmos_asset, 0))); diff --git a/src/lib/reel_writer.h b/src/lib/reel_writer.h index fd11d17aa..2b3b6e237 100644 --- a/src/lib/reel_writer.h +++ b/src/lib/reel_writer.h @@ -52,6 +52,7 @@ namespace dcp { class AtmosAsset; class ReelAsset; class Reel; + class ReelPictureAsset; } class ReelWriter @@ -97,6 +98,15 @@ private: Frame check_existing_picture_asset (boost::filesystem::path asset); bool existing_picture_frame_ok (FILE* asset_file, boost::shared_ptr info_file, Frame frame) const; + boost::shared_ptr create_reel_picture (boost::shared_ptr reel, std::list const & refs) const; + void create_reel_sound (boost::shared_ptr reel, std::list const & refs) const; + void create_reel_text ( + boost::shared_ptr reel, + std::list const & refs, std::list > const& fonts, + int64_t duration + ) const; + void create_reel_markers (boost::shared_ptr reel) const; + boost::shared_ptr _film; dcpomatic::DCPTimePeriod _period; -- 2.30.2