annotate audioio/AudioPulseAudioTarget.h @ 118:c41e340dfe8d

* timing updates; still much to be done
author Chris Cannam
date Wed, 21 May 2008 17:11:57 +0000
parents 2bc8bf6d016c
children 1ba557a20ca3
rev   line source
Chris@117 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@117 2
Chris@117 3 /*
Chris@117 4 Sonic Visualiser
Chris@117 5 An audio file viewer and annotation editor.
Chris@117 6 Centre for Digital Music, Queen Mary, University of London.
Chris@117 7 This file copyright 2008 QMUL.
Chris@117 8
Chris@117 9 This program is free software; you can redistribute it and/or
Chris@117 10 modify it under the terms of the GNU General Public License as
Chris@117 11 published by the Free Software Foundation; either version 2 of the
Chris@117 12 License, or (at your option) any later version. See the file
Chris@117 13 COPYING included with this distribution for more information.
Chris@117 14 */
Chris@117 15
Chris@117 16 #ifndef _AUDIO_PULSE_AUDIO_TARGET_H_
Chris@117 17 #define _AUDIO_PULSE_AUDIO_TARGET_H_
Chris@117 18
Chris@117 19 #ifdef HAVE_LIBPULSE
Chris@117 20
Chris@117 21 #include <pulse/pulseaudio.h>
Chris@117 22
Chris@117 23 #include <QObject>
Chris@117 24 #include <QMutex>
Chris@118 25 #include "base/Thread.h"
Chris@117 26
Chris@117 27 #include "AudioCallbackPlayTarget.h"
Chris@117 28
Chris@117 29 class AudioCallbackPlaySource;
Chris@117 30
Chris@117 31 class AudioPulseAudioTarget : public AudioCallbackPlayTarget
Chris@117 32 {
Chris@117 33 Q_OBJECT
Chris@117 34
Chris@117 35 public:
Chris@117 36 AudioPulseAudioTarget(AudioCallbackPlaySource *source);
Chris@117 37 virtual ~AudioPulseAudioTarget();
Chris@117 38
Chris@117 39 virtual void shutdown();
Chris@117 40
Chris@117 41 virtual bool isOK() const;
Chris@117 42
Chris@117 43 virtual double getCurrentTime() const;
Chris@117 44
Chris@117 45 public slots:
Chris@117 46 virtual void sourceModelReplaced();
Chris@117 47
Chris@117 48 protected:
Chris@117 49 void streamWrite(size_t);
Chris@117 50 void streamStateChanged();
Chris@117 51 void contextStateChanged();
Chris@117 52
Chris@117 53 static void streamWriteStatic(pa_stream *, size_t, void *);
Chris@117 54 static void streamStateChangedStatic(pa_stream *, void *);
Chris@117 55 static void contextStateChangedStatic(pa_context *, void *);
Chris@117 56
Chris@117 57 QMutex m_mutex;
Chris@117 58
Chris@118 59 class MainLoopThread : public Thread
Chris@117 60 {
Chris@117 61 public:
Chris@118 62 MainLoopThread(pa_mainloop *loop) : Thread(RTThread), m_loop(loop) { }
Chris@117 63 virtual void run() {
Chris@117 64 int rv = 0;
Chris@117 65 pa_mainloop_run(m_loop, &rv); //!!! check return value from this, and rv
Chris@117 66 }
Chris@117 67
Chris@117 68 private:
Chris@117 69 pa_mainloop *m_loop;
Chris@117 70 };
Chris@117 71
Chris@117 72 pa_mainloop *m_loop;
Chris@117 73 pa_mainloop_api *m_api;
Chris@117 74 pa_context *m_context;
Chris@117 75 pa_stream *m_stream;
Chris@117 76 pa_sample_spec m_spec;
Chris@117 77
Chris@117 78 MainLoopThread *m_loopThread;
Chris@117 79
Chris@117 80 int m_bufferSize;
Chris@117 81 int m_sampleRate;
Chris@117 82 int m_latency;
Chris@117 83 bool m_done;
Chris@117 84 };
Chris@117 85
Chris@117 86 #endif /* HAVE_PULSEAUDIO */
Chris@117 87
Chris@117 88 #endif
Chris@117 89