]> git.sesse.net Git - nageru/commitdiff
Call the done callback only when the entire playlist is done. Simplifies a fair amoun...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 28 Dec 2018 16:06:15 +0000 (17:06 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 28 Dec 2018 16:06:15 +0000 (17:06 +0100)
futatabi/clip_list.cpp
futatabi/clip_list.h
futatabi/export.cpp
futatabi/mainwindow.cpp
futatabi/mainwindow.h
futatabi/player.cpp

index c586b1a93dcd719db43e79221a24324d1fd74533..0bb73ae404e367bc8c52d106928a4e435749c044 100644 (file)
@@ -433,25 +433,6 @@ void ClipList::change_num_cameras(size_t num_cameras)
        emit any_content_changed();
 }
 
-void PlayList::set_currently_playing(int index, double progress)
-{
-       int old_index = currently_playing_index;
-       int column = int(Column::PLAYING);
-       if (index != old_index) {
-               currently_playing_index = index;
-               play_progress = progress;
-               if (old_index != -1) {
-                       emit dataChanged(this->index(old_index, column), this->index(old_index, column));
-               }
-               if (index != -1) {
-                       emit dataChanged(this->index(index, column), this->index(index, column));
-               }
-       } else if (index != -1 && fabs(progress - play_progress) > 1e-3) {
-               play_progress = progress;
-               emit dataChanged(this->index(index, column), this->index(index, column));
-       }
-}
-
 void PlayList::set_progress(const map<size_t, double> &progress)
 {
        const int column = int(Column::PLAYING);
index af3d1f524c42084ab77815f91cb4e30552cf5d07..99fdf5316f1acdb87138ff6f69034662beb7a337 100644 (file)
@@ -137,10 +137,6 @@ public:
        ClipProxy mutable_back() { return mutable_clip(size() - 1); }
        const Clip *back() const { return clip(size() - 1); }
 
-       // TODO: Move these out of PlayList.
-       void set_currently_playing(int index, double progress);  // -1 = none.
-       int get_currently_playing() const { return currently_playing_index; }
-
        void set_progress(const std::map<size_t, double> &progress);
 
        ClipListProto serialize() const;
@@ -157,7 +153,6 @@ signals:
 
 private:
        std::vector<Clip> clips;
-       int currently_playing_index = -1;
        double play_progress = 0.0;
        std::map<size_t, double> current_progress;
        size_t num_cameras = 2;
index 1aea044c224162398debf7fd6ae67aa4480871ff..5481007c79f055ec3c7a2835cda01008a369793f 100644 (file)
@@ -232,13 +232,10 @@ void export_interpolated_clip(const string &filename, const vector<Clip> &clips)
        promise<void> done_promise;
        future<void> done = done_promise.get_future();
        std::atomic<double> current_value{ 0.0 };
-       size_t clip_idx = 0;
 
        Player player(/*destination=*/nullptr, Player::FILE_STREAM_OUTPUT, closer.release());
-       player.set_done_callback([&done_promise, &clip_idx, &clips] {
-               if (clip_idx >= clips.size()) {
-                       done_promise.set_value();
-               }
+       player.set_done_callback([&done_promise] {
+               done_promise.set_value();
        });
        player.set_progress_callback([&current_value, &clips, total_length](const std::map<size_t, double> &player_progress, double time_remaining) {
                current_value = 1.0 - time_remaining / total_length;
index 22b8d9cda553bd51ce56db7da295dfb35132524a..3d3d8c11c908c13c53bd42a1bec5f3a9c26187e0 100644 (file)
@@ -186,7 +186,7 @@ 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<size_t, double> &progress, double time_remaining) {
@@ -493,7 +493,6 @@ void MainWindow::play_clicked()
        }
        live_player->play(clips);
        playlist_clips->set_progress({ { start_row, 0.0f } });
-       playlist_clips->set_currently_playing(start_row, 0.0f);
        playlist_selection_changed();
 
        ui->stop_btn->setEnabled(true);
@@ -504,23 +503,14 @@ 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->play(fake_clip);
 }
 
-void MainWindow::live_player_clip_done()
+void MainWindow::live_player_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);
-               ui->stop_btn->setEnabled(false);
-       } else {
-               playlist_clips->set_progress({ { row + 1, 0.0f } });
-               playlist_clips->set_currently_playing(row + 1, 0.0f);
-       }
+       set_output_status("paused");
+       playlist_clips->set_progress({});
+       ui->stop_btn->setEnabled(false);
 }
 
 static string format_duration(double t)
index e2934ff38463d128b4a48852a8e9d777109ff3d6..f93da89717cd355b00d5309c37c7d97948e69fd5 100644 (file)
@@ -102,7 +102,7 @@ private:
        void preview_angle_clicked(unsigned stream_idx);
        void play_clicked();
        void stop_clicked();
-       void live_player_clip_done();
+       void live_player_done();
        void live_player_clip_progress(const std::map<size_t, double> &progress, double time_remaining);
        void set_output_status(const std::string &status);
        void playlist_duplicate();
index 3545eb13c83c4008cf797324421ef7b1068d3ca5..0d9e0926b3795285c8a80d5d04fab1b2a153ff23 100644 (file)
@@ -50,6 +50,9 @@ void Player::thread_func(AVFormatContext *file_avctx)
 
        while (!should_quit) {
                play_playlist_once();
+               if (done_callback != nullptr) {
+                       done_callback();
+               }
        }
 }
 
@@ -322,9 +325,6 @@ void Player::play_playlist_once()
                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) {
@@ -332,10 +332,6 @@ void Player::play_playlist_once()
                        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)