/*
- 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
#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;
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);
}
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;
}
#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 */
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.");
+}