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
audio/audioengine.cpp
audio/audioenginethread.cpp
database/database.cpp
database/fuzzyindex.cpp
@@ -408,6 +408,7 @@ set( libHeaders
sip/sipinfo.h
audio/audioengine.h
audio/audioenginethread.h
database/database.h
database/fuzzyindex.h

View File

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

View File

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

View File

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