Fix missing subtitle language in CPL on auto-created empty subtitle assets (#2548).
authorCarl Hetherington <cth@carlh.net>
Wed, 31 May 2023 18:13:50 +0000 (20:13 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 4 Jun 2023 18:50:06 +0000 (20:50 +0200)
src/lib/reel_writer.cc
test/subtitle_language_test.cc

index 658de0a62953bbd5b498c8f58f09f9a7e198e8ae..aae2a6273f9835594ad12b3dac63277c2ffd1b4f 100644 (file)
@@ -655,12 +655,7 @@ ReelWriter::create_reel_text (
                _subtitle_asset, duration, reel, _reel_index, _reel_count, _content_summary, refs, film(), _period, output_dcp, _text_only
                );
 
-       if (subtitle) {
-               /* We have a subtitle asset that we either made or are referencing */
-               if (auto main_language = film()->subtitle_languages().first) {
-                       subtitle->set_language (*main_language);
-               }
-       } else if (ensure_subtitles) {
+       if (!subtitle && ensure_subtitles) {
                /* We had no subtitle asset, but we've been asked to make sure there is one */
                subtitle = maybe_add_text<dcp::ReelInteropSubtitleAsset, dcp::ReelSMPTESubtitleAsset, dcp::ReelSubtitleAsset> (
                        empty_text_asset(TextType::OPEN_SUBTITLE, optional<DCPTextTrack>(), true),
@@ -677,6 +672,13 @@ ReelWriter::create_reel_text (
                        );
        }
 
+       if (subtitle) {
+               /* We have a subtitle asset that we either made or are referencing */
+               if (auto main_language = film()->subtitle_languages().first) {
+                       subtitle->set_language (*main_language);
+               }
+       }
+
        for (auto const& i: _closed_caption_assets) {
                auto a = maybe_add_text<dcp::ReelInteropClosedCaptionAsset, dcp::ReelSMPTEClosedCaptionAsset, dcp::ReelClosedCaptionAsset> (
                        i.second, duration, reel, _reel_index, _reel_count, _content_summary, refs, film(), _period, output_dcp, _text_only
index 442910e901a76e1d8f2849952d0e263d80af694e..5b7a261fd2c038c80394eaf07fd665c2be5b5c0c 100644 (file)
@@ -81,3 +81,32 @@ BOOST_AUTO_TEST_CASE (subtitle_language_smpte_test)
        check_dcp (String::compose("test/data/%1", name), String::compose("build/test/%1/%2", name, film->dcp_name()));
 }
 
+
+BOOST_AUTO_TEST_CASE(subtitle_language_in_cpl_test)
+{
+       auto subs = content_factory("test/data/frames.srt")[0];
+       auto video1 = content_factory("test/data/flat_red.png")[0];
+       auto video2 = content_factory("test/data/flat_red.png")[0];
+       auto film = new_test_film2(boost::unit_test::framework::current_test_unit().full_name(), { subs, video1, video2 });
+       video2->set_position(film, dcpomatic::DCPTime::from_seconds(5));
+       film->set_reel_type(ReelType::BY_VIDEO_CONTENT);
+       subs->only_text()->set_language(dcp::LanguageTag("fr-FR"));
+
+       make_and_verify_dcp(
+               film,
+               {
+                       dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
+                       dcp::VerificationNote::Code::INVALID_SUBTITLE_DURATION,
+                       dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING
+               });
+
+       cxml::Document cpl("CompositionPlaylist");
+       cpl.read_file(find_file(film->dir(film->dcp_name()), "cpl_"));
+
+       for (auto reel: cpl.node_child("ReelList")->node_children("Reel")) {
+               auto subtitle = reel->node_child("AssetList")->node_child("MainSubtitle");
+               BOOST_REQUIRE(subtitle);
+               BOOST_CHECK(subtitle->optional_node_child("Language"));
+       }
+}
+