Make XML subtitle work at the very minimal level.
authorCarl Hetherington <cth@carlh.net>
Fri, 4 Jul 2014 15:34:13 +0000 (16:34 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 4 Jul 2014 15:34:13 +0000 (16:34 +0100)
src/lib/dcpomatic_time.cc
src/lib/film.cc
src/lib/film.h
src/lib/image_subtitle.h
src/lib/player_subtitles.h
src/lib/transcoder.cc
src/lib/writer.cc
src/lib/writer.h
test/wscript
test/xml_subtitle_test.cc [new file with mode: 0644]

index fa6271354bdd4013ded09ae3ff365160c4b0b04b..812c756ec27891224495b1a57b3e374ee793321d 100644 (file)
@@ -59,5 +59,5 @@ ContentTimePeriod::overlaps (ContentTimePeriod const & other) const
 bool
 ContentTimePeriod::contains (ContentTime const & other) const
 {
-       return (from >= other && to < other);
+       return (from <= other && other < to);
 }
index 4f4dc3187958c28c17383079a05f396c5a815d9a..85dc5b168d2012e0d98d78606656fcc221225dd4 100644 (file)
@@ -230,6 +230,12 @@ Film::audio_mxf_filename () const
        return filename_safe_name() + "_audio.mxf";
 }
 
+boost::filesystem::path
+Film::subtitle_xml_filename () const
+{
+       return filename_safe_name() + "_subtitle.xml";
+}
+
 string
 Film::filename_safe_name () const
 {
index 83505cc6d9be2cda0b1a4611dd8dc1f8cfc559b5..6c3f78895791221297b500ea64b1b4ea730777af 100644 (file)
@@ -70,6 +70,7 @@ public:
 
        boost::filesystem::path video_mxf_filename () const;
        boost::filesystem::path audio_mxf_filename () const;
+       boost::filesystem::path subtitle_xml_filename () const;
 
        void send_dcp_to_tms ();
        void make_dcp ();
index 6a4f902e6f38f259a1ccbced8c1dcc66c9b3aad1..b25943ae178aedc12010b515350e4bc0c6b295be 100644 (file)
 
 */
 
+#ifndef DCPOMATIC_IMAGE_SUBTITLE_H
+#define DCPOMATIC_IMAGE_SUBTITLE_H
+
+#include "rect.h"
+
 class Image;
 
 class ImageSubtitle
@@ -37,3 +42,5 @@ public:
         */
        dcpomatic::Rect<double> rectangle;
 };
+
+#endif
index 62b77c077f73026e1f6b1a133a9af6aa4ba5a4ee..46994ea3bd4f7924576f23b00c495ce1d23887ac 100644 (file)
 
 */
 
+#ifndef DCPOMATIC_PLAYER_SUBTITLES_H
+#define DCPOMATIC_PLAYER_SUBTITLES_H
+
+#include <dcp/subtitle_string.h>
+#include "image_subtitle.h"
+
 class PlayerSubtitles
 {
 public:
@@ -32,3 +38,5 @@ public:
        std::list<ImageSubtitle> image;
        std::list<dcp::SubtitleString> text; 
 };
+
+#endif
index df5f0221e9633ba8b06c8e9bdce7291c5694b03e..843524cce91dff5411b7378cfc5adb43e62dd4c3 100644 (file)
@@ -68,6 +68,7 @@ Transcoder::go ()
                        _encoder->enqueue (*i);
                }
                _writer->write (_player->get_audio (t, frame, true));
+               _writer->write (_player->get_subtitles (t, frame, true));
        }
 
        _finishing = true;
index 04eac854c8174ac18b23b975a3d283f76216d41a..b1dbca0e0053f4fdda45881cba4db4e4aaaba1fc 100644 (file)
@@ -27,6 +27,7 @@
 #include <dcp/reel_mono_picture_asset.h>
 #include <dcp/reel_stereo_picture_asset.h>
 #include <dcp/reel_sound_asset.h>
+#include <dcp/reel_subtitle_asset.h>
 #include <dcp/dcp.h>
 #include <dcp/cpl.h>
 #include "writer.h"
@@ -452,6 +453,12 @@ Writer::finish ()
                reel->add (shared_ptr<dcp::ReelSoundAsset> (new dcp::ReelSoundAsset (_sound_mxf, 0)));
                dcp.add (_sound_mxf);
        }
+
+       if (_subtitle_content) {
+               _subtitle_content->write_xml (_film->dir (_film->dcp_name ()) / _film->subtitle_xml_filename ());
+               reel->add (shared_ptr<dcp::ReelSubtitleAsset> (new dcp::ReelSubtitleAsset (_subtitle_content, 0)));
+               dcp.add (_subtitle_content);
+       }
        
        cpl->add (reel);
 
@@ -571,6 +578,20 @@ Writer::can_fake_write (int frame) const
        return (frame != 0 && frame < _first_nonexistant_frame);
 }
 
+void
+Writer::write (PlayerSubtitles subs)
+{
+       if (!_subtitle_content) {
+               _subtitle_content.reset (
+                       new dcp::SubtitleContent (dcp::Fraction (_film->video_frame_rate(), 1), _film->name(), _film->isdcf_metadata().subtitle_language)
+                       );
+       }
+       
+       for (list<dcp::SubtitleString>::const_iterator i = subs.text.begin(); i != subs.text.end(); ++i) {
+               _subtitle_content->add (*i);
+       }
+}
+
 bool
 operator< (QueueItem const & a, QueueItem const & b)
 {
index 2ddf70380181534d8f49b1326479dc5270b61f7a..66fe98ec734c914d3de27eeb4b4ccde15e6309b7 100644 (file)
 #include <boost/shared_ptr.hpp>
 #include <boost/thread.hpp>
 #include <boost/thread/condition.hpp>
+#include <dcp/subtitle_content.h>
 #include "exceptions.h"
 #include "types.h"
+#include "player_subtitles.h"
 
 class Film;
 class EncodedData;
@@ -91,6 +93,7 @@ public:
        void write (boost::shared_ptr<const EncodedData>, int, Eyes);
        void fake_write (int, Eyes);
        void write (boost::shared_ptr<const AudioBuffers>);
+       void write (PlayerSubtitles);
        void repeat (int f, Eyes);
        void finish ();
 
@@ -145,4 +148,5 @@ private:
        boost::shared_ptr<dcp::PictureMXFWriter> _picture_mxf_writer;
        boost::shared_ptr<dcp::SoundMXF> _sound_mxf;
        boost::shared_ptr<dcp::SoundMXFWriter> _sound_mxf_writer;
+       boost::shared_ptr<dcp::SubtitleContent> _subtitle_content;
 };
index 0ece839e61ff9ddbaa1093d59db03683360ed0ac..d968a5a8f2ea66ceb0a95898cdee4881a38df354 100644 (file)
@@ -53,6 +53,7 @@ def build(bld):
                  test.cc
                  threed_test.cc
                  util_test.cc
+                 xml_subtitle_test.cc
                  """
 
     obj.target = 'unit-tests'
diff --git a/test/xml_subtitle_test.cc b/test/xml_subtitle_test.cc
new file mode 100644 (file)
index 0000000..6c3cc9c
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+    Copyright (C) 2014 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
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+/** @file  test/burnt_subtitle_test.cc
+ *  @brief Test creation of XML DCP subtitles.
+ */
+
+#include <boost/test/unit_test.hpp>
+#include "lib/subrip_content.h"
+#include "lib/film.h"
+#include "lib/ratio.h"
+#include "lib/dcp_content_type.h"
+#include "test.h"
+
+using std::cout;
+using boost::shared_ptr;
+
+/** Build a small DCP with no picture and a single subtitle overlaid onto it */
+BOOST_AUTO_TEST_CASE (xml_subtitle_test)
+{
+       shared_ptr<Film> film = new_test_film ("xml_subtitle_test");
+       film->set_container (Ratio::from_id ("185"));
+       film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
+       film->set_name ("frobozz");
+       film->set_burn_subtitles (false);
+       shared_ptr<SubRipContent> content (new SubRipContent (film, "test/data/subrip2.srt"));
+       content->set_subtitle_use (true);
+       film->examine_and_add_content (content);
+       wait_for_jobs ();
+       film->make_dcp ();
+       wait_for_jobs ();
+
+       check_dcp ("test/data/xml_subtitle_test", film->dir (film->dcp_name ()));
+}