Commit b5f2e911 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Fix potential deadlock when parsing metadata.

Turns out setTime might process synchronously :(
parent 84f14435
......@@ -24,13 +24,15 @@
using namespace Backend::VLC;
EventWaiter::EventWaiter( LibVLCpp::MediaPlayer* mediaPlayer )
EventWaiter::EventWaiter( LibVLCpp::MediaPlayer* mediaPlayer, bool startLocked )
: m_mediaPlayer( mediaPlayer )
, m_validationCallback( NULL )
, m_found( true )
, m_startLocked( startLocked )
{
if ( startLocked == true )
m_mutex.lock();
m_mediaPlayer->registerEvents( &EventWaiter::eventsCallback, this );
m_mutex.lock();
}
EventWaiter::~EventWaiter()
......@@ -47,6 +49,8 @@ EventWaiter::add(libvlc_event_type_t event)
EventWaiter::Result
EventWaiter::wait(unsigned long timeoutMs)
{
if ( m_startLocked == false )
m_mutex.lock();
if ( m_waitCond.wait( &m_mutex, timeoutMs ) == false )
{
m_mutex.unlock();
......
......@@ -43,10 +43,13 @@ public:
* \li <whatever action that will lead to an asynchronous event>
* \li we->wait(...);
*
* @warning If the event comes synchronously, this will deadlock. But if
* it happens synchronously, why would you need this at all?
* @param startLocked Specify if the EventWaiter should immediatly lock the mutex
* If this is false, mutex will be locked when wait() is called. This should
* be set to false when the function leading to the event might process synchronously
* and if the event will be triggered again (for instance, time & position events)
*
*/
EventWaiter( LibVLCpp::MediaPlayer* mediaPlayer );
EventWaiter(LibVLCpp::MediaPlayer* mediaPlayer , bool startLocked);
~EventWaiter();
enum Result
......@@ -71,6 +74,7 @@ private:
QMutex m_mutex;
ValidationCallback m_validationCallback;
bool m_found;
bool m_startLocked;
};
} //VLC
......
......@@ -70,7 +70,7 @@ VLCSource::preparse()
VmemRenderer* renderer = new VmemRenderer( m_backend, this, NULL );
LibVLCpp::MediaPlayer* mediaPlayer = renderer->mediaPlayer();
{
EventWaiter ew( mediaPlayer );
EventWaiter ew( mediaPlayer, true );
ew.add( libvlc_MediaPlayerLengthChanged );
renderer->start();
if ( ew.wait( 3000 ) != EventWaiter::Success )
......@@ -120,7 +120,7 @@ VLCSource::computeSnapshot( VmemRenderer* renderer )
Q_ASSERT( m_snapshot == NULL );
LibVLCpp::MediaPlayer* mediaPlayer = renderer->mediaPlayer();
{
EventWaiter ew( mediaPlayer );
EventWaiter ew( mediaPlayer, false );
ew.add( libvlc_MediaPlayerPositionChanged );
ew.setValidationCallback( &checkTimeChanged );
renderer->setTime( m_length / 3 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment