Basics of forced reduction of JPEG2000 decode resolution.
[dcpomatic.git] / src / lib / player.cc
index a1adee0b0d08727c7362fdf8218a96e9821f8256..7e21ef937b82a98f5ff3198ac07c2ea0a469cbfb 100644 (file)
@@ -127,7 +127,10 @@ Player::setup_pieces ()
 
                shared_ptr<DCPDecoder> dcp = dynamic_pointer_cast<DCPDecoder> (decoder);
                if (dcp && _play_referenced) {
-                       dcp->set_decode_referenced ();
+                       if (_play_referenced) {
+                               dcp->set_decode_referenced ();
+                       }
+                       dcp->set_forced_reduction (_dcp_decode_reduction);
                }
 
                shared_ptr<Piece> piece (new Piece (i, decoder, frc));
@@ -156,8 +159,8 @@ Player::setup_pieces ()
                }
        }
 
-       _black = Empty (_film, bind(&Content::video, _1));
-       _silent = Empty (_film, bind(&Content::audio, _1));
+       _black = Empty (_film->content(), _film->length(), bind(&Content::video, _1));
+       _silent = Empty (_film->content(), _film->length(), bind(&Content::audio, _1));
 
        _last_video_time = DCPTime ();
        _last_audio_time = DCPTime ();
@@ -645,9 +648,8 @@ Player::video (weak_ptr<Piece> wp, ContentVideo video)
                return;
        }
 
-       /* Time and period of the frame we will emit */
+       /* Time of the first frame we will emit */
        DCPTime const time = content_video_to_dcp (piece, video.frame);
-       DCPTimePeriod const period (time, time + one_video_frame());
 
        /* Discard if it's outside the content's period or if it's before the last accurate seek */
        if (
@@ -687,7 +689,11 @@ Player::video (weak_ptr<Piece> wp, ContentVideo video)
                        )
                );
 
-       emit_video (_last_video[wp], time);
+       DCPTime t = time;
+       for (int i = 0; i < frc.repeat; ++i) {
+               emit_video (_last_video[wp], t);
+               t += one_video_frame ();
+       }
 }
 
 void
@@ -847,6 +853,10 @@ Player::subtitle_stop (weak_ptr<Piece> wp, ContentTime to)
 void
 Player::seek (DCPTime time, bool accurate)
 {
+       if (!_have_valid_pieces) {
+               setup_pieces ();
+       }
+
        if (_audio_processor) {
                _audio_processor->flush ();
        }
@@ -947,3 +957,15 @@ Player::discard_audio (shared_ptr<const AudioBuffers> audio, DCPTime time, DCPTi
        cut->copy_from (audio.get(), remaining_frames, discard_frames, 0);
        return make_pair(cut, time + discard_time);
 }
+
+void
+Player::set_dcp_decode_reduction (optional<int> reduction)
+{
+       if (reduction == _dcp_decode_reduction) {
+               return;
+       }
+
+       _dcp_decode_reduction = reduction;
+       _have_valid_pieces = false;
+       Changed (false);
+}