diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-11-20 11:10:02 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-11-20 11:10:02 +0000 |
| commit | a030a982fc4194e81b21a36c1fb0a505f8e2e28b (patch) | |
| tree | fdbcaa5f5bc3901078b9dcd9d20782c30c3c6899 /src/plugins/Output/pulseaudio | |
| parent | a008a77ed5aecdc1f1f000cff1cb7a5e03b18e3c (diff) | |
| download | qmmp-a030a982fc4194e81b21a36c1fb0a505f8e2e28b.tar.gz qmmp-a030a982fc4194e81b21a36c1fb0a505f8e2e28b.tar.bz2 qmmp-a030a982fc4194e81b21a36c1fb0a505f8e2e28b.zip | |
output api changes
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@622 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Output/pulseaudio')
| -rw-r--r-- | src/plugins/Output/pulseaudio/outputpulseaudio.cpp | 158 | ||||
| -rw-r--r-- | src/plugins/Output/pulseaudio/outputpulseaudio.h | 26 |
2 files changed, 31 insertions, 153 deletions
diff --git a/src/plugins/Output/pulseaudio/outputpulseaudio.cpp b/src/plugins/Output/pulseaudio/outputpulseaudio.cpp index daef291eb..422c49bb4 100644 --- a/src/plugins/Output/pulseaudio/outputpulseaudio.cpp +++ b/src/plugins/Output/pulseaudio/outputpulseaudio.cpp @@ -22,7 +22,8 @@ #include <QApplication> #include <QtGlobal> -extern "C" { +extern "C" +{ #include <pulse/error.h> } @@ -36,9 +37,7 @@ extern "C" { #include "outputpulseaudio.h" OutputPulseAudio::OutputPulseAudio(QObject * parent) - : 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) + : Output(parent) { m_connection = 0; } @@ -48,44 +47,8 @@ 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); - } -} - -qint64 OutputPulseAudio::written() -{ - return m_totalWritten; -} - -void OutputPulseAudio::seek(qint64 pos) -{ - m_totalWritten = (pos * m_bps); - m_currentSeconds = -1; -} - void OutputPulseAudio::configure(quint32 freq, int chan, int prec) { - 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; @@ -104,127 +67,50 @@ void OutputPulseAudio::configure(quint32 freq, int chan, int prec) if (!m_connection) { qWarning("OutputPulseAudio: pa_simple_new() failed: %s", pa_strerror(error)); - m_inited = FALSE; return; } qDebug("OutputPulseAudio: frequency=%d, channels=%d", uint(freq), chan); -} - -void OutputPulseAudio::pause() -{ - if (!m_play) - return; - m_pause = (m_pause) ? FALSE : TRUE; - Qmmp::State state = m_pause ? Qmmp::Paused: Qmmp::Playing; - dispatch(state); + Output::configure(freq, chan, prec); } bool OutputPulseAudio::initialize() { - m_inited = m_pause = m_play = m_userStop = FALSE; - m_currentSeconds = -1; - m_inited = TRUE; return TRUE; } qint64 OutputPulseAudio::latency() { - long used = 0; - - return used; + if (!m_connection) + return 0; + int error; + return pa_simple_get_latency(m_connection, &error); } -void OutputPulseAudio::run() +qint64 OutputPulseAudio::writeAudio(unsigned char *data, qint64 maxSize) { - - mutex()->lock (); - if (! m_inited) + int error; + if (!m_connection) + return -1; + if (pa_simple_write(m_connection, data, maxSize, &error) < 0) { mutex()->unlock(); - return; + qWarning("OutputPulseAudio: pa_simple_write() failed: %s", pa_strerror(error)); + return -1; } + return maxSize; +} - m_play = TRUE; - - mutex()->unlock(); - - Buffer *b = 0; - bool done = FALSE; +void OutputPulseAudio::flush() +{ int error; - - dispatch(Qmmp::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(Qmmp::Stopped); - mutex()->unlock(); - + if (m_connection) + pa_simple_flush(m_connection, &error); } 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) + if (m_connection) { qDebug("OutputPulseAudio: closing connection"); pa_simple_free(m_connection); diff --git a/src/plugins/Output/pulseaudio/outputpulseaudio.h b/src/plugins/Output/pulseaudio/outputpulseaudio.h index 704d95d27..4a2712998 100644 --- a/src/plugins/Output/pulseaudio/outputpulseaudio.h +++ b/src/plugins/Output/pulseaudio/outputpulseaudio.h @@ -22,8 +22,9 @@ #define OUTPUTPULSEAUDIO_H #include <QObject> -extern "C" { - #include <pulse/simple.h> +extern "C" +{ +#include <pulse/simple.h> } #include <qmmp/output.h> @@ -33,34 +34,25 @@ extern "C" { */ class OutputPulseAudio : public Output { -Q_OBJECT + Q_OBJECT public: OutputPulseAudio(QObject * parent = 0); ~OutputPulseAudio(); bool initialize(); - bool isInitialized() const { return m_inited; } - void uninitialize(); void configure(quint32, int, int); - void stop(); - void pause(); - qint64 written(); qint64 latency(); - void seek(qint64); private: - // thread run function - void run(); + //output api + qint64 writeAudio(unsigned char *data, qint64 maxSize); + void flush(); - // helper function + // helper functions void status(); + void uninitialize(); - bool m_inited, m_pause, m_play, m_userStop; - qint64 m_totalWritten, m_currentSeconds, m_bps; - quint32 m_frequency; - int m_rate, m_channels, m_precision; pa_simple *m_connection; - }; |
