]> git.sesse.net Git - nageru/blobdiff - player.cpp
Stop sending interpolated images through the cache.
[nageru] / player.cpp
index 1c26f60ddf184578273b99cf94f01c73f7700f6b..281462358358a70307d190b3db34a570e1474271 100644 (file)
@@ -194,17 +194,27 @@ got_clip:
                                break;
                        }
 
-                       // If the queue is full (which is really the state we'd like to be in),
-                       // wait until there's room for one more frame (ie., one was output from
-                       // VideoStream), or until or until there's a new clip we're supposed to play.
                        {
                                unique_lock<mutex> lock(queue_state_mu);
-                               new_clip_changed.wait(lock, [this]{
-                                       if (video_stream != nullptr && num_queued_frames < max_queued_frames) {
-                                               return true;
-                                       }
-                                       return new_clip_ready || override_stream_idx != -1;
-                               });
+                               if (video_stream == nullptr) {
+                                       // No queue, just wait until the right time and then show the frame.
+                                       new_clip_changed.wait_until(lock, next_frame_start, [this]{
+                                               return new_clip_ready || override_stream_idx != -1;
+                                       });
+                               } else {
+                                       // If the queue is full (which is really the state we'd like to be in),
+                                       // wait until there's room for one more frame (ie., one was output from
+                                       // VideoStream), or until or until there's a new clip we're supposed to play.
+                                       //
+                                       // In this case, we don't sleep until next_frame_start; the displaying is
+                                       // done by the queue.
+                                       new_clip_changed.wait(lock, [this]{
+                                               if (num_queued_frames < max_queued_frames) {
+                                                       return true;
+                                               }
+                                               return new_clip_ready || override_stream_idx != -1;
+                                       });
+                               }
                                if (new_clip_ready) {
                                        if (video_stream != nullptr) {
                                                lock.unlock();  // Urg.
@@ -222,7 +232,7 @@ got_clip:
 
                        if (in_pts_lower == in_pts_upper) {
                                auto display_func = [this, primary_stream_idx, in_pts_lower, secondary_stream_idx, secondary_pts, fade_alpha]{
-                                       destination->setFrame(primary_stream_idx, in_pts_lower, /*interpolated=*/false, secondary_stream_idx, secondary_pts, fade_alpha);
+                                       destination->setFrame(primary_stream_idx, in_pts_lower, secondary_stream_idx, secondary_pts, fade_alpha);
                                };
                                if (video_stream == nullptr) {
                                        display_func();
@@ -232,6 +242,7 @@ got_clip:
                                                        next_frame_start, pts, display_func, QueueSpotHolder(this),
                                                        primary_stream_idx, in_pts_lower);
                                        } else {
+                                               assert(secondary_pts != -1);
                                                video_stream->schedule_faded_frame(next_frame_start, pts, display_func,
                                                        QueueSpotHolder(this), primary_stream_idx, in_pts_lower,
                                                        secondary_stream_idx, secondary_pts, fade_alpha);
@@ -248,7 +259,7 @@ got_clip:
                                double snap_pts_as_frameno = (snap_pts - in_pts_origin) * output_framerate / TIMEBASE / speed;
                                if (fabs(snap_pts_as_frameno - frameno) < 0.01) {
                                        auto display_func = [this, primary_stream_idx, snap_pts, secondary_stream_idx, secondary_pts, fade_alpha]{
-                                               destination->setFrame(primary_stream_idx, snap_pts, /*interpolated=*/false, secondary_stream_idx, secondary_pts, fade_alpha);
+                                               destination->setFrame(primary_stream_idx, snap_pts, secondary_stream_idx, secondary_pts, fade_alpha);
                                        };
                                        if (video_stream == nullptr) {
                                                display_func();
@@ -258,6 +269,7 @@ got_clip:
                                                                next_frame_start, pts, display_func,
                                                                QueueSpotHolder(this), primary_stream_idx, snap_pts);
                                                } else {
+                                                       assert(secondary_pts != -1);
                                                        video_stream->schedule_faded_frame(
                                                                next_frame_start, pts, display_func, QueueSpotHolder(this),
                                                                primary_stream_idx, snap_pts, secondary_stream_idx, secondary_pts, fade_alpha);
@@ -283,10 +295,10 @@ got_clip:
                        if (video_stream == nullptr) {
                                // Previews don't do any interpolation.
                                assert(secondary_stream_idx == -1);
-                               destination->setFrame(primary_stream_idx, in_pts_lower, /*interpolated=*/false);
+                               destination->setFrame(primary_stream_idx, in_pts_lower);
                        } else {
-                               auto display_func = [this, primary_stream_idx, pts, secondary_stream_idx, secondary_pts, fade_alpha]{
-                                       destination->setFrame(primary_stream_idx, pts, /*interpolated=*/true, secondary_stream_idx, secondary_pts, fade_alpha);
+                               auto display_func = [this](shared_ptr<Frame> frame) {
+                                       destination->setFrame(frame);
                                };
                                video_stream->schedule_interpolated_frame(
                                        next_frame_start, pts, display_func, QueueSpotHolder(this),
@@ -419,7 +431,7 @@ void Player::override_angle(unsigned stream_idx)
        if (it == frames[stream_idx].end()) {
                return;
        }
-       destination->setFrame(stream_idx, *it, /*interpolated=*/false);
+       destination->setFrame(stream_idx, *it);
 }
 
 void Player::take_queue_spot()