From 3bb6308d1b17aa643021bddc82e954029076f780 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 6 Jul 2015 00:28:42 +0100 Subject: [PATCH] Implement missing support for DCP subs inside DCP content (#631). --- src/lib/dcp_decoder.cc | 57 +++++++++++++++++++++++++++++++++++---- src/lib/dcp_decoder.h | 3 +++ test/dcp_subtitle_test.cc | 44 ++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 5 deletions(-) diff --git a/src/lib/dcp_decoder.cc b/src/lib/dcp_decoder.cc index 0ec50e0cd..0c7e7589b 100644 --- a/src/lib/dcp_decoder.cc +++ b/src/lib/dcp_decoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington + Copyright (C) 2014-2015 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,9 +29,11 @@ #include #include #include +#include #include #include #include +#include using std::list; using std::cout; @@ -102,7 +104,25 @@ DCPDecoder::pass () audio (_dcp_content->audio_stream(), data, _next); } - /* XXX: subtitle */ + if ((*_reel)->main_subtitle ()) { + int64_t const entry_point = (*_reel)->main_subtitle()->entry_point (); + list subs = (*_reel)->main_subtitle()->subtitle_asset()->subtitles_during ( + dcp::Time (entry_point + frame, vfr, vfr), + dcp::Time (entry_point + frame + 1, vfr, vfr), + true + ); + + if (!subs.empty ()) { + /* XXX: assuming that all `subs' are at the same time; maybe this is ok */ + text_subtitle ( + ContentTimePeriod ( + ContentTime::from_seconds (subs.front().in().as_seconds ()), + ContentTime::from_seconds (subs.front().out().as_seconds ()) + ), + subs + ); + } + } _next += ContentTime::from_frames (1, vfr); @@ -139,8 +159,35 @@ DCPDecoder::image_subtitles_during (ContentTimePeriod, bool) const } list -DCPDecoder::text_subtitles_during (ContentTimePeriod, bool) const +DCPDecoder::text_subtitles_during (ContentTimePeriod period, bool starting) const { - /* XXX */ - return list (); + /* XXX: inefficient */ + + list ctp; + float const vfr = _dcp_content->video_frame_rate (); + + BOOST_FOREACH (shared_ptr r, _reels) { + if (!r->main_subtitle ()) { + continue; + } + + int64_t const entry_point = r->main_subtitle()->entry_point (); + + list subs = r->main_subtitle()->subtitle_asset()->subtitles_during ( + dcp::Time (period.from.seconds ()) - dcp::Time (entry_point, vfr, vfr), + dcp::Time (period.to.seconds ()) - dcp::Time (entry_point, vfr, vfr), + starting + ); + + BOOST_FOREACH (dcp::SubtitleString const & s, subs) { + ctp.push_back ( + ContentTimePeriod ( + ContentTime::from_seconds (s.in().as_seconds ()), + ContentTime::from_seconds (s.out().as_seconds ()) + ) + ); + } + } + + return ctp; } diff --git a/src/lib/dcp_decoder.h b/src/lib/dcp_decoder.h index 7d26139ba..d735ca6a5 100644 --- a/src/lib/dcp_decoder.h +++ b/src/lib/dcp_decoder.h @@ -31,6 +31,7 @@ namespace dcp { class DCPContent; class Log; +struct dcp_subtitle_within_dcp_test; class DCPDecoder : public VideoDecoder, public AudioDecoder, public SubtitleDecoder { @@ -38,6 +39,8 @@ public: DCPDecoder (boost::shared_ptr); private: + friend struct dcp_subtitle_within_dcp_test; + bool pass (); void seek (ContentTime t, bool accurate); diff --git a/test/dcp_subtitle_test.cc b/test/dcp_subtitle_test.cc index e8a5a4c04..9007ad611 100644 --- a/test/dcp_subtitle_test.cc +++ b/test/dcp_subtitle_test.cc @@ -24,11 +24,14 @@ #include #include "lib/film.h" #include "lib/dcp_subtitle_content.h" +#include "lib/dcp_content.h" #include "lib/ratio.h" +#include "lib/dcp_decoder.h" #include "lib/dcp_content_type.h" #include "test.h" using std::cout; +using std::list; using boost::shared_ptr; /** Test pass-through of a very simple DCP subtitle file */ @@ -51,3 +54,44 @@ BOOST_AUTO_TEST_CASE (dcp_subtitle_test) check_dcp ("test/data/dcp_subtitle_test", film->dir (film->dcp_name ())); } + +/** Test parsing of a subtitle within an existing DCP */ +BOOST_AUTO_TEST_CASE (dcp_subtitle_within_dcp_test) +{ + shared_ptr film = new_test_film ("dcp_subtitle_within_dcp_test"); + film->set_container (Ratio::from_id ("185")); + film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR")); + film->set_name ("frobozz"); + shared_ptr content (new DCPContent (film, private_data / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV")); + film->examine_and_add_content (content); + wait_for_jobs (); + + shared_ptr decoder (new DCPDecoder (content)); + + list ctp = decoder->text_subtitles_during ( + ContentTimePeriod ( + ContentTime::from_seconds (25), + ContentTime::from_seconds (26) + ), + true + ); + + BOOST_REQUIRE_EQUAL (ctp.size(), 2); + BOOST_CHECK_EQUAL (ctp.front().from, ContentTime::from_seconds (25 + 12 * 0.04)); + BOOST_CHECK_EQUAL (ctp.front().to, ContentTime::from_seconds (26 + 4 * 0.04)); + BOOST_CHECK_EQUAL (ctp.back().from, ContentTime::from_seconds (25 + 12 * 0.04)); + BOOST_CHECK_EQUAL (ctp.back().to, ContentTime::from_seconds (26 + 4 * 0.04)); + + list subs = decoder->get_text_subtitles ( + ContentTimePeriod ( + ContentTime::from_seconds (25), + ContentTime::from_seconds (26) + ), + true + ); + + BOOST_REQUIRE_EQUAL (subs.size(), 1); + BOOST_REQUIRE_EQUAL (subs.front().subs.size(), 2); + BOOST_CHECK_EQUAL (subs.front().subs.front().text(), "Noch mal."); + BOOST_CHECK_EQUAL (subs.front().subs.back().text(), "Encore une fois."); +} -- 2.30.2