Merge master.
[dcpomatic.git] / src / lib / player.cc
index ccc1ab2367e3e0fed2832790c4d97ccc9b9ce2db..e46d539f872c90fb1e130cdcd45049f77ddc169b 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"
 #include "content_video.h"
 #include "player_video.h"
 #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);
 
@@ -120,6 +125,12 @@ Player::setup_pieces ()
                        frc = FrameRateChange (fc->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, _film->log ()));
+                       frc = FrameRateChange (dc->video_frame_rate(), _film->video_frame_rate());
+               }
+
                /* ImageContent */
                shared_ptr<const ImageContent> ic = dynamic_pointer_cast<const ImageContent> (*i);
                if (ic) {
@@ -152,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 ())));
        }
 
@@ -172,14 +190,15 @@ 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 ||
@@ -323,7 +342,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;
@@ -350,7 +369,7 @@ Player::get_video (DCPTime time, bool accurate)
 
        /* Add subtitles (for possible burn-in) to whatever PlayerVideos we got */
 
-       PlayerSubtitles ps = get_subtitles (time, DCPTime::from_frames (1, _film->video_frame_rate ()));
+       PlayerSubtitles ps = get_subtitles (time, DCPTime::from_frames (1, _film->video_frame_rate ()), false);
 
        list<PositionImage> sub_images;
 
@@ -514,7 +533,7 @@ Player::statistics () const
 }
 
 PlayerSubtitles
-Player::get_subtitles (DCPTime time, DCPTime length)
+Player::get_subtitles (DCPTime time, DCPTime length, bool starting)
 {
        list<shared_ptr<Piece> > subs = overlaps<SubtitleContent> (time, time + length);
 
@@ -522,7 +541,7 @@ Player::get_subtitles (DCPTime time, DCPTime length)
 
        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;
                }
 
@@ -531,7 +550,7 @@ Player::get_subtitles (DCPTime time, DCPTime length)
                /* 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));
+               list<ContentImageSubtitle> image = subtitle_decoder->get_image_subtitles (ContentTimePeriod (from, to), starting);
                for (list<ContentImageSubtitle>::iterator i = image.begin(); i != image.end(); ++i) {
                        
                        /* Apply content's subtitle offsets */
@@ -549,7 +568,7 @@ Player::get_subtitles (DCPTime time, DCPTime length)
                        ps.image.push_back (i->sub);
                }
 
-               list<ContentTextSubtitle> text = subtitle_decoder->get_text_subtitles (ContentTimePeriod (from, to));
+               list<ContentTextSubtitle> text = subtitle_decoder->get_text_subtitles (ContentTimePeriod (from, to), starting);
                for (list<ContentTextSubtitle>::const_iterator i = text.begin(); i != text.end(); ++i) {
                        copy (i->subs.begin(), i->subs.end(), back_inserter (ps.text));
                }