]> git.sesse.net Git - pkanalytics/blobdiff - video_widget.cpp
Make columns sortable (no reverse sort).
[pkanalytics] / video_widget.cpp
index 0a7ff43eb7b2f4f77637e2553b9717e73e3653da..7bafa64e4b0a00f444eecbb40b2ef09d776cf98f 100644 (file)
@@ -30,6 +30,8 @@ extern "C" {
 #include <vector>
 #include <unordered_set>
 
+#include "post_to_main_thread.h"
+
 #include <QOpenGLFunctions>
 #include <QWheelEvent>
 #include <QMouseEvent>
@@ -192,7 +194,11 @@ bool VideoWidget::process_queued_commands(AVFormatContext *format_ctx, AVCodecCo
                                                queue.pop_front();
                                                queued_frames = std::move(queue);
                                        }
-                                       current_frame.reset(new Frame(make_video_frame(frame.get())));
+                                       Frame *new_frame = new Frame(make_video_frame(frame.get()));
+                                       {
+                                               lock_guard lock(current_frame_mu);
+                                               current_frame.reset(new_frame);
+                                       }
                                        update();
                                        store_pts(frame->pts);
                                        break;
@@ -223,7 +229,11 @@ bool VideoWidget::process_queued_commands(AVFormatContext *format_ctx, AVCodecCo
                if (frame == nullptr || error) {
                        return true;
                }
-               current_frame.reset(new Frame(make_video_frame(frame.get())));
+               Frame *new_frame = new Frame(make_video_frame(frame.get()));
+               {
+                       lock_guard lock(current_frame_mu);
+                       current_frame.reset(new_frame);
+               }
                update();
                store_pts(frame->pts);
        }
@@ -373,7 +383,11 @@ int num_levels(GLuint width, GLuint height)
 
 void VideoWidget::paintGL()
 {
-       std::shared_ptr<Frame> frame = current_frame;
+       std::shared_ptr<Frame> frame;
+       {
+               lock_guard lock(current_frame_mu);
+               frame = current_frame;
+       }
        if (frame == nullptr) {
                glClear(GL_COLOR_BUFFER_BIT);
                return;
@@ -497,7 +511,11 @@ void VideoWidget::wheelEvent(QWheelEvent *event)
 
 void VideoWidget::mousePressEvent(QMouseEvent *e)
 {
-       if (e->button() == Qt::LeftButton) {
+       if (e->button() == Qt::BackButton) {
+               emit mouse_back_clicked();
+       } else if (e->button() == Qt::ForwardButton) {
+               emit mouse_forward_clicked();
+       } else if (e->button() == Qt::LeftButton) {
                dragging = true;
                last_drag_x = e->position().x();
                last_drag_y = e->position().y();
@@ -907,7 +925,11 @@ bool VideoWidget::play_video(const string &pathname)
                        bool finished_wakeup;
                        finished_wakeup = producer_thread_should_quit.sleep_until(next_frame_start);
                        if (finished_wakeup) {
-                               current_frame.reset(new Frame(make_video_frame(frame.get())));
+                               Frame *new_frame = new Frame(make_video_frame(frame.get()));
+                               {
+                                       lock_guard lock(current_frame_mu);
+                                       current_frame.reset(new_frame);
+                               }
                                last_frame = steady_clock::now();
                                update();
                                break;
@@ -921,7 +943,11 @@ bool VideoWidget::play_video(const string &pathname)
 
                                if (paused) {
                                        // Just paused, so present the frame immediately and then go into deep sleep.
-                                       current_frame.reset(new Frame(make_video_frame(frame.get())));
+                                       Frame *new_frame = new Frame(make_video_frame(frame.get()));
+                                       {
+                                               lock_guard lock(current_frame_mu);
+                                               current_frame.reset(new_frame);
+                                       }
                                        last_frame = steady_clock::now();
                                        update();
                                        break;
@@ -942,7 +968,9 @@ void VideoWidget::store_pts(int64_t pts)
 {
        last_pts = pts;
        last_position = lrint(pts * double(video_timebase.num) / double(video_timebase.den) * 1000);
-       emit position_changed(last_position);
+       post_to_main_thread([this, last_position{last_position.load()}] {
+               emit position_changed(last_position);
+       });
 }
 
 // Taken from Movit (see the comment there for explanation)