]> git.sesse.net Git - nageru/blobdiff - futatabi/player.cpp
Fix some issues with the “time remaining” display.
[nageru] / futatabi / player.cpp
index 3545eb13c83c4008cf797324421ef7b1068d3ca5..263edbfce05590f5b4325c071557bd234eec0cfd 100644 (file)
@@ -50,6 +50,9 @@ void Player::thread_func(AVFormatContext *file_avctx)
 
        while (!should_quit) {
                play_playlist_once();
+               if (done_callback != nullptr) {
+                       done_callback();
+               }
        }
 }
 
@@ -64,7 +67,7 @@ double calc_progress(const Clip &clip, int64_t pts)
 
 void Player::play_playlist_once()
 {
-       vector<ClipWithRow> clip_list;
+       vector<ClipWithID> clip_list;
        bool clip_ready;
        steady_clock::time_point before_sleep = steady_clock::now();
 
@@ -180,11 +183,11 @@ void Player::play_playlist_once()
                        if (progress_callback != nullptr) {
                                // NOTE: None of this will take into account any snapping done below.
                                double clip_progress = calc_progress(clip, in_pts_for_progress);
-                               map<size_t, double> progress{ { clip_list[clip_idx].row, clip_progress } };
+                               map<uint64_t, double> progress{ { clip_list[clip_idx].id, clip_progress } };
                                double time_remaining;
                                if (next_clip != nullptr && time_left_this_clip <= next_clip_fade_time) {
                                        double next_clip_progress = calc_progress(*next_clip, in_pts_secondary_for_progress);
-                                       progress[clip_list[clip_idx + 1].row] = next_clip_progress;
+                                       progress[clip_list[clip_idx + 1].id] = next_clip_progress;
                                        time_remaining = compute_time_left(clip_list, clip_idx + 1, next_clip_progress);
                                } else {
                                        time_remaining = compute_time_left(clip_list, clip_idx, clip_progress);
@@ -322,9 +325,6 @@ void Player::play_playlist_once()
                if (should_quit) {
                        return;
                }
-               if (done_callback != nullptr) {
-                       done_callback();
-               }
 
                // Start the next clip from the point where the fade went out.
                if (next_clip != nullptr) {
@@ -332,10 +332,6 @@ void Player::play_playlist_once()
                        in_pts_origin = next_clip->pts_in + lrint(next_clip_fade_time * TIMEBASE * clip.speed);
                }
        }
-
-       if (done_callback != nullptr) {
-               done_callback();
-       }
 }
 
 void Player::display_single_frame(int primary_stream_idx, const FrameOnDisk &primary_frame, int secondary_stream_idx, const FrameOnDisk &secondary_frame, double fade_alpha, steady_clock::time_point frame_start, bool snapped)
@@ -425,7 +421,7 @@ Player::~Player()
        player_thread.join();
 }
 
-void Player::play(const vector<Player::ClipWithRow> &clips)
+void Player::play(const vector<ClipWithID> &clips)
 {
        lock_guard<mutex> lock(queue_state_mu);
        new_clip_ready = true;
@@ -486,7 +482,7 @@ void Player::release_queue_spot()
        new_clip_changed.notify_all();
 }
 
-double compute_time_left(const vector<Player::ClipWithRow> &clips, size_t currently_playing_idx, double progress_currently_playing) 
+double compute_time_left(const vector<ClipWithID> &clips, size_t currently_playing_idx, double progress_currently_playing) 
 {
        // Look at the last clip and then start counting from there.
        double remaining = 0.0;