From: Carl Hetherington Date: Thu, 6 May 2021 09:26:47 +0000 (+0200) Subject: Add Content::full_length_content and make full_length_dcp use it. X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=e5a65aba61329ee187fe2164cbd84c13cb93bda2;p=dcpomatic.git Add Content::full_length_content and make full_length_dcp use it. --- diff --git a/src/lib/atmos_mxf_content.cc b/src/lib/atmos_mxf_content.cc index 5c153309f..ebbfdb09b 100644 --- a/src/lib/atmos_mxf_content.cc +++ b/src/lib/atmos_mxf_content.cc @@ -106,11 +106,10 @@ AtmosMXFContent::as_xml (xmlpp::Node* node, bool with_paths) const } -DCPTime -AtmosMXFContent::full_length_dcp (shared_ptr film) const +ContentTime +AtmosMXFContent::full_length_content () const { - FrameRateChange const frc (film, shared_from_this()); - return DCPTime::from_frames (llrint(atmos->length() * frc.factor()), film->video_frame_rate()); + return ContentTime::from_frames (atmos->length(), atmos->edit_rate().as_float()); } diff --git a/src/lib/atmos_mxf_content.h b/src/lib/atmos_mxf_content.h index 912c818f6..fccc1e51a 100644 --- a/src/lib/atmos_mxf_content.h +++ b/src/lib/atmos_mxf_content.h @@ -40,7 +40,7 @@ public: void examine (std::shared_ptr film, std::shared_ptr job) override; std::string summary () const override; void as_xml (xmlpp::Node* node, bool with_path) const override; - dcpomatic::DCPTime full_length_dcp (std::shared_ptr film) const override; + dcpomatic::ContentTime full_length_content () const override; dcpomatic::DCPTime approximate_length () const override; static bool valid_mxf (boost::filesystem::path path); diff --git a/src/lib/content.cc b/src/lib/content.cc index 2dbb218a6..bcd4cabcc 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -541,3 +541,11 @@ Content::add_path (boost::filesystem::path p) auto last_write = boost::filesystem::last_write_time(p, ec); _last_write_times.push_back (ec ? 0 : last_write); } + + +DCPTime +Content::full_length_dcp (shared_ptr film) const +{ + return DCPTime (full_length_content(), FrameRateChange(film, shared_from_this())); +} + diff --git a/src/lib/content.h b/src/lib/content.h index 89ea28ab3..4255a0cb4 100644 --- a/src/lib/content.h +++ b/src/lib/content.h @@ -97,7 +97,8 @@ public: virtual std::string technical_summary () const; virtual void as_xml (xmlpp::Node *, bool with_paths) const; - virtual dcpomatic::DCPTime full_length_dcp (std::shared_ptr) const = 0; + virtual dcpomatic::DCPTime full_length_dcp (std::shared_ptr) const; + virtual dcpomatic::ContentTime full_length_content () const = 0; virtual dcpomatic::DCPTime approximate_length () const = 0; virtual std::string identifier () const; /** @return points at which to split this content when diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index 3c9e1fddd..2b67860b1 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -409,16 +409,19 @@ DCPContent::as_xml (xmlpp::Node* node, bool with_paths) const } } -DCPTime -DCPContent::full_length_dcp (shared_ptr film) const + +ContentTime +DCPContent::full_length_content () const { if (!video) { return {}; } - FrameRateChange const frc (film, shared_from_this()); - return DCPTime::from_frames (llrint(video->length() * frc.factor()), film->video_frame_rate()); + auto vfr = video_frame_rate(); + DCPOMATIC_ASSERT (vfr); + return ContentTime::from_frames (video->length(), *vfr); } + DCPTime DCPContent::approximate_length () const { diff --git a/src/lib/dcp_content.h b/src/lib/dcp_content.h index 29d5b2498..1fa9122ef 100644 --- a/src/lib/dcp_content.h +++ b/src/lib/dcp_content.h @@ -61,7 +61,7 @@ public: return std::dynamic_pointer_cast (Content::shared_from_this ()); } - dcpomatic::DCPTime full_length_dcp (std::shared_ptr film) const override; + dcpomatic::ContentTime full_length_content () const override; dcpomatic::DCPTime approximate_length () const override; void examine (std::shared_ptr film, std::shared_ptr) override; diff --git a/src/lib/dcp_subtitle_content.cc b/src/lib/dcp_subtitle_content.cc index d42076e5a..0ac659c06 100644 --- a/src/lib/dcp_subtitle_content.cc +++ b/src/lib/dcp_subtitle_content.cc @@ -78,12 +78,6 @@ DCPSubtitleContent::examine (shared_ptr film, shared_ptr job) } } -DCPTime -DCPSubtitleContent::full_length_dcp (shared_ptr film) const -{ - FrameRateChange const frc (film, shared_from_this()); - return DCPTime (_length, frc); -} DCPTime DCPSubtitleContent::approximate_length () const diff --git a/src/lib/dcp_subtitle_content.h b/src/lib/dcp_subtitle_content.h index f734d04ba..2858728ac 100644 --- a/src/lib/dcp_subtitle_content.h +++ b/src/lib/dcp_subtitle_content.h @@ -31,7 +31,9 @@ public: std::string summary () const override; std::string technical_summary () const override; void as_xml (xmlpp::Node *, bool with_paths) const override; - dcpomatic::DCPTime full_length_dcp (std::shared_ptr film) const override; + dcpomatic::ContentTime full_length_content () const override { + return _length; + } dcpomatic::DCPTime approximate_length () const override; private: diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 5cbc210ad..65826506e 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -43,6 +43,7 @@ extern "C" { } #include #include +#include #include "i18n.h" @@ -410,20 +411,18 @@ operator!= (FFmpegStream const & a, FFmpegStream const & b) } -DCPTime -FFmpegContent::full_length_dcp (shared_ptr film) const +ContentTime +FFmpegContent::full_length_content () const { - FrameRateChange const frc (film, shared_from_this()); if (video) { - return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film->video_frame_rate()); + return ContentTime::from_frames(video->length_after_3d_combine(), video_frame_rate().get()); } if (audio) { - DCPTime longest; - for (auto i: audio->streams()) { - longest = max (longest, DCPTime::from_frames(llrint(i->length() / frc.speed_up), i->frame_rate())); - } - return longest; + auto streams = audio->streams(); + return std::accumulate (streams.begin(), streams.end(), ContentTime(), [](ContentTime const& a, shared_ptr const& b) { + return std::max(a, ContentTime::from_frames(b->length(), b->frame_rate())); + }); } /* XXX: subtitle content? */ diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index a92e613f0..93a67f826 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -64,7 +64,7 @@ public: std::string summary () const override; std::string technical_summary () const override; void as_xml (xmlpp::Node *, bool with_paths) const override; - dcpomatic::DCPTime full_length_dcp (std::shared_ptr film) const override; + dcpomatic::ContentTime full_length_content () const override; dcpomatic::DCPTime approximate_length () const override; std::string identifier () const override; diff --git a/src/lib/image_content.cc b/src/lib/image_content.cc index 234930576..36059011d 100644 --- a/src/lib/image_content.cc +++ b/src/lib/image_content.cc @@ -132,13 +132,22 @@ ImageContent::examine (shared_ptr film, shared_ptr job) set_default_colour_conversion (); } + DCPTime ImageContent::full_length_dcp (shared_ptr film) const { - FrameRateChange const frc (film, shared_from_this()); - return DCPTime::from_frames (llrint(video->length_after_3d_combine() * frc.factor()), film->video_frame_rate()); + FrameRateChange const frc (film, shared_from_this()); + return DCPTime::from_frames (llrint(video->length_after_3d_combine() * frc.factor()), film->video_frame_rate()); +} + + +ContentTime +ImageContent::full_length_content () const +{ + return ContentTime::from_frames (video->length_after_3d_combine(), video_frame_rate().get_value_or(24)); } + DCPTime ImageContent::approximate_length () const { diff --git a/src/lib/image_content.h b/src/lib/image_content.h index f496e2531..a5d4a529a 100644 --- a/src/lib/image_content.h +++ b/src/lib/image_content.h @@ -42,6 +42,7 @@ public: std::string technical_summary () const override; void as_xml (xmlpp::Node *, bool with_paths) const override; dcpomatic::DCPTime full_length_dcp (std::shared_ptr film) const override; + dcpomatic::ContentTime full_length_content () const override; dcpomatic::DCPTime approximate_length () const override; std::string identifier () const override; diff --git a/src/lib/string_text_file_content.cc b/src/lib/string_text_file_content.cc index 8796b5ee9..5a2b3d87e 100644 --- a/src/lib/string_text_file_content.cc +++ b/src/lib/string_text_file_content.cc @@ -101,14 +101,6 @@ StringTextFileContent::as_xml (xmlpp::Node* node, bool with_paths) const } -DCPTime -StringTextFileContent::full_length_dcp (shared_ptr film) const -{ - FrameRateChange const frc (film, shared_from_this()); - return DCPTime (_length, frc); -} - - DCPTime StringTextFileContent::approximate_length () const { diff --git a/src/lib/string_text_file_content.h b/src/lib/string_text_file_content.h index d3c0368b9..ea8ac5787 100644 --- a/src/lib/string_text_file_content.h +++ b/src/lib/string_text_file_content.h @@ -46,7 +46,9 @@ public: std::string summary () const override; std::string technical_summary () const override; void as_xml (xmlpp::Node *, bool with_paths) const override; - dcpomatic::DCPTime full_length_dcp (std::shared_ptr film) const override; + dcpomatic::ContentTime full_length_content () const override { + return _length; + } dcpomatic::DCPTime approximate_length () const override; std::string identifier () const override; diff --git a/src/lib/video_mxf_content.cc b/src/lib/video_mxf_content.cc index 1be9787fb..1aa7282ff 100644 --- a/src/lib/video_mxf_content.cc +++ b/src/lib/video_mxf_content.cc @@ -129,11 +129,12 @@ VideoMXFContent::as_xml (xmlpp::Node* node, bool with_paths) const } -DCPTime -VideoMXFContent::full_length_dcp (shared_ptr film) const +ContentTime +VideoMXFContent::full_length_content () const { - FrameRateChange const frc (film, shared_from_this()); - return DCPTime::from_frames (llrint(video->length_after_3d_combine() * frc.factor()), film->video_frame_rate()); + auto vfr = video_frame_rate(); + DCPOMATIC_ASSERT (vfr); + return ContentTime::from_frames (video->length_after_3d_combine(), *vfr); } diff --git a/src/lib/video_mxf_content.h b/src/lib/video_mxf_content.h index 14d31f915..a0c986d13 100644 --- a/src/lib/video_mxf_content.h +++ b/src/lib/video_mxf_content.h @@ -41,7 +41,7 @@ public: std::string technical_summary () const override; std::string identifier () const override; void as_xml (xmlpp::Node* node, bool with_paths) const override; - dcpomatic::DCPTime full_length_dcp (std::shared_ptr film) const override; + dcpomatic::ContentTime full_length_content () const override; dcpomatic::DCPTime approximate_length () const override; void add_properties (std::shared_ptr film, std::list& p) const override;