From 8af8f331cb67d7a49c44a494aa2bb07d710d3f2b Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Fri, 19 Jan 2024 18:19:01 +0400 Subject: [PATCH] Avoid possible race in videoplayer --- extern/osg-ffmpeg-videoplayer/videostate.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/extern/osg-ffmpeg-videoplayer/videostate.cpp b/extern/osg-ffmpeg-videoplayer/videostate.cpp index 096651dfd8..c062c99b65 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.cpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.cpp @@ -598,8 +598,17 @@ public: if(av_read_frame(pFormatCtx, packet.get()) < 0) { - if (self->audioq.nb_packets == 0 && self->videoq.nb_packets == 0 && self->pictq_size == 0) - self->mVideoEnded = true; + if (self->audioq.nb_packets == 0 && self->videoq.nb_packets == 0) + { + self->pictq_mutex.lock(); + bool videoEnded = self->pictq_size == 0; + self->pictq_mutex.unlock(); + if (videoEnded) + self->mVideoEnded = true; + else + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + continue; } else