]> git.sesse.net Git - nageru/blobdiff - futatabi/player.cpp
Fix a Clang warning.
[nageru] / futatabi / player.cpp
index 2fb3939ec65d4f7c09276494845ab1abe51fe2ae..b7b22c8add9dea82b613f06bcc710e1dd529b92d 100644 (file)
@@ -138,7 +138,7 @@ got_clip:
                                if (next_clip.pts_in != -1) {
                                        got_next_clip = true;
 
-                                       double duration_next_clip = (next_clip.pts_out - next_clip.pts_in) / TIMEBASE / speed;
+                                       double duration_next_clip = double(next_clip.pts_out - next_clip.pts_in) / TIMEBASE / speed;
                                        next_clip_fade_time = std::min(time_left_this_clip, duration_next_clip);
                                        in_pts_start_next_clip = next_clip.pts_in + lrint(next_clip_fade_time * TIMEBASE * speed);
                                }
@@ -472,3 +472,27 @@ void Player::release_queue_spot()
        --num_queued_frames;
        new_clip_changed.notify_all();
 }
+
+double compute_time_left(const vector<Clip> &clips, const map<size_t, double> &progress)
+{
+       // Look at the last clip and then start counting from there.
+       assert(!progress.empty());
+       auto last_it = progress.end();
+       --last_it;
+       double remaining = 0.0;
+       double last_fade_time_seconds = 0.0;
+       for (size_t row = last_it->first; row < clips.size(); ++row) {
+               const Clip &clip = clips[row];
+               double clip_length = double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5;  // FIXME: stop hardcoding speed.
+               if (row == last_it->first) {
+                       // A clip we're playing: Subtract the part we've already played.
+                       remaining = clip_length * (1.0 - last_it->second);
+               } else {
+                       // A clip we haven't played yet: Subtract the part that's overlapping
+                       // with a previous clip (due to fade).
+                       remaining += max(clip_length - last_fade_time_seconds, 0.0);
+               }
+               last_fade_time_seconds = min(clip_length, clip.fade_time_seconds);
+       }
+       return remaining;
+}