Subtitle language handling tweaks; write multiple subtitle languages
authorCarl Hetherington <cth@carlh.net>
Thu, 19 Nov 2020 23:53:20 +0000 (00:53 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 20 Nov 2020 22:47:03 +0000 (23:47 +0100)
to SMPTE extended metadata.

cscript
src/lib/reel_writer.cc
src/lib/subtitle_encoder.cc
src/lib/writer.cc
test/data
test/subtitle_language_test.cc [new file with mode: 0644]
test/wscript

diff --git a/cscript b/cscript
index 44051ac..69d41b3 100644 (file)
--- a/cscript
+++ b/cscript
@@ -373,8 +373,8 @@ def dependencies(target, options):
             (target.platform == 'osx' and target.bits == 64) or
             (target.platform == 'windows')) else {}
 
-    deps.append(('libdcp', 'd989a83', cpp_lib_options))
-    deps.append(('libsub', 'f17a4fd', cpp_lib_options))
+    deps.append(('libdcp', 'f614b45', cpp_lib_options))
+    deps.append(('libsub', '97e8588', cpp_lib_options))
     deps.append(('leqm-nrt', 'carl'))
     deps.append(('rtaudio', 'carl'))
     # We get our OpenSSL libraries from the environment, but we
index c4df58f..345bcde 100644 (file)
@@ -597,7 +597,11 @@ ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr
        }
        reel->add (reel_sound_asset);
 
-       maybe_add_text<dcp::ReelSubtitleAsset> (_subtitle_asset, reel_picture_asset->actual_duration(), reel, refs, fonts, _film, _period);
+       shared_ptr<dcp::ReelSubtitleAsset> subtitle = maybe_add_text<dcp::ReelSubtitleAsset> (_subtitle_asset, reel_picture_asset->actual_duration(), reel, refs, fonts, _film, _period);
+       if (subtitle && !_film->subtitle_languages().empty()) {
+               subtitle->set_language (_film->subtitle_languages().front());
+       }
+
        for (map<DCPTextTrack, shared_ptr<dcp::SubtitleAsset> >::const_iterator i = _closed_caption_assets.begin(); i != _closed_caption_assets.end(); ++i) {
                shared_ptr<dcp::ReelClosedCaptionAsset> a = maybe_add_text<dcp::ReelClosedCaptionAsset> (
                        i->second, reel_picture_asset->actual_duration(), reel, refs, fonts, _film, _period
@@ -703,9 +707,9 @@ ReelWriter::write (PlayerText subs, TextType type, optional<DCPTextTrack> track,
                        s->set_content_title_text (_film->name ());
                        s->set_metadata (mxf_metadata());
                        if (type == TEXT_OPEN_SUBTITLE && !lang.empty()) {
-                               s->set_language (lang.front().to_string());
+                               s->set_language (lang.front());
                        } else {
-                               s->set_language (track->language);
+                               s->set_language (dcp::LanguageTag(track->language));
                        }
                        s->set_edit_rate (dcp::Fraction (_film->video_frame_rate (), 1));
                        s->set_reel_number (_reel_index + 1);
index 5e76f5e..61c4dc3 100644 (file)
@@ -141,9 +141,9 @@ SubtitleEncoder::text (PlayerText subs, TextType type, optional<DCPTextTrack> tr
                        shared_ptr<dcp::SMPTESubtitleAsset> s (new dcp::SMPTESubtitleAsset());
                        s->set_content_title_text (_film->name());
                        if (!lang.empty()) {
-                               s->set_language (lang.front().to_string());
+                               s->set_language (lang.front());
                        } else {
-                               s->set_language (track->language);
+                               s->set_language (dcp::LanguageTag(track->language));
                        }
                        s->set_edit_rate (dcp::Fraction (_film->video_frame_rate(), 1));
                        s->set_reel_number (_reel_index + 1);
index 79e5ad7..a9700f4 100644 (file)
@@ -620,6 +620,11 @@ Writer::finish ()
        cpl->set_main_picture_stored_area (_film->frame_size());
        cpl->set_main_picture_active_area (_film->active_area());
 
+       vector<dcp::LanguageTag> sl = _film->subtitle_languages();
+       if (sl.size() > 1) {
+               cpl->set_additional_subtitle_languages(std::vector<dcp::LanguageTag>(sl.begin() + 1, sl.end()));
+       }
+
        shared_ptr<const dcp::CertificateChain> signer;
        signer = Config::instance()->signer_chain ();
        /* We did check earlier, but check again here to be on the safe side */
index eebc165..fddd3fd 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit eebc165cf7df4af980e918bc3176d93521f5beea
+Subproject commit fddd3fd75d21d858d203ea615387ba3b668c9aec
diff --git a/test/subtitle_language_test.cc b/test/subtitle_language_test.cc
new file mode 100644 (file)
index 0000000..50efb71
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+    Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+/** @file  test/subtitle_language_test.cc
+ *  @brief Test that subtitle language information is correctly written to DCPs.
+ */
+
+
+#include "lib/content_factory.h"
+#include "lib/film.h"
+#include "test.h"
+#include <dcp/language_tag.h>
+#include <boost/test/unit_test.hpp>
+#include <vector>
+
+
+using std::string;
+using std::vector;
+using boost::shared_ptr;
+
+
+BOOST_AUTO_TEST_CASE (subtitle_language_interop_test)
+{
+       string const name = "subtitle_language_interop_test";
+       shared_ptr<Film> film = new_test_film2 (name);
+       film->examine_and_add_content (content_factory("test/data/frames.srt").front());
+       BOOST_REQUIRE (!wait_for_jobs());
+
+       vector<dcp::LanguageTag> langs;
+       langs.push_back(dcp::LanguageTag("fr-FR"));
+       langs.push_back(dcp::LanguageTag("de-DE"));
+       film->set_subtitle_languages(langs);
+       film->set_interop (true);
+
+       film->make_dcp ();
+       BOOST_REQUIRE (!wait_for_jobs());
+
+       check_dcp (String::compose("test/data/%1", name), String::compose("build/test/%1/%2", name, film->dcp_name()));
+}
+
+
+BOOST_AUTO_TEST_CASE (subtitle_language_smpte_test)
+{
+       string const name = "subtitle_language_smpte_test";
+       shared_ptr<Film> film = new_test_film2 (name);
+       film->examine_and_add_content (content_factory("test/data/frames.srt").front());
+       BOOST_REQUIRE (!wait_for_jobs());
+
+       vector<dcp::LanguageTag> langs;
+       langs.push_back(dcp::LanguageTag("fr-FR"));
+       langs.push_back(dcp::LanguageTag("de-DE"));
+       film->set_subtitle_languages(langs);
+       film->set_interop (false);
+
+       film->make_dcp ();
+       BOOST_REQUIRE (!wait_for_jobs());
+
+       check_dcp (String::compose("test/data/%1", name), String::compose("build/test/%1/%2", name, film->dcp_name()));
+}
+
index 9a3347b..c9e9f21 100644 (file)
@@ -118,6 +118,7 @@ def build(bld):
                  ssa_subtitle_test.cc
                  stream_test.cc
                  subtitle_charset_test.cc
+                 subtitle_language_test.cc
                  subtitle_metadata_test.cc
                  subtitle_reel_test.cc
                  subtitle_reel_number_test.cc