Chris@117: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@117: Chris@117: /* Chris@117: Sonic Visualiser Chris@117: An audio file viewer and annotation editor. Chris@117: Centre for Digital Music, Queen Mary, University of London. Chris@117: This file copyright 2008 QMUL. Chris@117: Chris@117: This program is free software; you can redistribute it and/or Chris@117: modify it under the terms of the GNU General Public License as Chris@117: published by the Free Software Foundation; either version 2 of the Chris@117: License, or (at your option) any later version. See the file Chris@117: COPYING included with this distribution for more information. Chris@117: */ Chris@117: Chris@117: #ifndef _AUDIO_PULSE_AUDIO_TARGET_H_ Chris@117: #define _AUDIO_PULSE_AUDIO_TARGET_H_ Chris@117: Chris@117: #ifdef HAVE_LIBPULSE Chris@117: Chris@117: #include Chris@117: Chris@117: #include Chris@117: #include Chris@118: #include "base/Thread.h" Chris@117: Chris@117: #include "AudioCallbackPlayTarget.h" Chris@117: Chris@117: class AudioCallbackPlaySource; Chris@117: Chris@117: class AudioPulseAudioTarget : public AudioCallbackPlayTarget Chris@117: { Chris@117: Q_OBJECT Chris@117: Chris@117: public: Chris@117: AudioPulseAudioTarget(AudioCallbackPlaySource *source); Chris@117: virtual ~AudioPulseAudioTarget(); Chris@117: Chris@117: virtual void shutdown(); Chris@117: Chris@117: virtual bool isOK() const; Chris@117: Chris@117: virtual double getCurrentTime() const; Chris@117: Chris@117: public slots: Chris@117: virtual void sourceModelReplaced(); Chris@117: Chris@117: protected: Chris@117: void streamWrite(size_t); Chris@117: void streamStateChanged(); Chris@117: void contextStateChanged(); Chris@117: Chris@117: static void streamWriteStatic(pa_stream *, size_t, void *); Chris@117: static void streamStateChangedStatic(pa_stream *, void *); Chris@117: static void contextStateChangedStatic(pa_context *, void *); Chris@117: Chris@117: QMutex m_mutex; Chris@117: Chris@118: class MainLoopThread : public Thread Chris@117: { Chris@117: public: Chris@118: MainLoopThread(pa_mainloop *loop) : Thread(RTThread), m_loop(loop) { } Chris@117: virtual void run() { Chris@117: int rv = 0; Chris@117: pa_mainloop_run(m_loop, &rv); //!!! check return value from this, and rv Chris@117: } Chris@117: Chris@117: private: Chris@117: pa_mainloop *m_loop; Chris@117: }; Chris@117: Chris@117: pa_mainloop *m_loop; Chris@117: pa_mainloop_api *m_api; Chris@117: pa_context *m_context; Chris@117: pa_stream *m_stream; Chris@117: pa_sample_spec m_spec; Chris@117: Chris@117: MainLoopThread *m_loopThread; Chris@117: Chris@117: int m_bufferSize; Chris@117: int m_sampleRate; Chris@117: int m_latency; Chris@117: bool m_done; Chris@117: }; Chris@117: Chris@117: #endif /* HAVE_PULSEAUDIO */ Chris@117: Chris@117: #endif Chris@117: