mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 11:35:24 +01:00
Fix the memory leak!
The scope's buffer, used by the analyzers, wasn't being cleared when the mainwindow (or the analyzer) was hidden. There was a timer that was supposed to clear it, but it wasn't being run because the xine engine is in a thread without an event loop. Fixes issue #5
This commit is contained in:
parent
43a8b89732
commit
7191f968a6
@ -29,6 +29,7 @@
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QLocale>
|
||||
#include <QTimer>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@ -69,6 +70,7 @@ XineEngine::XineEngine()
|
||||
, m_stopFader( false )
|
||||
, m_fadeOutRunning ( false )
|
||||
, m_equalizerEnabled( false )
|
||||
, prune_(NULL)
|
||||
{
|
||||
m_settings.beginGroup(kSettingsGroup);
|
||||
reloadSettings();
|
||||
@ -83,8 +85,15 @@ XineEngine::~XineEngine()
|
||||
s_fader->wait();
|
||||
}
|
||||
|
||||
// Wait until the prune scope thread is done
|
||||
if (prune_) {
|
||||
prune_->exit();
|
||||
prune_->wait();
|
||||
}
|
||||
|
||||
delete s_fader;
|
||||
delete s_outfader;
|
||||
delete prune_;
|
||||
|
||||
if( m_fadeoutOnExit ) {
|
||||
bool terminateFader = false;
|
||||
@ -149,7 +158,8 @@ XineEngine::init()
|
||||
makeNewStream();
|
||||
|
||||
#ifndef XINE_SAFE_MODE
|
||||
startTimer( 200 ); //prunes the scope
|
||||
prune_ = new PruneScopeThread(this);
|
||||
prune_->start();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@ -250,7 +260,7 @@ XineEngine::load( const QUrl &url, bool isStream )
|
||||
|
||||
#ifndef XINE_SAFE_MODE
|
||||
//we must ensure the scope is pruned of old buffers
|
||||
timerEvent( 0 );
|
||||
PruneScope();
|
||||
|
||||
xine_post_out_t *source = xine_get_audio_source( m_stream );
|
||||
xine_post_in_t *target = (xine_post_in_t*)xine_post_input( m_post, const_cast<char*>("audio in") );
|
||||
@ -683,7 +693,7 @@ XineEngine::scope()
|
||||
return m_scope;
|
||||
|
||||
//prune the buffer list and update m_currentVpts
|
||||
timerEvent( 0 );
|
||||
PruneScope();
|
||||
|
||||
for( int n, frame = 0; frame < 512; )
|
||||
{
|
||||
@ -737,7 +747,7 @@ XineEngine::scope()
|
||||
}
|
||||
|
||||
void
|
||||
XineEngine::timerEvent( QTimerEvent* )
|
||||
XineEngine::PruneScope()
|
||||
{
|
||||
if ( !m_stream )
|
||||
return;
|
||||
@ -1290,3 +1300,18 @@ OutFader::finish()
|
||||
{
|
||||
m_terminated = true;
|
||||
}
|
||||
|
||||
PruneScopeThread::PruneScopeThread(XineEngine *parent)
|
||||
: engine_(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void PruneScopeThread::run() {
|
||||
QTimer* timer = new QTimer;
|
||||
connect(timer, SIGNAL(timeout()), engine_, SLOT(PruneScope()), Qt::DirectConnection);
|
||||
timer->start(1000);
|
||||
|
||||
exec();
|
||||
|
||||
delete timer;
|
||||
}
|
||||
|
@ -45,12 +45,15 @@ private:
|
||||
void* data_;
|
||||
};
|
||||
|
||||
class PruneScopeThread;
|
||||
|
||||
class XineEngine : public Engine::Base
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class Fader;
|
||||
friend class OutFader;
|
||||
friend class PruneScopeThread;
|
||||
|
||||
~XineEngine();
|
||||
|
||||
@ -79,7 +82,6 @@ class XineEngine : public Engine::Base
|
||||
|
||||
static void XineEventListener( void*, const xine_event_t* );
|
||||
virtual bool event( QEvent* );
|
||||
virtual void timerEvent( QTimerEvent* );
|
||||
|
||||
virtual void playlistChanged();
|
||||
virtual void reloadSettings();
|
||||
@ -119,11 +121,16 @@ class XineEngine : public Engine::Base
|
||||
bool m_crossfadeEnabled;
|
||||
int m_fadeoutDuration;
|
||||
|
||||
PruneScopeThread* prune_;
|
||||
|
||||
mutable Engine::SimpleMetaBundle m_currentBundle;
|
||||
|
||||
public:
|
||||
XineEngine();
|
||||
|
||||
private slots:
|
||||
void PruneScope();
|
||||
|
||||
signals:
|
||||
void resetConfig(xine_t *xine);
|
||||
};
|
||||
@ -165,4 +172,15 @@ public:
|
||||
void finish();
|
||||
};
|
||||
|
||||
class PruneScopeThread : public QThread {
|
||||
public:
|
||||
PruneScopeThread(XineEngine* parent);
|
||||
|
||||
protected:
|
||||
virtual void run();
|
||||
|
||||
private:
|
||||
XineEngine* engine_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user