diff options
Diffstat (limited to 'src/plugins/Output/pulseaudio')
| -rw-r--r-- | src/plugins/Output/pulseaudio/CMakeLists.txt | 63 | ||||
| -rw-r--r-- | src/plugins/Output/pulseaudio/outputpulseaudio.cpp | 235 | ||||
| -rw-r--r-- | src/plugins/Output/pulseaudio/outputpulseaudio.h | 68 | ||||
| -rw-r--r-- | src/plugins/Output/pulseaudio/outputpulseaudiofactory.cpp | 61 | ||||
| -rw-r--r-- | src/plugins/Output/pulseaudio/outputpulseaudiofactory.h | 48 | ||||
| -rw-r--r-- | src/plugins/Output/pulseaudio/pulseaudio.pro | 35 |
6 files changed, 510 insertions, 0 deletions
diff --git a/src/plugins/Output/pulseaudio/CMakeLists.txt b/src/plugins/Output/pulseaudio/CMakeLists.txt new file mode 100644 index 000000000..9a7bc7b7f --- /dev/null +++ b/src/plugins/Output/pulseaudio/CMakeLists.txt @@ -0,0 +1,63 @@ +project(libpulseaudio) + +cmake_minimum_required(VERSION 2.4.0) + + +INCLUDE(UsePkgConfig) +INCLUDE(FindQt4) + +find_package(Qt4 REQUIRED) # find and setup Qt4 for this project +include(${QT_USE_FILE}) + +# qt plugin +ADD_DEFINITIONS( -Wall ) +ADD_DEFINITIONS(${QT_DEFINITIONS}) +ADD_DEFINITIONS(-DQT_PLUGIN) +ADD_DEFINITIONS(-DQT_NO_DEBUG) +ADD_DEFINITIONS(-DQT_SHARED) +ADD_DEFINITIONS(-DQT_THREAD) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +SET(QT_INCLUDES + ${QT_INCLUDES} + ${CMAKE_CURRENT_BINARY_DIR}/../../../ +) + +# libqmmp +include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmp) + +# pulseaudio +PKGCONFIG(libpulse-simple PULSE_INCLUDE_DIR PULSE_LINK_DIR PULSE_LINK_FLAGS PULSE_CFLAGS) + +IF(NOT PULSE_LINK_FLAGS) + SET(PULSE_LINK_FLAGS -lpulse -lpulse-simple) +ENDIF(NOT PULSE_LINK_FLAGS) + +SET(libpulseaudio_SRCS + outputpulseaudio.cpp + outputpulseaudiofactory.cpp +) + +SET(libpulseaudio_MOC_HDRS + outputpulseaudio.h + outputpulseaudiofactory.h +) + +#SET(libpulseaudio_RCCS translations/translations.qrc) + +QT4_ADD_RESOURCES(libpulseaudio_RCC_SRCS ${libpulseaudio_RCCS}) + +QT4_WRAP_CPP(libpulseaudio_MOC_SRCS ${libpulseaudio_MOC_HDRS}) + + +# Don't forget to include output directory, otherwise +# the UI file won't be wrapped! +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +ADD_LIBRARY(pulseaudio SHARED ${libpulseaudio_SRCS} ${libpulseaudio_MOC_SRCS} ${libpulseaudio_UIS_H} + ${libpulseaudio_RCC_SRCS}) +target_link_libraries(pulseaudio ${QT_LIBRARIES} -lqmmp ${PULSE_LINK_FLAGS}) +install(TARGETS pulseaudio DESTINATION ${LIB_DIR}/qmmp/Output) + diff --git a/src/plugins/Output/pulseaudio/outputpulseaudio.cpp b/src/plugins/Output/pulseaudio/outputpulseaudio.cpp new file mode 100644 index 000000000..02c4f52be --- /dev/null +++ b/src/plugins/Output/pulseaudio/outputpulseaudio.cpp @@ -0,0 +1,235 @@ +/*************************************************************************** + * Copyright (C) 2006-2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QObject> +#include <QApplication> +#include <QtGlobal> + +extern "C" { +#include <pulse/error.h> +} + +#include <stdio.h> +#include <string.h> +#include <iostream> + +#include <qmmp/constants.h> +#include <qmmp/buffer.h> +#include <qmmp/visual.h> +#include "outputpulseaudio.h" + +OutputPulseAudio::OutputPulseAudio(QObject * parent, bool useVolume) + : Output(parent), m_inited(FALSE), m_pause(FALSE), m_play(FALSE), + m_userStop(FALSE), m_totalWritten(0), m_currentSeconds(-1), + m_bps(-1), m_frequency(-1), m_channels(-1), m_precision(-1) +{ + Q_UNUSED(useVolume); + m_connection = 0; +} + +OutputPulseAudio::~OutputPulseAudio() +{ + uninitialize(); +} + +void OutputPulseAudio::stop() +{ + m_userStop = TRUE; +} + +void OutputPulseAudio::status() +{ + long ct = (m_totalWritten - latency()) / m_bps; + + if (ct < 0) + ct = 0; + + if (ct > m_currentSeconds) + { + m_currentSeconds = ct; + dispatch(m_currentSeconds, m_totalWritten, m_rate, + m_frequency, m_precision, m_channels); + } +} + +long OutputPulseAudio::written() +{ + return m_totalWritten; +} + +void OutputPulseAudio::seek(long pos) +{ + m_totalWritten = (pos * m_bps); + m_currentSeconds = -1; +} + +void OutputPulseAudio::configure(long freq, int chan, int prec, int brate) +{ + m_frequency = freq; + m_channels = chan; + m_precision = prec; + m_bps = freq * chan * (prec / 8); + + pa_sample_spec ss; + ss.format = PA_SAMPLE_S16LE; + ss.channels = chan; + ss.rate = freq; + int error; + m_connection = pa_simple_new(NULL, // Use the default server. + "Qmmp", // Our application's name. + PA_STREAM_PLAYBACK, + NULL, // Use the default device. + "Music", // Description of our stream. + &ss, // Our sample format. + NULL, // Use default channel map + NULL, // Use default buffering attributes. + &error // Error code. + ); + if (!m_connection) + { + qWarning("OutputPulseAudio: pa_simple_new() failed: %s", pa_strerror(error)); + m_inited = FALSE; + return; + } + qDebug("OutputPulseAudio: frequency=%d, channels=%d, bitrate=%d", uint(freq), chan, brate); +} + +void OutputPulseAudio::pause() +{ + if (!m_play) + return; + m_pause = (m_pause) ? FALSE : TRUE; + OutputState::Type state = m_pause ? OutputState::Paused: OutputState::Playing; + dispatch(state); +} + +bool OutputPulseAudio::initialize() +{ + m_inited = m_pause = m_play = m_userStop = FALSE; + m_currentSeconds = -1; + m_inited = TRUE; + return TRUE; +} + + +long OutputPulseAudio::latency() +{ + long used = 0; + + return used; +} + +void OutputPulseAudio::run() +{ + + mutex()->lock (); + if (! m_inited) + { + mutex()->unlock(); + return; + } + + m_play = TRUE; + + mutex()->unlock(); + + Buffer *b = 0; + bool done = FALSE; + int error; + + dispatch(OutputState::Playing); + + while (! done) + { + mutex()->lock (); + recycler()->mutex()->lock (); + + done = m_userStop; + + while (! done && (recycler()->empty() || m_pause)) + { + mutex()->unlock(); + recycler()->cond()->wakeOne(); + recycler()->cond()->wait(recycler()->mutex()); + mutex()->lock (); + done = m_userStop; + status(); + } + + if (! b) + { + b = recycler()->next(); + if (b->rate) + m_rate = b->rate; + } + + recycler()->cond()->wakeOne(); + recycler()->mutex()->unlock(); + + if (b) + { + if(pa_simple_write(m_connection, b->data, b->nbytes, &error) < 0) + { + mutex()->unlock(); + qWarning("OutputPulseAudio: pa_simple_write() failed: %s", pa_strerror(error)); + break; + } + + dispatchVisual(b, m_totalWritten, m_channels, m_precision); + status(); + m_totalWritten += b->nbytes; + mutex()->unlock(); + } + // force buffer change + recycler()->mutex()->lock (); + recycler()->done(); + recycler()->mutex()->unlock(); + b = 0; + } + + mutex()->lock (); + m_play = FALSE; + dispatch(OutputState::Stopped); + mutex()->unlock(); + +} + +void OutputPulseAudio::uninitialize() +{ + if (!m_inited) + return; + m_inited = FALSE; + m_pause = FALSE; + m_play = FALSE; + m_userStop = FALSE; + m_totalWritten = 0; + m_currentSeconds = -1; + m_bps = -1; + m_frequency = -1; + m_channels = -1; + m_precision = -1; + if (!m_connection) + { + qDebug("OutputPulseAudio: closing connection"); + pa_simple_free(m_connection); + m_connection = 0; + } + dispatch(OutputState::Stopped); +} diff --git a/src/plugins/Output/pulseaudio/outputpulseaudio.h b/src/plugins/Output/pulseaudio/outputpulseaudio.h new file mode 100644 index 000000000..8ef4b1cd0 --- /dev/null +++ b/src/plugins/Output/pulseaudio/outputpulseaudio.h @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (C) 2006-2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef OUTPUTPULSEAUDIO_H +#define OUTPUTPULSEAUDIO_H + +#include <QObject> +extern "C" { + #include <pulse/simple.h> +} + +#include <qmmp/output.h> + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class OutputPulseAudio : public Output +{ +Q_OBJECT +public: + OutputPulseAudio(QObject * parent = 0, bool useVolume = TRUE); + ~OutputPulseAudio(); + + bool initialize(); + bool isInitialized() const { return m_inited; } + void uninitialize(); + void configure(long, int, int, int); + void stop(); + void pause(); + long written(); + long latency(); + void seek(long); + //void setVolume(int l, int r); + //void volume(int *l, int *r); + +private: + // thread run function + void run(); + + // helper function + void status(); + + bool m_inited, m_pause, m_play, m_userStop; + long m_totalWritten, m_currentSeconds, m_bps; + int m_rate, m_frequency, m_channels, m_precision; + pa_simple *m_connection; + +}; + + +#endif // OUTPUTPULSEAUDIO_H diff --git a/src/plugins/Output/pulseaudio/outputpulseaudiofactory.cpp b/src/plugins/Output/pulseaudio/outputpulseaudiofactory.cpp new file mode 100644 index 000000000..197286d4d --- /dev/null +++ b/src/plugins/Output/pulseaudio/outputpulseaudiofactory.cpp @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2007-2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QtGui> + +#include "outputpulseaudio.h" +#include "outputpulseaudiofactory.h" + + +const OutputProperties OutputPulseAudioFactory::properties() const +{ + OutputProperties properties; + properties.name = tr("PulseAudio Plugin"); + properties.hasAbout = TRUE; + properties.hasSettings = FALSE; + return properties; +} + +Output* OutputPulseAudioFactory::create(QObject* parent, bool volume) +{ + return new OutputPulseAudio(parent, volume); +} + +void OutputPulseAudioFactory::showSettings(QWidget* parent) +{ + Q_UNUSED(parent); +} + +void OutputPulseAudioFactory::showAbout(QWidget *parent) +{ + QMessageBox::about (parent, tr("About PulseAudio Output Plugin"), + tr("Qmmp PulseAudio Output Plugin")+"\n"+ + tr("Writen by: Ilya Kotov <forkotov02@hotmail.ru>")); +} + +QTranslator *OutputPulseAudioFactory::createTranslator(QObject *parent) +{ + QTranslator *translator = new QTranslator(parent); + QString locale = QLocale::system().name(); + translator->load(QString(":/pulseaudio_plugin_") + locale); + return translator; +} + +Q_EXPORT_PLUGIN(OutputPulseAudioFactory) diff --git a/src/plugins/Output/pulseaudio/outputpulseaudiofactory.h b/src/plugins/Output/pulseaudio/outputpulseaudiofactory.h new file mode 100644 index 000000000..db3729c89 --- /dev/null +++ b/src/plugins/Output/pulseaudio/outputpulseaudiofactory.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2007-2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef OUTPUTPULSEAUDIOFACTORY_H +#define OUTPUTPULSEAUDIOFACTORY_H + + +#include <QObject> +#include <QString> +#include <QIODevice> +#include <QWidget> + +#include <qmmp/output.h> +#include <qmmp/outputfactory.h> + + +class OutputPulseAudioFactory : public QObject, + OutputFactory +{ +Q_OBJECT +Q_INTERFACES(OutputFactory); + +public: + const OutputProperties properties() const; + Output* create(QObject* parent, bool volume); + void showSettings(QWidget* parent); + void showAbout(QWidget *parent); + QTranslator *createTranslator(QObject *parent); + +}; + +#endif diff --git a/src/plugins/Output/pulseaudio/pulseaudio.pro b/src/plugins/Output/pulseaudio/pulseaudio.pro new file mode 100644 index 000000000..4e178a459 --- /dev/null +++ b/src/plugins/Output/pulseaudio/pulseaudio.pro @@ -0,0 +1,35 @@ +include(../../plugins.pri) + +HEADERS += outputpulseaudiofactory.h \ + outputpulseaudio.h + +SOURCES += outputpulseaudiofactory.cpp \ + outputpulseaudio.cpp + + +TARGET=$$PLUGINS_PREFIX/Output/pulseaudio +QMAKE_CLEAN =$$PLUGINS_PREFIX/Output/libpulseaudio.so + +INCLUDEPATH += ../../../ +QMAKE_LIBDIR += ../../../../lib + +CONFIG += release \ +warn_on \ +thread \ +plugin \ +link_pkgconfig + +TEMPLATE = lib +LIBS += -lqmmp + +PKGCONFIG += libpulse-simple + +#TRANSLATIONS = translations/pulseaudio_plugin_ru.ts +#RESOURCES = translations/translations.qrc + +isEmpty (LIB_DIR){ +LIB_DIR = /lib +} + +target.path = $$LIB_DIR/qmmp/Output +INSTALLS += target |
