Reasonably straightforward stuff; main things are adding
[dcpomatic.git] / src / lib / player.cc
index 3ae95cf5275d2ea0f5393c6d7d9abc40909e9501..2b65fd54e393d5c252fecb67a564115d45bb3630 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"
@@ -113,13 +113,13 @@ Player::setup_pieces ()
                shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (i);
                if (fc) {
                        decoder.reset (new FFmpegDecoder (fc, _film->log(), _fast));
-                       frc = FrameRateChange (fc->video_frame_rate(), _film->video_frame_rate());
+                       frc = FrameRateChange (fc->video->video_frame_rate(), _film->video_frame_rate());
                }
 
                shared_ptr<const DCPContent> dc = dynamic_pointer_cast<const DCPContent> (i);
                if (dc) {
-                       decoder.reset (new DCPDecoder (dc, _fast));
-                       frc = FrameRateChange (dc->video_frame_rate(), _film->video_frame_rate());
+                       decoder.reset (new DCPDecoder (dc, _film->log(), _fast));
+                       frc = FrameRateChange (dc->video->video_frame_rate(), _film->video_frame_rate());
                }
 
                /* ImageContent */
@@ -134,10 +134,10 @@ Player::setup_pieces ()
                        }
 
                        if (!decoder) {
-                               decoder.reset (new ImageDecoder (ic));
+                               decoder.reset (new ImageDecoder (ic, _film->log()));
                        }
 
-                       frc = FrameRateChange (ic->video_frame_rate(), _film->video_frame_rate());
+                       frc = FrameRateChange (ic->video->video_frame_rate(), _film->video_frame_rate());
                }
 
                /* SndfileContent */
@@ -147,22 +147,21 @@ Player::setup_pieces ()
 
                        /* Work out a FrameRateChange for the best overlap video for this content */
                        DCPTime best_overlap_t;
-                       shared_ptr<VideoContent> best_overlap;
+                       shared_ptr<Content> best_overlap;
                        BOOST_FOREACH (shared_ptr<Content> j, _playlist->content ()) {
-                               shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (j);
-                               if (!vc) {
+                               if (!j->video) {
                                        continue;
                                }
 
-                               DCPTime const overlap = min (vc->end(), i->end()) - max (vc->position(), i->position());
+                               DCPTime const overlap = min (j->end(), i->end()) - max (j->position(), i->position());
                                if (overlap > best_overlap_t) {
-                                       best_overlap = vc;
+                                       best_overlap = j;
                                        best_overlap_t = overlap;
                                }
                        }
 
                        if (best_overlap) {
-                               frc = FrameRateChange (best_overlap->video_frame_rate(), _film->video_frame_rate ());
+                               frc = FrameRateChange (best_overlap->video->video_frame_rate(), _film->video_frame_rate ());
                        } else {
                                /* No video overlap; e.g. if the DCP is just audio */
                                frc = FrameRateChange (_film->video_frame_rate(), _film->video_frame_rate ());
@@ -174,10 +173,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());
                }
 
@@ -219,7 +218,11 @@ 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 ||
+               property == FFmpegContentProperty::SUBTITLE_STREAM
                ) {
 
                _have_valid_pieces = false;
@@ -314,7 +317,8 @@ Player::transform_image_subtitles (list<ImageSubtitle> subs) const
                                        scaled_size,
                                        dcp::YUV_TO_RGB_REC601,
                                        i->image->pixel_format (),
-                                       true
+                                       true,
+                                       _fast
                                        ),
                                Position<int> (
                                        lrint (_video_container_size.width * i->rectangle.x),
@@ -392,17 +396,15 @@ Player::get_video (DCPTime time, bool accurate)
        } else {
                /* Some video content at this time */
                shared_ptr<Piece> last = *(ov.rbegin ());
-               VideoFrameType const last_type = dynamic_pointer_cast<VideoContent> (last->content)->video_frame_type ();
+               VideoFrameType const last_type = last->content->video->video_frame_type ();
 
                /* Get video from appropriate piece(s) */
                BOOST_FOREACH (shared_ptr<Piece> piece, ov) {
 
                        shared_ptr<VideoDecoder> decoder = dynamic_pointer_cast<VideoDecoder> (piece->decoder);
                        DCPOMATIC_ASSERT (decoder);
-                       shared_ptr<VideoContent> video_content = dynamic_pointer_cast<VideoContent> (piece->content);
-                       DCPOMATIC_ASSERT (video_content);
 
-                       shared_ptr<DCPContent> dcp_content = dynamic_pointer_cast<DCPContent> (video_content);
+                       shared_ptr<DCPContent> dcp_content = dynamic_pointer_cast<DCPContent> (piece->content);
                        if (dcp_content && dcp_content->reference_video () && !_play_referenced) {
                                continue;
                        }
@@ -411,8 +413,8 @@ Player::get_video (DCPTime time, bool accurate)
                                /* always use the last video */
                                piece == last ||
                                /* with a corresponding L/R eye if appropriate */
-                               (last_type == VIDEO_FRAME_TYPE_3D_LEFT && video_content->video_frame_type() == VIDEO_FRAME_TYPE_3D_RIGHT) ||
-                               (last_type == VIDEO_FRAME_TYPE_3D_RIGHT && video_content->video_frame_type() == VIDEO_FRAME_TYPE_3D_LEFT);
+                               (last_type == VIDEO_FRAME_TYPE_3D_LEFT && piece->content->video->video_frame_type() == VIDEO_FRAME_TYPE_3D_RIGHT) ||
+                               (last_type == VIDEO_FRAME_TYPE_3D_RIGHT && piece->content->video->video_frame_type() == VIDEO_FRAME_TYPE_3D_LEFT);
 
                        if (use) {
                                /* We want to use this piece */
@@ -420,7 +422,9 @@ Player::get_video (DCPTime time, bool accurate)
                                if (content_video.empty ()) {
                                        pvf.push_back (black_player_video_frame (time));
                                } else {
-                                       dcp::Size image_size = video_content->scale().size (video_content, _video_container_size, _film->frame_size ());
+                                       dcp::Size image_size = piece->content->video->scale().size (
+                                               piece->content->video, _video_container_size, _film->frame_size ()
+                                               );
 
                                        for (list<ContentVideo>::const_iterator i = content_video.begin(); i != content_video.end(); ++i) {
                                                pvf.push_back (
@@ -428,13 +432,13 @@ Player::get_video (DCPTime time, bool accurate)
                                                                new PlayerVideo (
                                                                        i->image,
                                                                        content_video_to_dcp (piece, i->frame),
-                                                                       video_content->crop (),
-                                                                       video_content->fade (i->frame),
+                                                                       piece->content->video->crop (),
+                                                                       piece->content->video->fade (i->frame),
                                                                        image_size,
                                                                        _video_container_size,
                                                                        i->eyes,
                                                                        i->part,
-                                                                       video_content->colour_conversion ()
+                                                                       piece->content->video->colour_conversion ()
                                                                        )
                                                                )
                                                        );
@@ -667,8 +671,17 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt,
                                s.set_v_position (s.v_position() + subtitle_content->subtitle_y_offset ());
                                float const xs = subtitle_content->subtitle_x_scale();
                                float const ys = subtitle_content->subtitle_y_scale();
-                               float const average = s.size() * (xs + ys) / 2;
-                               s.set_size (average);
+                               float size = s.size();
+
+                               /* Adjust size to express the common part of the scaling;
+                                  e.g. if xs = ys = 0.5 we scale size by 2.
+                               */
+                               if (xs > 1e-5 && ys > 1e-5) {
+                                       size *= 1 / min (1 / xs, 1 / ys);
+                               }
+                               s.set_size (size);
+
+                               /* Then express aspect ratio changes */
                                if (fabs (1.0 - xs / ys) > dcp::ASPECT_ADJUST_EPSILON) {
                                        s.set_aspect_adjust (xs / ys);
                                }
@@ -756,7 +769,7 @@ Player::get_reel_assets ()
 
                scoped_ptr<DCPDecoder> decoder;
                try {
-                       decoder.reset (new DCPDecoder (j, false));
+                       decoder.reset (new DCPDecoder (j, _film->log(), false));
                } catch (...) {
                        return a;
                }
@@ -783,6 +796,7 @@ Player::get_reel_assets ()
                        }
 
                        if (j->reference_subtitle ()) {
+                               DCPOMATIC_ASSERT (k->main_subtitle ());
                                a.push_back (
                                        ReferencedReelAsset (
                                                k->main_subtitle (),