1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-10 16:14:40 +02:00

Initial threaded audio work

This commit is contained in:
Jeff Mitchell
2011-11-16 18:00:42 -05:00
parent aaa2417e74
commit a11651f563
7 changed files with 132 additions and 32 deletions

View File

@@ -292,7 +292,7 @@ set( libSources
sip/sipinfo.cpp sip/sipinfo.cpp
audio/audioengine.cpp audio/audioengine.cpp
audio/audioenginethread.cpp
database/database.cpp database/database.cpp
database/fuzzyindex.cpp database/fuzzyindex.cpp
@@ -408,6 +408,7 @@ set( libHeaders
sip/sipinfo.h sip/sipinfo.h
audio/audioengine.h audio/audioengine.h
audio/audioenginethread.h
database/database.h database/database.h
database/fuzzyindex.h database/fuzzyindex.h

View File

@@ -100,6 +100,7 @@ AudioEngine::~AudioEngine()
delete m_audioOutput; delete m_audioOutput;
delete m_mediaObject; delete m_mediaObject;
s_instance = 0;
} }

View File

@@ -19,8 +19,9 @@
#ifndef AUDIOENGINE_H #ifndef AUDIOENGINE_H
#define AUDIOENGINE_H #define AUDIOENGINE_H
#include <QObject> #include <QtCore/QObject>
#include <QTimer> #include <QtCore/QTimer>
#include <QtCore/QMutex>
#include <phonon/MediaObject> #include <phonon/MediaObject>
#include <phonon/AudioOutput> #include <phonon/AudioOutput>

View File

@@ -0,0 +1,41 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "audioenginethread.h"
#include <utils/logger.h>
#include <audio/audioengine.h>
AudioEngineThread::AudioEngineThread( QObject *parent )
: QThread( parent )
{
tDebug() << Q_FUNC_INFO;
}
AudioEngineThread::~AudioEngineThread()
{
tDebug() << Q_FUNC_INFO;
}
void
AudioEngineThread::AudioEngineThread::run()
{
m_audioEngine = QWeakPointer< AudioEngine >( new AudioEngine() );
exec();
if( !m_audioEngine.isNull() )
delete m_audioEngine.data();
}

View File

@@ -0,0 +1,44 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AUDIOENGINETHREAD_H
#define AUDIOENGINETHREAD_H
#include <QtCore/QObject>
#include <QtCore/QThread>
#include <QtCore/QWeakPointer>
#include "dllmacro.h"
class AudioEngine;
class DLLEXPORT AudioEngineThread : public QThread
{
Q_OBJECT
public:
AudioEngineThread( QObject *parent = 0 );
virtual ~AudioEngineThread();
void run();
private:
QWeakPointer< AudioEngine > m_audioEngine;
};
#endif // AUDIOENGINETHREAD_H

View File

@@ -21,14 +21,15 @@
#include <iostream> #include <iostream>
#include <QPluginLoader> #include <QtCore/QPluginLoader>
#include <QDir> #include <QtCore/QDir>
#include <QMetaType> #include <QtCore/QMetaType>
#include <QTime> #include <QtCore/QTime>
#include <QNetworkReply> #include <QtNetwork/QNetworkReply>
#include <QFile> #include <QtCore/QFile>
#include <QFileInfo> #include <QtCore/QFileInfo>
#include <QNetworkProxy> #include <QtNetwork/QNetworkProxy>
#include <QtCore/QThread>
#include "actioncollection.h" #include "actioncollection.h"
#include "artist.h" #include "artist.h"
@@ -57,6 +58,7 @@
#include "EchonestCatalogSynchronizer.h" #include "EchonestCatalogSynchronizer.h"
#include "audio/audioengine.h" #include "audio/audioengine.h"
#include "audio/audioenginethread.h"
#include "utils/xspfloader.h" #include "utils/xspfloader.h"
#include "utils/jspfloader.h" #include "utils/jspfloader.h"
#include "utils/logger.h" #include "utils/logger.h"
@@ -70,7 +72,7 @@
#include "AtticaManager.h" #include "AtticaManager.h"
#include "tomahawkwindow.h" #include "tomahawkwindow.h"
#include "settingsdialog.h" #include "settingsdialog.h"
#include <QMessageBox> #include <QtGui/QMessageBox>
#include "widgets/HeaderLabel.h" #include "widgets/HeaderLabel.h"
#endif #endif
@@ -165,11 +167,13 @@ TomahawkApp::init()
// Cause the creation of the nam, but don't need to address it directly, so prevent warning // Cause the creation of the nam, but don't need to address it directly, so prevent warning
Q_UNUSED( TomahawkUtils::nam() ); Q_UNUSED( TomahawkUtils::nam() );
m_audioEngine = QWeakPointer<AudioEngine>( new AudioEngine ); m_audioEngineThread = QWeakPointer< AudioEngineThread >( new AudioEngineThread( this ) );
m_scanManager = QWeakPointer<ScanManager>( new ScanManager( this ) ); m_audioEngineThread.data()->start( QThread::HighPriority );
m_scanManager = QWeakPointer< ScanManager >( new ScanManager( this ) );
new Pipeline( this ); new Pipeline( this );
m_servent = QWeakPointer<Servent>( new Servent( this ) ); m_servent = QWeakPointer< Servent >( new Servent( this ) );
connect( m_servent.data(), SIGNAL( ready() ), SLOT( initSIP() ) ); connect( m_servent.data(), SIGNAL( ready() ), SLOT( initSIP() ) );
tDebug() << "Init Database."; tDebug() << "Init Database.";
@@ -198,16 +202,17 @@ TomahawkApp::init()
#endif #endif
// Connect up shortcuts // Connect up shortcuts
if ( !m_shortcutHandler.isNull() ) if ( !m_shortcutHandler.isNull() && AudioEngine::instance() )
{ {
connect( m_shortcutHandler.data(), SIGNAL( playPause() ), m_audioEngine.data(), SLOT( playPause() ) ); AudioEngine* audioEngine = AudioEngine::instance();
connect( m_shortcutHandler.data(), SIGNAL( pause() ), m_audioEngine.data(), SLOT( pause() ) ); connect( m_shortcutHandler.data(), SIGNAL( playPause() ), audioEngine, SLOT( playPause() ) );
connect( m_shortcutHandler.data(), SIGNAL( stop() ), m_audioEngine.data(), SLOT( stop() ) ); connect( m_shortcutHandler.data(), SIGNAL( pause() ), audioEngine, SLOT( pause() ) );
connect( m_shortcutHandler.data(), SIGNAL( previous() ), m_audioEngine.data(), SLOT( previous() ) ); connect( m_shortcutHandler.data(), SIGNAL( stop() ), audioEngine, SLOT( stop() ) );
connect( m_shortcutHandler.data(), SIGNAL( next() ), m_audioEngine.data(), SLOT( next() ) ); connect( m_shortcutHandler.data(), SIGNAL( previous() ), audioEngine, SLOT( previous() ) );
connect( m_shortcutHandler.data(), SIGNAL( volumeUp() ), m_audioEngine.data(), SLOT( raiseVolume() ) ); connect( m_shortcutHandler.data(), SIGNAL( next() ), audioEngine, SLOT( next() ) );
connect( m_shortcutHandler.data(), SIGNAL( volumeDown() ), m_audioEngine.data(), SLOT( lowerVolume() ) ); connect( m_shortcutHandler.data(), SIGNAL( volumeUp() ), audioEngine, SLOT( raiseVolume() ) );
connect( m_shortcutHandler.data(), SIGNAL( mute() ), m_audioEngine.data(), SLOT( mute() ) ); connect( m_shortcutHandler.data(), SIGNAL( volumeDown() ), audioEngine, SLOT( lowerVolume() ) );
connect( m_shortcutHandler.data(), SIGNAL( mute() ), audioEngine, SLOT( mute() ) );
} }
tDebug() << "Init InfoSystem."; tDebug() << "Init InfoSystem.";
@@ -293,8 +298,14 @@ TomahawkApp::~TomahawkApp()
if ( !m_scanManager.isNull() ) if ( !m_scanManager.isNull() )
delete m_scanManager.data(); delete m_scanManager.data();
if ( !m_audioEngine.isNull() ) if ( AudioEngine::instance() )
delete m_audioEngine.data(); {
m_audioEngineThread.data()->quit();
m_audioEngineThread.data()->wait( 60000 );
delete m_audioEngineThread.data();
m_audioEngineThread.clear();
}
if ( !m_infoSystem.isNull() ) if ( !m_infoSystem.isNull() )
delete m_infoSystem.data(); delete m_infoSystem.data();

View File

@@ -24,11 +24,11 @@
#include "headlesscheck.h" #include "headlesscheck.h"
#include "config.h" #include "config.h"
#include <QRegExp> #include <QtCore/QRegExp>
#include <QFile> #include <QtCore/QFile>
#include <QSettings> #include <QtCore/QSettings>
#include <QDir> #include <QtCore/QDir>
#include <QPersistentModelIndex> #include <QtCore/QPersistentModelIndex>
#include "QxtHttpServerConnector" #include "QxtHttpServerConnector"
#include "QxtHttpSessionManager" #include "QxtHttpSessionManager"
@@ -38,6 +38,7 @@
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#include "thirdparty/kdsingleapplicationguard/kdsingleapplicationguard.h" #include "thirdparty/kdsingleapplicationguard/kdsingleapplicationguard.h"
class AudioEngineThread;
class AudioEngine; class AudioEngine;
class Database; class Database;
class ScanManager; class ScanManager;
@@ -113,7 +114,7 @@ private:
QWeakPointer<Database> m_database; QWeakPointer<Database> m_database;
QWeakPointer<ScanManager> m_scanManager; QWeakPointer<ScanManager> m_scanManager;
QWeakPointer<AudioEngine> m_audioEngine; QWeakPointer<AudioEngineThread> m_audioEngineThread;
QWeakPointer<Servent> m_servent; QWeakPointer<Servent> m_servent;
QWeakPointer<Tomahawk::InfoSystem::InfoSystem> m_infoSystem; QWeakPointer<Tomahawk::InfoSystem::InfoSystem> m_infoSystem;
QWeakPointer<XMPPBot> m_xmppBot; QWeakPointer<XMPPBot> m_xmppBot;