summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-07-06 00:28:42 +0100
committerCarl Hetherington <cth@carlh.net>2015-07-06 00:28:42 +0100
commit3bb6308d1b17aa643021bddc82e954029076f780 (patch)
tree1edfbb47d93aa76e9dedea8e63be9f76797fdccc
parentd3d26828db1cc559b427e7ba1f5572622696d2d8 (diff)
Implement missing support for DCP subs inside DCP content (#631).
-rw-r--r--src/lib/dcp_decoder.cc57
-rw-r--r--src/lib/dcp_decoder.h3
-rw-r--r--test/dcp_subtitle_test.cc44
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 <cth@carlh.net>
+ Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
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 <dcp/stereo_picture_asset.h>
#include <dcp/reel_picture_asset.h>
#include <dcp/reel_sound_asset.h>
+#include <dcp/reel_subtitle_asset.h>
#include <dcp/mono_picture_frame.h>
#include <dcp/stereo_picture_frame.h>
#include <dcp/sound_frame.h>
+#include <boost/foreach.hpp>
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<dcp::SubtitleString> 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<ContentTimePeriod>
-DCPDecoder::text_subtitles_during (ContentTimePeriod, bool) const
+DCPDecoder::text_subtitles_during (ContentTimePeriod period, bool starting) const
{
- /* XXX */
- return list<ContentTimePeriod> ();
+ /* XXX: inefficient */
+
+ list<ContentTimePeriod> ctp;
+ float const vfr = _dcp_content->video_frame_rate ();
+
+ BOOST_FOREACH (shared_ptr<dcp::Reel> r, _reels) {
+ if (!r->main_subtitle ()) {
+ continue;
+ }
+
+ int64_t const entry_point = r->main_subtitle()->entry_point ();
+
+ list<dcp::SubtitleString> 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<const DCPContent>);
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 <boost/test/unit_test.hpp>
#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> 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<DCPContent> 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<DCPDecoder> decoder (new DCPDecoder (content));
+
+ list<ContentTimePeriod> 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<ContentTextSubtitle> 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.");
+}