]> git.sesse.net Git - pkanalytics/commitdiff
Fix a contention issue.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 20 Jul 2023 13:52:33 +0000 (15:52 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 20 Jul 2023 13:52:33 +0000 (15:52 +0200)
video_widget.cpp

index b50ea1c404a0494b8297180e8fc0f7c671c4bad6..7bafa64e4b0a00f444eecbb40b2ef09d776cf98f 100644 (file)
@@ -194,9 +194,10 @@ bool VideoWidget::process_queued_commands(AVFormatContext *format_ctx, AVCodecCo
                                                queue.pop_front();
                                                queued_frames = std::move(queue);
                                        }
+                                       Frame *new_frame = new Frame(make_video_frame(frame.get()));
                                        {
                                                lock_guard lock(current_frame_mu);
-                                               current_frame.reset(new Frame(make_video_frame(frame.get())));
+                                               current_frame.reset(new_frame);
                                        }
                                        update();
                                        store_pts(frame->pts);
@@ -228,9 +229,10 @@ bool VideoWidget::process_queued_commands(AVFormatContext *format_ctx, AVCodecCo
                if (frame == nullptr || error) {
                        return true;
                }
+               Frame *new_frame = new Frame(make_video_frame(frame.get()));
                {
                        lock_guard lock(current_frame_mu);
-                       current_frame.reset(new Frame(make_video_frame(frame.get())));
+                       current_frame.reset(new_frame);
                }
                update();
                store_pts(frame->pts);
@@ -923,9 +925,10 @@ bool VideoWidget::play_video(const string &pathname)
                        bool finished_wakeup;
                        finished_wakeup = producer_thread_should_quit.sleep_until(next_frame_start);
                        if (finished_wakeup) {
+                               Frame *new_frame = new Frame(make_video_frame(frame.get()));
                                {
                                        lock_guard lock(current_frame_mu);
-                                       current_frame.reset(new Frame(make_video_frame(frame.get())));
+                                       current_frame.reset(new_frame);
                                }
                                last_frame = steady_clock::now();
                                update();
@@ -940,9 +943,10 @@ bool VideoWidget::play_video(const string &pathname)
 
                                if (paused) {
                                        // Just paused, so present the frame immediately and then go into deep sleep.
+                                       Frame *new_frame = new Frame(make_video_frame(frame.get()));
                                        {
                                                lock_guard lock(current_frame_mu);
-                                               current_frame.reset(new Frame(make_video_frame(frame.get())));
+                                               current_frame.reset(new_frame);
                                        }
                                        last_frame = steady_clock::now();
                                        update();