svapp
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2008 QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _AUDIO_PULSE_AUDIO_TARGET_H_ 00017 #define _AUDIO_PULSE_AUDIO_TARGET_H_ 00018 00019 #ifdef HAVE_LIBPULSE 00020 00021 #include <pulse/pulseaudio.h> 00022 00023 #include <QObject> 00024 #include <QMutex> 00025 #include "base/Thread.h" 00026 00027 #include "AudioCallbackPlayTarget.h" 00028 00029 class AudioCallbackPlaySource; 00030 00031 class AudioPulseAudioTarget : public AudioCallbackPlayTarget 00032 { 00033 Q_OBJECT 00034 00035 public: 00036 AudioPulseAudioTarget(AudioCallbackPlaySource *source); 00037 virtual ~AudioPulseAudioTarget(); 00038 00039 virtual void shutdown(); 00040 00041 virtual bool isOK() const; 00042 00043 virtual double getCurrentTime() const; 00044 00045 public slots: 00046 virtual void sourceModelReplaced(); 00047 00048 protected: 00049 void streamWrite(int); 00050 void streamStateChanged(); 00051 void contextStateChanged(); 00052 00053 static void streamWriteStatic(pa_stream *, size_t, void *); 00054 static void streamStateChangedStatic(pa_stream *, void *); 00055 static void streamOverflowStatic(pa_stream *, void *); 00056 static void streamUnderflowStatic(pa_stream *, void *); 00057 static void contextStateChangedStatic(pa_context *, void *); 00058 00059 QMutex m_mutex; 00060 00061 class MainLoopThread : public Thread 00062 { 00063 public: 00064 MainLoopThread(pa_mainloop *loop) : Thread(NonRTThread), m_loop(loop) { } 00065 virtual void run() { 00066 int rv = 0; 00067 pa_mainloop_run(m_loop, &rv); 00068 } 00069 00070 private: 00071 pa_mainloop *m_loop; 00072 }; 00073 00074 pa_mainloop *m_loop; 00075 pa_mainloop_api *m_api; 00076 pa_context *m_context; 00077 pa_stream *m_stream; 00078 pa_sample_spec m_spec; 00079 00080 MainLoopThread *m_loopThread; 00081 00082 int m_bufferSize; 00083 int m_sampleRate; 00084 int m_latency; 00085 bool m_done; 00086 }; 00087 00088 #endif /* HAVE_PULSEAUDIO */ 00089 00090 #endif 00091