while (!should_quit) {
play_playlist_once();
+ if (done_callback != nullptr) {
+ done_callback();
+ }
}
}
void Player::play_playlist_once()
{
- vector<Clip> clip_list;
+ vector<ClipWithRow> clip_list;
bool clip_ready;
steady_clock::time_point before_sleep = steady_clock::now();
}
steady_clock::time_point origin = steady_clock::now(); // TODO: Add a 100 ms buffer for ramp-up?
- int64_t in_pts_origin = clip_list[0].pts_in;
+ int64_t in_pts_origin = clip_list[0].clip.pts_in;
for (size_t clip_idx = 0; clip_idx < clip_list.size(); ++clip_idx) {
- const Clip &clip = clip_list[clip_idx];
- const Clip *next_clip = (clip_idx + 1 < clip_list.size()) ? &clip_list[clip_idx + 1] : nullptr;
+ const Clip &clip = clip_list[clip_idx].clip;
+ const Clip *next_clip = (clip_idx + 1 < clip_list.size()) ? &clip_list[clip_idx + 1].clip : nullptr;
int64_t out_pts_origin = pts;
double next_clip_fade_time = -1.0;
if (progress_callback != nullptr) {
// NOTE: None of this will take into account any snapping done below.
- map<size_t, double> progress{ { clip_idx, calc_progress(clip, in_pts_for_progress) } };
+ double clip_progress = calc_progress(clip, in_pts_for_progress);
+ map<size_t, double> progress{ { clip_list[clip_idx].row, clip_progress } };
+ double time_remaining;
if (next_clip != nullptr && time_left_this_clip <= next_clip_fade_time) {
- progress[clip_idx + 1] = calc_progress(*next_clip, in_pts_secondary_for_progress);
+ double next_clip_progress = calc_progress(*next_clip, in_pts_secondary_for_progress);
+ progress[clip_list[clip_idx + 1].row] = 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);
}
- progress_callback(progress);
+ progress_callback(progress, time_remaining);
}
FrameOnDisk frame_lower, frame_upper;
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) {
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)
player_thread.join();
}
-void Player::play(const vector<Clip> &clips)
+void Player::play(const vector<Player::ClipWithRow> &clips)
{
lock_guard<mutex> lock(queue_state_mu);
new_clip_ready = true;
lock_guard<mutex> lock(queue_state_mu);
if (new_clip_ready) {
assert(queued_clip_list.size() == 1);
- queued_clip_list[0].stream_idx = stream_idx;
+ queued_clip_list[0].clip.stream_idx = stream_idx;
return;
}
new_clip_changed.notify_all();
}
-double compute_time_left(const vector<Clip> &clips, const map<size_t, double> &progress)
+double compute_time_left(const vector<Player::ClipWithRow> &clips, size_t currently_playing_idx, double progress_currently_playing)
{
// 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];
+ for (size_t row = currently_playing_idx; row < clips.size(); ++row) {
+ const Clip &clip = clips[row].clip;
double clip_length = double(clip.pts_out - clip.pts_in) / TIMEBASE / clip.speed;
- if (row == last_it->first) {
+ if (row == currently_playing_idx) {
// A clip we're playing: Subtract the part we've already played.
- remaining = clip_length * (1.0 - last_it->second);
+ remaining = clip_length * (1.0 - progress_currently_playing);
} else {
// A clip we haven't played yet: Subtract the part that's overlapping
// with a previous clip (due to fade).