#include <vector>
#include <unordered_set>
+#include "post_to_main_thread.h"
+
#include <QOpenGLFunctions>
#include <QWheelEvent>
#include <QMouseEvent>
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;
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);
}
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;
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;
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;
{
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)