]> git.sesse.net Git - nageru/blobdiff - player.cpp
Send refresh frames every 100 ms or so, so that the client does not think we are...
[nageru] / player.cpp
index 5c142ead63f1dfb98dbf8c35e47d3a8a00f3a185..2261ee43dff929f482aa0b2a6d52ec46dafbdb14 100644 (file)
@@ -55,16 +55,29 @@ void Player::thread_func(bool also_output_to_stream)
        double next_clip_fade_time = -1.0;
 
        for ( ;; ) {
+               bool clip_ready;
+               steady_clock::time_point before_sleep = steady_clock::now();
+
                // Wait until we're supposed to play something.
                {
                        unique_lock<mutex> lock(queue_state_mu);
-                       new_clip_changed.wait(lock, [this]{
+                       clip_ready = new_clip_changed.wait_for(lock, milliseconds(100), [this]{
                                return new_clip_ready && current_clip.pts_in != -1;
                        });
                        new_clip_ready = false;
                        playing = true;
                }
 
+               steady_clock::duration time_slept = steady_clock::now() - before_sleep;
+               pts += duration_cast<duration<size_t, TimebaseRatio>>(time_slept).count();
+
+               if (!clip_ready) {
+                       if (video_stream != nullptr) {
+                               video_stream->schedule_refresh_frame(pts);
+                       }
+                       continue;
+               }
+
                Clip clip;
                unsigned stream_idx;
                {
@@ -116,7 +129,6 @@ got_clip:
 
                                        double duration_next_clip = (next_clip.pts_out - next_clip.pts_in) / TIMEBASE / speed;
                                        next_clip_fade_time = std::min(time_left_this_clip, duration_next_clip);
-                                       fprintf(stderr, "decided on %.3f seconds fade time [%f %f]\n", next_clip_fade_time, time_left_this_clip, duration_next_clip);
                                }
                        }