From 2c1faeb15715794525f48110c2b8a9df96b387c1 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 15 Mar 2021 01:36:51 +0100 Subject: [PATCH] Fix various bugs in subtitle/ccap verification. Check that subtitles don't overlap reel boundaries, and fix a few tests that trip this check. Fix confusion when calculating subtitle timings during verification where the picture asset frame rate was being used rather than the subtitle asset's edit rate. Do the subtitle timing verification for Interop as well as SMPTE subtitles. Take tags into account when checking subtitles, even though Bv2.1 says they should be set to 0. Rename Time::as_editable_units to Time::as_editable_units_ceil and add a _floor variant, then use that to round down when checking reel boundary overlaps. --- src/dcp_time.cc | 9 +++- src/dcp_time.h | 10 ++++- src/reel_markers_asset.cc | 2 +- src/smpte_subtitle_asset.cc | 4 +- src/subtitle_asset_internal.cc | 4 +- src/verify.cc | 76 ++++++++++++++++++++++++---------- src/verify.h | 2 + test/verify_test.cc | 34 ++++++++++++--- 8 files changed, 105 insertions(+), 36 deletions(-) diff --git a/src/dcp_time.cc b/src/dcp_time.cc index 2895cd37..0bd0a409 100644 --- a/src/dcp_time.cc +++ b/src/dcp_time.cc @@ -340,7 +340,14 @@ Time::as_string (Standard standard) const int64_t -Time::as_editable_units (int tcr_) const +Time::as_editable_units_floor (int tcr_) const +{ + return floor(int64_t(e) * double(tcr_) / tcr) + int64_t(s) * tcr_ + int64_t(m) * 60 * tcr_ + int64_t(h) * 60 * 60 * tcr_; +} + + +int64_t +Time::as_editable_units_ceil (int tcr_) const { return ceil(int64_t(e) * double(tcr_) / tcr) + int64_t(s) * tcr_ + int64_t(m) * 60 * tcr_ + int64_t(h) * 60 * 60 * tcr_; } diff --git a/src/dcp_time.h b/src/dcp_time.h index dcbadf31..dbfdb7f0 100644 --- a/src/dcp_time.h +++ b/src/dcp_time.h @@ -126,11 +126,17 @@ public: /** @return the total number of seconds that this time consists of */ double as_seconds () const; + /** @param tcr_ Timecode rate with which the return value should be counted + * @return the total number of editable units that this time consists of at the specified timecode rate, rounded down + * to the nearest editable unit. For example, as_editable_units_floor(24) returns the total time in frames at 24fps. + */ + int64_t as_editable_units_floor (int tcr_) const; + /** @param tcr_ Timecode rate with which the return value should be counted * @return the total number of editable units that this time consists of at the specified timecode rate, rounded up - * to the nearest editable unit. For example, as_editable_units (24) returns the total time in frames at 24fps. + * to the nearest editable unit. For example, as_editable_units_ceil(24) returns the total time in frames at 24fps. */ - int64_t as_editable_units (int tcr_) const; + int64_t as_editable_units_ceil (int tcr_) const; /** @param tcr_ New timecode rate * @return A new Time which is this time at the spcified new timecode rate diff --git a/src/reel_markers_asset.cc b/src/reel_markers_asset.cc index 360a855a..c6339df5 100644 --- a/src/reel_markers_asset.cc +++ b/src/reel_markers_asset.cc @@ -110,7 +110,7 @@ ReelMarkersAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const for (auto const& i: _markers) { auto m = ml->add_child("Marker"); m->add_child("Label")->add_child_text(marker_to_string(i.first)); - m->add_child("Offset")->add_child_text(raw_convert(i.second.as_editable_units(tcr))); + m->add_child("Offset")->add_child_text(raw_convert(i.second.as_editable_units_ceil(tcr))); } return asset; diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 15a366ba..a55b91ae 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -195,7 +195,7 @@ SMPTESubtitleAsset::parse_xml (shared_ptr xml) } /* Guess intrinsic duration */ - _intrinsic_duration = latest_subtitle_out().as_editable_units (_edit_rate.numerator / _edit_rate.denominator); + _intrinsic_duration = latest_subtitle_out().as_editable_units_ceil(_edit_rate.numerator / _edit_rate.denominator); } @@ -547,5 +547,5 @@ void SMPTESubtitleAsset::add (shared_ptr s) { SubtitleAsset::add (s); - _intrinsic_duration = latest_subtitle_out().as_editable_units (_edit_rate.numerator / _edit_rate.denominator); + _intrinsic_duration = latest_subtitle_out().as_editable_units_ceil(_edit_rate.numerator / _edit_rate.denominator); } diff --git a/src/subtitle_asset_internal.cc b/src/subtitle_asset_internal.cc index f1674789..80e861f1 100644 --- a/src/subtitle_asset_internal.cc +++ b/src/subtitle_asset_internal.cc @@ -233,8 +233,8 @@ order::Subtitle::as_xml (xmlpp::Element* parent, Context& context) const e->set_attribute ("FadeUpTime", _fade_up.rebase(context.time_code_rate).as_string(context.standard)); e->set_attribute ("FadeDownTime", _fade_down.rebase(context.time_code_rate).as_string(context.standard)); } else { - e->set_attribute ("FadeUpTime", raw_convert (_fade_up.as_editable_units(context.time_code_rate))); - e->set_attribute ("FadeDownTime", raw_convert (_fade_down.as_editable_units(context.time_code_rate))); + e->set_attribute ("FadeUpTime", raw_convert (_fade_up.as_editable_units_ceil(context.time_code_rate))); + e->set_attribute ("FadeDownTime", raw_convert (_fade_down.as_editable_units_ceil(context.time_code_rate))); } return e; } diff --git a/src/verify.cc b/src/verify.cc index bddf1683..97758e61 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -763,7 +763,7 @@ static void verify_text_timing ( vector> reels, - optional picture_frame_rate, + int edit_rate, vector& notes, std::function)> check, std::function)> xml, @@ -775,32 +775,39 @@ verify_text_timing ( auto too_short = false; auto too_close = false; auto too_early = false; + auto reel_overlap = false; /* current reel start time (in editable units) */ int64_t reel_offset = 0; - std::function parse; - parse = [&parse, &last_out, &too_short, &too_close, &too_early, &reel_offset](cxml::ConstNodePtr node, int tcr, int pfr, bool first_reel) { + std::function, optional