1 #include "mainwindow.h"
4 #include "disk_space_estimator.h"
7 #include "post_to_main_thread.h"
9 #include "ui_mainwindow.h"
11 #include <QMouseEvent>
14 #include <QWheelEvent>
21 using namespace std::placeholders;
23 MainWindow *global_mainwindow = nullptr;
24 static ClipList *cliplist_clips;
25 static PlayList *playlist_clips;
27 extern int64_t current_pts;
28 extern mutex frame_mu;
29 extern vector<int64_t> frames[MAX_STREAMS];
31 MainWindow::MainWindow()
32 : ui(new Ui::MainWindow),
33 db(global_flags.working_directory + "/futatabi.db")
35 global_mainwindow = this;
39 connect(ui->exit_action, &QAction::triggered, this, &MainWindow::exit_triggered);
41 global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2));
42 disk_free_label = new QLabel(this);
43 disk_free_label->setStyleSheet("QLabel {padding-right: 5px;}");
44 ui->menuBar->setCornerWidget(disk_free_label);
46 StateProto state = db.get_state();
48 cliplist_clips = new ClipList(state.clip_list());
49 ui->clip_list->setModel(cliplist_clips);
50 connect(cliplist_clips, &ClipList::any_content_changed, this, &MainWindow::content_changed);
52 playlist_clips = new PlayList(state.play_list());
53 ui->playlist->setModel(playlist_clips);
54 connect(playlist_clips, &PlayList::any_content_changed, this, &MainWindow::content_changed);
56 // For un-highlighting when we lose focus.
57 ui->clip_list->installEventFilter(this);
59 // For scrubbing in the pts columns.
60 ui->clip_list->viewport()->installEventFilter(this);
61 ui->playlist->viewport()->installEventFilter(this);
63 QShortcut *cue_in = new QShortcut(QKeySequence(Qt::Key_A), this);
64 connect(cue_in, &QShortcut::activated, ui->cue_in_btn, &QPushButton::click);
65 connect(ui->cue_in_btn, &QPushButton::clicked, this, &MainWindow::cue_in_clicked);
67 QShortcut *cue_out = new QShortcut(QKeySequence(Qt::Key_S), this);
68 connect(cue_out, &QShortcut::activated, ui->cue_out_btn, &QPushButton::click);
69 connect(ui->cue_out_btn, &QPushButton::clicked, this, &MainWindow::cue_out_clicked);
71 QShortcut *queue = new QShortcut(QKeySequence(Qt::Key_Q), this);
72 connect(queue, &QShortcut::activated, ui->queue_btn, &QPushButton::click);
73 connect(ui->queue_btn, &QPushButton::clicked, this, &MainWindow::queue_clicked);
75 QShortcut *preview = new QShortcut(QKeySequence(Qt::Key_W), this);
76 connect(preview, &QShortcut::activated, ui->preview_btn, &QPushButton::click);
77 connect(ui->preview_btn, &QPushButton::clicked, this, &MainWindow::preview_clicked);
79 QShortcut *play = new QShortcut(QKeySequence(Qt::Key_Space), this);
80 connect(play, &QShortcut::activated, ui->play_btn, &QPushButton::click);
81 connect(ui->play_btn, &QPushButton::clicked, this, &MainWindow::play_clicked);
83 QShortcut *preview_1 = new QShortcut(QKeySequence(Qt::Key_1), this);
84 connect(preview_1, &QShortcut::activated, ui->preview_1_btn, &QPushButton::click);
85 connect(ui->input1_display, &JPEGFrameView::clicked, ui->preview_1_btn, &QPushButton::click);
86 connect(ui->preview_1_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(0); });
87 ui->input1_display->set_overlay("1");
89 QShortcut *preview_2 = new QShortcut(QKeySequence(Qt::Key_2), this);
90 connect(preview_2, &QShortcut::activated, ui->preview_2_btn, &QPushButton::click);
91 connect(ui->input2_display, &JPEGFrameView::clicked, ui->preview_2_btn, &QPushButton::click);
92 connect(ui->preview_2_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(1); });
93 ui->input2_display->set_overlay("2");
95 QShortcut *preview_3 = new QShortcut(QKeySequence(Qt::Key_3), this);
96 connect(preview_3, &QShortcut::activated, ui->preview_3_btn, &QPushButton::click);
97 connect(ui->input3_display, &JPEGFrameView::clicked, ui->preview_3_btn, &QPushButton::click);
98 connect(ui->preview_3_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(2); });
99 ui->input3_display->set_overlay("3");
101 QShortcut *preview_4 = new QShortcut(QKeySequence(Qt::Key_4), this);
102 connect(preview_4, &QShortcut::activated, ui->preview_4_btn, &QPushButton::click);
103 connect(ui->input4_display, &JPEGFrameView::clicked, ui->preview_4_btn, &QPushButton::click);
104 connect(ui->preview_4_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(3); });
105 ui->input4_display->set_overlay("4");
107 connect(ui->playlist_duplicate_btn, &QPushButton::clicked, this, &MainWindow::playlist_duplicate);
109 connect(ui->playlist_remove_btn, &QPushButton::clicked, this, &MainWindow::playlist_remove);
110 QShortcut *delete_key = new QShortcut(QKeySequence(Qt::Key_Delete), ui->playlist);
111 connect(delete_key, &QShortcut::activated, [this] {
112 if (ui->playlist->hasFocus()) {
117 // TODO: support drag-and-drop.
118 connect(ui->playlist_move_up_btn, &QPushButton::clicked, [this]{ playlist_move(-1); });
119 connect(ui->playlist_move_down_btn, &QPushButton::clicked, [this]{ playlist_move(1); });
121 connect(ui->playlist->selectionModel(), &QItemSelectionModel::selectionChanged,
122 this, &MainWindow::playlist_selection_changed);
123 playlist_selection_changed(); // First time set-up.
125 preview_player = new Player(ui->preview_display, /*also_output_to_stream=*/false);
126 live_player = new Player(ui->live_display, /*also_output_to_stream=*/true);
127 live_player->set_done_callback([this]{
128 post_to_main_thread([this]{
129 live_player_clip_done();
132 live_player->set_next_clip_callback(bind(&MainWindow::live_player_get_next_clip, this));
133 live_player->set_progress_callback([this](double played_this_clip, double total_length) {
134 post_to_main_thread([this, played_this_clip, total_length] {
135 live_player_clip_progress(played_this_clip, total_length);
138 set_output_status("paused");
140 defer_timeout = new QTimer(this);
141 defer_timeout->setSingleShot(true);
142 connect(defer_timeout, &QTimer::timeout, this, &MainWindow::defer_timer_expired);
144 connect(ui->clip_list->selectionModel(), &QItemSelectionModel::currentChanged,
145 this, &MainWindow::clip_list_selection_changed);
148 void MainWindow::cue_in_clicked()
150 if (!cliplist_clips->empty() && cliplist_clips->back()->pts_out < 0) {
151 cliplist_clips->mutable_back()->pts_in = current_pts;
155 clip.pts_in = current_pts;
156 cliplist_clips->add_clip(clip);
157 playlist_selection_changed();
160 void MainWindow::cue_out_clicked()
162 if (!cliplist_clips->empty()) {
163 cliplist_clips->mutable_back()->pts_out = current_pts;
164 // TODO: select the row in the clip list?
168 void MainWindow::queue_clicked()
170 if (cliplist_clips->empty()) {
174 QItemSelectionModel *selected = ui->clip_list->selectionModel();
175 if (!selected->hasSelection()) {
176 Clip clip = *cliplist_clips->back();
178 if (clip.pts_out != -1) {
179 playlist_clips->add_clip(clip);
180 playlist_selection_changed();
185 QModelIndex index = selected->currentIndex();
186 Clip clip = *cliplist_clips->clip(index.row());
187 if (index.column() >= int(ClipList::Column::CAMERA_1) &&
188 index.column() <= int(ClipList::Column::CAMERA_4)) {
189 clip.stream_idx = index.column() - int(ClipList::Column::CAMERA_1);
191 clip.stream_idx = ui->preview_display->get_stream_idx();
194 if (clip.pts_out != -1) {
195 playlist_clips->add_clip(clip);
196 playlist_selection_changed();
200 void MainWindow::preview_clicked()
202 if (cliplist_clips->empty())
205 QItemSelectionModel *selected = ui->clip_list->selectionModel();
206 if (!selected->hasSelection()) {
207 preview_player->play_clip(*cliplist_clips->back(), 0);
211 QModelIndex index = selected->currentIndex();
213 if (index.column() >= int(ClipList::Column::CAMERA_1) &&
214 index.column() <= int(ClipList::Column::CAMERA_4)) {
215 stream_idx = index.column() - int(ClipList::Column::CAMERA_1);
217 stream_idx = ui->preview_display->get_stream_idx();
219 preview_player->play_clip(*cliplist_clips->clip(index.row()), stream_idx);
222 void MainWindow::preview_angle_clicked(unsigned stream_idx)
224 preview_player->override_angle(stream_idx);
226 // Change the selection if we were previewing a clip from the clip list.
227 // (The only other thing we could be showing is a pts scrub, and if so,
228 // that would be selected.)
229 QItemSelectionModel *selected = ui->clip_list->selectionModel();
230 if (selected->hasSelection()) {
231 QModelIndex cell = selected->selectedIndexes()[0];
232 int column = int(ClipList::Column::CAMERA_1) + stream_idx;
233 selected->setCurrentIndex(cell.sibling(cell.row(), column), QItemSelectionModel::ClearAndSelect);
237 void MainWindow::playlist_duplicate()
239 QItemSelectionModel *selected = ui->playlist->selectionModel();
240 if (!selected->hasSelection()) {
241 // Should have been grayed out, but OK.
244 QModelIndexList rows = selected->selectedRows();
245 int first = rows.front().row(), last = rows.back().row();
246 playlist_clips->duplicate_clips(first, last);
247 playlist_selection_changed();
250 void MainWindow::playlist_remove()
252 QItemSelectionModel *selected = ui->playlist->selectionModel();
253 if (!selected->hasSelection()) {
254 // Should have been grayed out, but OK.
257 QModelIndexList rows = selected->selectedRows();
258 int first = rows.front().row(), last = rows.back().row();
259 playlist_clips->erase_clips(first, last);
261 // TODO: select the next one in the list?
263 playlist_selection_changed();
266 void MainWindow::playlist_move(int delta)
268 QItemSelectionModel *selected = ui->playlist->selectionModel();
269 if (!selected->hasSelection()) {
270 // Should have been grayed out, but OK.
274 QModelIndexList rows = selected->selectedRows();
275 int first = rows.front().row(), last = rows.back().row();
276 if ((delta == -1 && first == 0) ||
277 (delta == 1 && size_t(last) == playlist_clips->size() - 1)) {
278 // Should have been grayed out, but OK.
282 playlist_clips->move_clips(first, last, delta);
283 playlist_selection_changed();
286 void MainWindow::defer_timer_expired()
288 state_changed(deferred_state);
291 void MainWindow::content_changed()
293 if (defer_timeout->isActive() &&
294 (!currently_deferring_model_changes || deferred_change_id != current_change_id)) {
295 // There's some deferred event waiting, but this event is unrelated.
296 // So it's time to short-circuit that timer and do the work it wanted to do.
297 defer_timeout->stop();
298 state_changed(deferred_state);
301 *state.mutable_clip_list() = cliplist_clips->serialize();
302 *state.mutable_play_list() = playlist_clips->serialize();
303 if (currently_deferring_model_changes) {
304 deferred_change_id = current_change_id;
305 deferred_state = std::move(state);
306 defer_timeout->start(200);
309 state_changed(state);
312 void MainWindow::state_changed(const StateProto &state)
314 db.store_state(state);
317 void MainWindow::play_clicked()
319 if (playlist_clips->empty())
322 QItemSelectionModel *selected = ui->playlist->selectionModel();
324 if (!selected->hasSelection()) {
327 row = selected->selectedRows(0)[0].row();
330 const Clip &clip = *playlist_clips->clip(row);
331 live_player->play_clip(clip, clip.stream_idx);
332 playlist_clips->set_currently_playing(row, 0.0f);
333 playlist_selection_changed();
336 void MainWindow::live_player_clip_done()
338 int row = playlist_clips->get_currently_playing();
339 if (row == -1 || row == int(playlist_clips->size()) - 1) {
340 set_output_status("paused");
341 playlist_clips->set_currently_playing(-1, 0.0f);
343 playlist_clips->set_currently_playing(row + 1, 0.0f);
347 Clip MainWindow::live_player_get_next_clip()
349 // playlist_clips can only be accessed on the main thread.
350 // Hopefully, we won't have to wait too long for this to come back.
351 promise<Clip> clip_promise;
352 future<Clip> clip = clip_promise.get_future();
353 post_to_main_thread([this, &clip_promise] {
354 int row = playlist_clips->get_currently_playing();
355 if (row != -1 && row < int(playlist_clips->size()) - 1) {
356 clip_promise.set_value(*playlist_clips->clip(row + 1));
358 clip_promise.set_value(Clip());
364 static string format_duration(double t)
366 int t_ms = lrint(t * 1e3);
368 int ms = t_ms % 1000;
375 snprintf(buf, sizeof(buf), "%d:%02d.%03d", m, s, ms);
379 void MainWindow::live_player_clip_progress(double played_this_clip, double total_length)
381 playlist_clips->set_currently_playing(playlist_clips->get_currently_playing(), played_this_clip / total_length);
383 double remaining = total_length - played_this_clip;
384 for (int row = playlist_clips->get_currently_playing() + 1; row < int(playlist_clips->size()); ++row) {
385 const Clip clip = *playlist_clips->clip(row);
386 remaining += double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5; // FIXME: stop hardcoding speed.
388 set_output_status(format_duration(remaining) + " left");
391 void MainWindow::resizeEvent(QResizeEvent *event)
393 QMainWindow::resizeEvent(event);
395 // Ask for a relayout, but only after the event loop is done doing relayout
396 // on everything else.
397 QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
400 void MainWindow::relayout()
402 ui->live_display->setMinimumWidth(ui->live_display->height() * 16 / 9);
403 ui->preview_display->setMinimumWidth(ui->preview_display->height() * 16 / 9);
406 void set_pts_in(int64_t pts, int64_t current_pts, ClipProxy &clip)
408 pts = std::max<int64_t>(pts, 0);
409 if (clip->pts_out == -1) {
410 pts = std::min(pts, current_pts);
412 pts = std::min(pts, clip->pts_out);
417 bool MainWindow::eventFilter(QObject *watched, QEvent *event)
419 constexpr int dead_zone_pixels = 3; // To avoid that simple clicks get misinterpreted.
420 constexpr int scrub_sensitivity = 100; // pts units per pixel.
421 constexpr int wheel_sensitivity = 100; // pts units per degree.
422 constexpr int camera_degrees_per_pixel = 15; // One click of most mice.
424 unsigned stream_idx = ui->preview_display->get_stream_idx();
426 if (watched == ui->clip_list) {
427 if (event->type() == QEvent::FocusOut) {
428 highlight_camera_input(-1);
433 if (event->type() != QEvent::Wheel) {
434 last_mousewheel_camera_row = -1;
437 if (event->type() == QEvent::MouseButtonPress) {
438 QMouseEvent *mouse = (QMouseEvent *)event;
440 QTableView *destination;
443 if (watched == ui->clip_list->viewport()) {
444 destination = ui->clip_list;
445 type = SCRUBBING_CLIP_LIST;
446 } else if (watched == ui->playlist->viewport()) {
447 destination = ui->playlist;
448 type = SCRUBBING_PLAYLIST;
452 int column = destination->columnAt(mouse->x());
453 int row = destination->rowAt(mouse->y());
454 if (column == -1 || row == -1)
457 if (type == SCRUBBING_CLIP_LIST) {
458 if (ClipList::Column(column) == ClipList::Column::IN) {
459 scrub_pts_origin = cliplist_clips->clip(row)->pts_in;
460 preview_single_frame(scrub_pts_origin, stream_idx, FIRST_AT_OR_AFTER);
461 } else if (ClipList::Column(column) == ClipList::Column::OUT) {
462 scrub_pts_origin = cliplist_clips->clip(row)->pts_out;
463 preview_single_frame(scrub_pts_origin, stream_idx, LAST_BEFORE);
468 if (PlayList::Column(column) == PlayList::Column::IN) {
469 scrub_pts_origin = playlist_clips->clip(row)->pts_in;
470 preview_single_frame(scrub_pts_origin, stream_idx, FIRST_AT_OR_AFTER);
471 } else if (PlayList::Column(column) == PlayList::Column::OUT) {
472 scrub_pts_origin = playlist_clips->clip(row)->pts_out;
473 preview_single_frame(scrub_pts_origin, stream_idx, LAST_BEFORE);
481 scrub_column = column;
482 scrub_x_origin = mouse->x();
484 } else if (event->type() == QEvent::MouseMove) {
486 QMouseEvent *mouse = (QMouseEvent *)event;
487 int offset = mouse->x() - scrub_x_origin;
489 if (offset >= dead_zone_pixels) {
490 adjusted_offset = offset - dead_zone_pixels;
491 } else if (offset < -dead_zone_pixels) {
492 adjusted_offset = offset + dead_zone_pixels;
497 int64_t pts = scrub_pts_origin + adjusted_offset * scrub_sensitivity;
498 currently_deferring_model_changes = true;
499 if (scrub_type == SCRUBBING_CLIP_LIST) {
500 ClipProxy clip = cliplist_clips->mutable_clip(scrub_row);
501 if (scrub_column == int(ClipList::Column::IN)) {
502 current_change_id = "cliplist:in:" + to_string(scrub_row);
503 set_pts_in(pts, current_pts, clip);
504 preview_single_frame(pts, stream_idx, FIRST_AT_OR_AFTER);
506 current_change_id = "cliplist:out" + to_string(scrub_row);
507 pts = std::max(pts, clip->pts_in);
508 pts = std::min(pts, current_pts);
510 preview_single_frame(pts, stream_idx, LAST_BEFORE);
513 ClipProxy clip = playlist_clips->mutable_clip(scrub_row);
514 if (scrub_column == int(PlayList::Column::IN)) {
515 current_change_id = "playlist:in:" + to_string(scrub_row);
516 set_pts_in(pts, current_pts, clip);
517 preview_single_frame(pts, clip->stream_idx, FIRST_AT_OR_AFTER);
519 current_change_id = "playlist:out:" + to_string(scrub_row);
520 pts = std::max(pts, clip->pts_in);
521 pts = std::min(pts, current_pts);
523 preview_single_frame(pts, clip->stream_idx, LAST_BEFORE);
526 currently_deferring_model_changes = false;
528 return true; // Don't use this mouse movement for selecting things.
530 } else if (event->type() == QEvent::Wheel) {
531 QWheelEvent *wheel = (QWheelEvent *)event;
533 QTableView *destination;
534 int in_column, out_column, camera_column;
535 if (watched == ui->clip_list->viewport()) {
536 destination = ui->clip_list;
537 in_column = int(ClipList::Column::IN);
538 out_column = int(ClipList::Column::OUT);
540 last_mousewheel_camera_row = -1;
541 } else if (watched == ui->playlist->viewport()) {
542 destination = ui->playlist;
543 in_column = int(PlayList::Column::IN);
544 out_column = int(PlayList::Column::OUT);
545 camera_column = int(PlayList::Column::CAMERA);
547 last_mousewheel_camera_row = -1;
550 int column = destination->columnAt(wheel->x());
551 int row = destination->rowAt(wheel->y());
552 if (column == -1 || row == -1) return false;
554 // Only adjust pts with the wheel if the given row is selected.
555 if (!destination->hasFocus() ||
556 row != destination->selectionModel()->currentIndex().row()) {
560 currently_deferring_model_changes = true;
562 current_change_id = (watched == ui->clip_list->viewport()) ? "cliplist:" : "playlist:";
563 ClipProxy clip = (watched == ui->clip_list->viewport()) ?
564 cliplist_clips->mutable_clip(row) : playlist_clips->mutable_clip(row);
565 if (watched == ui->playlist->viewport()) {
566 stream_idx = clip->stream_idx;
569 if (column != camera_column) {
570 last_mousewheel_camera_row = -1;
572 if (column == in_column) {
573 current_change_id += "in:" + to_string(row);
574 int64_t pts = clip->pts_in + wheel->angleDelta().y() * wheel_sensitivity;
575 set_pts_in(pts, current_pts, clip);
576 preview_single_frame(pts, stream_idx, FIRST_AT_OR_AFTER);
577 } else if (column == out_column) {
578 current_change_id += "out:" + to_string(row);
579 int64_t pts = clip->pts_out + wheel->angleDelta().y() * wheel_sensitivity;
580 pts = std::max(pts, clip->pts_in);
581 pts = std::min(pts, current_pts);
583 preview_single_frame(pts, stream_idx, LAST_BEFORE);
584 } else if (column == camera_column) {
585 current_change_id += "camera:" + to_string(row);
586 int angle_degrees = wheel->angleDelta().y();
587 if (last_mousewheel_camera_row == row) {
588 angle_degrees += leftover_angle_degrees;
591 int stream_idx = clip->stream_idx + angle_degrees / camera_degrees_per_pixel;
592 stream_idx = std::max(stream_idx, 0);
593 stream_idx = std::min(stream_idx, NUM_CAMERAS - 1);
594 clip->stream_idx = stream_idx;
596 last_mousewheel_camera_row = row;
597 leftover_angle_degrees = angle_degrees % camera_degrees_per_pixel;
599 // Don't update the live view, that's rarely what the operator wants.
602 currently_deferring_model_changes = false;
603 return true; // Don't scroll.
604 } else if (event->type() == QEvent::MouseButtonRelease) {
610 void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWindow::Rounding rounding)
612 if (rounding == LAST_BEFORE) {
613 lock_guard<mutex> lock(frame_mu);
614 if (frames[stream_idx].empty())
616 auto it = lower_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts);
617 if (it != frames[stream_idx].end()) {
621 assert(rounding == FIRST_AT_OR_AFTER);
622 lock_guard<mutex> lock(frame_mu);
623 if (frames[stream_idx].empty())
625 auto it = upper_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts - 1);
626 if (it != frames[stream_idx].end()) {
632 fake_clip.pts_in = pts;
633 fake_clip.pts_out = pts + 1;
634 preview_player->play_clip(fake_clip, stream_idx);
637 void MainWindow::playlist_selection_changed()
639 QItemSelectionModel *selected = ui->playlist->selectionModel();
640 bool any_selected = selected->hasSelection();
641 ui->playlist_duplicate_btn->setEnabled(any_selected);
642 ui->playlist_remove_btn->setEnabled(any_selected);
643 ui->playlist_move_up_btn->setEnabled(
644 any_selected && selected->selectedRows().front().row() > 0);
645 ui->playlist_move_down_btn->setEnabled(
646 any_selected && selected->selectedRows().back().row() < int(playlist_clips->size()) - 1);
647 ui->play_btn->setEnabled(!playlist_clips->empty());
650 set_output_status("paused");
652 double remaining = 0.0;
653 for (int row = selected->selectedRows().front().row(); row < int(playlist_clips->size()); ++row) {
654 const Clip clip = *playlist_clips->clip(row);
655 remaining += double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5; // FIXME: stop hardcoding speed.
657 set_output_status(format_duration(remaining) + " ready");
661 void MainWindow::clip_list_selection_changed(const QModelIndex ¤t, const QModelIndex &)
663 int camera_selected = -1;
664 if (current.column() >= int(ClipList::Column::CAMERA_1) &&
665 current.column() <= int(ClipList::Column::CAMERA_4)) {
666 camera_selected = current.column() - int(ClipList::Column::CAMERA_1);
668 highlight_camera_input(camera_selected);
671 void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left)
674 if (estimated_seconds_left < 60.0) {
675 strcpy(time_str, "<font color=\"red\">Less than a minute</font>");
676 } else if (estimated_seconds_left < 1800.0) { // Less than half an hour: Xm Ys (red).
677 int s = lrintf(estimated_seconds_left);
680 snprintf(time_str, sizeof(time_str), "<font color=\"red\">%dm %ds</font>", m, s);
681 } else if (estimated_seconds_left < 3600.0) { // Less than an hour: Xm.
682 int m = lrintf(estimated_seconds_left / 60.0);
683 snprintf(time_str, sizeof(time_str), "%dm", m);
684 } else if (estimated_seconds_left < 36000.0) { // Less than ten hours: Xh Ym.
685 int m = lrintf(estimated_seconds_left / 60.0);
688 snprintf(time_str, sizeof(time_str), "%dh %dm", h, m);
689 } else { // More than ten hours: Xh.
690 int h = lrintf(estimated_seconds_left / 3600.0);
691 snprintf(time_str, sizeof(time_str), "%dh", h);
694 snprintf(buf, sizeof(buf), "Disk free: %'.0f MB (approx. %s)", free_bytes / 1048576.0, time_str);
696 std::string label = buf;
698 post_to_main_thread([this, label] {
699 disk_free_label->setText(QString::fromStdString(label));
700 ui->menuBar->setCornerWidget(disk_free_label); // Need to set this again for the sizing to get right.
704 void MainWindow::exit_triggered()
709 void MainWindow::highlight_camera_input(int stream_idx)
711 if (stream_idx == 0) {
712 ui->input1_frame->setStyleSheet("background: rgb(0,255,0)");
714 ui->input1_frame->setStyleSheet("");
716 if (stream_idx == 1) {
717 ui->input2_frame->setStyleSheet("background: rgb(0,255,0)");
719 ui->input2_frame->setStyleSheet("");
721 if (stream_idx == 2) {
722 ui->input3_frame->setStyleSheet("background: rgb(0,255,0)");
724 ui->input3_frame->setStyleSheet("");
726 if (stream_idx == 3) {
727 ui->input4_frame->setStyleSheet("background: rgb(0,255,0)");
729 ui->input4_frame->setStyleSheet("");
733 void MainWindow::set_output_status(const string &status)
735 ui->live_label->setText(QString::fromStdString("Current output (" + status + ")"));
737 lock_guard<mutex> lock(queue_status_mu);
738 queue_status = status;
741 pair<string, string> MainWindow::get_queue_status() const {
742 lock_guard<mutex> lock(queue_status_mu);
743 return {queue_status, "text/plain"};