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

Backend: VLC: Remove EventWaiter class

parent 895a51bf
/*****************************************************************************
* EventWaiter.cpp: Helper to wait on a LibVLC event
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "EventWaiter.h"
using namespace Backend::VLC;
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 );
}
EventWaiter::~EventWaiter()
{
m_mediaPlayer->unregisterEvents( &EventWaiter::eventsCallback, this );
}
void
EventWaiter::add(libvlc_event_type_t event)
{
m_events.push_back( 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();
return Timeout;
}
m_mutex.unlock();
return m_found == true ? Success : Canceled;
}
void
EventWaiter::setValidationCallback(EventWaiter::ValidationCallback callback)
{
m_validationCallback = callback;
}
void EventWaiter::eventsCallback( const libvlc_event_t* event, void *data )
{
EventWaiter* self = reinterpret_cast<EventWaiter*>( data );
QMutexLocker lock( &self->m_mutex );
if ( self->m_events.contains( event->type ) == true )
{
if ( self->m_validationCallback != NULL && self->m_validationCallback( event ) == false )
return;
self->m_found = true;
self->m_waitCond.wakeAll();
return;
}
if ( event->type == libvlc_MediaPlayerEncounteredError ||
event->type == libvlc_MediaPlayerEndReached )
{
self->m_waitCond.wakeAll();
}
}
/*****************************************************************************
* EventWaiter.h: Helper to wait on a LibVLC event
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef EVENTWAITER_H
#define EVENTWAITER_H
#include "VLCMediaPlayer.h"
#include <QList>
#include <QMutex>
#include <QWaitCondition>
namespace Backend
{
namespace VLC
{
class EventWaiter
{
public:
/**
* @brief initialize the EventWaiter
*
* This method will lock a mutex, preventing any further event processing.
* Basic use scheme is
* \li EventWaiter* ew = new EventWaiter( mediaPlayer );
* \li ev->add( <event> );
* \li <whatever action that will lead to an asynchronous event>
* \li we->wait(...);
*
* @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 , bool startLocked);
~EventWaiter();
enum Result
{
Success, ///The event has been emited.
Canceled,///A cancelation event has been emited first.
Timeout ///Timeout has been reached.
};
void add( libvlc_event_type_t event );
Result wait( unsigned long timeoutMs );
typedef bool (*ValidationCallback)( const libvlc_event_t* event );
void setValidationCallback( ValidationCallback callback );
private:
static void eventsCallback( const libvlc_event_t *event, void* data );
private:
LibVLCpp::MediaPlayer* m_mediaPlayer;
QList<libvlc_event_type_t> m_events;
QWaitCondition m_waitCond;
QMutex m_mutex;
ValidationCallback m_validationCallback;
bool m_found;
bool m_startLocked;
};
} //VLC
} //Backend
#endif // EVENTWAITER_H
......@@ -11,7 +11,6 @@ SET(VLMC_SRCS
Backend/IBackend.h
Backend/ISourceRenderer.h
Backend/ISource.h
Backend/VLC/EventWaiter.cpp
Backend/VLC/VLCBackend.cpp
Backend/VLC/VLCSourceRenderer.cpp
Backend/VLC/VLCVmemRenderer.cpp
......
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