Rename SubRip -> TextSubtitle.
[dcpomatic.git] / src / lib / player.cc
index 116410046e5f0eaa3b5acfc9eddb8aee533d1b0b..fc13325730142222a5bbc18185ebe6d019416689 100644 (file)
@@ -27,8 +27,8 @@
 #include "sndfile_decoder.h"
 #include "sndfile_content.h"
 #include "subtitle_content.h"
-#include "subrip_decoder.h"
-#include "subrip_content.h"
+#include "text_subtitle_decoder.h"
+#include "text_subtitle_content.h"
 #include "dcp_content.h"
 #include "job.h"
 #include "image.h"
@@ -74,6 +74,7 @@ using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
 using boost::optional;
+using boost::scoped_ptr;
 
 Player::Player (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist)
        : _film (film)
@@ -173,10 +174,10 @@ Player::setup_pieces ()
                   as simultaneous video content (like we do with audio).
                */
 
-               /* SubRipContent */
-               shared_ptr<const SubRipContent> rc = dynamic_pointer_cast<const SubRipContent> (i);
+               /* TextSubtitleContent */
+               shared_ptr<const TextSubtitleContent> rc = dynamic_pointer_cast<const TextSubtitleContent> (i);
                if (rc) {
-                       decoder.reset (new SubRipDecoder (rc));
+                       decoder.reset (new TextSubtitleDecoder (rc));
                        frc = FrameRateChange (rc->subtitle_video_frame_rate(), _film->video_frame_rate());
                }
 
@@ -218,7 +219,10 @@ Player::playlist_content_changed (weak_ptr<Content> w, int property, bool freque
                property == ContentProperty::TRIM_END ||
                property == ContentProperty::PATH ||
                property == VideoContentProperty::VIDEO_FRAME_TYPE ||
-               property == DCPContentProperty::CAN_BE_PLAYED
+               property == DCPContentProperty::CAN_BE_PLAYED ||
+               property == TextSubtitleContentProperty::TEXT_SUBTITLE_COLOUR ||
+               property == TextSubtitleContentProperty::TEXT_SUBTITLE_OUTLINE ||
+               property == TextSubtitleContentProperty::TEXT_SUBTITLE_OUTLINE_COLOUR
                ) {
 
                _have_valid_pieces = false;
@@ -357,7 +361,7 @@ Player::get_video (DCPTime time, bool accurate)
 
        /* Find subtitles for possible burn-in */
 
-       PlayerSubtitles ps = get_subtitles (time, DCPTime::from_frames (1, _film->video_frame_rate ()), false, true);
+       PlayerSubtitles ps = get_subtitles (time, DCPTime::from_frames (1, _film->video_frame_rate ()), false, true, accurate);
 
        list<PositionImage> sub_images;
 
@@ -619,7 +623,7 @@ Player::content_subtitle_to_dcp (shared_ptr<const Piece> piece, ContentTime t) c
  *  _always_burn_subtitles is true; in this case, all subtitles will be returned.
  */
 PlayerSubtitles
-Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt)
+Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt, bool accurate)
 {
        list<shared_ptr<Piece> > subs = overlaps<SubtitleContent> (time, time + length);
 
@@ -641,7 +645,7 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt)
                /* XXX: this video_frame_rate() should be the rate that the subtitle content has been prepared for */
                ContentTime const to = from + ContentTime::from_frames (1, _film->video_frame_rate ());
 
-               list<ContentImageSubtitle> image = subtitle_decoder->get_image_subtitles (ContentTimePeriod (from, to), starting);
+               list<ContentImageSubtitle> image = subtitle_decoder->get_image_subtitles (ContentTimePeriod (from, to), starting, accurate);
                for (list<ContentImageSubtitle>::iterator i = image.begin(); i != image.end(); ++i) {
 
                        /* Apply content's subtitle offsets */
@@ -659,7 +663,7 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt)
                        ps.image.push_back (i->sub);
                }
 
-               list<ContentTextSubtitle> text = subtitle_decoder->get_text_subtitles (ContentTimePeriod (from, to), starting);
+               list<ContentTextSubtitle> text = subtitle_decoder->get_text_subtitles (ContentTimePeriod (from, to), starting, accurate);
                BOOST_FOREACH (ContentTextSubtitle& ts, text) {
                        BOOST_FOREACH (dcp::SubtitleString s, ts.subs) {
                                s.set_h_position (s.h_position() + subtitle_content->subtitle_x_offset ());
@@ -752,9 +756,16 @@ Player::get_reel_assets ()
                if (!j) {
                        continue;
                }
-               DCPDecoder decoder (j, false);
+
+               scoped_ptr<DCPDecoder> decoder;
+               try {
+                       decoder.reset (new DCPDecoder (j, false));
+               } catch (...) {
+                       return a;
+               }
+
                int64_t offset = 0;
-               BOOST_FOREACH (shared_ptr<dcp::Reel> k, decoder.reels()) {
+               BOOST_FOREACH (shared_ptr<dcp::Reel> k, decoder->reels()) {
                        DCPTime const from = i->position() + DCPTime::from_frames (offset, _film->video_frame_rate());
                        if (j->reference_video ()) {
                                a.push_back (
@@ -775,6 +786,7 @@ Player::get_reel_assets ()
                        }
 
                        if (j->reference_subtitle ()) {
+                               DCPOMATIC_ASSERT (k->main_subtitle ());
                                a.push_back (
                                        ReferencedReelAsset (
                                                k->main_subtitle (),