Remove approximate size stuff where playback viewer would round
[dcpomatic.git] / src / lib / player.cc
index 5c29efc4674ede50a6a9f759a52cb30b0ad76672..436ae3fe88fb33adaee5aacb1c2f3cfd99799b7f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2015 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
@@ -36,7 +36,6 @@
 #include "raw_image_proxy.h"
 #include "ratio.h"
 #include "log.h"
-#include "scaler.h"
 #include "render_subtitles.h"
 #include "config.h"
 #include "content_video.h"
@@ -72,7 +71,6 @@ Player::Player (shared_ptr<const Film> f, shared_ptr<const Playlist> p)
        : _film (f)
        , _playlist (p)
        , _have_valid_pieces (false)
-       , _approximate_size (false)
        , _ignore_video (false)
 {
        _playlist_changed_connection = _playlist->Changed.connect (bind (&Player::playlist_changed, this));
@@ -223,7 +221,6 @@ Player::content_changed (weak_ptr<Content> w, int property, bool frequent)
        }
 }
 
-/** @param already_resampled true if this data has already been through the chain up to the resampler */
 void
 Player::playlist_changed ()
 {
@@ -248,7 +245,7 @@ Player::film_changed (Film::Property p)
           last time we were run.
        */
 
-       if (p == Film::SCALER || p == Film::CONTAINER || p == Film::VIDEO_FRAME_RATE) {
+       if (p == Film::CONTAINER || p == Film::VIDEO_FRAME_RATE) {
                Changed (false);
        }
 }
@@ -282,7 +279,7 @@ Player::transform_image_subtitles (list<ImageSubtitle> subs) const
                        PositionImage (
                                i->image->scale (
                                        scaled_size,
-                                       Scaler::from_id ("bicubic"),
+                                       dcp::YUV_TO_RGB_REC601,
                                        i->image->pixel_format (),
                                        true
                                        ),
@@ -297,12 +294,6 @@ Player::transform_image_subtitles (list<ImageSubtitle> subs) const
        return all;
 }
 
-void
-Player::set_approximate_size ()
-{
-       _approximate_size = true;
-}
-
 shared_ptr<PlayerVideo>
 Player::black_player_video_frame (DCPTime time) const
 {
@@ -314,7 +305,6 @@ Player::black_player_video_frame (DCPTime time) const
                        optional<float> (),
                        _video_container_size,
                        _video_container_size,
-                       Scaler::from_id ("bicubic"),
                        EYES_BOTH,
                        PART_WHOLE,
                        Config::instance()->colour_conversions().front().conversion
@@ -355,11 +345,7 @@ Player::get_video (DCPTime time, bool accurate)
                        return pvf;
                }
                
-               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;
-               }
+               dcp::Size image_size = content->scale().size (content, _video_container_size, _film->frame_size ());
 
                for (list<ContentVideo>::const_iterator i = content_video.begin(); i != content_video.end(); ++i) {
                        pvf.push_back (
@@ -371,7 +357,6 @@ Player::get_video (DCPTime time, bool accurate)
                                                content->fade (i->frame),
                                                image_size,
                                                _video_container_size,
-                                               _film->scaler(),
                                                i->eyes,
                                                i->part,
                                                content->colour_conversion ()
@@ -436,19 +421,24 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate)
 
                /* The time that we should request from the content */
                DCPTime request = time - DCPTime::from_seconds (content->audio_delay() / 1000.0);
+               AudioFrame request_frames = length_frames;
                DCPTime offset;
                if (request < DCPTime ()) {
                        /* We went off the start of the content, so we will need to offset
                           the stuff we get back.
                        */
                        offset = -request;
+                       request_frames += request.frames (_film->audio_frame_rate ());
+                       if (request_frames < 0) {
+                               request_frames = 0;
+                       }
                        request = DCPTime ();
                }
 
                AudioFrame const content_frame = dcp_to_content_audio (*i, request);
 
                /* Audio from this piece's decoder (which might be more or less than what we asked for) */
-               shared_ptr<ContentAudio> all = decoder->get_audio (content_frame, length_frames, accurate);
+               shared_ptr<ContentAudio> all = decoder->get_audio (content_frame, request_frames, accurate);
 
                /* Gain */
                if (content->audio_gain() != 0) {
@@ -480,7 +470,7 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate)
                        all->audio.get(),
                        content_frame - all->frame,
                        offset.frames (_film->audio_frame_rate()),
-                       min (AudioFrame (all->audio->frames()), length_frames) - offset.frames (_film->audio_frame_rate ())
+                       min (AudioFrame (all->audio->frames()), request_frames)
                        );
        }