[vlc-commits] [Git][videolan/vlc][3.0.x] 5 commits: demux: mkv: make ResetPci() thread safe
Steve Lhomme (@robUx4)
gitlab at videolan.org
Tue Nov 24 14:56:26 UTC 2026
Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC
Commits:
c4493f77 by Steve Lhomme at 2026-11-24T14:39:05+01:00
demux: mkv: make ResetPci() thread safe
The thread closing should only be done once, regardless of which thread is calling it.
- - - - -
4a9e4cc2 by Steve Lhomme at 2026-11-24T14:39:05+01:00
demux: mkv: destroy the event thread early on destroy
In the unlikely case it's still handling some input commands.
- - - - -
87f22a17 by Steve Lhomme at 2026-11-24T14:39:05+01:00
demux: mkv: allow ending the event thread without waiting for it
Signaling the abort is sufficient, especially for reentrant calls.
Only when Closing the demuxer we should ensure the event thread not using it
while it's being closed.
Fixes #30385
Reported-by: Anthropic (ANT-2026-VO5YMWQZ)
- - - - -
0864d90c by Steve Lhomme at 2026-11-24T14:39:05+01:00
demux: mkv: exit event thread early on abort
- - - - -
241bcdf5 by Steve Lhomme at 2026-11-24T14:39:05+01:00
demux: mkv: merge b_abort into is_running
The atomic boolean represents both if the thread has been started
and if it should keep running.
- - - - -
4 changed files:
- modules/demux/mkv/demux.cpp
- modules/demux/mkv/demux.hpp
- modules/demux/mkv/matroska_segment.cpp
- modules/demux/mkv/mkv.cpp
Changes:
=====================================
modules/demux/mkv/demux.cpp
=====================================
@@ -154,24 +154,23 @@ void event_thread_t::SetPci(const uint8_t *data, size_t size)
btn.cmd.bytes[i] = bs_read(&bs, 8);
}
- if( !is_running )
+ if( !is_running.exchange( true ) )
{
- b_abort = false;
- is_running = !vlc_clone( &thread, EventThread, this, VLC_THREAD_PRIORITY_LOW );
+ if ( vlc_clone( &thread, EventThread, this, VLC_THREAD_PRIORITY_LOW ) )
+ is_running = false;
}
}
-void event_thread_t::ResetPci()
+void event_thread_t::ResetPci(bool join_thread)
{
- if( !is_running )
+ if( !is_running.exchange(false) )
return;
vlc_mutex_lock( &lock );
- b_abort = true;
vlc_cond_signal( &wait );
vlc_mutex_unlock( &lock );
- vlc_join( thread, NULL );
- is_running = false;
+ if (join_thread) // otherwise let the thread finish its loop
+ vlc_join( thread, NULL );
}
int event_thread_t::EventMouse( vlc_object_t *p_this, char const *psz_var,
vlc_value_t, vlc_value_t, void *p_data )
@@ -240,10 +239,10 @@ void event_thread_t::EventThread()
for( ;; )
{
vlc_mutex_lock( &lock );
- while( !b_abort && !i_key_action && !b_moved && !b_clicked && !b_vout)
+ while( is_running && !i_key_action && !b_moved && !b_clicked && !b_vout)
vlc_cond_wait( &wait, &lock );
- if( b_abort )
+ if( !is_running )
{
vlc_mutex_unlock( &lock );
break;
@@ -374,7 +373,7 @@ void event_thread_t::EventThread()
}
/* MOUSE part */
- if( p_vout && ( b_moved || b_clicked ) )
+ if( p_vout && ( b_moved || b_clicked ) && is_running )
{
int x, y;
@@ -484,7 +483,7 @@ void event_thread_t::EventThread()
vlc_mutex_unlock( &lock );
/* Always check vout */
- if( p_vout == NULL )
+ if( p_vout == NULL && is_running )
{
p_vout = (vlc_object_t*) input_GetVout(p_demux->p_input);
if( p_vout)
=====================================
modules/demux/mkv/demux.hpp
=====================================
@@ -30,6 +30,8 @@
#include "chapter_command.hpp"
#include "virtual_segment.hpp"
+#include <atomic>
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*************************************
* taken from libdvdnav / libdvdread
@@ -214,7 +216,7 @@ public:
virtual ~event_thread_t();
void SetPci(const uint8_t *data, size_t);
- void ResetPci();
+ void ResetPci(bool join_thread = true);
private:
void EventThread();
@@ -226,12 +228,11 @@ private:
demux_t *p_demux;
- bool is_running;
+ std::atomic<bool> is_running; // thread is started and should keep running
vlc_thread_t thread;
vlc_mutex_t lock;
vlc_cond_t wait;
- bool b_abort;
bool b_moved;
bool b_clicked;
int i_key_action;
=====================================
modules/demux/mkv/matroska_segment.cpp
=====================================
@@ -1163,7 +1163,9 @@ bool matroska_segment_c::ESCreate()
void matroska_segment_c::ESDestroy( )
{
- sys.p_ev->ResetPci();
+ // close the event thread. A new thread will be created if SetPci() is called
+ if (sys.p_ev)
+ sys.p_ev->ResetPci( false );
for( tracks_map_t::iterator it = tracks.begin(); it != tracks.end(); ++it )
{
=====================================
modules/demux/mkv/mkv.cpp
=====================================
@@ -267,6 +267,12 @@ static void Close( vlc_object_t *p_this )
{
demux_t *p_demux = reinterpret_cast<demux_t*>( p_this );
demux_sys_t *p_sys = p_demux->p_sys;
+
+ /* a button command may still be running in the event thread, and it may
+ * be switching the current segment */
+ delete p_sys->p_ev;
+ p_sys->p_ev = nullptr;
+
virtual_segment_c *p_vsegment = p_sys->p_current_vsegment;
if( p_vsegment )
{
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ae82d8c65f1f3bb8196e206b258b8c441a21ab57...241bcdf519428f39a2ae57dc469b870f7a654485
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ae82d8c65f1f3bb8196e206b258b8c441a21ab57...241bcdf519428f39a2ae57dc469b870f7a654485
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list