X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fmainwindow.cpp;h=154537c7c4c05791c8532d8f35eb29536d3a46a2;hb=0403c737e76f127d046fcdf9eec7b2e3258833d8;hp=6553c8c56190e6f75571eee2d53e628563e2bd5c;hpb=4a9e97065dade428e373a83618bc973cd93cbe52;p=nageru diff --git a/futatabi/mainwindow.cpp b/futatabi/mainwindow.cpp index 6553c8c..154537c 100644 --- a/futatabi/mainwindow.cpp +++ b/futatabi/mainwindow.cpp @@ -186,12 +186,12 @@ MainWindow::MainWindow() live_player.reset(new Player(ui->live_display, Player::HTTPD_STREAM_OUTPUT)); live_player->set_done_callback([this] { post_to_main_thread([this] { - live_player_clip_done(); + live_player_done(); }); }); - live_player->set_progress_callback([this](const map &progress) { - post_to_main_thread([this, progress] { - live_player_clip_progress(progress); + live_player->set_progress_callback([this](const map &progress, double time_remaining) { + post_to_main_thread([this, progress, time_remaining] { + live_player_clip_progress(progress, time_remaining); }); }); set_output_status("paused"); @@ -336,7 +336,7 @@ void MainWindow::preview_clicked() if (selected->hasSelection()) { QModelIndex index = selected->currentIndex(); const Clip &clip = *playlist_clips->clip(index.row()); - preview_player->play({ clip }); + preview_player->play(clip); return; } } @@ -346,7 +346,7 @@ void MainWindow::preview_clicked() QItemSelectionModel *selected = ui->clip_list->selectionModel(); if (!selected->hasSelection()) { - preview_player->play({ *cliplist_clips->back() }); + preview_player->play(*cliplist_clips->back()); return; } @@ -357,7 +357,7 @@ void MainWindow::preview_clicked() } else { clip.stream_idx = ui->preview_display->get_stream_idx(); } - preview_player->play({ clip }); + preview_player->play(clip); } void MainWindow::preview_angle_clicked(unsigned stream_idx) @@ -431,6 +431,14 @@ void MainWindow::defer_timer_expired() void MainWindow::content_changed() { + // If we are playing, update the part of the playlist that's not playing yet. + vector clips; + for (unsigned row = 0; row < playlist_clips->size(); ++row) { + clips.emplace_back(*playlist_clips->clip_with_id(row)); + } + live_player->splice_play(clips); + + // Serialize the state. if (defer_timeout->isActive() && (!currently_deferring_model_changes || deferred_change_id != current_change_id)) { // There's some deferred event waiting, but this event is unrelated. @@ -487,16 +495,13 @@ void MainWindow::play_clicked() start_row = selected->selectedRows(0)[0].row(); } - live_player_index_to_row.clear(); - - vector clips; + vector clips; for (unsigned row = start_row; row < playlist_clips->size(); ++row) { - live_player_index_to_row.emplace(clips.size(), row); - clips.push_back(*playlist_clips->clip(row)); + clips.emplace_back(*playlist_clips->clip_with_id(row)); } live_player->play(clips); playlist_clips->set_progress({ { start_row, 0.0f } }); - playlist_clips->set_currently_playing(start_row, 0.0f); + ui->playlist->selectionModel()->clear(); playlist_selection_changed(); ui->stop_btn->setEnabled(true); @@ -507,77 +512,22 @@ void MainWindow::stop_clicked() Clip fake_clip; fake_clip.pts_in = 0; fake_clip.pts_out = 0; - size_t last_row = playlist_clips->size() - 1; - playlist_clips->set_currently_playing(last_row, 0.0f); - live_player_index_to_row.clear(); - live_player->play({ fake_clip }); -} - -void MainWindow::live_player_clip_done() -{ - int row = playlist_clips->get_currently_playing(); - if (row == -1 || row == int(playlist_clips->size()) - 1) { - set_output_status("paused"); - playlist_clips->set_progress({}); - playlist_clips->set_currently_playing(-1, 0.0f); - } else { - playlist_clips->set_progress({ { row + 1, 0.0f } }); - playlist_clips->set_currently_playing(row + 1, 0.0f); - } + playlist_clips->set_progress({}); + live_player->play(fake_clip); ui->stop_btn->setEnabled(false); } -pair MainWindow::live_player_get_next_clip() +void MainWindow::live_player_done() { - // playlist_clips can only be accessed on the main thread. - // Hopefully, we won't have to wait too long for this to come back. - // - // TODO: If MainWindow is in the process of being destroyed and waiting - // for Player to shut down, we could have a deadlock here. - promise> clip_promise; - future> clip = clip_promise.get_future(); - post_to_main_thread([&clip_promise] { - int row = playlist_clips->get_currently_playing(); - if (row != -1 && row < int(playlist_clips->size()) - 1) { - clip_promise.set_value(make_pair(*playlist_clips->clip(row + 1), row + 1)); - } else { - clip_promise.set_value(make_pair(Clip(), 0)); - } - }); - return clip.get(); -} - -static string format_duration(double t) -{ - int t_ms = lrint(t * 1e3); - - int ms = t_ms % 1000; - t_ms /= 1000; - int s = t_ms % 60; - t_ms /= 60; - int m = t_ms; - - char buf[256]; - snprintf(buf, sizeof(buf), "%d:%02d.%03d", m, s, ms); - return buf; + playlist_selection_changed(); + playlist_clips->set_progress({}); + ui->stop_btn->setEnabled(false); } -void MainWindow::live_player_clip_progress(const map &progress) +void MainWindow::live_player_clip_progress(const map &progress, double time_remaining) { - map converted_progress; - for (const auto &it : progress) { - if (live_player_index_to_row.count(it.first)) { - converted_progress.emplace(live_player_index_to_row[it.first], it.second); - } - } - playlist_clips->set_progress(converted_progress); - - vector clips; - for (size_t row = 0; row < playlist_clips->size(); ++row) { - clips.push_back(*playlist_clips->clip(row)); - } - double remaining = compute_time_left(clips, progress); - set_output_status(format_duration(remaining) + " left"); + playlist_clips->set_progress(progress); + set_output_status(format_duration(time_remaining) + " left"); } void MainWindow::resizeEvent(QResizeEvent *event) @@ -841,7 +791,7 @@ void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWind Clip fake_clip; fake_clip.pts_in = pts; fake_clip.pts_out = pts + 1; - preview_player->play({ fake_clip }); + preview_player->play(fake_clip); } void MainWindow::playlist_selection_changed() @@ -859,11 +809,11 @@ void MainWindow::playlist_selection_changed() if (!any_selected) { set_output_status("paused"); } else { - vector clips; - for (size_t row = 0; row < playlist_clips->size(); ++row) { - clips.push_back(*playlist_clips->clip(row)); + vector clips; + for (size_t row = selected->selectedRows().front().row(); row < playlist_clips->size(); ++row) { + clips.emplace_back(*playlist_clips->clip_with_id(row)); } - double remaining = compute_time_left(clips, { { selected->selectedRows().front().row(), 0.0 } }); + double remaining = compute_total_time(clips); set_output_status(format_duration(remaining) + " ready"); } } @@ -1071,6 +1021,9 @@ void MainWindow::highlight_camera_input(int stream_idx) void MainWindow::set_output_status(const string &status) { ui->live_label->setText(QString::fromStdString("Current output (" + status + ")")); + if (live_player != nullptr) { + live_player->set_pause_status(status); + } lock_guard lock(queue_status_mu); queue_status = status;