Bv2.1 7.2.1: Check size of closed caption XML is not larger than 256KB.
authorCarl Hetherington <cth@carlh.net>
Sun, 13 Dec 2020 21:23:07 +0000 (22:23 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 17 Jan 2021 19:13:22 +0000 (20:13 +0100)
BRANCH
src/verify.cc
src/verify.h
test/verify_test.cc

diff --git a/BRANCH b/BRANCH
index 11a7d47bf9cc5cc702464e73c9686c930b859ab7..d8b3370a2e7acc675545023376640ac22eb306f6 100644 (file)
--- a/BRANCH
+++ b/BRANCH
@@ -2,7 +2,7 @@ Mark things with [Bv2.1_paragraph]
 [/] done
 [*] not done
 
---- got to top of page 8
+--- got to top of page 9
 
 6 [/]
 6.1 must be smpte [/]
@@ -18,4 +18,7 @@ Mark things with [Bv2.1_paragraph]
 
 7 [/]
 7.1 picture essence encoding; frame size, rate and 2D/3D will be one of the four allowed combinations [/]
+7.1.1 active image area (should; not checked) [/]
+7.2 [/]
+7.2.1 Timed text XML files for closed captions must be < 256kB [/]
 
index 78c087da86ff79030c1fe5959afc935441ab0d20..9cfcd4b9c38657bad4fb6a0562cb3844db3aa902 100644 (file)
@@ -663,6 +663,26 @@ verify_subtitle_asset (
 }
 
 
+static void
+verify_closed_caption_asset (
+       shared_ptr<const SubtitleAsset> asset,
+       function<void (string, optional<boost::filesystem::path>)> stage,
+       boost::filesystem::path xsd_dtd_directory,
+       list<VerificationNote>& notes
+       )
+{
+       verify_subtitle_asset (asset, stage, xsd_dtd_directory, notes);
+
+       if (asset->raw_xml().size() > 256 * 1024) {
+               notes.push_back (
+                       VerificationNote(
+                               VerificationNote::VERIFY_BV21_ERROR, VerificationNote::CLOSED_CAPTION_XML_TOO_LARGE_IN_BYTES, *asset->file()
+                               )
+                       );
+       }
+}
+
+
 list<VerificationNote>
 dcp::verify (
        vector<boost::filesystem::path> directories,
@@ -763,7 +783,7 @@ dcp::verify (
                                BOOST_FOREACH (shared_ptr<dcp::ReelClosedCaptionAsset> i, reel->closed_captions()) {
                                        verify_closed_caption_reel (i, notes);
                                        if (i->asset_ref().resolved()) {
-                                               verify_subtitle_asset (i->asset(), stage, xsd_dtd_directory, notes);
+                                               verify_closed_caption_asset (i->asset(), stage, xsd_dtd_directory, notes);
                                        }
                                }
                        }
@@ -835,7 +855,8 @@ dcp::note_to_string (dcp::VerificationNote note)
                return String::compose("A picture asset's frame rate (%1) is not 24fps as required for 4K DCPs by Bv2.1", note.note().get());
        case dcp::VerificationNote::PICTURE_ASSET_4K_3D:
                return "3D 4K DCPs are not allowed by Bv2.1";
-
+       case dcp::VerificationNote::CLOSED_CAPTION_XML_TOO_LARGE_IN_BYTES:
+               return String::compose("The XML for the closed caption asset %1 is longer than the 256KB maximum required by Bv2.1", note.file()->filename());
        }
 
        return "";
index 500918deb1fb43e744de78fb08b09a6531e19942..24c19b2b375916608bc609c8496b7fa428188818 100644 (file)
@@ -102,6 +102,8 @@ public:
                PICTURE_ASSET_INVALID_FRAME_RATE_FOR_4K,
                /** A picture asset is 4K but is 3D which is not allowed by Bv2.1 [Bv2.1_7.1] */
                PICTURE_ASSET_4K_3D,
+               /** A closed caption's XML file is larger than 256KB [Bv2.1_7.2.1] */
+               CLOSED_CAPTION_XML_TOO_LARGE_IN_BYTES,
        };
 
        VerificationNote (Type type, Code code)
index e8396dd1a389f6532c823f31a16d574c2d07ee02..cf00202b8c6e8b2beeba0dd1bb4fa545fecfda51 100644 (file)
@@ -1157,3 +1157,56 @@ BOOST_AUTO_TEST_CASE (verify_picture_size)
        BOOST_CHECK_EQUAL (notes.front().type(), dcp::VerificationNote::VERIFY_BV21_ERROR);
        BOOST_CHECK_EQUAL (notes.front().code(), dcp::VerificationNote::PICTURE_ASSET_4K_3D);
 }
+
+
+BOOST_AUTO_TEST_CASE (verify_closed_caption_xml_too_large)
+{
+       boost::filesystem::path const dir("build/test/verify_closed_caption_xml_too_large");
+       prepare_directory (dir);
+
+       shared_ptr<dcp::SMPTESubtitleAsset> asset(new dcp::SMPTESubtitleAsset());
+       for (int i = 0; i < 2048; ++i) {
+               asset->add (
+                       shared_ptr<dcp::Subtitle>(
+                               new dcp::SubtitleString(
+                                       optional<string>(),
+                                       false,
+                                       false,
+                                       false,
+                                       dcp::Colour(),
+                                       42,
+                                       1,
+                                       dcp::Time(i * 24, 24, 24),
+                                       dcp::Time(i * 24 + 20, 24, 24),
+                                       0,
+                                       dcp::HALIGN_CENTER,
+                                       0,
+                                       dcp::VALIGN_CENTER,
+                                       dcp::DIRECTION_LTR,
+                                       "Hello",
+                                       dcp::NONE,
+                                       dcp::Colour(),
+                                       dcp::Time(),
+                                       dcp::Time()
+                                       )
+                               )
+                       );
+       }
+       asset->write (dir / "subs.mxf");
+       shared_ptr<dcp::ReelClosedCaptionAsset> reel_asset(new dcp::ReelClosedCaptionAsset(asset, dcp::Fraction(24, 1), 16 * 24, 0));
+       shared_ptr<dcp::Reel> reel(new dcp::Reel());
+       reel->add (reel_asset);
+       shared_ptr<dcp::CPL> cpl(new dcp::CPL("hello", dcp::FEATURE));
+       cpl->add (reel);
+       shared_ptr<dcp::DCP> dcp(new dcp::DCP(dir));
+       dcp->add (cpl);
+       dcp->write_xml (dcp::SMPTE);
+
+       vector<boost::filesystem::path> dirs;
+       dirs.push_back (dir);
+       list<dcp::VerificationNote> notes = dcp::verify (dirs, &stage, &progress, xsd_test);
+       BOOST_REQUIRE_EQUAL (notes.size(), 1U);
+       BOOST_CHECK_EQUAL (notes.front().type(), dcp::VerificationNote::VERIFY_BV21_ERROR);
+       BOOST_CHECK_EQUAL (notes.front().code(), dcp::VerificationNote::CLOSED_CAPTION_XML_TOO_LARGE_IN_BYTES);
+}
+