Merge master.
[dcpomatic.git] / src / lib / player.cc
index 9f9f8db2e3374b369f7c206e480310b9d278dd01..f83c9563b29ce80cab262ad02c22c913219cf835 100644 (file)
 #include "subtitle_content.h"
 #include "subrip_decoder.h"
 #include "subrip_content.h"
+#include "dcp_content.h"
 #include "playlist.h"
 #include "job.h"
 #include "image.h"
-#include "image_proxy.h"
+#include "raw_image_proxy.h"
 #include "ratio.h"
 #include "log.h"
 #include "scaler.h"
@@ -45,6 +46,8 @@
 #include "frame_rate_change.h"
 #include "dcp_content.h"
 #include "dcp_decoder.h"
+#include "dcp_subtitle_content.h"
+#include "dcp_subtitle_decoder.h"
 
 #define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL);
 
@@ -160,6 +163,13 @@ Player::setup_pieces ()
                        frc = best_overlap_frc;
                }
 
+               /* DCPSubtitleContent */
+               shared_ptr<const DCPSubtitleContent> dsc = dynamic_pointer_cast<const DCPSubtitleContent> (*i);
+               if (dsc) {
+                       decoder.reset (new DCPSubtitleDecoder (dsc));
+                       frc = best_overlap_frc;
+               }
+
                _pieces.push_back (shared_ptr<Piece> (new Piece (*i, decoder, frc.get ())));
        }
 
@@ -180,17 +190,19 @@ Player::content_changed (weak_ptr<Content> w, int property, bool frequent)
                property == ContentProperty::TRIM_START ||
                property == ContentProperty::TRIM_END ||
                property == ContentProperty::PATH ||
-               property == VideoContentProperty::VIDEO_FRAME_TYPE
+               property == VideoContentProperty::VIDEO_FRAME_TYPE ||
+               property == DCPContentProperty::CAN_BE_PLAYED
                ) {
                
                _have_valid_pieces = false;
                Changed (frequent);
 
        } else if (
-               property == SubtitleContentProperty::SUBTITLE_USE ||
+               property == SubtitleContentProperty::USE_SUBTITLES ||
                property == SubtitleContentProperty::SUBTITLE_X_OFFSET ||
                property == SubtitleContentProperty::SUBTITLE_Y_OFFSET ||
-               property == SubtitleContentProperty::SUBTITLE_SCALE ||
+               property == SubtitleContentProperty::SUBTITLE_X_SCALE ||
+               property == SubtitleContentProperty::SUBTITLE_Y_SCALE ||
                property == VideoContentProperty::VIDEO_CROP ||
                property == VideoContentProperty::VIDEO_SCALE ||
                property == VideoContentProperty::VIDEO_FRAME_RATE
@@ -249,8 +261,8 @@ Player::transform_image_subtitles (list<ImageSubtitle> subs) const
                 *     rect.x * _video_container_size.width and rect.y * _video_container_size.height.
                 *
                 * 2.  that to shift the origin of the scale by subtitle_scale to the centre of the subtitle; this will be
-                *     (width_before_subtitle_scale * (1 - subtitle_scale) / 2) and
-                *     (height_before_subtitle_scale * (1 - subtitle_scale) / 2).
+                *     (width_before_subtitle_scale * (1 - subtitle_x_scale) / 2) and
+                *     (height_before_subtitle_scale * (1 - subtitle_y_scale) / 2).
                 *
                 * Combining these two translations gives these expressions.
                 */
@@ -331,7 +343,7 @@ Player::get_video (DCPTime time, bool accurate)
                        return pvf;
                }
                
-               dcp::Size image_size = content->scale().size (content, _video_container_size, _film->frame_size ());
+               dcp::Size image_size = content->scale().size (content, _video_container_size, _film->frame_size (), _approximate_size ? 4 : 1);
                if (_approximate_size) {
                        image_size.width &= ~3;
                        image_size.height &= ~3;
@@ -530,7 +542,7 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting)
 
        for (list<shared_ptr<Piece> >::const_iterator j = subs.begin(); j != subs.end(); ++j) {
                shared_ptr<SubtitleContent> subtitle_content = dynamic_pointer_cast<SubtitleContent> ((*j)->content);
-               if (!subtitle_content->subtitle_use ()) {
+               if (!subtitle_content->use_subtitles ()) {
                        continue;
                }
 
@@ -547,12 +559,12 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting)
                        i->sub.rectangle.y += subtitle_content->subtitle_y_offset ();
 
                        /* Apply content's subtitle scale */
-                       i->sub.rectangle.width *= subtitle_content->subtitle_scale ();
-                       i->sub.rectangle.height *= subtitle_content->subtitle_scale ();
+                       i->sub.rectangle.width *= subtitle_content->subtitle_x_scale ();
+                       i->sub.rectangle.height *= subtitle_content->subtitle_y_scale ();
 
                        /* Apply a corrective translation to keep the subtitle centred after that scale */
-                       i->sub.rectangle.x -= i->sub.rectangle.width * (subtitle_content->subtitle_scale() - 1);
-                       i->sub.rectangle.y -= i->sub.rectangle.height * (subtitle_content->subtitle_scale() - 1);
+                       i->sub.rectangle.x -= i->sub.rectangle.width * (subtitle_content->subtitle_x_scale() - 1);
+                       i->sub.rectangle.y -= i->sub.rectangle.height * (subtitle_content->subtitle_y_scale() - 1);
                        
                        ps.image.push_back (i->sub);
                }