Commit 541c1d97 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: add deduplication for some events.

Some events are fired on each meta type detection, while we just handle
those events on a global change basis.
Qt has some similar deduplication for repaint() or touch events, but
does not provide it to user.
parent ca83393c
...@@ -73,6 +73,7 @@ nodist_SOURCES_qt4 = \ ...@@ -73,6 +73,7 @@ nodist_SOURCES_qt4 = \
util/qmenuview.moc.cpp \ util/qmenuview.moc.cpp \
util/qvlcapp.moc.cpp \ util/qvlcapp.moc.cpp \
util/pictureflow.moc.cpp \ util/pictureflow.moc.cpp \
util/uniqueevent.moc.cpp \
util/buttons/RoundButton.moc.cpp \ util/buttons/RoundButton.moc.cpp \
util/buttons/DeckButtonsLayout.moc.cpp \ util/buttons/DeckButtonsLayout.moc.cpp \
util/buttons/BrowseButton.moc.cpp \ util/buttons/BrowseButton.moc.cpp \
...@@ -312,6 +313,7 @@ SOURCES_qt4 = qt4.cpp \ ...@@ -312,6 +313,7 @@ SOURCES_qt4 = qt4.cpp \
util/qmenuview.cpp \ util/qmenuview.cpp \
util/qt_dirs.cpp \ util/qt_dirs.cpp \
util/pictureflow.cpp \ util/pictureflow.cpp \
util/uniqueevent.cpp \
util/buttons/BrowseButton.cpp \ util/buttons/BrowseButton.cpp \
util/buttons/DeckButtonsLayout.cpp \ util/buttons/DeckButtonsLayout.cpp \
util/buttons/RoundButton.cpp \ util/buttons/RoundButton.cpp \
...@@ -391,6 +393,7 @@ noinst_HEADERS = \ ...@@ -391,6 +393,7 @@ noinst_HEADERS = \
util/qt_dirs.hpp \ util/qt_dirs.hpp \
util/registry.hpp \ util/registry.hpp \
util/pictureflow.hpp \ util/pictureflow.hpp \
util/uniqueevent.hpp \
util/singleton.hpp \ util/singleton.hpp \
util/buttons/RoundButton.hpp \ util/buttons/RoundButton.hpp \
util/buttons/DeckButtonsLayout.hpp \ util/buttons/DeckButtonsLayout.hpp \
......
...@@ -79,10 +79,12 @@ InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) : ...@@ -79,10 +79,12 @@ InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
timeA = 0; timeA = 0;
timeB = 0; timeB = 0;
f_cache = -1.; /* impossible initial value, different from all */ f_cache = -1.; /* impossible initial value, different from all */
rateLimitedEventPoster = new RateLimitedEventPoster();
} }
InputManager::~InputManager() InputManager::~InputManager()
{ {
delete rateLimitedEventPoster;
delInput(); delInput();
} }
...@@ -167,6 +169,11 @@ void InputManager::delInput() ...@@ -167,6 +169,11 @@ void InputManager::delInput()
emit cachingChanged( 1 ); emit cachingChanged( 1 );
} }
void InputManager::postUniqueEvent( QObject *target, UniqueEvent *e )
{
rateLimitedEventPoster->postEvent( e, target );
}
/* Convert the event from the callbacks in actions */ /* Convert the event from the callbacks in actions */
void InputManager::customEvent( QEvent *event ) void InputManager::customEvent( QEvent *event )
{ {
...@@ -282,7 +289,7 @@ static int ItemChanged( vlc_object_t *p_this, const char *psz_var, ...@@ -282,7 +289,7 @@ static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
input_item_t *p_item = static_cast<input_item_t *>(newval.p_address); input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
IMEvent *event = new IMEvent( ItemChanged_Type, p_item ); IMEvent *event = new IMEvent( ItemChanged_Type, p_item );
QApplication::postEvent( im, event ); im->postUniqueEvent( im, event );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -293,6 +300,7 @@ static int InputEvent( vlc_object_t *p_this, const char *, ...@@ -293,6 +300,7 @@ static int InputEvent( vlc_object_t *p_this, const char *,
InputManager *im = (InputManager*)param; InputManager *im = (InputManager*)param;
IMEvent *event; IMEvent *event;
bool b_unified = false;
switch( newval.i_int ) switch( newval.i_int )
{ {
...@@ -331,6 +339,7 @@ static int InputEvent( vlc_object_t *p_this, const char *, ...@@ -331,6 +339,7 @@ static int InputEvent( vlc_object_t *p_this, const char *,
break; break;
case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */ case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
b_unified = true;
event = new IMEvent( MetaChanged_Type ); event = new IMEvent( MetaChanged_Type );
break; break;
case INPUT_EVENT_ITEM_INFO: /* Codec Info */ case INPUT_EVENT_ITEM_INFO: /* Codec Info */
...@@ -377,7 +386,12 @@ static int InputEvent( vlc_object_t *p_this, const char *, ...@@ -377,7 +386,12 @@ static int InputEvent( vlc_object_t *p_this, const char *,
} }
if( event ) if( event )
QApplication::postEvent( im, event ); {
if ( b_unified )
im->postUniqueEvent( im, event );
else
QApplication::postEvent( im, event );
}
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "qt4.hpp" #include "qt4.hpp"
#include "util/singleton.hpp" #include "util/singleton.hpp"
#include "util/uniqueevent.hpp"
#include "variables.hpp" #include "variables.hpp"
#include <QObject> #include <QObject>
...@@ -74,13 +75,13 @@ enum { NORMAL, /* loop: 0, repeat: 0 */ ...@@ -74,13 +75,13 @@ enum { NORMAL, /* loop: 0, repeat: 0 */
REPEAT_ALL,/* loop: 1, repeat: 0 */ REPEAT_ALL,/* loop: 1, repeat: 0 */
}; };
class IMEvent : public QEvent class IMEvent : public UniqueEvent
{ {
friend class InputManager; friend class InputManager;
friend class MainInputManager; friend class MainInputManager;
public: public:
IMEvent( int type, input_item_t *p_input = NULL ) IMEvent( int type, input_item_t *p_input = NULL )
: QEvent( (QEvent::Type)(type) ) : UniqueEvent( (QEvent::Type)(type) )
{ {
if( (p_item = p_input) != NULL ) if( (p_item = p_input) != NULL )
vlc_gc_incref( p_item ); vlc_gc_incref( p_item );
...@@ -90,7 +91,15 @@ friend class MainInputManager; ...@@ -90,7 +91,15 @@ friend class MainInputManager;
if( p_item ) if( p_item )
vlc_gc_decref( p_item ); vlc_gc_decref( p_item );
} }
bool itemEquals( input_item_t *p_item_ ) const
{
return p_item_ == p_item;
};
virtual bool equals(UniqueEvent *e) const
{
IMEvent *ev = static_cast<IMEvent *>(e);
return ( ev->itemEquals( p_item ) && ev->type() == type() );
}
private: private:
input_item_t *p_item; input_item_t *p_item;
}; };
...@@ -141,6 +150,7 @@ public: ...@@ -141,6 +150,7 @@ public:
QString getName() { return oldName; } QString getName() { return oldName; }
static const QString decodeArtURL( input_item_t *p_item ); static const QString decodeArtURL( input_item_t *p_item );
void postUniqueEvent( QObject *, UniqueEvent * );
private: private:
intf_thread_t *p_intf; intf_thread_t *p_intf;
...@@ -156,6 +166,7 @@ private: ...@@ -156,6 +166,7 @@ private:
mtime_t timeA, timeB; mtime_t timeA, timeB;
void customEvent( QEvent * ); void customEvent( QEvent * );
RateLimitedEventPoster *rateLimitedEventPoster;
void addCallbacks(); void addCallbacks();
void delCallbacks(); void delCallbacks();
......
/*****************************************************************************
* Copyright © 2012 VideoLAN
*
* 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 "uniqueevent.hpp"
#include "qt4.hpp"
#include <QTimer>
#include <QApplication>
RateLimitedEventPoster::RateLimitedEventPoster( int i_millisec_interval )
{
timer = new QTimer();
timer->setSingleShot( true );
/* Assuming a 24fps event loop, delays at least events to the next frame */
if ( i_millisec_interval < 1 )
i_millisec_interval = 1000 / 48;
timer->setInterval( i_millisec_interval );
CONNECT( timer, timeout(), this, commit() );
}
RateLimitedEventPoster::~RateLimitedEventPoster()
{
timer->stop();
commit();
delete timer;
}
void RateLimitedEventPoster::postEvent( UniqueEvent *e, QObject *target )
{
event_tuple newtuple = { target, e };
foreach( event_tuple tuple, eventsList )
{
if ( target == tuple.target && tuple.event->equals( e ) )
{
delete e;
return;
}
}
eventsList << newtuple;
if ( !timer->isActive() ) timer->start();
}
void RateLimitedEventPoster::commit()
{
foreach( event_tuple tuple, eventsList )
{
QApplication::postEvent( tuple.target, tuple.event );
}
eventsList.clear();
}
/*****************************************************************************
* Copyright © 2012 VideoLAN
*
* 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 UNIQUEEVENT_HPP
#define UNIQUEEVENT_HPP
#include <QObject>
#include <QEvent>
#include <QList>
class QTimer;
class UniqueEvent : public QEvent
{
public:
UniqueEvent( QEvent::Type type ) : QEvent( type ) {};
virtual bool equals( UniqueEvent *e ) const = 0;
};
class RateLimitedEventPoster : public QObject
{
Q_OBJECT
public:
RateLimitedEventPoster( int i_millisec_interval = -1 );
~RateLimitedEventPoster();
void postEvent( UniqueEvent *e, QObject *target );
private slots:
void commit();
private:
struct event_tuple
{
QObject *target;
UniqueEvent *event;
};
QList<event_tuple> eventsList;
QTimer *timer;
};
#endif // UNIQUEEVENT_HPP
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