]> git.sesse.net Git - nageru/commitdiff
Show time remaining when playing clips live.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 22 Sep 2018 19:04:50 +0000 (21:04 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 22 Sep 2018 19:04:50 +0000 (21:04 +0200)
mainwindow.cpp
mainwindow.h
player.cpp
player.h
ui_mainwindow.ui

index f0a0341b89c0a758e0d61d325ac70a566d3b32eb..c16861102ce4dada625002a8337ec82219ae2c62 100644 (file)
@@ -3,6 +3,7 @@
 #include "clip_list.h"
 #include "player.h"
 #include "post_to_main_thread.h"
+#include "timebase.h"
 #include "ui_mainwindow.h"
 
 #include <string>
@@ -107,6 +108,11 @@ MainWindow::MainWindow()
                        live_player_clip_done();
                });
        });
+       live_player->set_progress_callback([this](double played_this_clip, double total_length) {
+               post_to_main_thread([this, played_this_clip, total_length] {
+                       live_player_clip_progress(played_this_clip, total_length);
+               });
+       });
 }
 
 void MainWindow::cue_in_clicked()
@@ -263,7 +269,28 @@ void MainWindow::live_player_clip_done()
                playlist_clips->set_currently_playing(row);
        } else {
                playlist_clips->set_currently_playing(-1);
+               ui->live_label->setText("Current output (paused)");
+       }
+}
+
+void MainWindow::live_player_clip_progress(double played_this_clip, double total_length)
+{
+       double remaining = total_length - played_this_clip;
+       for (int row = playlist_clips->get_currently_playing() + 1; row < int(playlist_clips->size()); ++row) {
+               const Clip clip = *playlist_clips->clip(row);
+               remaining += double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5;   // FIXME: stop hardcoding speed.
        }
+       int remaining_ms = lrint(remaining * 1e3);
+
+       int ms = remaining_ms % 1000;
+       remaining_ms /= 1000;
+       int s = remaining_ms % 60;
+       remaining_ms /= 60;
+       int m = remaining_ms;
+
+       char buf[256];
+       snprintf(buf, sizeof(buf), "Current output (%d:%02d.%03d left)", m, s, ms);
+       ui->live_label->setText(buf);
 }
 
 void MainWindow::resizeEvent(QResizeEvent *event)
index 4801667b5f2f1175e01394aa820d45abc8ca9f31..24eea609e03bbdf24049018b03cb9193b15cfa38 100644 (file)
@@ -47,6 +47,7 @@ private:
        void preview_angle_clicked(unsigned stream_idx);
        void play_clicked();
        void live_player_clip_done();
+       void live_player_clip_progress(double played_this_clip, double total_length);
        void playlist_duplicate();
        void playlist_remove();
        void playlist_move(int delta);
index 5ff448c4bc239ec2b0975a9b7597e27da81891df..1eea8d706c883d07a6d0592131cc8e7e6a8e15ab 100644 (file)
@@ -136,6 +136,13 @@ void Player::thread_func(bool also_output_to_stream)
                                }
                        }
 
+                       if (progress_callback != nullptr) {
+                               // NOTE: None of this will take into account any snapping done below.
+                               double played_this_clip = double(in_pts - clip.pts_in) / TIMEBASE / speed;
+                               double total_length = double(clip.pts_out - clip.pts_in) / TIMEBASE / speed;
+                               progress_callback(played_this_clip, total_length);
+                       }
+
                        if (in_pts_lower == in_pts_upper) {
                                destination->setFrame(stream_idx, in_pts_lower, /*interpolated=*/false);
                                if (video_stream != nullptr) {
index 10e0b6ab471bc477cf86c17d843239a16f3a590a..a10a7cb9671f09924b5eda46266d6a492baccb25 100644 (file)
--- a/player.h
+++ b/player.h
@@ -28,6 +28,11 @@ public:
        using done_callback_func = std::function<void()>;
        void set_done_callback(done_callback_func cb) { done_callback = cb; }
 
+       // Not thread-safe to set concurrently with playing.
+       // Will be called back from the player thread.
+       using progress_callback_func = std::function<void(double played_this_clip, double total_length)>;
+       void set_progress_callback(progress_callback_func cb) { progress_callback = cb; }
+
 private:
        void thread_func(bool also_output_to_stream);
        void open_output_stream();
@@ -36,6 +41,7 @@ private:
 
        JPEGFrameView *destination;
        done_callback_func done_callback;
+       progress_callback_func progress_callback;
 
        std::mutex mu;
        Clip current_clip;  // Under mu. Can have pts_in = -1 for no clip.
index 183fcea121446e026b0d44ae6030c940386e63a3..01b05b34b581668bb841a2f57680127ccb901844 100644 (file)
            <widget class="JPEGFrameView" name="live_display" native="true"/>
           </item>
           <item>
-           <widget class="QLabel" name="label_3">
+           <widget class="QLabel" name="live_label">
             <property name="text">
-             <string>Current output</string>
+             <string>Current output (paused)</string>
             </property>
             <property name="alignment">
              <set>Qt::AlignCenter</set>